X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs2.git;a=blobdiff_plain;f=direct%2Ftests%2Fnor_stress.c;h=730bd4353c088255a8443867c53bc17bbc37fbff;hp=5a7b5297fde80cce4d16f673e018ff6c1abc75c9;hb=22f31a41cbb9a08e67204279fb3b37e400309f1c;hpb=6104166e07b5ffbc8a6004639c9ba3da200bc7a7 diff --git a/direct/tests/nor_stress.c b/direct/tests/nor_stress.c index 5a7b529..730bd43 100644 --- a/direct/tests/nor_stress.c +++ b/direct/tests/nor_stress.c @@ -1,3 +1,17 @@ +/* + * YAFFS: Yet another FFS. A NAND-flash specific file system. + * + * Copyright (C) 2002-2010 Aleph One Ltd. + * for Toby Churchill Ltd and Brightstar Engineering + * + * Created by Charles Manning + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + */ + #include "nor_stress.h" @@ -7,6 +21,7 @@ #include +extern int fuzz_test; #if 1 #define FSX_INIT(mount_pt) do{ if(interleave_fsx) yaffs_fsx_init(mount_pt); } while(0) @@ -35,6 +50,8 @@ static unsigned cycleEnds; static int interleave_fsx; +static int no_verification; + char fullPathName[100]; char fullPowerUpName[100]; char fullStartName[100]; @@ -70,9 +87,13 @@ void MakeFullNames(const char *prefix) MakeName(fullTempMainName,prefix,"tmp-main"); } -static void FatalError(int lineNo) +static void FatalError(int line_no) { - printf("Integrity error %d\n",lineNo); + printf("Integrity error %d\n",line_no); + + if(fuzz_test) + return; + if(ext_fatal) ext_fatal(); @@ -105,8 +126,9 @@ static void UpdateCounter(const char *name, unsigned *val, int initialise) yaffs_close(inh); } - if(nread != sizeof(x) || - x[0] + 1 != x[1]){ + if(!no_verification && + (nread != sizeof(x) || + x[0] + 1 != x[1])){ printf("Error reading counter %s handle %d, x[0] %u x[1] %u last error %d\n", name, inh, x[0], x[1],yaffsfs_GetLastError()); FatalError(__LINE__); @@ -118,12 +140,14 @@ static void UpdateCounter(const char *name, unsigned *val, int initialise) FSX(); outh = yaffs_open(fullTempCounterName, O_RDWR | O_TRUNC | O_CREAT, S_IREAD | S_IWRITE); + if(outh >= 0){ struct yaffs_stat tmpstat, oldstat, tmpfstat; FSX(); + yaffs_fstat(outh,&tmpfstat); + printf("\n\n\n*** Writing file %s inode %d\n",fullTempCounterName,tmpfstat.st_ino); nwritten = yaffs_write(outh,x,sizeof(x)); FSX(); - yaffs_fstat(outh,&tmpfstat); yaffs_close(outh); FSX(); @@ -158,6 +182,7 @@ static void dump_directory_tree_worker(const char *dname,int recursive) struct yaffs_stat s; char str[1000]; int error_line = 0; + int nentries; d = yaffs_opendir(dname); @@ -167,11 +192,13 @@ static void dump_directory_tree_worker(const char *dname,int recursive) } else { + nentries = 0; while((de = yaffs_readdir(d)) != NULL) { strcpy(str,dname); strcat(str,"/"); strcat(str,de->d_name); + nentries++; yaffs_lstat(str,&s); @@ -200,11 +227,16 @@ static void dump_directory_tree_worker(const char *dname,int recursive) dump_directory_tree_worker(str,1); if(s.st_ino > 10000) - error_line = __LINE__; + error_line = __LINE__; } - if(error_line) + if(strstr(dname,"lost+found") && nentries >0){ + printf("\n\n!!! HEY lost+found not empty, had %d entries\n\n\n",nentries); + error_line = __LINE__; + } + + if(error_line && !no_verification) FatalError(error_line); yaffs_closedir(d); @@ -226,7 +258,7 @@ static void dump_directory_tree(const char *dname) static unsigned xx[XX_SIZE]; -static int yWriteFile(const char *fname, unsigned sz32) +static int y_wr_file(const char *fname, unsigned sz32) { int h; int r; @@ -238,7 +270,7 @@ static int yWriteFile(const char *fname, unsigned sz32) FSX(); h = yaffs_open(fname,O_RDWR | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE); yaffs_fstat(h,&st); - printf("Writing file %s inode %d\n",fname, st.st_ino); + printf("\n\n\n**** Open writing file %s inode %d\n",fname, st.st_ino); FSX(); @@ -275,6 +307,7 @@ static int yWriteFile(const char *fname, unsigned sz32) FSX(); yaffs_close(h); + printf("File closed\n"); return 0; WRITE_ERROR: @@ -284,7 +317,7 @@ WRITE_ERROR: } -static int yVerifyFile(const char *fName) +static int y_verify_file(const char *fName) { unsigned checksum = 0; unsigned totalSize; @@ -295,6 +328,8 @@ static int yVerifyFile(const char *fName) int i; int retval = 0; + if(no_verification) + return 0; printf("Verifying file %s\n",fName); @@ -365,10 +400,11 @@ static void DoUpdateMainFile(void) int sz32; sz32 = (myrand() % 1000) + 20; - result = yWriteFile(fullTempMainName,sz32); + result = y_wr_file(fullTempMainName,sz32); FSX(); - if(result) + if(!no_verification && result) FatalError(__LINE__); + printf("Raname file %s to %s\n",fullTempMainName,fullMainName); yaffs_rename(fullTempMainName,fullMainName); FSX(); } @@ -376,7 +412,9 @@ static void DoUpdateMainFile(void) static void DoVerifyMainFile(void) { int result; - result = yVerifyFile(fullMainName); + if(no_verification) + return; + result = y_verify_file(fullMainName); if(result) FatalError(__LINE__); @@ -396,10 +434,14 @@ void NorStressTestInitialise(const char *prefix) } -void NorStressTestRun(const char *prefix, int n_cycles, int do_fsx) +void NorStressTestRun(const char *prefix, int n_cycles, int do_fsx, int skip_verification) { + interleave_fsx = do_fsx; + no_verification = skip_verification; + MakeFullNames(prefix); + dump_directory_tree(fullPathName); FSX_INIT(prefix); dump_directory_tree(fullPathName);