Beispiel #1
0
void simple_rw_test(const char *mountpt)
{
	int i;
	int h;
	char a[100];
	
	int x;
	int result;

	sprintf(a,"%s/aaa",mountpt);
	
	yaffs_StartUp();
	
	yaffs_mount(mountpt);
	
	yaffs_unlink(a);
	
	h = yaffs_open(a,O_CREAT| O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
	
	for(i = 100000;i < 200000; i++){
		result = yaffs_write(h,&i,sizeof(i));
		
		if(result != 4)
		{
			printf("write error\n");
			exit(1);
		}
	}
	
	//yaffs_close(h);
	
	// h = yaffs_open(a,O_RDWR, S_IREAD | S_IWRITE);
	
	
	yaffs_lseek(h,0,SEEK_SET);
	
	for(i = 100000; i < 200000; i++){
		result = yaffs_read(h,&x,sizeof(x));
		
		if(result != 4 || x != i){
			printf("read error %d %x %x\n",i,result,x);
		}
	}
	
	printf("Simple rw test passed\n");
	
	
	
}
Beispiel #2
0
void null_name_test(const char *path)
{
	char fn[100];
	int h;
	yaffs_StartUp();

	yaffs_mount(path);

	sprintf(fn,"%s",path);

	h = yaffs_open(fn,O_CREAT| O_TRUNC| O_RDWR, 0666);

	printf("%d\n",h);

}
int cache_bypass_bug_test(void)
{
	// This test reporoduces a bug whereby YAFFS caching *was* buypassed
	// resulting in erroneous reads after writes.
	// This bug has been fixed.
	
	int a;
	int i;
	char buffer1[1000];
	char buffer2[1000];
	
	memset(buffer1,0,sizeof(buffer1));
	memset(buffer2,0,sizeof(buffer2));
		
	yaffs_StartUp();
	
	yaffs_mount("/boot");
	
	// Create a file of 2000 bytes.
	make_a_file("/boot/a",'X',2000);

	a = yaffs_open("/boot/a",O_RDWR, S_IREAD | S_IWRITE);
	
	// Write a short sequence to the file.
	// This will go into the cache.
	yaffs_lseek(a,0,SEEK_SET);
	yaffs_write(a,"abcdefghijklmnopqrstuvwxyz",20); 

	// Read a short sequence from the file.
	// This will come from the cache.
	yaffs_lseek(a,0,SEEK_SET);
	yaffs_read(a,buffer1,30); 

	// Read a page size sequence from the file.
	yaffs_lseek(a,0,SEEK_SET);
	yaffs_read(a,buffer2,512); 
	
	printf("buffer 1 %s\n",buffer1);
	printf("buffer 2 %s\n",buffer2);
	
	if(strncmp(buffer1,buffer2,20))
	{
		printf("Cache bypass bug detected!!!!!\n");
	}
	
	
	return 1;
}
void huge_array_test(const char *mountpt,int n)
{

	char a[50];

	
	int i;
	int j;
	int h;
	
	int fnum;
	
	sprintf(a,"mount point %s",mountpt);
	

	
	yaffs_StartUp();

	yaffs_mount(mountpt);
	
	while(n>0){
		n--;
		fnum = 0;
		printf("\n\n START run\n\n");
		while(yaffs_freespace(mountpt) > 25000000){
			sprintf(a,"%s/file%d",mountpt,fnum);
			fnum++;
			printf("create file %s\n",a);
			create_file_of_size(a,10000000);
			printf("verifying file %s\n",a);
			verify_file_of_size(a,10000000);
		}
		
		printf("\n\n\ verification/deletion\n\n");
		
		for(i = 0; i < fnum; i++){
			sprintf(a,"%s/file%d",mountpt,i);
			printf("verifying file %s\n",a);
			verify_file_of_size(a,10000000);
			printf("deleting file %s\n",a);
			yaffs_unlink(a);
		}
		printf("\n\n\ done \n\n");
			
		   
	}
}
Beispiel #5
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");
	}
	
}
Beispiel #6
0
void long_name_test(const char *mountpt)
{
	int i;
	yaffs_StartUp();
	char fullName[1000];
	char name[300];
	int result = 0;
	
	int f;
	
	// Make a 256 byte name
	memset(name,0,sizeof(name));
	for(i = 0; i < 256; i++)
		name[i] = '0' + i % 10;
		
	sprintf(fullName,"%s/%s",mountpt,name);

	for(i = 0; i < 1; i++)
	{
		yaffs_mount(mountpt);
		
		printf("Files at start\n");
		dumpDir(mountpt);
		
		printf("Creating file %s\n",fullName);
		
		f = yaffs_open(fullName,O_CREAT | O_RDWR,0);
		yaffs_close(f);
		
		printf("Result %d\n",f);
			
		printf("Files\n");
		dumpDir(mountpt);
		
		printf("Deleting %s\n",fullName);
		result = yaffs_unlink(fullName);
		printf("Result %d\n",result);
		
		printf("Files\n");
		
		dumpDir(mountpt);
		
		yaffs_unmount(mountpt);
	}
	
}
Beispiel #7
0
void short_scan_test(const char *path, int fsize, int niterations)
{
	int i;
	char fn[100];
	
	sprintf(fn,"%s/%s",path,"f1");
	
	yaffs_StartUp();
	for(i = 0; i < niterations; i++)
	{
		printf("\n*****************\nIteration %d\n",i);
		yaffs_mount(path);
		printf("\nmount: Directory look-up of %s\n",path);
		dumpDir(path);
		make_a_file(fn,1,fsize);
		yaffs_unmount(path);
	}
}
Beispiel #8
0
void link_test0(const char *mountpt)
{
	char namea[300];
	char nameb[300];
	int result = 0;
	

	yaffs_StartUp();
	yaffs_mount(mountpt);
	
		
	sprintf(namea,"%s/a",mountpt);
	sprintf(nameb,"%s/b",mountpt);

	printf("mounted\n");
        dumpDir(mountpt);

	yaffs_unlink(namea);
	printf("a unlinked\n");
        dumpDir(mountpt);

	yaffs_unlink(nameb);
	printf("b unlinked\n");
        dumpDir(mountpt);
	
	result = yaffs_open(namea,O_CREAT| O_RDWR,0666);
        yaffs_close(result);
	printf("a created\n");
        dumpDir(mountpt);

        yaffs_link(namea,nameb);
        printf("linked\n");
        dumpDir(mountpt);
        yaffs_unlink(namea);
        printf("a ulinked\n");
        dumpDir(mountpt);
        yaffs_unlink(nameb);
        printf("b unlinked\n");
        dumpDir(mountpt);

	yaffs_unmount(mountpt);
}
Beispiel #9
0
void big_xattr_test(const char *mountpt)
{
	char name[100];
	int h;
	int result;
	char val[1000];

	yaffs_StartUp();

	yaffs_mount(mountpt);

	strcpy(name,mountpt);
	strcat(name,"/");
	strcat(name,"xfile");

	yaffs_unlink(name);
	h = yaffs_open(name,O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
	yaffs_close(h);

	printf("Start\n");
	list_xattr(name);

	printf("Add a large  attribute\n");
	memset(val,0x1,sizeof(val));
	result = yaffs_setxattr(name,"aaa",val,200,0);
	printf("wrote attribute aaa: result %d\n",result);
	list_xattr(name);

	printf("Add a large  attribute\n");
	memset(val,0x2,sizeof(val));
	result = yaffs_setxattr(name,"bbb",val,1000,0);
	printf("wrote attribute bbb: result %d\n",result);
	list_xattr(name);

	printf("Replace attribute\n");
	memset(val,0x3,sizeof(val));
	result = yaffs_setxattr(name,"aaa",val,1000,0);
	printf("wrote attribute aaa: result %d\n",result);
	list_xattr(name);

}
Beispiel #10
0
int root_perm_remount(const char *path)
{
   struct yaffs_stat s;
   
   yaffs_StartUp();
   
   yaffs_mount(path);
   
   yaffs_stat(path,&s);
   printf("root perms after mount %x\n",s.st_mode);
   
   yaffs_chmod(path, 0777);

   yaffs_stat(path,&s);
   printf("root perms after setting to 0777 is  %x\n",s.st_mode);
   
   yaffs_unmount(path);
      
   return 0;
   
}
int test_yaffs_mount_ENAMETOOLONG(void)
{
	int output = 0;
	int x = 0;
	int error_code = 0;
	int file_name_length = 1000000;
	char file_name[file_name_length];

	/* if a second file system is mounted then yaffs will return EBUSY. so first unmount yaffs */
	output = test_yaffs_unmount();
	if (output<0){
		print_message("yaffs failed to unmount\n", 2);
		return -1;
	} 

	/* set up the file name */
	for (x=0; x<file_name_length -1; x++){
		file_name[x]='a';
	}
	file_name[file_name_length-2]='\0';
	



	output=yaffs_mount(file_name);

	if (output<0){
		error_code=yaffs_get_error();
		if (abs(error_code)== ENAMETOOLONG){
			return 1;
		} else {
			print_message("different error than expected\n", 2);
			return -1;
		}
	} else {
		print_message("mounted a too long mount point name.(which is a bad thing)\n", 2);
		return -1;
	}
}
Beispiel #12
0
int truncate_test(void)
{
	int a;
	int r;
	int i;
	int l;

	char y[10];

	yaffs_StartUp();
	yaffs_mount("/boot");

	yaffs_unlink("/boot/trunctest");
	
	a = yaffs_open("/boot/trunctest", O_CREAT | O_TRUNC | O_RDWR,  S_IREAD | S_IWRITE);
	
	yaffs_write(a,"abcdefghijklmnopqrstuvwzyz",26);
	
	yaffs_ftruncate(a,3);
	l= yaffs_lseek(a,0,SEEK_END);
	
	printf("truncated length is %d\n",l);

	yaffs_lseek(a,5,SEEK_SET);
	yaffs_write(a,"1",1);

	yaffs_lseek(a,0,SEEK_SET);
	
	r = yaffs_read(a,y,10);

	printf("read %d bytes:",r);

	for(i = 0; i < r; i++) printf("[%02X]",y[i]);

	printf("\n");

	return 0;

}
Beispiel #13
0
void NorStressTestRun(const char *prefix)
{
  MakeFullNames(prefix);

  yaffs_StartUp();
  yaffs_mount(fullPathName);
  
  dump_directory_tree(fullPathName);
  
  UpdateCounter(fullPowerUpName,&powerUps,0);
  dump_directory_tree(fullPathName);
  
  while(1){
    UpdateCounter(fullStartName, &cycleStarts,0);
    dump_directory_tree(fullPathName);
    DoVerifyMainFile();
    DoUpdateMainFile();
    dump_directory_tree(fullPathName);
  
    UpdateCounter(fullEndName,&cycleEnds,0);
    dump_directory_tree(fullPathName);
  }
}
Beispiel #14
0
void seek_overwrite_test(const char *mountpt,int nmounts)
{
        static char xx[5000];
	char a[30];
	
	int i;
	int j;

	int h0;

	
	sprintf(a,"%s/f",mountpt);

	yaffs_StartUp();
	
	yaffs_mount(mountpt);
	
	
	for(i = 0; i < nmounts; i++){
		
		h0 = yaffs_open(a, O_RDWR | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
			
		for(j = 0; j < 100000; j++){
			yaffs_lseek(h0,0,SEEK_SET);
			yaffs_write(h0,xx,5000);
			yaffs_lseek(h0,0x100000,SEEK_SET);
			yaffs_write(h0,xx,5000);
			
			if(early_exit)
				exit(0);
		}
		
		yaffs_close(h0);
		
	}
}
Beispiel #15
0
void rename_over_test(const char *mountpt)
{
	int i;
	char a[100];
	char b[100];
	
	sprintf(a,"%s/a",mountpt);
	sprintf(b,"%s/b",mountpt);
	
	yaffs_StartUp();
	
	yaffs_mount(mountpt);
	i = yaffs_open(a,O_CREAT | O_TRUNC | O_RDWR, 0); 
	yaffs_close(i);
	i = yaffs_open(b,O_CREAT | O_TRUNC | O_RDWR, 0);
	yaffs_close(i);
	yaffs_rename(a,b); // rename over
	yaffs_rename(b,a); // rename back again (not renaimng over)
	yaffs_rename(a,b); // rename back again (not renaimng over)
	
	
	yaffs_unmount(mountpt);
	
}
Beispiel #16
0
void multi_mount_test(const char *mountpt,int nmounts)
{

	char a[30];
	char b[30];
	char c[30];
	
	int i;
	int j;
	
	sprintf(a,"%s/a",mountpt);
	

	
	
	yaffs_StartUp();
	
	for(i = 0; i < nmounts; i++){
		printf("############### Iteration %d   Start\n",i);
		yaffs_mount(mountpt);
		dump_directory_tree(mountpt);
		yaffs_mkdir(a,0);
		for(j = 0; j < i; j++){
			sprintf(b,"%s/%d",a,j);
			verify_200k_file(b);
		}
		sprintf(b,"%s/%d",a,i);

		write_200k_file(b,"","");
		
		printf("######## Iteration %d   End\n",i);
		dump_directory_tree(mountpt);
		
		yaffs_unmount(mountpt);
	}
}
Beispiel #17
0
int long_test(int argc, char *argv[])
{

	int f;
	int r;
	char buffer[20];
	
	char str[100];
	
	int h;
	mode_t temp_mode;
	struct yaffs_stat ystat;
	
	yaffs_StartUp();
	
	yaffs_mount("/boot");
	yaffs_mount("/data");
	yaffs_mount("/flash");
	yaffs_mount("/ram");
	
	printf("\nDirectory look-up of /boot\n");
	dumpDir("/boot");
	printf("\nDirectory look-up of /data\n");
	dumpDir("/data");
	printf("\nDirectory look-up of /flash\n");
	dumpDir("/flash");

	//leave_unlinked_file("/flash",20000,0);
	//leave_unlinked_file("/data",20000,0);
	
	leave_unlinked_file("/ram",20,0);
	

	f = yaffs_open("/boot/b1", O_RDONLY,0);
	
	printf("open /boot/b1 readonly, f=%d\n",f);
	
	f = yaffs_open("/boot/b1", O_CREAT,S_IREAD | S_IWRITE);
	
	printf("open /boot/b1 O_CREAT, f=%d\n",f);
	
	
	r = yaffs_write(f,"hello",1);
	printf("write %d attempted to write to a read-only file\n",r);
	
	r = yaffs_close(f);
	
	printf("close %d\n",r);

	f = yaffs_open("/boot/b1", O_RDWR,0);
	
	printf("open /boot/b1 O_RDWR,f=%d\n",f);
	
	
	r = yaffs_write(f,"hello",2);
	printf("write %d attempted to write to a writeable file\n",r);
	r = yaffs_write(f,"world",3);
	printf("write %d attempted to write to a writeable file\n",r);
	
	r= yaffs_lseek(f,0,SEEK_END);
	printf("seek end %d\n",r);
	memset(buffer,0,20);
	r = yaffs_read(f,buffer,10);
	printf("read %d \"%s\"\n",r,buffer);
	r= yaffs_lseek(f,0,SEEK_SET);
	printf("seek set %d\n",r);
	memset(buffer,0,20);
	r = yaffs_read(f,buffer,10);
	printf("read %d \"%s\"\n",r,buffer);
	memset(buffer,0,20);
	r = yaffs_read(f,buffer,10);
	printf("read %d \"%s\"\n",r,buffer);

	// Check values reading at end.
	// A read past end of file should return 0 for 0 bytes read.
		
	r= yaffs_lseek(f,0,SEEK_END);
	r = yaffs_read(f,buffer,10);
	printf("read at end returned  %d\n",r); 
	r= yaffs_lseek(f,500,SEEK_END);
	r = yaffs_read(f,buffer,10);
	printf("read past end returned  %d\n",r);       
	
	r = yaffs_close(f);
	
	printf("close %d\n",r);
	
	copy_in_a_file("/boot/yyfile","xxx");
	
	// Create a file with a long name
	
	copy_in_a_file("/boot/file with a long name","xxx");
	
	
	printf("\nDirectory look-up of /boot\n");
	dumpDir("/boot");

	// Check stat
	r = yaffs_stat("/boot/file with a long name",&ystat);
	
	// Check rename
	
	r = yaffs_rename("/boot/file with a long name","/boot/r1");
	
	printf("\nDirectory look-up of /boot\n");
	dumpDir("/boot");
	
	// Check unlink
	r = yaffs_unlink("/boot/r1");
	
	printf("\nDirectory look-up of /boot\n");
	dumpDir("/boot");

	// Check mkdir
	
	r = yaffs_mkdir("/boot/directory1",0);
	
	printf("\nDirectory look-up of /boot\n");
	dumpDir("/boot");
	printf("\nDirectory look-up of /boot/directory1\n");
	dumpDir("/boot/directory1");

	// add a file to the directory                  
	copy_in_a_file("/boot/directory1/file with a long name","xxx");
	
	printf("\nDirectory look-up of /boot\n");
	dumpDir("/boot");
	printf("\nDirectory look-up of /boot/directory1\n");
	dumpDir("/boot/directory1");
	
	//  Attempt to delete directory (should fail)
	
	r = yaffs_rmdir("/boot/directory1");
	
	printf("\nDirectory look-up of /boot\n");
	dumpDir("/boot");
	printf("\nDirectory look-up of /boot/directory1\n");
	dumpDir("/boot/directory1");
	
	// Delete file first, then rmdir should work
	r = yaffs_unlink("/boot/directory1/file with a long name");
	r = yaffs_rmdir("/boot/directory1");
	
	
	printf("\nDirectory look-up of /boot\n");
	dumpDir("/boot");
	printf("\nDirectory look-up of /boot/directory1\n");
	dumpDir("/boot/directory1");

#if 0
	fill_disk_and_delete("/boot",20,20);
			
	printf("\nDirectory look-up of /boot\n");
	dumpDir("/boot");
#endif

	yaffs_symlink("yyfile","/boot/slink");
	
	yaffs_readlink("/boot/slink",str,100);
	printf("symlink alias is %s\n",str);
	
	
	
	
	printf("\nDirectory look-up of /boot\n");
	dumpDir("/boot");
	printf("\nDirectory look-up of /boot (using stat instead of lstat)\n");
	dumpDirFollow("/boot");
	printf("\nDirectory look-up of /boot/directory1\n");
	dumpDir("/boot/directory1");

	h = yaffs_open("/boot/slink",O_RDWR,0);
	
	printf("file length is %d\n",(int)yaffs_lseek(h,0,SEEK_END));
	
	yaffs_close(h);
	
	yaffs_unlink("/boot/slink");

	
	printf("\nDirectory look-up of /boot\n");
	dumpDir("/boot");
	
	// Check chmod
	
	yaffs_stat("/boot/yyfile",&ystat);
	temp_mode = ystat.st_mode;
	
	yaffs_chmod("/boot/yyfile",0x55555);
	printf("\nDirectory look-up of /boot\n");
	dumpDir("/boot");
	
	yaffs_chmod("/boot/yyfile",temp_mode);
	printf("\nDirectory look-up of /boot\n");
	dumpDir("/boot");
	
	// Permission checks...
	PermissionsCheck("/boot/yyfile",0, O_WRONLY,0);
	PermissionsCheck("/boot/yyfile",0, O_RDONLY,0);
	PermissionsCheck("/boot/yyfile",0, O_RDWR,0);

	PermissionsCheck("/boot/yyfile",S_IREAD, O_WRONLY,0);
	PermissionsCheck("/boot/yyfile",S_IREAD, O_RDONLY,1);
	PermissionsCheck("/boot/yyfile",S_IREAD, O_RDWR,0);

	PermissionsCheck("/boot/yyfile",S_IWRITE, O_WRONLY,1);
	PermissionsCheck("/boot/yyfile",S_IWRITE, O_RDONLY,0);
	PermissionsCheck("/boot/yyfile",S_IWRITE, O_RDWR,0);
	
	PermissionsCheck("/boot/yyfile",S_IREAD | S_IWRITE, O_WRONLY,1);
	PermissionsCheck("/boot/yyfile",S_IREAD | S_IWRITE, O_RDONLY,1);
	PermissionsCheck("/boot/yyfile",S_IREAD | S_IWRITE, O_RDWR,1);

	yaffs_chmod("/boot/yyfile",temp_mode);
	
	//create a zero-length file and unlink it (test for scan bug)
	
	h = yaffs_open("/boot/zlf",O_CREAT | O_TRUNC | O_RDWR,0);
	yaffs_close(h);
	
	yaffs_unlink("/boot/zlf");
	
	
	yaffs_DumpDevStruct("/boot");
	
	fill_disk_and_delete("/boot",20,20);
	
	yaffs_DumpDevStruct("/boot");
	
	fill_files("/boot",1,10000,0);
	fill_files("/boot",1,10000,5000);
	fill_files("/boot",2,10000,0);
	fill_files("/boot",2,10000,5000);
	
	leave_unlinked_file("/data",20000,0);
	leave_unlinked_file("/data",20000,5000);
	leave_unlinked_file("/data",20000,5000);
	leave_unlinked_file("/data",20000,5000);
	leave_unlinked_file("/data",20000,5000);
	leave_unlinked_file("/data",20000,5000);
	
	yaffs_DumpDevStruct("/boot");
	yaffs_DumpDevStruct("/data");
	
		
		
	return 0;

}
Beispiel #18
0
int huge_directory_test_on_path(char *path)
{

	yaffs_DIR *d;
	yaffs_dirent *de;
	struct yaffs_stat s;

	int f;
	int i;
	int r;
	int total = 0;
	int lastTotal = 0;
	char buffer[20];
	
	char str[100];
	char name[100];
	char name2[100];
	
	int h;
	mode_t temp_mode;
	struct yaffs_stat ystat;
	
	yaffs_StartUp();
	
	yaffs_mount(path);
	
	// Create a large number of files
	
	for(i = 0; i < 2000; i++)
	{
	  sprintf(str,"%s/%d",path,i);
	  
	   f = yaffs_open(str,O_CREAT,S_IREAD | S_IWRITE);
	   yaffs_close(f);
	}
	
	
	
	d = yaffs_opendir(path);
	i = 0;
	if (d) {
	while((de = yaffs_readdir(d)) != NULL) {
	if (total >lastTotal+100*9*1024||(i & 1023)==0){
	printf("files = %d, total = %d\n",i, total);
	lastTotal = total;
	}
		i++;
		sprintf(str,"%s/%s",path,de->d_name);
		yaffs_lstat(str,&s);
		switch(s.st_mode & S_IFMT){
		case S_IFREG:
	//printf("data file");
	total += s.st_size;
	break;
	}
	}
	
	yaffs_closedir(d);
	}
	
	return 0;
}
Beispiel #19
0
void random_small_file_test(const char *mountpt,int iterations)
{

	char a[NSMALLFILES][50];

	
	int i;
	int n;
	int h[NSMALLFILES];
	int r;
	
	
	yaffs_StartUp();

	yaffs_mount(mountpt);
	
	for(i = 0; i < NSMALLFILES; i++){
		h[i]=-1;
		strcpy(a[i],"");
	}
	
	for(n = 0; n < iterations; n++){
				
		for(i = 0; i < NSMALLFILES; i++) {
			r = random();
			
			if(strlen(a[i]) == 0){
				sprintf(a[i],"%s/%dx%d",mountpt,n,i);
				h[i] = yaffs_open(a[i],O_RDWR | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
			}
			
			if(h[i] < -1)
				printf("Could not open yaffs file %d %d error %d\n",n,i,h[i]);
			else {
				r = r & 7;
				switch(r){
					case 0:
					case 1:
					case 2:
						random_write(h[i]);
						break;
					case 3:
						random_truncate(h[i],a[i]);
						break;
					case 4:
					case 5:	random_seek(h[i]);
						break;
					case 6:
						yaffs_close(h[i]);
						h[i] = -1;
						break;
					case 7:
						yaffs_close(h[i]);
						yaffs_unlink(a[i]);
						strcpy(a[i],"");
						h[i] = -1;
				}
			}
		}
		   
	}
	
	for(i = 0; i < NSMALLFILES; i++)
		yaffs_close(h[i]);
		
	yaffs_unmount(mountpt);
}
Beispiel #20
0
int do_mount(int argc,char **argv)
{
	yaffs_mount("/boot");
	yaffs_mkdir("/boot/mydoc", 0);
	cmd_yaffs_ls("/boot",0);
}
Beispiel #21
0
void fs_init(void)
{
	yaffs_add_device(&flash_dev);
	yaffs_mount("/");
}
Beispiel #22
0
int resize_stress_test_no_grow(const char *path,int iters)
{
   int a,b,i,j;
   int x;
   int r;
   char aname[100];
   char bname[100];
   
   char abuffer[1000];
   char bbuffer[1000];
   
   yaffs_StartUp();
   
   yaffs_mount(path);
   
   sprintf(aname,"%s%s",path,"/a");
   sprintf(bname,"%s%s",path,"/b");
   
   memset(abuffer,'a',1000);
   memset(bbuffer,'b',1000);
   
   a = yaffs_open(aname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
   b = yaffs_open(bname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
   
   printf(" %s %d %s %d\n",aname,a,bname,b);
  
   x = 0;
   
   for(j = 0; j < iters; j++)
   {
		yaffs_lseek(a,0,SEEK_END);

		
		for(i = 0; i <20000; i++)
		{
		   //r =        yaffs_lseek(b,i,SEEK_SET);
			//r = yaffs_write(b,bbuffer,1000);
			
			if(!(x%20))
			{
				// shrink
				int syz = yaffs_lseek(a,0,SEEK_END);
				
				while(syz > 4000)
				{
				
					syz -= 2050;
					if(syz < 0) syz = 0;
					yaffs_ftruncate(a,syz);
					syz = yaffs_lseek(a,0,SEEK_END);
					printf("shrink to %d\n",syz);
				}
				
				
			}
			else
			{
				//expand
				r = yaffs_lseek(a,-500,SEEK_END);
				r = yaffs_write(a,abuffer,1000);
			}
			x++;
			
					
		}
		printf("file size is %lld\n",(long long)yaffs_lseek(a,0,SEEK_END));

   }
   
   return 0;
   
}
Beispiel #23
0
int resize_stress_test(const char *path)
{
   int a,b,i,j;
   int x;
   int r;
   char aname[100];
   char bname[100];
   
   char abuffer[1000];
   char bbuffer[1000];
   
   yaffs_StartUp();
   
   yaffs_mount(path);
   
   sprintf(aname,"%s%s",path,"/a");
   sprintf(bname,"%s%s",path,"/b");
   
   memset(abuffer,'a',1000);
   memset(bbuffer,'b',1000);
   
   a = yaffs_open(aname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
   b = yaffs_open(bname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
   
   printf(" %s %d %s %d\n",aname,a,bname,b);
  
   x = 0;
   
   for(j = 0; j < 100; j++)
   {
		yaffs_lseek(a,0,SEEK_END);

		
		for(i = 0; i <20000; i++)
		{
		   //r =        yaffs_lseek(b,i,SEEK_SET);
			//r = yaffs_write(b,bbuffer,1000);
			
			if(x & 0x16)
			{
				// shrink
				int syz = yaffs_lseek(a,0,SEEK_END);
				
				syz -= 500;
				if(syz < 0) syz = 0;
				yaffs_ftruncate(a,syz);
				
			}
			else
			{
				//expand
				r = yaffs_lseek(a,i * 500,SEEK_SET);
				r = yaffs_write(a,abuffer,1000);
			}
			x++;
			
		}
   }
   
   return 0;
   
}
Beispiel #24
0
void small_mount_test(const char *mountpt,int nmounts)
{

	char a[30];
	
	int i;
	int j;

	int h0;
	int h1;
	int len0;
	int len1;
	int nread;
	
	sprintf(a,"%s/a",mountpt);

	yaffs_StartUp();
	
	
	
	for(i = 0; i < nmounts; i++){
		
		static char xx[1000];
		
		printf("############### Iteration %d   Start\n",i);
		if(1 || i == 0 || i == 5) 
			yaffs_mount(mountpt);

		dump_directory_tree(mountpt);
		
		yaffs_mkdir(a,0);
		
		sprintf(xx,"%s/0",a);
		if(i ==0){
		
			h0 = yaffs_open(xx, O_RDWR | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
			for(j = 0; j < 130; j++)
				yaffs_write(h0,xx,1000);
			yaffs_close(h0);
		}
		
		h0 = yaffs_open(xx,O_RDONLY,0);
		
		sprintf(xx,"%s/1",a);
		h1 = yaffs_open(xx, O_RDWR | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
		
		while((nread = yaffs_read(h0,xx,1000)) > 0)
			yaffs_write(h1,xx,nread);
		
		
		len0 = yaffs_lseek(h0,0,SEEK_END);
		len1 = yaffs_lseek(h1,0,SEEK_END);
		
		yaffs_lseek(h0,0,SEEK_SET);
		yaffs_lseek(h1,0,SEEK_SET);

		for(j = 0; j < 200; j++){
		   yaffs_read(h0,xx,1000);
		   yaffs_read(h1,xx,1000);
		}
		
		yaffs_close(h0);
		yaffs_close(h1);
		
		printf("########### %d\n",i);
		dump_directory_tree(mountpt);

		if(1 || i == 4 || i == nmounts -1)
			yaffs_unmount(mountpt);
	}
}
Beispiel #25
0
//void main(void)
void yaffstest(void)
{
	int i = 0,j;
	int f = -1,f1=-1;
	int fd[Nfile];
#if 1
	char file[20];
	char buf[2048];
	char buffer[2048];
#endif
	struct yaffs_stat s;
	int ret;
	unsigned int block;
	unsigned int page;
	int size;

#if 0
	unsigned char buffer0[16];
	unsigned char buffer1[2048];
	unsigned char buffer2[64];
	unsigned char buffer3[2048];
	

	jz_nand_init ();
	
#if mkyaffs
	/* we want to write the oob to spare here */
	memset(buffer1,0xff,2048);
	memset(buffer0,0xff,16);
#else
	memset(buffer0,0x2,16);
	buffer0[0]=0xff;
	memset(buffer1,0xb,2048);
#endif

	for(i=16;i<80;i++)
		nand_flash_erase_block(i);

for(i=16;i<80;i++)
{
	block=i;
	printf("block=%d ok\n",block);
	for(j=0;j<128;j++){
	memset(buffer2,0,16);
	memset(buffer3,0,2048);
	
	page=block*128+j;

	nand_flash_program_buf(page, buffer1,buffer0);//writeing data
//	nand_flash_program_buf(page, NULL, buffer0);//writeing spare
	if(nand_flash_read_buf(page, buffer3,buffer2)!=0)
		printf("*********read nand failed\n");
	if(nand_flash_read_buf(page, NULL,buffer2)!=0)
		printf("*********read nand oob failed\n");

//	ret=memcmp(buffer1+512+256+128,buffer3+512+256+128,64);
	ret=memcmp(buffer1,buffer3,512);
	if(ret!=0)
		printf("ret=%d\n",ret);
	ret=memcmp(buffer2,buffer0,16);
	if(ret!=0)
		printf("ret=%d\n \r\n",ret); 
	}
}
/*
	for(i=0;i<16;i++)
		printf("***data[%d]=%x,spare[%d]=%x\n",i,buffer3[i],i,buffer2[i]);
	for(i=896+64;i>896;i--)
		printf("*** buffer3[%d]=%x,buffer1[%d]=%x\n",i,buffer3[i],i,buffer1[i]); 
*/
#else
#if 1
	yaffs_StartUp();
	yaffs_mount("/mnt");
//	yaffs_mount("/d");
//	return;
//	ListDir("/mnt");
	yaffs_mkdir("/mnt/mtdblock", 0);
	yaffs_mkdir("/mnt/mtdblock/font", 0);
//	yaffs_mkdir("/c/data1", 0);
//	ListDir("/mnt/mtdblock");
//	ListDir("/mnt/mtdblock/font");
#endif
#if 0
	printf("testing serial\n\n");
	Updatefile();
	ReadOptions("/mnt/mtdblock/test1");
	ReadOptions("/mnt/mtdblock/options.cfg");
//	ReadOptions("/mnt/mtdblock/font/LANGUAGE.E");
	ListDir("/mnt/mtdblock");
	ListDir("/mnt/mtdblock/font");

	return;
#else
	/* testing memory */
	return;
#endif


#if 1
//	f = yaffs_open("/mnt/mtdblock/bigfile", O_CREAT | O_RDWR , S_IREAD | S_IWRITE);
	f = yaffs_open("/mnt/mtdblock/options.cfg", O_CREAT | O_RDWR , S_IREAD | S_IWRITE);
	if(f<0)
		printf("Yaffs Open File Failed\n");
	#if 1
//	for(i=0;i<12000;i++)
	for(i=0;i<1200;i++)
	{
		
		yaffs_lseek(f,0,SEEK_SET);
		yaffs_read(f,buffer,50);
		memset(buffer,i%255,2048);
		size=yaffs_lseek(f,0,SEEK_END);
//		ret=yaffs_write(f,buffer,2048);
		ret=yaffs_write(f,buffer,100);
//		printf("the result write  = %d,No.%d\n",ret,i);
		yaffs_lseek(f,0,SEEK_SET);
		yaffs_read(f,buffer,50);
	}
	#endif
	yaffs_lseek(f,0,SEEK_SET);
	size=yaffs_lseek(f,0,SEEK_END);

	yaffs_close(f);

	printf("the length of file =%d,it should be %d\n",size,i*2048);
	ListDir("/mnt/mtdblock");
//	yaffs_unlink("/c/data1/bigfile");
//	ListDir("/c/data1");
	
#else
	for(i=0;i<Nfile;i++)
	{
		sprintf(file,"/c/data0/file%d",i);
		printf("will open file %s\n",file);		
	//	fd[i] = yaffs_open(file, O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE);
		fd[i] = yaffs_open(file, O_CREAT | O_RDWR , S_IREAD | S_IWRITE);
	//	printf("**************fd[%d]=%d\n",i,fd[i]);

		memset(buffer,0x5b+i,2048);
#if 1

		size=yaffs_lseek(fd[i],0,SEEK_END);
		ret=yaffs_write(fd[i],buffer,2048);
		printf("the result of yaffs write file %s = %d\n",file,ret);

/*		for(j=0;j<2;j++)
		{
			printf("buffer[%i]=%x\n",j,buffer[j]);
		}*/

		yaffs_lseek(fd[i],0,SEEK_SET);
#endif
		size=yaffs_lseek(fd[i],0,SEEK_END);
		printf("the length of file %s=%d\n",file,size);
		yaffs_lseek(fd[i],-2048,SEEK_END);
#if 1
		memset(buf,0,2048);
		ret=yaffs_read(fd[i],buf,2048);
		printf("the result of yaffs read file %s ==%d\n",file,ret);
/*
		for(j=0;j<2;j++)
		{
			printf("buf[%i]=%x\n",j,buf[j]);
		} */

		ret=memcmp(buffer,buf,2048);
		printf("the result of compare read*write file %s = %d\n",file,ret);
#endif
	

	//	yaffs_close(fd[i]);
	}
#endif

#endif
#if 0
	yaffs_mkdir("/c/mydoc", 0);
	yaffs_mkdir("/d/data0", 0);
	yaffs_mkdir("/d/data1", 0);
	
	f = yaffs_open("/d/data0/file1.gsk", O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE);
	yaffs_close(f);
	
	f = yaffs_open("/d/data0/file2.gsk", O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE);
	yaffs_close(f);
#endif 
//	yaffs_unlink("/d/data0/file1");
//	ListDir("/d/data0");
}
int main(int argc, char **argv)
{
	int ch;
	int random_mallocs=0;
	ext_fatal = test_fatal;

#if 1
	signal(SIGSEGV,bad_ptr_handler);
	signal(SIGBUS,bad_ptr_handler);
	signal(SIGABRT,bad_ptr_handler);
#endif	
	while ((ch = getopt(argc,argv, "bfilmn:ps:t:uz"))
	       != EOF)
		switch (ch) {
		case 's':
			random_seed = atoi(optarg);
			break;
		case 'p':
			simulate_power_failure =1;
			break;
		case 'i':
			init_test = 1;
			break;
		case 'b':
			do_bash_around = 1;
			break;
		case 'f':
			do_fsx = 1;
			break;
		case 'l':
			ops_multiplier *= 5;
			break;
		case 'u':
			do_upgrade = 1;
			break;
		case 'm':
			random_mallocs=1;
			break;
		case 'n':
			n_cycles = atoi(optarg);
			break;
		case 't':
			yaffs_traceMask = strtol(optarg,NULL,0);
			break;
		case 'z':fuzz_test=1;
			break;
		default:
			BadUsage();
			/* NOTREACHED */
		}
	argc -= optind;
	argv += optind;
	
	if(random_mallocs){
		yaffs_test_maxMallocs = 0xFFF & random_seed;
	}
	
	if(argc == 1) {
		int result;

		strcpy(mount_point,argv[0]);
		
		if(simulate_power_failure)
			n_cycles = -1;
		printf("Running test %s %s %s %s %s seed %d cycles %d\n",
			do_upgrade ? "fw_upgrade" : "",
			init_test ? "initialise":"",
			fuzz_test ? "fuzz-test" : "",
			do_fsx ? "fsx" :"",
			simulate_power_failure ? "power_fail" : "",
			random_seed, n_cycles);

		yaffs_StartUp();
		result = yaffs_mount(mount_point);
		if(result < 0){
			printf("Mount of %s failed\n",mount_point);
			printf("pid %d sleeping\n",getpid());
			
			while(!sleep_exit){
				sleep(1);
				sleep_time++;
			}
		}
		printf("Mount complete\n");
			
		if(do_upgrade && init_test){
			simulate_power_failure = 0;
			NorStressTestInitialise(mount_point);
		} else if(do_upgrade){
			printf("Running stress on %s with seed %d\n",mount_point,random_seed);
			NorStressTestRun(mount_point,n_cycles,do_fsx,fuzz_test);
		} else if(do_fsx){
			yaffs_fsx_main(mount_point,n_cycles);
		} else if(do_bash_around){
			yaffs_bash_around(mount_point,n_cycles);
		}else {
			printf("No test to run!\n");
			BadUsage();
		}
		yaffs_unmount(mount_point);
		
		printf("Test run completed!\n");
	}
	else
		BadUsage();
	return 0;
}
Beispiel #27
0
int main()
{
	int output = 0;
	int output2 = 0;
	yaffs_start_up();

	printf("\n\n starting test\n");
	yaffs_set_trace(0);
	output = yaffs_mount(YAFFS_MOUNT_POINT);

	if (output>=0){  
		printf("yaffs mounted: %s\n",YAFFS_MOUNT_POINT); 
	} else {
		printf("error\n yaffs failed to mount: %s\nerror\n",YAFFS_MOUNT_POINT);
		return (0);
	}
	//now create a file.
	output = yaffs_open(FILE_PATH,O_CREAT | O_RDWR, S_IREAD | S_IWRITE);
	if (output>=0){  
		printf("file created: %s\n",FILE_PATH); 
	} else {
		printf("error\n yaffs failed to create the file: %s\nerror\n",FILE_PATH);
		return (0);
	}
	output2 = yaffs_close(output);
	if (output2>=0){  
		printf("file closed: %s\n",FILE_PATH); 
	} else {
		printf("error\n yaffs failed to close the file: %s\nerror\n",FILE_PATH);
		return (0);
	}
	//unmount and remount the mount point.
	output = yaffs_unmount(YAFFS_MOUNT_POINT);
	if (output>=0){  
		printf("yaffs unmounted: %s\n",YAFFS_MOUNT_POINT); 
	} else {
		printf("error\n yaffs failed to unmount: %s\nerror\n",YAFFS_MOUNT_POINT);
		return (0);
	}
	output = yaffs_mount(YAFFS_MOUNT_POINT);
	if (output>=0){  
		printf("yaffs mounted: %s\n",YAFFS_MOUNT_POINT); 
	} else {
		printf("error\n yaffs failed to mount: %s\nerror\n",YAFFS_MOUNT_POINT);
		return (0);
	}
	//now open the existing file.
	output = yaffs_open(FILE_PATH, O_RDWR, S_IREAD | S_IWRITE);
	if (output>=0){  
		printf("file created: %s\n",FILE_PATH); 
	} else {
		printf("error\n yaffs failed to create the file: %s\nerror\n",FILE_PATH);
		return (0);
	}
	//close the file.
	output2 = yaffs_close(output);
	if (output2>=0){  
		printf("file closed: %s\n",FILE_PATH); 
	} else {
		printf("error\n yaffs failed to close the file: %s\nerror\n",FILE_PATH);
		return (0);
	}

	//unmount the mount point.
	output = yaffs_unmount(YAFFS_MOUNT_POINT);
	if (output>=0){  
		printf("yaffs unmounted: %s\n",YAFFS_MOUNT_POINT); 
	} else {
		printf("error\n yaffs failed to unmount: %s\nerror\n",YAFFS_MOUNT_POINT);
		return (0);
	}

	printf("test passed. yay!\n");
	
}
Beispiel #28
0
void lookup_test(const char *mountpt)
{
	int i;
	int h;
	char a[100];
	

	yaffs_DIR *d;
	yaffs_dirent *de;

	yaffs_StartUp();
	
	yaffs_mount(mountpt);
				
	d = yaffs_opendir(mountpt);
	
	if(!d)
	{
		printf("opendir failed\n");
	}
	else
	{
		
		for(i = 0; (de = yaffs_readdir(d)) != NULL; i++)
		{
			printf("unlinking %s\n",de->d_name);
			yaffs_unlink(de->d_name);
		}
		
		printf("%d files deleted\n",i);
	}
	
	
	for(i = 0; i < 2000; i++){
	sprintf(a,"%s/%d",mountpt,i);
		h =  yaffs_open(a,O_CREAT | O_TRUNC | O_RDWR, 0);
		yaffs_close(h);
	}

	yaffs_rewinddir(d);
	for(i = 0; (de = yaffs_readdir(d)) != NULL; i++)
	{
		printf("%d  %s\n",i,de->d_name);
	}	
	
	printf("%d files listed\n\n\n",i);
	
	yaffs_rewinddir(d);
	yaffs_readdir(d);
	yaffs_readdir(d);
	yaffs_readdir(d);
	
	for(i = 0; i < 2000; i++){
		sprintf(a,"%s/%d",mountpt,i);
		yaffs_unlink(a);
	}
	
		
	yaffs_unmount(mountpt);
	
}