yaffs Added another test to direct/timothy_tests/threading
[yaffs2.git] / direct / timothy_tests / threading / test_a.c
1 /*
2  * YAFFS: Yet another FFS. A NAND-flash specific file system.
3  *
4  * Copyright (C) 2002-2010 Aleph One Ltd.
5  *   for Toby Churchill Ltd and Brightstar Engineering
6  *
7  * Created by Timothy Manning <timothy@yaffs.net>
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 #include "test_a.h"
15
16
17
18
19
20 void test_a(void *x)
21 {
22         struct bovver_context *bc = (struct bovver_context *)x;
23
24         int i;
25         int op;
26         int pos;
27         int n;
28         int n1;
29         
30         char name[200];
31         char name1[200];
32         
33         int start_op;
34         
35         
36         i = rand() % BOVVER_HANDLES;
37         op = rand() % bc->opMax;
38         pos = rand() & 20000000;
39         n = rand() % 100;
40         n1 = rand() % 100;
41         
42         start_op = op;
43                 
44         sprintf(name, "%s/xx%d",bc->baseDir,n);
45         sprintf(name1,"%s/xx%d",bc->baseDir,n1);
46
47         bc->op = op;
48         bc->cycle++;
49         
50         op-=1;
51         if(op < 0){
52                 if(bc->h[i]>= 0){
53                         yaffs_close(bc->h[i]);
54                         bc->h[i] = -1;
55                 }
56                 return;
57         }
58
59         op-=1;
60         if(op < 0){
61                 if(bc->h[i] < 0)
62                         bc->h[i] = yaffs_open(name,O_CREAT| O_RDWR, 0666);
63                 return;
64         }
65
66         op-=5;
67         if(op< 0){
68                 yaffs_lseek(bc->h[i],pos,SEEK_SET);
69                 yaffs_write(bc->h[i],name,n);
70                 return;
71         }
72
73         op-=1;
74         if(op < 0){
75                 yaffs_unlink(name);
76                 return;
77         }
78         op-=1;
79         if(op < 0){
80                 yaffs_rename(name,name1);
81                 return;
82         }
83         op-=1;
84         if(op < 0){
85                 yaffs_mkdir(name,0666);
86                 return;
87         }
88         op-=1;
89         if(op < 0){
90                 yaffs_rmdir(name);
91                 return;
92         }
93
94         bc->opMax = (start_op - op -1);
95         
96         return;         
97         
98 }
99