apps/odroid_vm/components/helloworld/linux_userlevel/build/vchan_code/sel4_vchan_testsuite.c
int vchantests_bigwrite(libvchan_t *ctrl) {
    int fd, ret;
    char compare_command[bigwrite_cmd_size];
    pid_t child_pid;
    size_t sz;

    struct stat buf;
    char *wbuf = NULL;

    fd = open(bigwrite_file, O_RDWR);
    if(fd < 0) {
    	TERROR("bigwrite: failed to open test file '%s'\n", bigwrite_file);
    	return -1;
    }

    fstat(fd, &buf);
    sz = (size_t) buf.st_size;
    libvchan_send(ctrl, &sz, sizeof(size_t));

    wbuf = malloc(sz * sizeof(char));
    ret = read(fd, wbuf, sz);
    if(ret < 0) {
    	TERROR("bigwrite: could not read from file\n");
    	return -1;
    }

    child_pid = fork();
    if(child_pid < 0) {
    	TERROR("bigwrite: could not fork thread for testing\n");
    	return -1;
    } else if(child_pid == 0) {
    	int rcode = vchantests_bigwrite_child(ctrl, (size_t) buf.st_size);
	    exit(rcode);
    }

    TDPRINTF(4, "bigwrite (parent): sending %d bytes to client\n", (int) sz);
    ret = libvchan_send(ctrl, wbuf, sz);
    if(ret < 0 || ret != sz)  {
    	TERROR("bigwrite-parent: failed to send data, %d|%d", ret, (int) sz);
    }

    TDPRINTF(4, "bigwrite (parent): wait for child\n");
    if(waitpid(child_pid, &ret, 0) == -1) {
    	TERROR("bigwrite-parent: failed to wait for child");
    	return -1;
    }

    if(WIFEXITED(ret)) {
    	if(WEXITSTATUS(ret) == EXIT_FAILURE) {
    		TERROR("bigwrite-parent: child failed somewhere..\n");
    		return -1;
    	}
    }

    ret = snprintf(compare_command, bigwrite_cmd_size, "diff %s %s", bigwrite_file, bigwrite_out);
    if(ret < 0) {
        TERROR("bigwrite-parent: failed to snprintf compare command\n");
    }

    TDPRINTF(2, "Running '%s' to compare files\n", compare_command);

    /* Check that the files are the same with diff */
    ret = system(compare_command);
    if(ret != EXIT_SUCCESS) {
    	TERROR("bigwrite-parent: original and readback file failed diff\n");
    	return -1;
    }

    TDPRINTF(2, "bigwrite-parent: concluded\n");
    return 0;
}
/*
    vchantests_bigwrite:
        Open up a large file, and load in its data
        We then fork a parent and child
            Parent:
                Send file data to server
            Child:
                Readback file data from server and write it to a file
        When child and parent are finished, we compare file and readback file
        Tests simple blocking and multiple active vchan simples
*/
Open up a large file, and load in its data
We then fork a parent and child
Parent:
Send file data to server
Child:
Readback file data from server and write it to a file
When child and parent are finished, we compare file and readback file
Tests simple blocking and multiple active vchan simples
Open up a large file and load in its data We then fork a parent and child Parent : Send file data to server Child : Readback file data from server and write it to a file When child and parent are finished we compare file and readback file Tests simple blocking and multiple active vchan simples
int vchantests_bigwrite(libvchan_t *ctrl) {
    int fd, ret;
    char compare_command[bigwrite_cmd_size];
    pid_t child_pid;
    size_t sz;
    struct stat buf;
    char *wbuf = NULL;
    fd = open(bigwrite_file, O_RDWR);
    if(fd < 0) {
    	TERROR("bigwrite: failed to open test file '%s'\n", bigwrite_file);
    	return -1;
    }
    fstat(fd, &buf);
    sz = (size_t) buf.st_size;
    libvchan_send(ctrl, &sz, sizeof(size_t));
    wbuf = malloc(sz * sizeof(char));
    ret = read(fd, wbuf, sz);
    if(ret < 0) {
    	TERROR("bigwrite: could not read from file\n");
    	return -1;
    }
    child_pid = fork();
    if(child_pid < 0) {
    	TERROR("bigwrite: could not fork thread for testing\n");
    	return -1;
    } else if(child_pid == 0) {
    	int rcode = vchantests_bigwrite_child(ctrl, (size_t) buf.st_size);
	    exit(rcode);
    }
    TDPRINTF(4, "bigwrite (parent): sending %d bytes to client\n", (int) sz);
    ret = libvchan_send(ctrl, wbuf, sz);
    if(ret < 0 || ret != sz)  {
    	TERROR("bigwrite-parent: failed to send data, %d|%d", ret, (int) sz);
    }
    TDPRINTF(4, "bigwrite (parent): wait for child\n");
    if(waitpid(child_pid, &ret, 0) == -1) {
    	TERROR("bigwrite-parent: failed to wait for child");
    	return -1;
    }
    if(WIFEXITED(ret)) {
    	if(WEXITSTATUS(ret) == EXIT_FAILURE) {
    		TERROR("bigwrite-parent: child failed somewhere..\n");
    		return -1;
    	}
    }
    ret = snprintf(compare_command, bigwrite_cmd_size, "diff %s %s", bigwrite_file, bigwrite_out);
    if(ret < 0) {
        TERROR("bigwrite-parent: failed to snprintf compare command\n");
    }
    TDPRINTF(2, "Running '%s' to compare files\n", compare_command);
    ret = system(compare_command);
    if(ret != EXIT_SUCCESS) {
    	TERROR("bigwrite-parent: original and readback file failed diff\n");
    	return -1;
    }
    TDPRINTF(2, "bigwrite-parent: concluded\n");
    return 0;
}
int vchantests_bigwrite ( libvchan_t * ctrl ) { int fd , ret ; char compare_command [ bigwrite_cmd_size ] ; pid_t child_pid ; size_t sz ; struct stat buf ; char * wbuf = NULL ; fd = open ( bigwrite_file , O_RDWR ) ; if ( fd < 0 ) { TERROR ( " \n " , bigwrite_file ) ; return -1 ; } fstat ( fd , & buf ) ; sz = ( size_t ) buf . st_size ; libvchan_send ( ctrl , & sz , sizeof ( size_t ) ) ; wbuf = malloc ( sz * sizeof ( char ) ) ; ret = read ( fd , wbuf , sz ) ; if ( ret < 0 ) { TERROR ( " \n " ) ; return -1 ; } child_pid = fork ( ) ; if ( child_pid < 0 ) { TERROR ( " \n " ) ; return -1 ; } else if ( child_pid == 0 ) { int rcode = vchantests_bigwrite_child ( ctrl , ( size_t ) buf . st_size ) ; exit ( rcode ) ; } TDPRINTF ( 4 , " \n " , ( int ) sz ) ; ret = libvchan_send ( ctrl , wbuf , sz ) ; if ( ret < 0 || ret != sz ) { TERROR ( " " , ret , ( int ) sz ) ; } TDPRINTF ( 4 , " \n " ) ; if ( waitpid ( child_pid , & ret , 0 ) == -1 ) { TERROR ( " " ) ; return -1 ; } if ( WIFEXITED ( ret ) ) { if ( WEXITSTATUS ( ret ) == EXIT_FAILURE ) { TERROR ( " \n " ) ; return -1 ; } } ret = snprintf ( compare_command , bigwrite_cmd_size , " " , bigwrite_file , bigwrite_out ) ; if ( ret < 0 ) { TERROR ( " \n " ) ; } TDPRINTF ( 2 , " \n " , compare_command ) ; ret = system ( compare_command ) ; if ( ret != EXIT_SUCCESS ) { TERROR ( " \n " ) ; return -1 ; } TDPRINTF ( 2 , " \n " ) ; return 0 ; }
vchantests_bigwrite:
Open up a large file, and load in its data
We then fork a parent and child
Parent:
Send file data to server
Child:
Readback file data from server and write it to a file
When child and parent are finished, we compare file and readback file
Tests simple blocking and multiple active vchan simples
vchantests_bigwrite : Open up a large file and load in its data We then fork a parent and child Parent : Send file data to server Child : Readback file data from server and write it to a file When child and parent are finished we compare file and readback file Tests simple blocking and multiple active vchan simples
/* Check that the files are the same with diff */