changeset 167:d6bcfc56f939

Add more test harness stuff
author charles
date Mon, 13 Nov 2006 07:16:37 +0000
parents ed9d8be64cde
children da300036f023
files direct/dtest.c direct/yaffs_fileem2k.c
diffstat 2 files changed, 131 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/direct/dtest.c
+++ b/direct/dtest.c
@@ -1791,6 +1791,81 @@ void multi_mount_test(const char *mountp
 }
 
 
+void small_mount_test(const char *mountpt,int nmounts)
+{
+
+	char a[30];
+	char b[30];
+	char c[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);
+	}
+}
+
+
 void yaffs_touch(const char *fn)
 {
 	yaffs_chmod(fn, S_IREAD | S_IWRITE);
@@ -1996,7 +2071,7 @@ int main(int argc, char *argv[])
 	 
 	 //scan_pattern_test("/flash",10000,10);
 	//short_scan_test("/flash/flash",40000,200);
-	  multi_mount_test("/flash/flash",1000);
+	  small_mount_test("/flash/flash",1000);
 	 //checkpoint_fill_test("/flash/flash",20);
 	 //checkpoint_upgrade_test("/flash/flash",20);
 	 // huge_array_test("/flash/flash",10);
--- a/direct/yaffs_fileem2k.c
+++ b/direct/yaffs_fileem2k.c
@@ -32,7 +32,7 @@ const char *yaffs_flashif_c_version = "$
 #include "yaffs_fileem2k.h"
 #include "yaffs_packedtags2.h"
 
-#define SIMULATE_FAILURES
+//#define SIMULATE_FAILURES
 
 typedef struct 
 {
@@ -61,6 +61,10 @@ static yflash_Device filedisk;
 int yaffs_testPartialWrite = 0;
 
 
+
+
+static __u8 localBuffer[PAGE_SIZE];
+
 static char *NToName(char *buf,int n)
 {
 	sprintf(buf,"emfile%d",n);
@@ -144,6 +148,9 @@ int yflash_WriteChunkWithTagsToNAND(yaff
 	int written;
 	int pos;
 	int h;
+	int i;
+	int nRead;
+	int error;
 	
 	T(YAFFS_TRACE_MTD,(TSTR("write chunk %d data %x tags %x" TENDSTR),chunkInNAND,(unsigned)data, (unsigned)tags));
 
@@ -157,7 +164,23 @@ int yflash_WriteChunkWithTagsToNAND(yaff
 		h = filedisk.handle[(chunkInNAND / (PAGES_PER_BLOCK * BLOCKS_PER_HANDLE))];
 		
 		lseek(h,pos,SEEK_SET);
-		written = write(h,data,dev->nDataBytesPerChunk);
+		nRead =  read(h, localBuffer,dev->nDataBytesPerChunk);
+		for(i = error = 0; i < dev->nDataBytesPerChunk && !error; i++){
+			if(localBuffer[i] != 0xFF){
+				printf("nand simulation: chunk %d data byte %d was %0x2\n",
+					chunkInNAND,i,localBuffer[i]);
+				error = 1;
+			}
+		}
+		
+		for(i = 0; i < dev->nDataBytesPerChunk; i++)
+		  localBuffer[i] &= data[i];
+		  
+		if(memcmp(localBuffer,data,dev->nDataBytesPerChunk))
+			printf("nand simulator: data does not match\n");
+			
+		lseek(h,pos,SEEK_SET);
+		written = write(h,localBuffer,dev->nDataBytesPerChunk);
 		
 		if(yaffs_testPartialWrite){
 			close(h);
@@ -182,6 +205,7 @@ int yflash_WriteChunkWithTagsToNAND(yaff
 		h = filedisk.handle[(chunkInNAND / (PAGES_PER_BLOCK * BLOCKS_PER_HANDLE))];
 		
 		lseek(h,pos,SEEK_SET);
+
 		if( 0 && dev->isYaffs2)
 		{
 			
@@ -192,8 +216,26 @@ int yflash_WriteChunkWithTagsToNAND(yaff
 		{
 			yaffs_PackedTags2 pt;
 			yaffs_PackTags2(&pt,tags);
+			__u8 * ptab = (__u8 *)&pt;
 
-			written = write(h,&pt,sizeof(pt));
+			nRead = read(h,localBuffer,sizeof(pt));
+			for(i = error = 0; i < sizeof(pt) && !error; i++){
+				if(localBuffer[i] != 0xFF){
+					printf("nand simulation: chunk %d oob byte %d was %0x2\n",
+						chunkInNAND,i,localBuffer[i]);
+						error = 1;
+				}
+			}
+		
+			for(i = 0; i < sizeof(pt); i++)
+			  localBuffer[i] &= ptab[i];
+			 
+			if(memcmp(localBuffer,&pt,sizeof(pt)))
+				printf("nand sim: tags corruption\n");
+				
+			lseek(h,pos,SEEK_SET);
+			
+			written = write(h,localBuffer,sizeof(pt));
 			if(written != sizeof(pt)) return YAFFS_FAIL;
 		}
 	}
@@ -218,6 +260,8 @@ int yaffs_CheckAllFF(const __u8 *ptr, in
 static int fail300 = 1;
 static int fail320 = 1;
 
+static int failRead10 = 2;
+
 int yflash_ReadChunkWithTagsFromNAND(yaffs_Device *dev,int chunkInNAND, __u8 *data, yaffs_ExtendedTags *tags)
 {
 	int nread;
@@ -238,6 +282,7 @@ int yflash_ReadChunkWithTagsFromNAND(yaf
 		lseek(h,pos,SEEK_SET);
 		nread = read(h,data,dev->nDataBytesPerChunk);
 		
+		
 		if(nread != dev->nDataBytesPerChunk) return YAFFS_FAIL;
 	}
 	
@@ -280,6 +325,11 @@ int yflash_ReadChunkWithTagsFromNAND(yaf
 			    }
 			}
 #endif
+			if(failRead10>0 && chunkInNAND == 10){
+				failRead10--;
+				nread = 0;
+			}
+			
 			if(nread != sizeof(pt)) return YAFFS_FAIL;
 		}
 	}
@@ -319,6 +369,8 @@ int yflash_EraseBlockInNAND(yaffs_Device
 		
 	CheckInit();
 	
+	printf("erase block %d\n",blockNumber);
+	
 	if(blockNumber == 320)
 		fail320 = 1;