summaryrefslogtreecommitdiff
path: root/direct
diff options
context:
space:
mode:
authorCharles Manning <cdhmanning@gmail.com>2011-01-07 14:22:56 +1300
committerCharles Manning <cdhmanning@gmail.com>2011-01-07 14:22:56 +1300
commitae68942c23ba444fc820519ac25865ab38edc3c5 (patch)
treec7d05e45e9aabe9cbda830476ec689e8a0e3b84f /direct
parent5907bcd9553ddbddfbfbf116193834a3f444c70b (diff)
parentcaf4f0d199647715e398aa87ad4b35dd26413c92 (diff)
Merge branch 'master' of ssh://www.aleph1.co.uk/home/aleph1/git/yaffs2
Diffstat (limited to 'direct')
-rwxr-xr-xdirect/python/yaffs_browser.py28
-rwxr-xr-xdirect/timothy_tests/linux_tests/mkdir_linkbin0 -> 7262 bytes
-rw-r--r--direct/timothy_tests/linux_tests/mkdir_link.c18
-rw-r--r--direct/timothy_tests/linux_tests/mkdir_link.h0
-rwxr-xr-xdirect/timothy_tests/linux_tests/renamebin0 -> 7220 bytes
-rw-r--r--direct/timothy_tests/linux_tests/rename.c17
-rw-r--r--direct/timothy_tests/linux_tests/rename.h0
-rw-r--r--direct/timothy_tests/mirror_tests/Makefile3
-rw-r--r--direct/timothy_tests/mirror_tests/README.txt24
-rw-r--r--direct/timothy_tests/mirror_tests/current_bugs.txt4
-rw-r--r--direct/timothy_tests/mirror_tests/lib.c31
-rw-r--r--direct/timothy_tests/mirror_tests/lib.h6
-rw-r--r--direct/timothy_tests/mirror_tests/linux_test_write.c37
-rw-r--r--direct/timothy_tests/mirror_tests/linux_test_write.h27
-rw-r--r--direct/timothy_tests/mirror_tests/mirror_tests.c390
-rw-r--r--direct/timothy_tests/mirror_tests/mirror_tests.h13
-rw-r--r--direct/timothy_tests/mirror_tests/yaffs_test_write.c85
-rw-r--r--direct/timothy_tests/mirror_tests/yaffs_test_write.h27
-rw-r--r--direct/timothy_tests/quick_tests/quick_tests.c40
-rw-r--r--direct/timothy_tests/quick_tests/quick_tests.h1
-rw-r--r--direct/timothy_tests/threading/Makefile115
-rw-r--r--direct/timothy_tests/threading/lib.c42
-rw-r--r--direct/timothy_tests/threading/lib.h38
-rw-r--r--direct/timothy_tests/threading/test_a.c99
-rw-r--r--direct/timothy_tests/threading/test_a.h22
-rw-r--r--direct/timothy_tests/threading/test_b.c39
-rw-r--r--direct/timothy_tests/threading/test_b.h21
-rw-r--r--direct/timothy_tests/threading/thread_function.c70
-rw-r--r--direct/timothy_tests/threading/thread_function.h28
-rw-r--r--direct/timothy_tests/threading/threading.c80
-rw-r--r--direct/timothy_tests/threading/threading.h24
31 files changed, 1221 insertions, 108 deletions
diff --git a/direct/python/yaffs_browser.py b/direct/python/yaffs_browser.py
index effe5a3..462038d 100755
--- a/direct/python/yaffs_browser.py
+++ b/direct/python/yaffs_browser.py
@@ -16,6 +16,7 @@ import Tkinter as tk
from yaffsfs import *
#import examples
import ctypes
+from operator import itemgetter
yaffs_start_up()
yaffs_mount("/yaffs2/")
@@ -105,9 +106,21 @@ def load_dir():
name_list_box.delete(0, tk.END)
current_directory_dict=yaffs_ls(mount_list_text_variable.get())
print "new directory", current_directory_dict
+
+
+
##copy directory into file box
for x in range(0,len(current_directory_dict)):
- name_list_box.insert(x,(current_directory_dict[x]["inodes"]+" "+ current_directory_dict[x]["type"]+" "+ current_directory_dict[x]["size"]+" "+ current_directory_dict[x]["path"]+" "+current_directory_dict[x]["extra_data"]))
+ permissions_string=""
+ if current_directory_dict[x]["permissions"] & yaffs_S_IREAD:
+ permissions_string ='r'
+ else :
+ permissions_string ='-'
+ if current_directory_dict[x]["permissions"] & yaffs_S_IWRITE:
+ permissions_string+='w'
+ else :
+ permissions_string+='-'
+ name_list_box.insert(x,(current_directory_dict[x]["inodes"]+" "+permissions_string+" "+ current_directory_dict[x]["type"]+" "+ current_directory_dict[x]["size"]+" "+ current_directory_dict[x]["path"]+" "+current_directory_dict[x]["extra_data"]))
name_list_box.grid(column=0, row=1)
return current_directory_dict
@@ -193,20 +206,21 @@ def yaffs_ls(dname):
fullname = dname + se.d_name
st = yaffs_stat_struct()
result = yaffs_lstat(fullname,byref(st))
- perms = st.st_mode & 0777
+ #perms = st.st_mode & 0777
+ perms = st.st_mode
ftype = st.st_mode & yaffs_S_IFMT
isFile = True if ftype == yaffs_S_IFREG else False
isDir = True if ftype == yaffs_S_IFDIR else False
isSymlink= True if ftype == yaffs_S_IFLNK else False
if isFile :
- ls_dict.append ({"type" :"file", "inodes" : str(se.d_ino), "permissions" : str(hex(perms)), "size": str(st.st_size), "path": fullname,"extra_data":""})
+ ls_dict.append ({"type" :"file", "inodes" : str(se.d_ino), "permissions" : perms, "size": str(st.st_size), "path": fullname,"extra_data":""})
print "file st.st_mode:", st.st_mode
elif isDir :
print "dir st.st_mode:", st.st_mode
- ls_dict.append({"type":"dir", "inodes" :str(se.d_ino), "permissions":str( hex(perms)),"size":"0", "path": fullname+"/", "extra_data":""})
+ ls_dict.append({"type":"dir", "inodes" :str(se.d_ino), "permissions":perms,"size":"0", "path": fullname+"/", "extra_data":""})
elif isSymlink:
print "symlink st.st_mode:", st.st_mode
file_contents=ctypes.create_string_buffer(30)
@@ -217,14 +231,14 @@ def yaffs_ls(dname):
print "string", string, "###"
- ls_dict.append ({"type" :"link", "inodes" : str(se.d_ino), "permissions" : str(hex(perms)), "size": str(st.st_size), "path": fullname, "extra_data":"> "+string})
+ ls_dict.append ({"type" :"link", "inodes" : str(se.d_ino), "permissions" : perms, "size": str(st.st_size), "path": fullname, "extra_data":"> "+string})
else :
print "unknown st.st_mode:", st.st_mode
- ls_dict.append({ "type":"Other", "inodes":str(se.d_ino), "permissions":str( hex(perms)), "size":"0", "path": fullname,"extra_data":""})
+ ls_dict.append({ "type":"Other", "inodes":str(se.d_ino), "permissions":perms, "size":"0", "path": fullname,"extra_data":""})
sep = yaffs_readdir(dc)
yaffs_closedir(dc)
- return ls_dict
+ return sorted(ls_dict,key=itemgetter("path"))
else:
print "Could not open directory"
return -1
diff --git a/direct/timothy_tests/linux_tests/mkdir_link b/direct/timothy_tests/linux_tests/mkdir_link
new file mode 100755
index 0000000..7f92f37
--- /dev/null
+++ b/direct/timothy_tests/linux_tests/mkdir_link
Binary files differ
diff --git a/direct/timothy_tests/linux_tests/mkdir_link.c b/direct/timothy_tests/linux_tests/mkdir_link.c
new file mode 100644
index 0000000..d466958
--- /dev/null
+++ b/direct/timothy_tests/linux_tests/mkdir_link.c
@@ -0,0 +1,18 @@
+#include <stdio.h>
+#include <errno.h>
+
+
+int main()
+{
+ int output=0;
+ int error_code =0 ;
+ output =symlink("timothy/home/tests/new_dir" "timothy/home/test/new_dir_link");
+ output=mkdir("timothy/home/test/new_dir_link" );
+ printf("output %d\n",output);
+ if (output <0 ) {
+ error_code = errno;
+ printf("error code %d\n",error_code);
+ printf("Error description is : %s\n",strerror(errno));
+ }
+ return 0;
+}
diff --git a/direct/timothy_tests/linux_tests/mkdir_link.h b/direct/timothy_tests/linux_tests/mkdir_link.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/direct/timothy_tests/linux_tests/mkdir_link.h
diff --git a/direct/timothy_tests/linux_tests/rename b/direct/timothy_tests/linux_tests/rename
new file mode 100755
index 0000000..a168978
--- /dev/null
+++ b/direct/timothy_tests/linux_tests/rename
Binary files differ
diff --git a/direct/timothy_tests/linux_tests/rename.c b/direct/timothy_tests/linux_tests/rename.c
new file mode 100644
index 0000000..9c40c2f
--- /dev/null
+++ b/direct/timothy_tests/linux_tests/rename.c
@@ -0,0 +1,17 @@
+#include <stdio.h>
+#include <errno.h>
+
+
+int main()
+{
+ int output=0;
+ int error_code =0 ;
+ output=rename( "/home/timothy/test/cat/","/home/timothy/test/dog/");
+ printf("output %d\n",output);
+ if (output <0 ) {
+ error_code = errno;
+ printf("error code %d\n",error_code);
+ printf("Error description is : %s\n",strerror(errno));
+ }
+ return 0;
+}
diff --git a/direct/timothy_tests/linux_tests/rename.h b/direct/timothy_tests/linux_tests/rename.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/direct/timothy_tests/linux_tests/rename.h
diff --git a/direct/timothy_tests/mirror_tests/Makefile b/direct/timothy_tests/mirror_tests/Makefile
index 4362cd9..8d74acf 100644
--- a/direct/timothy_tests/mirror_tests/Makefile
+++ b/direct/timothy_tests/mirror_tests/Makefile
@@ -49,7 +49,8 @@ COMMONTESTOBJS = yaffscfg2k.o yaffs_osglue.o yaffs_hweight.o \
TESTFILES = mirror_tests.o lib.o\
linux_test_open.o yaffs_test_open.o\
linux_test_truncate.o yaffs_test_truncate.o \
- linux_test_unlink.o yaffs_test_unlink.o
+ linux_test_unlink.o yaffs_test_unlink.o \
+ linux_test_write.o yaffs_test_write.o
diff --git a/direct/timothy_tests/mirror_tests/README.txt b/direct/timothy_tests/mirror_tests/README.txt
new file mode 100644
index 0000000..1edc620
--- /dev/null
+++ b/direct/timothy_tests/mirror_tests/README.txt
@@ -0,0 +1,24 @@
+Made by Timothy Manning on 24/12/10 <timothy@yaffs.net>
+
+
+ mirror_tests is designed to check that yaffs behaves the same way as linux.
+ This is done by applying the same command to both linux and yaffs and
+ then checking the output of the functions.
+ The default place for creating linux files is direct/timothy_tests/mirror_tests/tests/
+ This directory is removed and is recreated at the beginning of each test,
+ However some of the files may be read only and cannot be deleted.
+ It is much better to remove this directory via the command line.
+
+ rm test/*;rmdir test/;./mirror_tests -n 100 -v
+
+Command line arguments
+ -yaffs_path [PATH] //sets the path for yaffs.
+ -linux_path [PATH] //sets the path for linux.
+ -p [NUMBER] //sets the print level for mirror_tests.
+ -v //verbose mode everything is printed
+ -q //quiet mode nothing is printed.
+ -n [number] //sets the number of random tests to run.
+ -s [number] //seeds rand with the number
+ -t [number] //sets yaffs_trace to the number
+ -clean //removes emfile and test dir
+
diff --git a/direct/timothy_tests/mirror_tests/current_bugs.txt b/direct/timothy_tests/mirror_tests/current_bugs.txt
index 523fd3b..8e3251a 100644
--- a/direct/timothy_tests/mirror_tests/current_bugs.txt
+++ b/direct/timothy_tests/mirror_tests/current_bugs.txt
@@ -1,3 +1,5 @@
BUGS
- In yaffs having a pathname "yaffs2/tests//.." appears to create a file called ".." unstead of going back a directory.
+ NO Bugs.
+
+
diff --git a/direct/timothy_tests/mirror_tests/lib.c b/direct/timothy_tests/mirror_tests/lib.c
index 1a9d6ac..e21e77d 100644
--- a/direct/timothy_tests/mirror_tests/lib.c
+++ b/direct/timothy_tests/mirror_tests/lib.c
@@ -22,6 +22,10 @@ void set_print_level(int new_level)
{
PRINT_LEVEL=new_level;
}
+int get_print_level(void)
+{
+ return PRINT_LEVEL;
+}
void set_exit_on_error(int num)
{
@@ -38,6 +42,33 @@ void display_error(void)
}
+void get_error_yaffs(void)
+{
+ int error_code=0;
+ char message[30];
+ message[0]='\0';
+
+ error_code=yaffs_get_error();
+ sprintf(message,"yaffs_error code %d\n",error_code);
+ print_message(1,message);
+ sprintf(message,"error is : %s\n",yaffs_error_to_str(error_code));
+ print_message(1,message);
+}
+
+void get_error_linux(void)
+{
+ int error_code=0;
+ char message[30];
+ message[0]='\0';
+
+ error_code=errno;
+ sprintf(message,"linux_error code %d\n",error_code);
+ print_message(1,message);
+ strcpy(message,"error code");
+ sprintf(message,"error is : %s\n",yaffs_error_to_str(error_code));
+ //perror(message);
+ print_message(1,message);
+}
void generate_random_string(char *ptr,int length_of_str){
unsigned int x;
unsigned int length=((rand() %(length_of_str-3))+3); /*creates a int with the number of charecters been between 1 and 51*/
diff --git a/direct/timothy_tests/mirror_tests/lib.h b/direct/timothy_tests/mirror_tests/lib.h
index 99c2763..48adc94 100644
--- a/direct/timothy_tests/mirror_tests/lib.h
+++ b/direct/timothy_tests/mirror_tests/lib.h
@@ -19,7 +19,7 @@
#include <stdio.h>
#include <string.h>
#include "yaffsfs.h"
-
+#include <errno.h>
typedef struct arg_temp2{
char char1;
@@ -44,8 +44,10 @@ void generate_random_string(char *ptr,int length_of_str);
void join_paths(char *path1,char *path2,char *new_path );
void print_message(char print_level, char *message);
void set_print_level(int new_level);
+int get_print_level(void);
void set_exit_on_error(int num);
int get_exit_on_error(void);
void display_error(void);
-
+void get_error_yaffs(void);
+void get_error_linux(void);
#endif
diff --git a/direct/timothy_tests/mirror_tests/linux_test_write.c b/direct/timothy_tests/mirror_tests/linux_test_write.c
new file mode 100644
index 0000000..9714c19
--- /dev/null
+++ b/direct/timothy_tests/mirror_tests/linux_test_write.c
@@ -0,0 +1,37 @@
+/*
+ * 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 Timothy Manning <timothy@yaffs.net>
+ *
+ * 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 "linux_test_write.h"
+
+int linux_test_write(arg_temp *args_struct)
+{
+ char path[200];
+ char message[200];
+ int output=0;
+ int handle=-1;
+ join_paths(linux_struct.root_path,args_struct->string1, path );
+ sprintf(message,"trying to write to: %s\nwith mode set to %o \n",path,args_struct->char1 );
+ print_message(3,message);
+ printf("mode S_IREAD %d S_IWRITE %d\n",(args_struct->char2 & S_IREAD),(args_struct->char2 & S_IWRITE));
+ handle=open(path,((args_struct->char1 &(O_TRUNC|O_EXCL|O_CREAT|O_APPEND))|O_RDWR),(args_struct->char2&(S_IREAD|S_IWRITE)));
+ printf("handle %d\n",handle);
+ if (handle<0){
+ print_message(3,"failed to open a handle\n");
+ return -1; //handle failed to open
+ }
+ sprintf(message,"trying to write: %d bytes into the file\n",strlen(args_struct->string2));
+ print_message(3,message);
+ output=write(handle,args_struct->string2,strlen(args_struct->string2));
+ close(handle);
+ return output;
+}
diff --git a/direct/timothy_tests/mirror_tests/linux_test_write.h b/direct/timothy_tests/mirror_tests/linux_test_write.h
new file mode 100644
index 0000000..ceb29fa
--- /dev/null
+++ b/direct/timothy_tests/mirror_tests/linux_test_write.h
@@ -0,0 +1,27 @@
+/*
+ * YAFFS: Yet another Flash File System . A NAND-flash specific file system.
+ *
+ * Copyright (C) 2002-2010 Aleph One Ltd.
+ * for Toby Churchill Ltd and Brightstar Engineering
+ *
+ * Created by Timothy Manning <timothy@yaffs.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1 as
+ * published by the Free Software Foundation.
+ *
+ * Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL.
+ */
+
+#ifndef __linux_test_write_h__
+#define __linux_test_write_h__
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include "yaffsfs.h"
+#include "lib.h"
+
+int linux_test_write(arg_temp *args_struct);
+
+#endif
diff --git a/direct/timothy_tests/mirror_tests/mirror_tests.c b/direct/timothy_tests/mirror_tests/mirror_tests.c
index 88c509f..aa9cd5b 100644
--- a/direct/timothy_tests/mirror_tests/mirror_tests.c
+++ b/direct/timothy_tests/mirror_tests/mirror_tests.c
@@ -31,26 +31,43 @@ typedef struct test_temp2 {
}test_temp;
test_temp yaffs_tests={
- 3,
+ 4,
{{"yaffs_test_open",yaffs_test_open},
{"yaffs_test_truncate",yaffs_test_truncate},
- {"yaffs_test_unlink",yaffs_test_unlink}
+ {"yaffs_test_unlink",yaffs_test_unlink},
+ {"yaffs_test_write",yaffs_test_write}
}
};
test_temp linux_tests={
- 3,
+ 4,
{{"linux_test_open",linux_test_open},
{"linux_test_truncate",linux_test_truncate},
- {"linux_test_unlink",linux_test_unlink}
+ {"linux_test_unlink",linux_test_unlink},
+ {"linux_test_write",linux_test_write}
}
};
+const struct option long_options[]={
+ {"help", 0,NULL,'h'},
+ {"yaffs_path", 1,NULL,'y'},
+ {"linux_path", 1,NULL,'l'},
+ {"print_level", 1,NULL,'p'},
+ {"quiet", 0,NULL,'q'},
+ {"number", 1,NULL,'n'},
+ {"seed", 1,NULL,'s'},
+ {"trace", 1,NULL,'t'},
+ {"clean", 0,NULL,'c'},
+ {"verbose", 0,NULL,'v'}
+};
+
+const char short_options[]="hy:l:p:qn:s:t:cv";
+
int main(int argc, char *argv[])
{
char message[100];
- int x;
+
// yaffs_tests.num_of_tests=(sizeof(yaffs_tests)/sizeof(test_temp));
// linux_tests.num_of_tests=(sizeof(linux_tests)/sizeof(test_temp));
@@ -66,7 +83,7 @@ int main(int argc, char *argv[])
print_message(3,message);
run_random_test(num_of_random_tests);
- compare_linux_and_yaffs();
+ //compare_linux_and_yaffs();
yaffs_unmount("yaffs2");
return 0;
}
@@ -77,8 +94,12 @@ void init(int argc, char *argv[])
dir[0]='\0';
int x=-1;
char message[100];
+ int new_option;
- srand((unsigned)time(NULL));
+ x=(unsigned)time(NULL);
+ sprintf(message,"seeding srand with: %d\n",x);
+ print_message(2,message);
+ srand(x);
yaffs_set_trace(0);
linux_struct.type_of_test =LINUX;
yaffs_struct.type_of_test =YAFFS;
@@ -93,8 +114,9 @@ void init(int argc, char *argv[])
strcpy(yaffs_struct.root_path,"yaffs2/test/");
- for (x=0;x<argc;x++){
- if (strcmp(argv[x],"-h")==0){
+ do {
+ new_option=getopt_long(argc,argv,short_options,long_options,NULL);
+ if (new_option=='h'){
printf("mirror_tests help\n");
printf("arguments:\n");
printf("\t-yaffs_path [PATH] //sets the path for yaffs.\n");
@@ -107,27 +129,33 @@ void init(int argc, char *argv[])
printf("\t-t [number] //sets yaffs_trace to the number\n");
printf("\t-clean //removes emfile and test dir\n");
exit(0);
- } else if (strcmp(argv[x],"-yaffs_path")==0){
- strcpy(yaffs_struct.root_path, argv[x+1]);
- } else if (strcmp(argv[x],"-linux_path")==0){
- strcpy(linux_struct.root_path, argv[x+1]);
- } else if (strcmp(argv[x],"-p")==0){
- set_print_level(atoi(argv[x+1]));
- } else if (strcmp(argv[x],"-v")==0){
+ } else if (new_option=='y'){
+ strcpy(yaffs_struct.root_path, optarg);
+ } else if (new_option=='l'){
+ strcpy(linux_struct.root_path, optarg);
+ } else if (new_option=='p'){
+ set_print_level(atoi(optarg));
+ } else if (new_option=='v'){
set_print_level(5);
- } else if (strcmp(argv[x],"-q")==0){
+ } else if (new_option=='q'){
set_print_level(-1);
- } else if (strcmp(argv[x],"-n")==0){
- num_of_random_tests=atoi(argv[x+1]);
- } else if (strcmp(argv[x],"-s")==0){
+ } else if (new_option=='n'){
+ num_of_random_tests=atoi(optarg);
+ } else if (new_option=='s'){
srand(atoi(argv[x+1]));
- } else if (strcmp(argv[x],"-t")==0){
- yaffs_set_trace(atoi(argv[x+1]));
- } else if (strcmp(argv[x],"-clean")==0){
+ } else if (new_option=='t'){
+ yaffs_set_trace(atoi(optarg));
+ } else if (new_option=='c'){
clean_dir();
exit(0);
+ } else if (new_option==-1){
+
+ } else if (new_option=='?') {
+ printf("bad argument\n");
+ exit(0);
}
- }
+
+ } while(new_option!=-1);
clean_dir();
yaffs_start_up();
print_message(2,"\nmounting yaffs\n");
@@ -165,11 +193,11 @@ int run_random_test(int num_of_random_tests)
int x=-1;
int id=0;
int test_id=-1;
- int num_of_tests_before_check=10;
- char message[100];
+ int num_of_tests_before_check=1;
+ char message[200];
arg_temp args_struct;
for (y=0;(y*num_of_tests_before_check)<num_of_random_tests;y++){
- for (x=0;x<num_of_tests_before_check;x++) {
+ for (x=0;x<num_of_tests_before_check && (x+(y*num_of_tests_before_check)<num_of_random_tests);x++) {
errno=0;
yaffs_set_error(0);
test_id = select_test_id(yaffs_tests.num_of_tests);
@@ -177,10 +205,20 @@ int run_random_test(int num_of_random_tests)
print_message(3,message);
generate_random_numbers(&args_struct);
run_yaffs_test(test_id, &args_struct);
+
+ //check_mode(&args_struct);
+
run_linux_test(test_id, &args_struct);
+
+ if (get_print_level()>=4){
+ get_error_yaffs();
+ get_error_linux();
+ }
+
if ((abs(yaffs_get_error())!=abs(errno)) &&
(abs(yaffs_get_error())!=EISDIR && abs(errno) != 0) &&
- (abs(yaffs_get_error())!=ENOENT && abs(errno) != EACCES)
+ (abs(yaffs_get_error())!=ENOENT && abs(errno) != EACCES)&&
+ (abs(yaffs_get_error())!=EINVAL && abs(errno) != EBADF)
){
print_message(2,"\ndifference in returned errors######################################\n");
get_error_yaffs();
@@ -189,9 +227,13 @@ int run_random_test(int num_of_random_tests)
exit(0);
}
}
- }
- compare_linux_and_yaffs();
+ }
+ //check_mode(&args_struct);
+ compare_linux_and_yaffs(&args_struct);
+ //check_mode(&args_struct);
+
}
+ compare_linux_and_yaffs(&args_struct);
}
int select_test_id(int test_len)
@@ -204,53 +246,253 @@ int select_test_id(int test_len)
}
-int compare_linux_and_yaffs(void)
+int check_mode(arg_temp *args_struct)
{
- int x=0;
+ char path[200];
+ char message[200];
+ int output=0;
+
+ struct yaffs_stat yaffs_stat_struct;
+ join_paths(yaffs_struct.root_path,args_struct->string1, path );
+ sprintf(message,"\ntrying to stat to: %s\n",path);
+ print_message(3,message);
+ output=yaffs_stat(path,&yaffs_stat_struct);
+ if (output < 0){
+ sprintf(message,"failed to stat the file\n");
+ print_message(3,message);
+ get_error_yaffs();
+ } else {
+ sprintf(message,"stated the file\n");
+ print_message(3,message);
+ sprintf(message," yaffs file mode is %d\n",(yaffs_stat_struct.st_mode & (S_IREAD| S_IWRITE)));
+ print_message(3,message);
+ sprintf(message,"mode S_IREAD %d S_IWRITE %d\n",(yaffs_stat_struct.st_mode & S_IREAD),(yaffs_stat_struct.st_mode & S_IWRITE));
+ print_message(3,message);
+ }
+ return 1;
+}
+
+int check_mode_file(char *path)
+{
+ char message[200];
+ int output=0;
+
+ struct yaffs_stat yaffs_stat_struct;
+
+ sprintf(message,"\ntrying to stat to: %s\n",path);
+ print_message(3,message);
+ output=yaffs_stat(path,&yaffs_stat_struct);
+ if (output < 0){
+ sprintf(message,"failed to stat the file\n");
+ print_message(3,message);
+ get_error_yaffs();
+ } else {
+ sprintf(message,"stated the file\n");
+ print_message(3,message);
+ sprintf(message," yaffs file mode is %d\n",(yaffs_stat_struct.st_mode & (S_IREAD| S_IWRITE)));
+ print_message(3,message);
+ sprintf(message,"mode S_IREAD %d S_IWRITE %d\n\n",(yaffs_stat_struct.st_mode & S_IREAD),(yaffs_stat_struct.st_mode & S_IWRITE));
+ print_message(3,message);
+ }
+ return 1;
+}
+
+int compare_linux_and_yaffs(arg_temp *args_struct)
+{
+ int x=0,y=0;
+ char l_path[200];
+ char y_path[200];
+ char file_name[200];
+ int exit_bool=0;
+ int number_of_files_in_yaffs=0;
+ int number_of_files_in_linux=0;
+ char message[200];
+ char **yaffs_file_list=NULL;
+ char **linux_file_list=NULL;
+
+ struct yaffs_stat yaffs_stat_struct;
+ struct stat linux_stat_struct;
yaffs_DIR *yaffs_open_dir;
yaffs_dirent *yaffs_current_file;
DIR *linux_open_dir;
struct dirent *linux_current_file;
-
+
+ l_path[0]='\0';
+ y_path[0]='\0';
+ file_name[0]='\0';
+ message[0]='\0';
+ print_message(2,"\n\n\n comparing folders\n");
+// check_mode_file("yaffs2/test/YY");
+ //find out the number of files in the directory
yaffs_open_dir = yaffs_opendir(yaffs_struct.root_path);
if (yaffs_open_dir) {
- for (x=0;NULL!=yaffs_readdir(yaffs_open_dir);x++){}
- printf("number of files in yaffs dir= %d\n",x);
-
- char yaffs_file_list[x][100];
+ for (x=0;yaffs_readdir(yaffs_open_dir);x++){}
+ number_of_files_in_yaffs=x;
+ sprintf(message,"number of files in yaffs dir= %d\n",number_of_files_in_yaffs);
+ print_message(2,message);
yaffs_rewinddir(yaffs_open_dir);
-
- for (x=0 ;NULL!=yaffs_current_file;x++)
+ } else {
+ print_message(3,"failed to open yaffs test dir\n");
+ }
+ //create array
+ yaffs_file_list= (char **)malloc(x*sizeof(char*));
+ for (x=0;x<number_of_files_in_yaffs;x++) {
+ yaffs_file_list[x]=malloc(200);
+ }
+
+ //check_mode_file("yaffs2/test/YY");
+ //copy file names into array
+ if (yaffs_open_dir){
+ yaffs_current_file =yaffs_readdir(yaffs_open_dir);
+ for (x=0 ;yaffs_current_file;x++)
{
- yaffs_current_file =yaffs_readdir(yaffs_open_dir);
- if (NULL!=yaffs_current_file){
+ printf("x= %d \n",x);
+ printf("yaffs_current_file->d_name = %s\n",yaffs_current_file->d_name);
+ if (yaffs_current_file){
strcpy(yaffs_file_list[x],yaffs_current_file->d_name);
+
}
+ yaffs_current_file =yaffs_readdir(yaffs_open_dir);
}
+ yaffs_closedir(yaffs_open_dir);
+ } else {
+ print_message(3,"failed to populate yaffs test list\n");
}
+
+ //find out the number of files in the directory
linux_open_dir = opendir(linux_struct.root_path);
if (linux_open_dir){
- for (x=0;NULL!=readdir(linux_open_dir);x++){}
- printf("number of files in linux dir= %d\n",(x-2));
+ for (x=0;readdir(linux_open_dir);x++){}
+ number_of_files_in_linux=(x-2);
+ sprintf(message,"number of files in linux dir= %d\n",(number_of_files_in_linux));
+ print_message(2,message);
//the -2 is because linux shows 2 extra files which are automaticly created.
- char linux_file_list[x][100];
+ rewinddir(linux_open_dir);
+ } else {
+ print_message(3,"failed to open linux test dir\n");
+ }
+
+ //create array
+ linux_file_list= (char **)malloc(number_of_files_in_linux*sizeof(char*));
- for (x=0 ;NULL!=linux_current_file;x++)
+ for (x=0;x<number_of_files_in_linux;x++) {
+ linux_file_list[x]=malloc(200);
+ }
+
+ //check_mode_file("yaffs2/test/YY");
+ //copy file names into array
+ if (linux_open_dir){
+ linux_current_file =readdir(linux_open_dir);
+ for (x=0, y=0 ;linux_current_file;x++)
{
+
+ if (linux_current_file){
+ strcpy(message,linux_current_file->d_name);
+ print_message(7,"opened file: ");
+ print_message(7,message);
+ print_message(7,"\n");
+ }
+ if (linux_current_file &&
+ 0!=strcmp(message,".")&&
+ 0!=strcmp(message,"..")){
+ strcpy(file_name,linux_current_file->d_name);
+ //sprintf("file opened: %s\n",linux_current_file->d_name);
+ //print_message(3,message);
+ print_message(7,"added file to list\n");
+ strcpy(linux_file_list[y],file_name);
+ sprintf(message,"file added to list: %s\n",linux_file_list[y]);
+ print_message(7,message);
+ y++;
+ }
linux_current_file =readdir(linux_open_dir);
- if (NULL!=linux_current_file){
- strcpy(linux_file_list[x],linux_current_file->d_name);
+ }
+ closedir(linux_open_dir);
+ } else {
+ print_message(3,"failed to populate linux test dir\n");
+ }
+
+
+ //match the files in both folders
+ for (x=0;x<number_of_files_in_yaffs;x++){
+ sprintf(message,"\nsearching for yaffs file: %s\n",yaffs_file_list[x]);
+ print_message(3,message);
+ for (y=0;y<number_of_files_in_linux;y++){
+ sprintf(message,"comparing to linux file: %s\n",linux_file_list[y]);
+ print_message(7,message);
+
+ if (0==strcmp(yaffs_file_list[x],linux_file_list[y])){
+ sprintf(message,"file matched: %s\n",linux_file_list[y]);
+ print_message(3,message);
+ //check that the modes of both files are the same
+ join_paths(yaffs_struct.root_path,yaffs_file_list[x],y_path);
+ join_paths(linux_struct.root_path,linux_file_list[y],l_path);
+ if (yaffs_stat(y_path,&yaffs_stat_struct)>=0&&
+ stat(l_path,&linux_stat_struct)>=0){
+ sprintf(message," yaffs file mode is %d\n",(yaffs_stat_struct.st_mode & (S_IREAD| S_IWRITE)));
+ print_message(3,message);
+ sprintf(message,"mode S_IREAD %d S_IWRITE %d\n",(yaffs_stat_struct.st_mode & S_IREAD),(yaffs_stat_struct.st_mode & S_IWRITE));
+ print_message(3,message);
+ sprintf(message," linux file mode is %d\n",(linux_stat_struct.st_mode & (S_IREAD|S_IWRITE)));
+ print_message(3,message);
+ sprintf(message,"mode S_IREAD %d S_IWRITE %d\n",(linux_stat_struct.st_mode & S_IREAD),(linux_stat_struct.st_mode & S_IWRITE));
+ print_message(3,message);
+ if ((yaffs_stat_struct.st_mode & (S_IREAD| S_IWRITE))==
+ ( linux_stat_struct.st_mode & (S_IREAD|S_IWRITE))){
+ print_message(2,"file modes match\n");
+ } else {
+ print_message(2,"file modes do not match\n");
+ exit_bool=1;
+ }
+ linux_file_list[y][0]=NULL;
+ yaffs_file_list[x][0]=NULL;
+ } else {
+ print_message(2,"failed to stat one of the files\n");
+ get_error_yaffs();
+ get_error_linux();
+ }
+
+ //read file contents
+
+
+ break;
}
}
}
+ //print remaining files
+ for (x=0;x<number_of_files_in_linux;x++){
+ if (linux_file_list[x][0]){
+ sprintf(message,"unmatched file in linux: %s\n",linux_file_list[x]);
+ print_message(2,message);
+ exit_bool=1;
+ }
+ }
+ for (x=0;x<number_of_files_in_yaffs;x++){
+ if (yaffs_file_list[x][0]){
+ sprintf(message,"unmatched file in yaffs: %s\n",yaffs_file_list[x]);
+ print_message(2,message);
+ exit_bool=1;
+ }
+ }
+ if (exit_bool==1&& get_exit_on_error()==1){
+ print_message(2,"exiting program\n");
+ exit(0);
+ }
+
+ for (x=0;x<number_of_files_in_yaffs;x++) {
+ free(yaffs_file_list[x]);
+ }
+ free(yaffs_file_list);
+ for (x=0;x<number_of_files_in_linux;x++) {
+ free(linux_file_list[x]);
+ }
+ free(linux_file_list);
-
//printf("file_name %s\n", yaffs_current_file->d_name);
// generate_array_of_objects_in_yaffs();
// generate_array_of_objects_in_linux();
@@ -259,6 +501,7 @@ int compare_linux_and_yaffs(void)
//read the text of each file and compare them.
//show the diffrences by printing them.
+ return 1;
}
@@ -309,33 +552,6 @@ void run_linux_test(int id,arg_temp *args_struct)
}
}
-void get_error_yaffs(void)
-{
- int error_code=0;
- char message[30];
- message[0]='\0';
-
- error_code=yaffs_get_error();
- sprintf(message,"yaffs_error code %d\n",error_code);
- print_message(1,message);
- sprintf(message,"error is : %s\n",yaffs_error_to_str(error_code));
- print_message(1,message);
-}
-
-void get_error_linux(void)
-{
- int error_code=0;
- char message[30];
- message[0]='\0';
-
- error_code=errno;
- sprintf(message,"linux_error code %d\n",error_code);
- print_message(1,message);
- strcpy(message,"error code");
- sprintf(message,"error is : %s\n",yaffs_error_to_str(error_code));
- //perror(message);
- print_message(1,message);
-}
void clean_dir(void)
{
@@ -344,7 +560,7 @@ void clean_dir(void)
char message[200];
DIR *linux_open_dir;
struct dirent *linux_current_file;
- int x=0;
+ int x=0,output=0;
getcwd(string,200);
strcat(string,"/emfile-2k-0");
@@ -355,19 +571,31 @@ void clean_dir(void)
linux_open_dir = opendir(linux_struct.root_path);
if (linux_open_dir){
- for (x=0 ;NULL!=linux_current_file ;x++)
+
+ do
{
+
linux_current_file =readdir(linux_open_dir);
if (NULL!=linux_current_file){
strcpy(file,linux_struct.root_path);
strcat(file,linux_current_file->d_name);
- sprintf(message,"unlinking file %d\n",linux_current_file->d_name);
+ sprintf(message,"unlinking file %s\n",file);
print_message(3,message);
- unlink(file);
+ print_message(3,"chmoding file\n");
+ output=chmod(file,(S_IRUSR|S_IWUSR));
+ if (output<0) {
+ get_error_linux();
+ }
+ print_message(3,"unlinking file\n");
+ output=unlink(file);
+ if (output<0) {
+ get_error_linux();
+ }
}
- }
- unlink(linux_struct.root_path);
+ } while(linux_current_file);
+ closedir(linux_open_dir);
+ rmdir(linux_struct.root_path);
}
}
diff --git a/direct/timothy_tests/mirror_tests/mirror_tests.h b/direct/timothy_tests/mirror_tests/mirror_tests.h
index 208f845..31b6c14 100644
--- a/direct/timothy_tests/mirror_tests/mirror_tests.h
+++ b/direct/timothy_tests/mirror_tests/mirror_tests.h
@@ -24,7 +24,8 @@
#include "yaffsfs.h"
#include "lib.h"
#include <time.h>
-
+#include <getopt.h>
+#include <sys/stat.h>
#include "linux_test_open.h"
#include "yaffs_test_open.h"
@@ -32,6 +33,8 @@
#include "yaffs_test_truncate.h"
#include "linux_test_unlink.h"
#include "yaffs_test_unlink.h"
+#include "linux_test_write.h"
+#include "yaffs_test_write.h"
#define LINUX 1
#define YAFFS 2
@@ -42,14 +45,16 @@
void init(int argc, char *argv[]);
int run_random_test(int num_of_random_tests);
-int compare_linux_and_yaffs(void);
-void get_error_yaffs(void);
-void get_error_linux(void);
+int compare_linux_and_yaffs(arg_temp *args_struct);
+
int select_test_id(int test_len);
void generate_random_numbers(arg_temp *args_struct);
void run_yaffs_test(int id,arg_temp *args_struct);
void run_linux_test(int id,arg_temp *args_struct);
void clean_dir(void);
+int select_test_id(int test_len);
+int check_mode(arg_temp *args_struct);
+int check_mode_file(char *path);
//void generate_array_of_objects_in_yaffs(void);
//void generate_array_of_objects_in_linux(void);
diff --git a/direct/timothy_tests/mirror_tests/yaffs_test_write.c b/direct/timothy_tests/mirror_tests/yaffs_test_write.c
new file mode 100644
index 0000000..a348003
--- /dev/null
+++ b/direct/timothy_tests/mirror_tests/yaffs_test_write.c
@@ -0,0 +1,85 @@
+/*
+ * 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 Timothy Manning <timothy@yaffs.net>
+ *
+ * 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 "yaffs_test_write.h"
+
+int yaffs_test_write(arg_temp *args_struct)
+{
+ char path[200];
+ char message[200];
+ int output=0,output2=0;
+ int handle;
+ struct yaffs_stat yaffs_stat_struct;
+ join_paths(yaffs_struct.root_path,args_struct->string1, path );
+ sprintf(message,"trying to write to: %s\nwith mode set to %o \n",path,args_struct->char1);
+ print_message(3,message);
+ printf("mode S_IREAD %d S_IWRITE %d\n",(args_struct->char2 & S_IREAD),(args_struct->char2 & S_IWRITE));
+ handle=yaffs_open(path,((args_struct->char1 &(O_TRUNC|O_EXCL|O_CREAT|O_APPEND))|O_RDWR),(args_struct->char2&(S_IREAD|S_IWRITE)));
+ printf("handle %d\n",handle);
+ if (handle<0){
+ print_message(3,"failed to open a handle\n");
+ return -1; //handle failed to open
+ }
+
+/* output=yaffs_fstat(handle,&yaffs_stat_struct);
+ if (output < 0){
+ sprintf(message,"failed to stat the file\n");
+ print_message(3,message);
+ get_error_yaffs();
+ } else {
+ sprintf(message,"stated the file\n");
+ print_message(3,message);
+ sprintf(message," yaffs file mode is %d\n",(yaffs_stat_struct.st_mode & (S_IREAD| S_IWRITE)));
+ print_message(3,message);
+ sprintf(message,"mode S_IREAD %d S_IWRITE %d\n",(yaffs_stat_struct.st_mode & S_IREAD),(yaffs_stat_struct.st_mode & S_IWRITE));
+ print_message(3,message);
+ }
+
+ sprintf(message,"trying to write: %d bytes into the file\n",strlen(args_struct->string2));
+ print_message(3,message);
+*/
+ output=yaffs_write(handle,&args_struct->string2,strlen(args_struct->string2));
+
+/* print_message(3,"\n wrote to the file\n");
+ output2=yaffs_fstat(handle,&yaffs_stat_struct);
+ if (output2 < 0){
+ sprintf(message,"failed to stat the file\n");
+ print_message(3,message);
+ get_error_yaffs();
+ } else {
+ sprintf(message,"stated the file\n");
+ print_message(3,message);
+ sprintf(message," yaffs file mode is %d\n",(yaffs_stat_struct.st_mode & (S_IREAD| S_IWRITE)));
+ print_message(3,message);
+ sprintf(message,"mode S_IREAD %d S_IWRITE %d\n",(yaffs_stat_struct.st_mode & S_IREAD),(yaffs_stat_struct.st_mode & S_IWRITE));
+ print_message(3,message);
+ }
+*/ yaffs_close(handle);
+/* print_message(3,"\n closing the file\n");
+ output2=yaffs_stat(path,&yaffs_stat_struct);
+ if (output2 < 0){
+ sprintf(message,"failed to stat the file\n");
+ print_message(3,message);
+ get_error_yaffs();
+ } else {
+ sprintf(message,"stated the file\n");
+ print_message(3,message);
+ sprintf(message," yaffs file mode is %d\n",(yaffs_stat_struct.st_mode & (S_IREAD| S_IWRITE)));
+ print_message(3,message);
+ sprintf(message,"mode S_IREAD %d S_IWRITE %d\n",(yaffs_stat_struct.st_mode & S_IREAD),(yaffs_stat_struct.st_mode & S_IWRITE));
+ print_message(3,message);
+ }
+*/
+
+ return output;
+}
diff --git a/direct/timothy_tests/mirror_tests/yaffs_test_write.h b/direct/timothy_tests/mirror_tests/yaffs_test_write.h
new file mode 100644
index 0000000..3d6220e
--- /dev/null
+++ b/direct/timothy_tests/mirror_tests/yaffs_test_write.h
@@ -0,0 +1,27 @@
+/*
+ * YAFFS: Yet another Flash File System . A NAND-flash specific file system.
+ *
+ * Copyright (C) 2002-2010 Aleph One Ltd.
+ * for Toby Churchill Ltd and Brightstar Engineering
+ *
+ * Created by Timothy Manning <timothy@yaffs.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1 as
+ * published by the Free Software Foundation.
+ *
+ * Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL.
+ */
+
+#ifndef __yaffs_test_write_h__
+#define __yaffs_test_write_h__
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include "yaffsfs.h"
+#include "lib.h"
+
+int yaffs_test_write(arg_temp *args_struct);
+
+#endif
diff --git a/direct/timothy_tests/quick_tests/quick_tests.c b/direct/timothy_tests/quick_tests/quick_tests.c
index 0e34ea7..b2864a0 100644
--- a/direct/timothy_tests/quick_tests/quick_tests.c
+++ b/direct/timothy_tests/quick_tests/quick_tests.c
@@ -25,6 +25,20 @@ static unsigned int num_of_tests_pass=0;
static unsigned int num_of_tests_failed=0;
static unsigned int total_number_of_tests=(sizeof(test_list)/sizeof(test_template));
+
+const struct option long_options[]={
+ {"help", 0,NULL,'h'},
+ {"quiet", 0,NULL,'q'},
+ {"number", 1,NULL,'n'},
+ {"trace", 1,NULL,'t'},
+ {"continue", 0,NULL,'c'},
+ {"verbose", 0,NULL,'v'}
+};
+
+const char short_options[]="hqn:t:cv";
+
+
+
int main(int argc, char *argv[])
{
int x=0;
@@ -137,30 +151,32 @@ void get_error(void)
void init_quick_tests(int argc, char *argv[])
{
int trace=0;
+ int new_option;
int x=0;
- for (x = 0; x < argc; x++){
- if (0==strcmp(argv[x],"-h")){
+ do{
+ new_option=getopt_long(argc,argv,short_options,long_options,NULL);
+ if (new_option=='h'){
printf("help\n");
printf("-h will print the commands available\n");
- printf("-c will continue after a test failes else the program will exit\n");
+ printf("-c will continue after a test fails else the program will exit\n");
printf("-v will print all messages\n");
printf("-q quiet mode only the number of tests passed and failed will be printed\n");
printf("-t [number] set yaffs_trace to number\n");
- printf("-r [number] sets the number of random loops to run after the the test has run\n");
+ printf("-n [number] sets the number of random loops to run after the the test has run\n");
exit(0);
- } else if (0==strcmp(argv[x],"-c")) {
+ } else if (new_option=='c') {
set_exit_on_error(0);
- } else if (0==strcmp(argv[x],"-q")) {
+ } else if (new_option=='q') {
set_print_level(-3);
- } else if (0==strcmp(argv[x],"-t")) {
- trace = atoi(argv[x+1]);
- } else if (0==strcmp(argv[x],"-v")) {
+ } else if (new_option=='t') {
+ trace = atoi(optarg);
+ } else if (new_option=='v') {
set_print_level(5);
- } else if (0==strcmp(argv[x],"-r")) {
- number_of_random_tests=atoi(argv[x+1]);
+ } else if (new_option=='n') {
+ number_of_random_tests=atoi(optarg);
}
- }
+ }while (new_option!=-1);
yaffs_start_up();
yaffs_set_trace(trace);
diff --git a/direct/timothy_tests/quick_tests/quick_tests.h b/direct/timothy_tests/quick_tests/quick_tests.h
index 50d17dc..725ead2 100644
--- a/direct/timothy_tests/quick_tests/quick_tests.h
+++ b/direct/timothy_tests/quick_tests/quick_tests.h
@@ -16,6 +16,7 @@
#ifndef __quick_tests_h__
#define __quick_tests_h__
#include <stdio.h>
+#include <getopt.h>
#include "test_yaffs_mount.h"
#include "test_yaffs_mount_ENODEV.h"
diff --git a/direct/timothy_tests/threading/Makefile b/direct/timothy_tests/threading/Makefile
new file mode 100644
index 0000000..8006b79
--- /dev/null
+++ b/direct/timothy_tests/threading/Makefile
@@ -0,0 +1,115 @@
+# Makefile for YAFFS direct stress tests
+#
+#
+# YAFFS: Yet another Flash File System. A NAND-flash specific file system.
+#
+# Copyright (C) 2003-2010 Aleph One Ltd.
+#
+#
+# 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.
+#
+# NB Warning this Makefile does not include header dependencies.
+#
+# $Id: Makefile,v 1.7 2010-02-25 22:34:47 charles Exp $
+
+#EXTRA_COMPILE_FLAGS = -DYAFFS_IGNORE_TAGS_ECC
+
+CFLAGS = -DCONFIG_YAFFS_DIRECT -DCONFIG_YAFFS_YAFFS2
+CFLAGS += -DCONFIG_YAFFS_PROVIDE_DEFS -DCONFIG_YAFFSFS_PROVIDE_VALUES
+CFLAGS += -Wall -g $(EXTRA_COMPILE_FLAGS) -Wstrict-aliasing
+#CFLAGS += -fno-strict-aliasing
+CFLAGS += -O0
+CFLAGS += -Wextra -Wpointer-arith
+#CFLAGS += -DCONFIG_YAFFS_VALGRIND_TEST
+
+#CFLAGS+= -Wshadow -Wpointer-arith -Wwrite-strings -Wstrict-prototypes -Wmissing-declarations
+#CFLAGS+= -Wmissing-prototypes -Wredundant-decls -Wnested-externs -Winline
+
+
+COMMONTESTOBJS = yaffscfg2k.o yaffs_osglue.o yaffs_hweight.o \
+ yaffs_ecc.o yaffs_fileem.o yaffs_fileem2k.o yaffsfs.o yaffs_guts.o \
+ yaffs_packedtags1.o yaffs_ramdisk.o yaffs_ramem2k.o \
+ yaffs_tagscompat.o yaffs_packedtags2.o yaffs_tagsvalidity.o yaffs_nand.o \
+ yaffs_checkptrw.o yaffs_qsort.o\
+ yaffs_nameval.o yaffs_attribs.o \
+ yaffs_norif1.o ynorsim.o \
+ yaffs_allocator.o \
+ yaffs_bitmap.o \
+ yaffs_yaffs1.o \
+ yaffs_yaffs2.o \
+ yaffs_verify.o \
+ yaffs_error.o
+
+# yaffs_checkptrwtest.o\
+
+TESTFILES = threading.o thread_function.o \
+ test_a.o test_b.o lib.o
+
+
+
+YAFFSTESTOBJS = $(COMMONTESTOBJS) $(TESTFILES)
+
+ALLOBJS = $(sort $(YAFFSTESTOBJS))
+
+YAFFSSYMLINKS = yaffs_ecc.c yaffs_ecc.h yaffs_guts.c yaffs_guts.h yaffs_tagscompat.c yaffs_tagscompat.h \
+ yaffs_packedtags1.c yaffs_packedtags1.h yaffs_packedtags2.c yaffs_packedtags2.h \
+ yaffs_nand.c yaffs_nand.h yaffs_getblockinfo.h \
+ yaffs_tagsvalidity.c yaffs_tagsvalidity.h yaffs_checkptrw.h yaffs_checkptrw.c \
+ yaffs_nameval.c yaffs_nameval.h \
+ yaffs_trace.h yaffs_attribs.h \
+ yaffs_allocator.c yaffs_allocator.h \
+ yaffs_yaffs1.c yaffs_yaffs1.h \
+ yaffs_yaffs2.c yaffs_yaffs2.h \
+ yaffs_bitmap.c yaffs_bitmap.h \
+ yaffs_verify.c yaffs_verify.h
+
+YAFFSDIRECTSYMLINKS = yaffsfs.c yaffs_flashif.h yaffs_flashif2.h\
+ yaffsfs.h ydirectenv.h \
+ yaffs_flashif.c yaffscfg.h yaffs_qsort.c \
+ yaffs_nandemul2k.h yaffs_list.h \
+ yaffs_attribs.c yaffs_osglue.h \
+ yaffs_nandif.c yaffs_nandif.h yportenv.h \
+ yaffs_hweight.h yaffs_hweight.c \
+ yaffs_error.c
+
+
+DIRECTEXTRASYMLINKS = yaffscfg2k.c yaffs_fileem2k.c yaffs_fileem2k.h\
+ yaffs_fileem.c yaffs_norif1.c yaffs_norif1.h \
+ yaffs_ramdisk.c yaffs_ramdisk.h yaffs_ramem2k.c \
+ ynorsim.h ynorsim.c yaffs_osglue.c
+
+SYMLINKS = $(YAFFSSYMLINKS) $(YAFFSDIRECTSYMLINKS) $(DIRECTEXTRASYMLINKS) $(PYTONOSYMLINKS)
+#all: directtest2k boottest
+
+all: threading
+
+$(ALLOBJS): %.o: %.c
+ gcc -c $(CFLAGS) -o $@ $<
+
+$(PYTONOSYMLINKS):
+ ln -s ../../python/$@ $@
+
+$(YAFFSSYMLINKS):
+ ln -s ../../../$@ $@
+
+$(YAFFSDIRECTSYMLINKS):
+ ln -s ../../$@ $@
+
+$(DIRECTEXTRASYMLINKS):
+ ln -s ../../basic-test/$@ $@
+
+
+threading: $(SYMLINKS) $(ALLOBJS)
+ gcc $(CFLLAG) -o $@ $(ALLOBJS) -lpthread
+
+
+
+
+
+
+clean:
+ rm -f threading $(ALLOBJS) core $(SYMLINKS)
diff --git a/direct/timothy_tests/threading/lib.c b/direct/timothy_tests/threading/lib.c
new file mode 100644
index 0000000..6456958
--- /dev/null
+++ b/direct/timothy_tests/threading/lib.c
@@ -0,0 +1,42 @@
+/*
+ * 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 Timothy Manning <timothy@yaffs.net>
+ *
+ * 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 "lib.h"
+static unsigned int *p_counter;
+static unsigned int numberOfThreads=5;
+
+unsigned int get_num_of_threads(void)
+{
+ return numberOfThreads;
+}
+
+void number_of_threads(unsigned int num)
+{
+ numberOfThreads=num;
+}
+
+int get_counter(int x)
+{
+ return p_counter[x];
+}
+
+void set_counter(int x, unsigned int value)
+{
+ p_counter[x]=value;
+}
+
+void init_counter(unsigned int size_of_counter)
+{
+ p_counter=malloc(size_of_counter*sizeof(int));
+}
+
diff --git a/direct/timothy_tests/threading/lib.h b/direct/timothy_tests/threading/lib.h
new file mode 100644
index 0000000..f635294
--- /dev/null
+++ b/direct/timothy_tests/threading/lib.h
@@ -0,0 +1,38 @@
+/*
+ * YAFFS: Yet another Flash File System . A NAND-flash specific file system.
+ *
+ * Copyright (C) 2002-2010 Aleph One Ltd.
+ * for Toby Churchill Ltd and Brightstar Engineering
+ *
+ * Created by Timothy Manning <timothy@yaffs.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1 as
+ * published by the Free Software Foundation.
+ *
+ * Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL.
+ */
+
+#ifndef __lib_h__
+#define __lib_h__
+
+#define BOVVER_HANDLES 10
+#include "yaffsfs.h"
+struct bovver_context {
+ int bovverType;
+ int threadId;
+ char baseDir[200];
+ int h[BOVVER_HANDLES];
+ yaffs_DIR *dirH;
+ int opMax;
+ int op;
+ int cycle;
+};
+
+int get_counter(int x);
+void set_counter(int x, unsigned int value);
+void init_counter(unsigned int size_of_counter);
+void number_of_threads(unsigned int num);
+unsigned int get_num_of_threads(void);
+
+#endif
diff --git a/direct/timothy_tests/threading/test_a.c b/direct/timothy_tests/threading/test_a.c
new file mode 100644
index 0000000..391530c
--- /dev/null
+++ b/direct/timothy_tests/threading/test_a.c
@@ -0,0 +1,99 @@
+/*
+ * 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 Timothy Manning <timothy@yaffs.net>
+ *
+ * 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 "test_a.h"
+
+
+
+
+
+void test_a(void *x)
+{
+ struct bovver_context *bc = (struct bovver_context *)x;
+
+ int i;
+ int op;
+ int pos;
+ int n;
+ int n1;
+
+ char name[200];
+ char name1[200];
+
+ int start_op;
+
+
+ i = rand() % BOVVER_HANDLES;
+ op = rand() % bc->opMax;
+ pos = rand() & 20000000;
+ n = rand() % 100;
+ n1 = rand() % 100;
+
+ start_op = op;
+
+ sprintf(name, "%s/xx%d",bc->baseDir,n);
+ sprintf(name1,"%s/xx%d",bc->baseDir,n1);
+
+ bc->op = op;
+ bc->cycle++;
+
+ op-=1;
+ if(op < 0){
+ if(bc->h[i]>= 0){
+ yaffs_close(bc->h[i]);
+ bc->h[i] = -1;
+ }
+ return;
+ }
+
+ op-=1;
+ if(op < 0){
+ if(bc->h[i] < 0)
+ bc->h[i] = yaffs_open(name,O_CREAT| O_RDWR, 0666);
+ return;
+ }
+
+ op-=5;
+ if(op< 0){
+ yaffs_lseek(bc->h[i],pos,SEEK_SET);
+ yaffs_write(bc->h[i],name,n);
+ return;
+ }
+
+ op-=1;
+ if(op < 0){
+ yaffs_unlink(name);
+ return;
+ }
+ op-=1;
+ if(op < 0){
+ yaffs_rename(name,name1);
+ return;
+ }
+ op-=1;
+ if(op < 0){
+ yaffs_mkdir(name,0666);
+ return;
+ }
+ op-=1;
+ if(op < 0){
+ yaffs_rmdir(name);
+ return;
+ }
+
+ bc->opMax = (start_op - op -1);
+
+ return;
+
+}
+
diff --git a/direct/timothy_tests/threading/test_a.h b/direct/timothy_tests/threading/test_a.h
new file mode 100644
index 0000000..87cb3df
--- /dev/null
+++ b/direct/timothy_tests/threading/test_a.h
@@ -0,0 +1,22 @@
+/*
+ * YAFFS: Yet another Flash File System . A NAND-flash specific file system.
+ *
+ * Copyright (C) 2002-2010 Aleph One Ltd.
+ * for Toby Churchill Ltd and Brightstar Engineering
+ *
+ * Created by Timothy Manning <timothy@yaffs.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1 as
+ * published by the Free Software Foundation.
+ *
+ * Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL.
+ */
+
+#ifndef __test_a_h__
+#define __test_a_h__
+
+#include "yaffsfs.h"
+#include "lib.h"
+void test_a(void *x);
+#endif
diff --git a/direct/timothy_tests/threading/test_b.c b/direct/timothy_tests/threading/test_b.c
new file mode 100644
index 0000000..0476113
--- /dev/null
+++ b/direct/timothy_tests/threading/test_b.c
@@ -0,0 +1,39 @@
+/*
+ * 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 Timothy Manning <timothy@yaffs.net>
+ *
+ * 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 "test_b.h"
+
+void test_b(void *x)
+{
+ struct bovver_context *bc = (struct bovver_context *)x;
+ int n = rand() % 20;
+
+ bc->cycle++;
+
+ if(!bc->dirH)
+ bc->dirH = yaffs_opendir(bc->baseDir);
+
+ if(!bc->dirH)
+ return;
+
+ if(n == 0){
+ yaffs_closedir(bc->dirH);
+ bc->dirH = NULL;
+ } else {
+ while(n > 1){
+ n--;
+ yaffs_readdir(bc->dirH);
+ }
+ }
+}
+
diff --git a/direct/timothy_tests/threading/test_b.h b/direct/timothy_tests/threading/test_b.h
new file mode 100644
index 0000000..c242a93
--- /dev/null
+++ b/direct/timothy_tests/threading/test_b.h
@@ -0,0 +1,21 @@
+/*
+ * YAFFS: Yet another Flash File System . A NAND-flash specific file system.
+ *
+ * Copyright (C) 2002-2010 Aleph One Ltd.
+ * for Toby Churchill Ltd and Brightstar Engineering
+ *
+ * Created by Timothy Manning <timothy@yaffs.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1 as
+ * published by the Free Software Foundation.
+ *
+ * Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL.
+ */
+
+#ifndef __test_b_h__
+#define __test_b_h__
+#include "yaffsfs.h"
+#include "lib.h"
+void test_b(void *x);
+#endif
diff --git a/direct/timothy_tests/threading/thread_function.c b/direct/timothy_tests/threading/thread_function.c
new file mode 100644
index 0000000..52b78d0
--- /dev/null
+++ b/direct/timothy_tests/threading/thread_function.c
@@ -0,0 +1,70 @@
+/*
+ * 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 Timothy Manning <timothy@yaffs.net>
+ *
+ * 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 "thread_function.h"
+
+
+
+int number_of_tests=2;
+
+
+void * init(int threadId, const char *baseDir, int bovver_type)
+{
+ struct bovver_context *bc = malloc(sizeof(struct bovver_context));
+
+ if(bc){
+ memset(bc,0,sizeof(*bc));
+ bc->threadId = threadId;
+ strncpy(bc->baseDir,baseDir,200);
+ bc->bovverType = bovver_type;
+ bc->opMax = 99;
+ printf("bovver_init %d \"%s\"\n",threadId,baseDir);
+ }
+ return (void *)bc;
+}
+
+
+typedef struct test {
+ void (*p_function)(void *); /*pointer to test function*/
+ /*char pass_message[50]; will not need a pass message*/
+ char *name_of_test; /*pointer to fail message, needs to include name of test*/
+}test_template;
+
+
+test_template test_list[]={
+ //{dummy_test,dummy_test_clean,"dummy_test"},
+ {test_a, "test_a"},
+ {test_b, "test_b"}
+};
+
+int thread_function(void *thread_id_ptr)
+{
+ int thread_id = (int) thread_id_ptr;
+ int test_id=0;
+ unsigned int y=0;
+ printf("Starting thread %d, id %d\n", pthread_self(),thread_id);
+ void *x=init(thread_id,"/yaffs2/",0);
+ while(1){
+ y++;
+ //set_counter(thread_id,y);
+ test_id=(rand()%(number_of_tests-1));
+ test_list[test_id].p_function(x);
+ //printf("thread: %d. ran test: %d\n",thread_id,y);
+ //printf("counter before %d\n",get_counter(thread_id));
+ set_counter(thread_id,y);
+ //printf("counter after setting %d\n",get_counter(thread_id));
+ }
+ //select random file name from a list.
+ //run a random function on the file.
+ return 1;
+}
diff --git a/direct/timothy_tests/threading/thread_function.h b/direct/timothy_tests/threading/thread_function.h
new file mode 100644
index 0000000..106793f
--- /dev/null
+++ b/direct/timothy_tests/threading/thread_function.h
@@ -0,0 +1,28 @@
+/*
+ * YAFFS: Yet another Flash File System . A NAND-flash specific file system.
+ *
+ * Copyright (C) 2002-2010 Aleph One Ltd.
+ * for Toby Churchill Ltd and Brightstar Engineering
+ *
+ * Created by Timothy Manning <timothy@yaffs.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1 as
+ * published by the Free Software Foundation.
+ *
+ * Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL.
+ */
+
+#ifndef __thread_function_h__
+#define __thread_function_h__
+
+
+#include <string.h>
+#include <stdlib.h>
+
+#include "test_a.h"
+#include "test_b.h"
+#include "lib.h"
+int thread_function(void * thread_id);
+void * init(int threadId, const char *baseDir, int bovver_type);
+#endif
diff --git a/direct/timothy_tests/threading/threading.c b/direct/timothy_tests/threading/threading.c
new file mode 100644
index 0000000..4b65e38
--- /dev/null
+++ b/direct/timothy_tests/threading/threading.c
@@ -0,0 +1,80 @@
+/*
+ * 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 Timothy Manning <timothy@yaffs.net>
+ *
+ * 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 "threading.h"
+
+int random_seed;
+int simulate_power_failure = 0;
+
+const struct option long_options[]={
+ {"help", 0,NULL,'h'},
+ {"threads", 1,NULL,'t'}
+};
+
+const char short_options[]="ht:";
+
+
+
+
+void main_init(int argc, char *argv[])
+{
+ int new_option;
+ int x=0;
+ int new_num_of_threads=5;
+ x=(unsigned)time(NULL);
+ printf("seeding srand with: %d\n",x);
+ srand(x);
+ do{
+ new_option=getopt_long(argc,argv,short_options,long_options,NULL);
+ if (new_option=='h'){
+ printf("help\n");
+ printf("-h will print the commands available\n");
+ printf("-t [number] sets the number of threads\n");
+ exit(0);
+ } else if (new_option=='t') {
+ new_num_of_threads=atoi(optarg);
+ }
+ }while (new_option!=-1);
+ number_of_threads(new_num_of_threads);
+ init_counter(new_num_of_threads);
+
+}
+
+int main(int argc, char *argv[])
+{
+ main_init(argc,argv);
+ pthread_t threads[get_num_of_threads()];
+ unsigned int x=0;
+ int output=0;
+ int y=0;
+
+ for (x=0;x<get_num_of_threads();x++)
+ {
+
+ output=pthread_create(&threads[x], NULL,thread_function, (void *)x );
+ if (output>0){
+ printf("failed to create thread %d. Error is %d\n",x,output);
+ }
+
+ }
+ while (1){
+ y=0;
+ printf("thread counter: %d ",get_counter(y));
+ for (y=1;y<get_num_of_threads();y++){
+ printf("| %d ",get_counter(y));
+ }
+ printf("\n");
+ }
+
+}
+
diff --git a/direct/timothy_tests/threading/threading.h b/direct/timothy_tests/threading/threading.h
new file mode 100644
index 0000000..307a30c
--- /dev/null
+++ b/direct/timothy_tests/threading/threading.h
@@ -0,0 +1,24 @@
+/*
+ * YAFFS: Yet another Flash File System . A NAND-flash specific file system.
+ *
+ * Copyright (C) 2002-2010 Aleph One Ltd.
+ * for Toby Churchill Ltd and Brightstar Engineering
+ *
+ * Created by Timothy Manning <timothy@yaffs.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1 as
+ * published by the Free Software Foundation.
+ *
+ * Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL.
+ */
+
+#ifndef __threading_h__
+#define __threading_h__
+#include <time.h>
+#include <pthread.h>
+#include <stdio.h>
+#include "thread_function.h"
+#include "lib.h"
+#include <getopt.h>
+#endif