Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add simple pipe syscall and unit test method for linux syscall #132

Merged
merged 6 commits into from
Aug 10, 2020

Conversation

yunwei37
Copy link
Contributor

@yunwei37 yunwei37 commented Aug 7, 2020

TODO:

  • add syscall
  • add test for pipe
    • pipe can be used on single thread now
    • pipe can be used with vfork and execve
    • add unit test and change the makefile
  • add document for pipe

it seems unit test on ipc may be complex, so here is just user mode test.

after that, here is some possible improvement for pipe, but need more dependencies:

  • add async poll
  • try to fix fork...

these can be fix in the future, maybe not in this pull-request.

@coveralls
Copy link

coveralls commented Aug 7, 2020

Pull Request Test Coverage Report for Build 198586745

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 5 of 89 (5.62%) changed or added relevant lines in 6 files are covered.
  • 17 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.2%) to 32.473%

Changes Missing Coverage Covered Lines Changed/Added Lines %
linux-object/src/fs/file.rs 0 1 0.0%
linux-syscall/src/lib.rs 0 2 0.0%
linux-object/src/fs/mod.rs 4 8 50.0%
linux-syscall/src/file/fd.rs 0 18 0.0%
linux-object/src/fs/pipe.rs 0 59 0.0%
Files with Coverage Reduction New Missed Lines %
../../../../../usr/share/rust/.cargo/registry/src/jackfan.us.kg-1ecc6299db9ec823/async-task-3.0.0/src/waker_fn.rs 4 80.95%
linux-object/src/fs/mod.rs 13 74.36%
Totals Coverage Status
Change from base Build 198552974: -0.2%
Covered Lines: 4090
Relevant Lines: 12595

💛 - Coveralls

@yunwei37
Copy link
Contributor Author

yunwei37 commented Aug 7, 2020

Test pipe with vfork and execve is success:

testfork:

#include<sys/types.h>
#include<unistd.h>
#include<stdio.h>
#include<string.h>
#include <stdlib.h>

int main()
{
    pid_t pid;
    int cnt = 0;
    int pipefd[2];
    char buf;
    char w[12];
    char r[12];
    if (pipe(pipefd) == -1) {
        printf("pipe");
        exit(-1);
    }
    sprintf(w,"%d",pipefd[1]);
    sprintf(r,"%d",pipefd[0]);
    pid = vfork();
    if(pid<0)
        printf("error in fork!\n");
    else if(pid == 0)
    {	
    	execl("/bin/testec","/bin/testec",r,w,NULL);
    	exit(0);
    }
    else if(pid > 0)
    {	
       close(pipefd[1]);
       while (read(pipefd[0], &buf, 1) > 0)
          write(STDOUT_FILENO, &buf, 1);
       write(STDOUT_FILENO, "\n", 1);
       close(pipefd[0]);  
    }
    return 0;
}

testec:

#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

int main(int argc, char *argv[])
{	
	int writefd, readfd;
	sscanf(argv[2],"%d",&writefd);
	sscanf(argv[1],"%d",&readfd);
	close(readfd);
        write(writefd, "hello pipe", strlen("hello pipe"));
        close(writefd);
        exit(0);
}

@wangrunji0408 wangrunji0408 added the enhancement New feature or request label Aug 7, 2020
@yunwei37 yunwei37 changed the title Add simple pipe syscall Add simple pipe syscall and unit test method for linux syscall Aug 7, 2020
@yunwei37
Copy link
Contributor Author

yunwei37 commented Aug 7, 2020

Currently you can add c language unit test like this:

  1. add c files in linux-syscall/test/;
  2. add a cargo unit test in linux-loader like ( the program name is the same as source file )
    #[async_std::test]
    async fn test_pipe() {
        test("/bin/testpipe1").await;
    }
    
  • if you want to run the unit test locally right away, you can run make rootfs again.
  • if you want to inspect the output of program, maybe output the content to a file and read it in rust can be helpful.

@yunwei37 yunwei37 marked this pull request as ready for review August 7, 2020 10:46
Copy link
Member

@wangrunji0408 wangrunji0408 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@wangrunji0408 wangrunji0408 merged commit 15ce4bb into rcore-os:master Aug 10, 2020
zhangsn-19 pushed a commit to zhangsn-19/zCore that referenced this pull request Apr 23, 2022
Add simple pipe syscall and unit test method for linux syscall
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants