int main(int argc, char **argv) { int ret; TEST_OPERATION_RESULT(s_test_value, &ret, ret==2); const char* envvar_testdir = getenv("TESTDIR"); CHECK_PATH_EXISTANCE(envvar_testdir); fprintf(stderr, "main value=%d\n", s_test_value); return 0; }
int main(int argc, char **argv) { int ret; char* nullstr = NULL; TEST_OPERATION_RESULT( mkdir(nullstr, S_IRWXU), &ret, ret==-1&&errno==EINVAL ); TEST_OPERATION_RESULT( mkdir("/" DIR_NAME, S_IRWXU), &ret, ret==0 ); TEST_OPERATION_RESULT( mkdir(DIR_NAME, S_IRWXU), &ret, ret==-1&&errno==EEXIST ); CHECK_PATH_EXISTANCE("/" DIR_NAME); return 0; }
void test_zrt_issue_67(const char* dirname, const char* name){ //https://github.com/zerovm/zrt/issues/67 /*Since unlink returns no error if file in use, then unlinked file should not be available for getdents/stat; but must be available for fstat/read/write and another functions that get fd/FILE as argument.*/ int ret; struct stat st; char fullpath[PATH_MAX]; snprintf(fullpath, sizeof(fullpath), "%s/%s", dirname, name ); fprintf(stderr, "dirname=%s, fullpath=%s\n", dirname, fullpath); /*create test dir, and delete for final test */ TEST_OPERATION_RESULT( mkdir(dirname, 0700), &ret, ret==0&&errno==0); /*open file, now it's referenced and it's means that file in use*/ int fd = open(fullpath, O_CREAT|O_RDWR|O_TRUNC, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH); TEST_OPERATION_RESULT( fd>=0&&errno==0, &ret, ret!=0); /*file can be accessed as dir item via getdents */ TEST_OPERATION_RESULT( match_file_inode_in_dir(dirname, name), &ret, ret!=-1); /*try to unlink file that in use - file removing is postponed */ TEST_OPERATION_RESULT( unlink(fullpath), &ret, ret==0&&errno==0); /*can be accessed by fd via fstat*/ TEST_OPERATION_RESULT( fstat(fd, &st), &ret, ret==0&&errno==0); /*can't be accessed by name via stat*/ CHECK_PATH_NOT_EXIST( name ); /*can't be accessed as dir item via getdents */ TEST_OPERATION_RESULT( match_file_inode_in_dir(dirname, name), &ret, ret==-1); errno=0; TEST_OPERATION_RESULT( write(fd, name, 2), &ret, ret==2&&errno==0 ) printf("res=%d err=%d\n", ret, errno); /*create file with the same name as unlink'ing now, it should be valid*/ { int fd2 = open(fullpath, O_CREAT|O_RDWR|O_TRUNC, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH); TEST_OPERATION_RESULT( fd2>=0&&errno==0, &ret, ret!=0); CHECK_PATH_EXISTANCE( fullpath ); close(fd2); TEST_OPERATION_RESULT( unlink(fullpath), &ret, ret==0&&errno==0); } /*delete dir with opened file */ TEST_OPERATION_RESULT( rmdir(dirname), &ret, ret==0&&errno==0); TEST_OPERATION_RESULT( close(fd), &ret, ret==0&&errno==0); /*file closed, from now it should not be available at all*/ /*delete dir for final test */ TEST_OPERATION_RESULT( rmdir(dirname), &ret, ret==-1&&errno==ENOENT); /*can't be accessed by fd via fstat*/ TEST_OPERATION_RESULT( fstat(fd, &st), &ret, ret==-1&&errno==EBADF); }