Add a test for problem reported by Stephane stephanetest
authorCharles Manning <cdhmanning@gmail.com>
Fri, 1 Jun 2012 00:05:19 +0000 (12:05 +1200)
committerCharles Manning <cdhmanning@gmail.com>
Fri, 1 Jun 2012 00:05:19 +0000 (12:05 +1200)
Signed-off-by: Charles Manning <cdhmanning@gmail.com>
direct/basic-test/Makefile
direct/basic-test/stephanetest.c [new file with mode: 0644]

index 026c0b83c55297de59a4be9c8f9bb5b1c948cfe0..3d883b6be613c95d9624bd887cae53af3708c954 100644 (file)
@@ -75,12 +75,13 @@ YAFFSDIRECTSYMLINKS = \
 
 
 DIRECTTESTOBJS = $(COMMONTESTOBJS) dtest.o
+STEPHANETESTOBJS = $(COMMONTESTOBJS) stephanetest.o
 
 BOOTTESTOBJS = bootldtst.o yboot.o yaffs_fileem.o nand_ecc.o
 
-ALLOBJS = $(sort $(DIRECTTESTOBJS) $(YAFFSTESTOBJS))
+ALLOBJS = $(sort $(DIRECTTESTOBJS) $(YAFFSTESTOBJS)$(STEPHANETESTOBJS))
 
-TARGETS = directtest2k
+TARGETS = directtest2k stephanetest
 
 all: $(TARGETS)
 
@@ -92,6 +93,9 @@ $(YAFFSDIRECTSYMLINKS):
        ln -s ../$@ $@
 
 
+stephanetest: $(YAFFSDIRECTSYMLINKS) $(STEPHANETESTOBJS)
+       gcc -o $@ $(STEPHANETESTOBJS)
+
 directtest2k: $(YAFFSDIRECTSYMLINKS) $(DIRECTTESTOBJS)
        gcc -o $@ $(DIRECTTESTOBJS)
 
diff --git a/direct/basic-test/stephanetest.c b/direct/basic-test/stephanetest.c
new file mode 100644 (file)
index 0000000..87dc922
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ * YAFFS: Yet another FFS. A NAND-flash specific file system.
+ *
+ * Copyright (C) 2002-2011 Aleph One Ltd.
+ *   for Toby Churchill Ltd and Brightstar Engineering
+ *
+ * Created by Charles Manning <charles@aleph1.co.uk>
+ *
+ * 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 <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <time.h>
+
+#include "yaffsfs.h"
+
+
+const char *mp="yaffs2";
+const char *fn = "yaffs2/fn";
+
+
+void run_step(int test_type)
+{
+       int fd;
+       int n;
+       struct yaffs_stat s;
+       unsigned char x;
+       int i;
+
+       printf("\n\n\nTest type %d\n", test_type);
+
+       switch(test_type) {
+       case 0:
+       case 1:
+               printf("Regular mount\n");
+               yaffs_mount(mp);
+               break;
+       case 2:
+               printf("mount ro checkpt\n");
+               yaffs_mount_common(mp, 1, 0);
+               break;
+       case 3:
+               printf("mount ro no-checkpt\n");
+               yaffs_mount_common(mp, 1, 1);
+               break;
+       }
+
+       if(test_type < 2) {
+               if(test_type == 0)
+                       fd = yaffs_open(fn, O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE);
+               else
+                       fd = yaffs_open(fn, O_CREAT | O_RDWR | O_APPEND, S_IREAD | S_IWRITE);
+
+               if(fd <0) {
+                       printf("open failed\n");
+                       exit(1);
+               }
+               n = yaffs_write(fd, "foo bar ", 8);
+               printf("write returned %d\n", n);
+               yaffs_close(fd);
+       }
+
+       n = yaffs_stat(fn, &s);
+       if(n < 0)
+               printf("yaffs_stat returned %d\n", n);
+
+       printf("file length %d\n", (int)s.st_size);
+
+       fd = yaffs_open(fn, O_RDONLY, 0);
+
+       for(i = 0; i < (int)s.st_size; i++) {
+               yaffs_read(fd, &x, 1);
+               printf("[%02x]", x);
+       }
+       printf("\n");
+
+       yaffs_close(fd);
+
+       n = yaffs_unmount(mp);
+
+       printf("unmount returned %d\n", n);
+}
+
+
+int random_seed;
+int simulate_power_failure;
+
+int main(int argc, char *argv[])
+{
+       yaffs_start_up();
+       run_step(0);
+       run_step(1);
+       run_step(2);
+       run_step(3);
+
+}