Esempio n. 1
0
int test_yaffs_rmdir_EINVAL(void)
{
	int output=0;
	int error_code =0;

	if (0 !=  yaffs_access(DIR_PATH,0)) {
		output = yaffs_mkdir(DIR_PATH,S_IWRITE | S_IREAD);
		if (output < 0) {
			print_message("failed to create directory\n",2);
			return -1;
		}
	}
	output = yaffs_rmdir("/yaffs2/.");
	if (output<0){ 
		error_code=yaffs_get_error();
		if (abs(error_code)==EINVAL){
			return 1;
		} else {
			print_message("returned error does not match the the expected error\n",2);
			return -1;
		}
	} else{
		print_message("removed /yaffs2/ directory (which is a bad thing)\n",2);
		return -1;
	}	
}
int test_yaffs_rmdir_ENOTDIR(void)
{
	int output=0;
	int error_code =0;
	if (yaffs_close(yaffs_open(FILE_PATH,O_CREAT | O_RDWR, FILE_MODE))==-1){
		print_message("failed to create file\n",1);
		return -1;
	}
	if (0 !=  yaffs_access(DIR_PATH,0)) {
		output = yaffs_mkdir(DIR_PATH,S_IWRITE | S_IREAD);
		if (output < 0) {
			print_message("failed to create directory\n",2);
			return -1;
		}
	}
	output = yaffs_rmdir("/yaffs2/test_dir/foo/dir/");
	if (output<0){ 
		error_code=yaffs_get_error();
		if (abs(error_code)==ENOTDIR){
			return 1;
		} else {
			print_message("returned error does not match the the expected error\n",2);
			return -1;
		}
	} else{
		print_message("removed /yaffs2/ directory (which is a bad thing)\n",2);
		return -1;
	}	
}
int test_yaffs_rename_file_to_dir(void)
{
    int output=0;

    if (0 !=  yaffs_access(FILE_PATH,0)) {
        output = test_yaffs_open();
        if (output < 0) {
            print_message("failed to create file\n",2);
            return -1;
        } else {
            output = yaffs_close(output);
            if (output < 0) {
                print_message("failed to close file\n",2);
                return -1;
            }
        }
    }
    output = yaffs_rename( "/yaffs2/foo" , RENAME_DIR_PATH);
    if (output<0) {
        print_message("failed to rename a file over an empty directory\n",2);
        return -1;
    } else {
        return 1;
    }

}
int test_yaffs_symlink_EEXIST(void)
{
	int error_code = 0;
	if (-1==yaffs_access(SYMLINK_PATH,0)){
		output=yaffs_symlink(FILE_PATH,SYMLINK_PATH);
		if (output>0){
			print_message("failed to create the first symlink\n",2);
			return -1;
		}
	}

	output = yaffs_symlink(FILE_PATH,SYMLINK_PATH);
	if (output<0){ 
		error_code=yaffs_get_error();
		if (abs(error_code)==EEXIST){
			return 1;
		} else {
			print_message("returned error does not match the the expected error\n",2);
			return -1;
		}
	} else {
		print_message("created a symlink over an existing symlink (which is a bad thing)\n",2);
		return -1;
	}	

}
Esempio n. 5
0
int test_yaffs_open_EACCES(void)
{
	int error_code=0;
	int output =-1;
	if (yaffs_access(FILE_PATH,0)!=0){
		output=yaffs_close(test_yaffs_open());
		if (output<0){
			print_message("failed to open file\n",2);
			return -1;
		}
	}

	output=yaffs_chmod(FILE_PATH,S_IREAD);
	if (output<0){
		print_message("failed to chmod file\n",2);
		return -1;
	}
	handle=yaffs_open(FILE_PATH, O_TRUNC| O_RDWR,FILE_MODE );
	if (handle <0){
		error_code=yaffs_get_error();
		if (abs(error_code)==EACCES){
			return 1;
		}
		else {
			print_message("different error than expected\n",2);
			return -1;
		}
	}
	else {
		print_message("file opened with read and write permissions, chmoded to read only.(which is a bad thing)\n",2);
		return -1;
	}
}
int test_yaffs_access(void)
{

    if (-1==yaffs_close(yaffs_open(FILE_PATH,O_CREAT | O_RDWR, FILE_MODE))) {
        print_message("failed to create file\n",1);
        return -1;
    }
    return yaffs_access(FILE_PATH,0);
}
int test_yaffs_rename_EEXISTS(void)
{
	int output=0;
	int error_code =0;

	if (0 !=  yaffs_access(DIR_PATH,0)) {
		output = yaffs_mkdir(DIR_PATH,S_IWRITE | S_IREAD);
		if (output < 0) {
			print_message("failed to create directory\n",2);
			return -1;
		}
	}
	if (0 !=  yaffs_access(RENAME_DIR_PATH,0)) {
		output = yaffs_mkdir(RENAME_DIR_PATH,S_IWRITE | S_IREAD);
		if (output < 0) {
			error_code=yaffs_get_error();
			if (abs(error_code)!=EEXIST){
				print_message("failed to create second directory\n",2);
				return -1;
			}
		}
	}
	output= yaffs_open("/yaffs2/dir2/file",O_CREAT | O_RDWR, FILE_MODE);
	if (output<0){
		print_message("failed to open file in the second directory\n",2);
		return -1;
	}
	output = yaffs_rename(DIR_PATH , RENAME_DIR_PATH);
	if (output<0){ 
		error_code=yaffs_get_error();
		if (abs(error_code)==ENOTEMPTY){
			return 1;
		} else {
			print_message("returned error does not match the the expected error\n",2);
			return -1;
		}
	} else{
		print_message("removed /yaffs2/ directory (which is a bad thing)\n",2);
		return -1;
	}	
}
int test_yaffs_rmdir_ENOTEMPTY_clean(void)
{
	int output = -1;
	int output2 = -1;
	if (0 ==  yaffs_access("/yaffs2/test_dir/new_directory/dir",0)) {
		output = yaffs_rmdir("/yaffs2/test_dir/new_directory/dir");
		if (output < 0) {
			print_message("failed to remove the directory\n",2);
			output=1;
		}
	}
	if (0 ==  yaffs_access(DIR_PATH,0)) {
		output = yaffs_rmdir(DIR_PATH);
		if (output < 0) {
			print_message("failed to remove the directory\n",2);
			output2=1;
		}
	}
	return (output && output2);

}
int test_yaffs_rename_dir_clean(void)
{
	int output = 0;
	if (0 ==  yaffs_access("/yaffs2/new_directory/file",0)) {
		output = yaffs_unlink("/yaffs2/new_directory/file");
		if (output < 0) {
			print_message("failed to remove file\n",2);
			return -1;
		}
	}

	if (0 ==  yaffs_access(RENAME_DIR_PATH,0)) {
		output = yaffs_rename(RENAME_DIR_PATH,DIR_PATH);
		if (output < 0) {
			print_message("failed to rename the dir\n",2);
			return -1;
		}
	}
	return 1;

}
Esempio n. 10
0
int test_yaffs_rename_EEXISTS_clean(void)
{
	int output = 0;
	if (0 ==  yaffs_access("/yaffs2/dir2/file",0) ) {
		output = yaffs_unlink("/yaffs2/dir2/file");
		if (output < 0) {
			print_message("failed to remove the file\n",2);
			return -1;
		}
	}
	if (0 ==  yaffs_access(RENAME_PATH,0) && 0 != yaffs_access(DIR_PATH,0)) {
		output = yaffs_rename(RENAME_PATH,FILE_PATH);
		if (output < 0) {
			print_message("failed to remove the directory\n",2);
			return -1;
		}
	}
	
	return 1;

}
Esempio n. 11
0
int test_yaffs_rename_dir_clean(void)
{
	int output = 0;
	if (0 ==  yaffs_access(RENAME_DIR_PATH,0)) {
		output = yaffs_rename(RENAME_DIR_PATH,DIR_PATH);
		if (output < 0) {
			print_message("failed to rename the file\n",2);
			return -1;
		}
	}
	return 1;

}
int test_yaffs_rmdir_ENOTDIR_clean(void)
{
	int output = 0;
	if (0 ==  yaffs_access(DIR_PATH,0)) {
		output = yaffs_rmdir(DIR_PATH);
		if (output < 0) {
			print_message("failed to remove the directory\n",2);
			return -1;
		}
	}
	return 1;

}
Esempio n. 13
0
int test_yaffs_rename_dir(void)
{
	int output=0;


	if (0 !=  yaffs_access(DIR_PATH,0)) {
		output = yaffs_mkdir(DIR_PATH,S_IREAD|S_IWRITE);
		if (output < 0) {
			print_message("failed to create file\n",2);
			return -1;
		}
	}
	output = yaffs_rename( DIR_PATH , RENAME_DIR_PATH);
	return output;	
}
Esempio n. 14
0
void init(char *yaffs_test_dir,char *yaffs_mount_dir,int argc, char *argv[]){
	char output=0;
	int x=0;
	int seed=-1;
	FILE *log_handle;
	/*these variables are already set to zero, but it is better not to take chances*/
	message_buffer.head=0;				 
	message_buffer.tail=0;


	log_handle=fopen(LOG_FILE,"w");
	if (log_handle!=NULL){
		fputs("log file for yaffs tester\n",log_handle);
		fclose(log_handle);
	}
	add_to_buffer(&message_buffer,"welcome to the yaffs tester",MESSAGE_LEVEL_BASIC_TASKS,PRINT);/* print boot up message*/	
	yaffs_start_up();
    	yaffs_mount(yaffs_mount_dir);
	for (x=0;x<argc;x++){
//		add_to_buffer(&message_buffer,"argv ",MESSAGE_LEVEL_BASIC_TASKS,PRINT);
//		add_to_buffer(&message_buffer,argv[x],MESSAGE_LEVEL_BASIC_TASKS,PRINT);
		if (strcmp("-seed",argv[x])==0){			/*warning only compares the length of the strings, quick fix*/
			seed= atoi(argv[x+1]);
			/*add_to_buffer(&message_buffer,"setting seed to ",MESSAGE_LEVEL_BASIC_TASKS,NPRINT);
			append_int_to_buffer(&message_buffer,seed,MESSAGE_LEVEL_BASIC_TASKS,NPRINT);			
			append_to_buffer(&message_buffer,"\n",MESSAGE_LEVEL_BASIC_TASKS,PRINT);*/
		}
	}
	if (seed==-1){
		seed=time(NULL);
		srand(seed); 
	}
	else {
	srand(seed);
	}
	add_to_buffer(&message_buffer,"setting seed to ",MESSAGE_LEVEL_BASIC_TASKS,NPRINT);
	append_int_to_buffer(&message_buffer,seed,MESSAGE_LEVEL_BASIC_TASKS,PRINT);/* print boot up message*/	

	if (yaffs_access(yaffs_test_dir,0))	/* if the test folder does not exist then create it */
	{
		add_to_buffer(&message_buffer,"creating dir: ",MESSAGE_LEVEL_BASIC_TASKS,NPRINT);
		append_to_buffer(&message_buffer,yaffs_test_dir,MESSAGE_LEVEL_BASIC_TASKS,PRINT);	
		output=yaffs_mkdir(yaffs_test_dir,S_IREAD | S_IWRITE);
		yaffs_check_for_errors(output, &message_buffer,"could not create dir","created dir\n\n");
	}
	
}
/*tests renaming a non empty file */
int test_yaffs_rename_dir(void)
{
	int output=0;
	int error_code =0;
	output = yaffs_open("/yaffs2/new_directory/file",O_CREAT | O_RDWR, S_IREAD | S_IWRITE);
	if (output < 0 )

	if (0 !=  yaffs_access(FILE_PATH,0)) {
		output = test_yaffs_open();
		if (output < 0) {
			print_message("failed to create file\n",2);
			return -1;
		}
	}
	output = yaffs_rename( DIR_PATH , RENAME_DIR_PATH);
	return output;	
}
int test_yaffs_rename_file_to_dir_clean(void)
{
    int output = 0;
    test_yaffs_open();
    if (0 ==  yaffs_access(RENAME_DIR_PATH,0)) {
        output = yaffs_unlink(RENAME_DIR_PATH);
        if (output < 0) {
            print_message("failed to unlink the file\n",2);
            return -1;
        }
        output = test_yaffs_open();
        if (output < 0) {
            print_message("failed to open a new\n",2);
            return -1;
        }
    }
    return 1;

}
Esempio n. 17
0
int test_yaffs_access_ENOENT(void)
{
	int output=0;
	int error_code=0;

	output=yaffs_access("/yaffs2/non_existant_file",0);
	if (output==-1){
		error_code=yaffs_get_error();
		if (abs(error_code)==ENOENT){
			return 1;
		} else {
			print_message("different error than expected\n",2);
			return -1;
		}
	} else {
		print_message("non existant file accessed.(which is a bad thing)\n",2);
		return -1;
	}

}
Esempio n. 18
0
int test_yaffs_access_NULL(void)
{
	int output=0;
	int error=0;
	if (set_up_ELOOP()<0){
		print_message("failed to setup symlinks\n",2);
		return -1;
	}
	output= yaffs_access(NULL,0);
	if (output<0){
		error=yaffs_get_error();
		if ( abs(error)== EFAULT){
			return 1;
		} else {
			print_message("error does not match expected error\n",2);
			return -1;
		}
	} else{
		print_message("accessed an existing file with bad mode (which is a bad thing\n",2);

		return -1;
	}
}
Esempio n. 19
0
int test_yaffs_access_EACCES(void)
{
	int output=0;
	int error=0;
	output=yaffs_chmod(FILE_PATH,S_IREAD);
	if (output<0){
		print_message("failed to chmod file\n",2);
		return -1;
	}
	output= yaffs_access(FILE_PATH,W_OK);
	if (output<0){
		error=yaffs_get_error();
		if ( abs(error)== EACCES){
			return 1;
		} else {
			print_message("error does not match expected error\n",2);
			return -1;
		}
	} else{
		print_message("accessed an existing file with bad mode (which is a bad thing\n",2);

		return -1;
	}
}
Esempio n. 20
0
static int __yaffs_access(mount_point_t *point, const char *path, int amode)
{
    return yaffs_access(vfs_path_add_mount_point(path), amode);