Add a test for problem reported by Stephane
[yaffs2.git] / direct / basic-test / stephanetest.c
1 /*
2  * YAFFS: Yet another FFS. A NAND-flash specific file system.
3  *
4  * Copyright (C) 2002-2011 Aleph One Ltd.
5  *   for Toby Churchill Ltd and Brightstar Engineering
6  *
7  * Created by Charles Manning <charles@aleph1.co.uk>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 2 as
11  * published by the Free Software Foundation.
12  */
13
14
15 #include <stdio.h>
16 #include <string.h>
17 #include <unistd.h>
18 #include <fcntl.h>
19 #include <time.h>
20
21 #include "yaffsfs.h"
22
23
24 const char *mp="yaffs2";
25 const char *fn = "yaffs2/fn";
26
27
28 void run_step(int test_type)
29 {
30         int fd;
31         int n;
32         struct yaffs_stat s;
33         unsigned char x;
34         int i;
35
36         printf("\n\n\nTest type %d\n", test_type);
37
38         switch(test_type) {
39         case 0:
40         case 1:
41                 printf("Regular mount\n");
42                 yaffs_mount(mp);
43                 break;
44         case 2:
45                 printf("mount ro checkpt\n");
46                 yaffs_mount_common(mp, 1, 0);
47                 break;
48         case 3:
49                 printf("mount ro no-checkpt\n");
50                 yaffs_mount_common(mp, 1, 1);
51                 break;
52         }
53
54         if(test_type < 2) {
55                 if(test_type == 0)
56                         fd = yaffs_open(fn, O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE);
57                 else
58                         fd = yaffs_open(fn, O_CREAT | O_RDWR | O_APPEND, S_IREAD | S_IWRITE);
59
60                 if(fd <0) {
61                         printf("open failed\n");
62                         exit(1);
63                 }
64                 n = yaffs_write(fd, "foo bar ", 8);
65                 printf("write returned %d\n", n);
66                 yaffs_close(fd);
67         }
68
69         n = yaffs_stat(fn, &s);
70         if(n < 0)
71                 printf("yaffs_stat returned %d\n", n);
72
73         printf("file length %d\n", (int)s.st_size);
74
75         fd = yaffs_open(fn, O_RDONLY, 0);
76
77         for(i = 0; i < (int)s.st_size; i++) {
78                 yaffs_read(fd, &x, 1);
79                 printf("[%02x]", x);
80         }
81         printf("\n");
82
83         yaffs_close(fd);
84
85         n = yaffs_unmount(mp);
86
87         printf("unmount returned %d\n", n);
88 }
89
90
91 int random_seed;
92 int simulate_power_failure;
93
94 int main(int argc, char *argv[])
95 {
96         yaffs_start_up();
97         run_step(0);
98         run_step(1);
99         run_step(2);
100         run_step(3);
101
102 }