From: Timothy Manning Date: Sun, 12 Dec 2010 23:21:56 +0000 (+1300) Subject: yaffs Added some more tests to timothy_tests. X-Git-Tag: linux-mainline-patchset-4~10 X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs2.git;a=commitdiff_plain;h=137f935f6d622bffdef2fece0c5194e85f5174e9 yaffs Added some more tests to timothy_tests. Signed-off-by: Timothy Manning --- diff --git a/direct/timothy_tests/handle_tests/Makefile b/direct/timothy_tests/handle_tests/Makefile new file mode 100644 index 0000000..6ad275c --- /dev/null +++ b/direct/timothy_tests/handle_tests/Makefile @@ -0,0 +1,113 @@ +# 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 +# +# 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 = handle_test.o + + + + +YAFFSTESTOBJS = $(COMMONTESTOBJS) $(TESTFILES) + + +ALLOBJS = $(sort $(YAFFSTESTOBJS)) $(PYTHONOBJS) + +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: handle_test + +$(ALLOBJS): %.o: %.c + gcc -c $(CFLAGS) -o $@ $< + +$(PYTONOSYMLINKS): + ln -s ../../python/$@ $@ + +$(YAFFSSYMLINKS): + ln -s ../../../$@ $@ + +$(YAFFSDIRECTSYMLINKS): + ln -s ../../$@ $@ + +$(DIRECTEXTRASYMLINKS): + ln -s ../../basic-test/$@ $@ + + +handle_test: $(SYMLINKS) $(ALLOBJS) + gcc $(CFLLAG) -o $@ $(ALLOBJS) + + + +clean: + rm -f handle_test $(ALLOBJS) core $(SYMLINKS) diff --git a/direct/timothy_tests/handle_tests/handle_test.c b/direct/timothy_tests/handle_tests/handle_test.c new file mode 100644 index 0000000..6182abf --- /dev/null +++ b/direct/timothy_tests/handle_tests/handle_test.c @@ -0,0 +1,120 @@ +/* + * 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 + * + * 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 "handle_test.h" + +int random_seed; +int simulate_power_failure = 0; + +int main() +{ + + int test_batch = 1000000; + int output =0; + unsigned int total_number_of_tests_run=0; + yaffs_start_up(); + yaffs_mount("yaffs2"); + + printf("running tests\n"); + + output=dup_test(); + printf("dup test: %d\n ",output); + + while (1){ + output = open_close_handle_test(test_batch); + if (output>=0){ + total_number_of_tests_run ++; + } else { + get_error(); + return -1; + } + printf("total number of tests = %d\n",(total_number_of_tests_run*test_batch)); + } + + + return 0; +} +int dup_test(void){ + int handle = -1; + int handle2 = -1; + int output =-1; + + handle =open_handle(); + if (handle<0){ + printf("error: failed to open handle\n"); + return -1; + } + handle2=yaffs_dup(handle); + if (handle2<0){ + printf("error: failed to open handle2\n"); + return -1; + } + + output=yaffs_lseek(handle,20,SEEK_SET); + if (output >= 0) { + output = yaffs_lseek(handle,0,SEEK_CUR); + if (output = 20){ + printf("dup is working\n"); + return 1; + } else if (output <0){ + printf("failed to lseek the second time\n"); + return -1; + } else { + printf("lseek position is diffrent than expected\n"); + return -1; + } + } else { + printf("failed to lseek the first time\n"); + return -1; + } + +} + +int open_close_handle_test(int num_of_tests) +{ + int handle_number=open_handle(); + int handle=0; + int x =0; + int output=0; + yaffs_close(handle_number); + for (x=0;x + * + * 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 __handle_test_h__ +#define __handle_test_h__ + +#include +#include "yaffsfs.h" + +#define FILE_PATH "/yaffs2/foo" + +int open_close_handle_test(int num_of_tests); +int open_handle(void); +void get_error(void); +#endif diff --git a/direct/timothy_tests/mirror_tests/Makefile b/direct/timothy_tests/mirror_tests/Makefile new file mode 100644 index 0000000..f26ff4c --- /dev/null +++ b/direct/timothy_tests/mirror_tests/Makefile @@ -0,0 +1,114 @@ +# 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 +# +# 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 = mirror_tests.o lib.o\ + linux_test_open.o yaffs_test_open.o + + + + +YAFFSTESTOBJS = $(COMMONTESTOBJS) $(TESTFILES) + + +ALLOBJS = $(sort $(YAFFSTESTOBJS)) $(PYTHONOBJS) + +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: mirror_tests + +$(ALLOBJS): %.o: %.c + gcc -c $(CFLAGS) -o $@ $< + +$(PYTONOSYMLINKS): + ln -s ../../python/$@ $@ + +$(YAFFSSYMLINKS): + ln -s ../../../$@ $@ + +$(YAFFSDIRECTSYMLINKS): + ln -s ../../$@ $@ + +$(DIRECTEXTRASYMLINKS): + ln -s ../../basic-test/$@ $@ + + +mirror_tests: $(SYMLINKS) $(ALLOBJS) + gcc $(CFLLAG) -o $@ $(ALLOBJS) + + + +clean: + rm -f mirror_tests $(ALLOBJS) core $(SYMLINKS) diff --git a/direct/timothy_tests/mirror_tests/lib.c b/direct/timothy_tests/mirror_tests/lib.c new file mode 100644 index 0000000..4b9ebd6 --- /dev/null +++ b/direct/timothy_tests/mirror_tests/lib.c @@ -0,0 +1,88 @@ +/* + * 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 + * + * 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 int EXIT_ON_ERROR = 1; +static int PRINT_LEVEL = 2; //This sets the level of detail which is printed. There are 3 levels 0,1,2 and 3 + //0 just prints the number of tests passed and failed. + //1 is the basic print level. it will print the details of a failed test. + //2 will print if a test passes and cleans. +void set_print_level(int new_level) +{ + PRINT_LEVEL=new_level; +} + +void set_exit_on_error(int num) +{ + EXIT_ON_ERROR=num; +} + +int get_exit_on_error(void) +{ + return EXIT_ON_ERROR; +} + +void display_error(void) +{ + +} +void join_paths(char *path1,char *path2,char *new_path ) +{ + char message[100]; + print_message(3,"joining paths\n"); + sprintf(message,"path1: %s\n",path1); + print_message(3,message); + sprintf(message,"path2: %s\n",path2); + print_message(3,message); + strcpy(new_path,""); + //strcat(new_path,path1); /*since all functions have this then pull it out*/ + if ( (path1[(sizeof(path1)/sizeof(char))-2]=='/') && path2[0]!='/') { + /*paths are compatiable. concatanate them. note -2 is because of \0*/ + strcat(new_path,path1); + strcat(new_path,path2); + //char new_path[(sizeof(path1)/sizeof(char))+(sizeof(path2)/sizeof(char))]; + //strcpy(new_path,strcat(path1,path2)); + //return new_path; + } else if ((path1[(sizeof(path1)/sizeof(char))-2]!='/') && path2[0]=='/') { + /*paths are compatiable. concatanate them*/ + strcat(new_path,path1); + strcat(new_path,path2); + + } else if ((path1[(sizeof(path1)/sizeof(char))-2]!='/') && path2[0]!='/') { + /*need to add a "/". */ + strcat(new_path,path1); + strcat(new_path,"/"); + strcat(new_path,path2); + + } else if ((path1[(sizeof(path1)/sizeof(char))-2]=='/') && path2[0]=='/') { + /*need to remove a "/". */ + /*yaffs does not mind the extra slash. */ + strcat(new_path,path1); + strcat(new_path,path2); + + } else { + //error + //return -1; + } +} + +void print_message(char print_level,char *message) +{ + if (print_level <= PRINT_LEVEL){ + printf(message); + } +} + + + diff --git a/direct/timothy_tests/mirror_tests/lib.h b/direct/timothy_tests/mirror_tests/lib.h new file mode 100644 index 0000000..2e03573 --- /dev/null +++ b/direct/timothy_tests/mirror_tests/lib.h @@ -0,0 +1,51 @@ +/* + * 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 + * + * 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__ + +#include +#include +#include "yaffsfs.h" + + +typedef struct arg_temp2{ + char char1; + char char2; + char string1[100]; + char string2[100]; + int int1; + int int2; +} arg_temp; + + +typedef struct test_dir_temp +{ + int type_of_test; //used to tell if it is LINUX of YAFFS + char root_path[200]; +} test_dir; +test_dir yaffs_struct,linux_struct; + + + + +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); +void set_exit_on_error(int num); +int get_exit_on_error(void); +void display_error(void); + +#endif diff --git a/direct/timothy_tests/mirror_tests/linux_test_open.c b/direct/timothy_tests/mirror_tests/linux_test_open.c new file mode 100644 index 0000000..7817c3a --- /dev/null +++ b/direct/timothy_tests/mirror_tests/linux_test_open.c @@ -0,0 +1,25 @@ +/* + * 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 + * + * 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_open.h" + +int linux_test_open(arg_temp *args_struct) +{ + char path[200]; + char message[100]; + join_paths(linux_struct.root_path,args_struct->string1, path ); + sprintf(message,"file path: %s\n",path); + print_message(3,message); + + return open(path,args_struct->char1,args_struct->char2); +} diff --git a/direct/timothy_tests/mirror_tests/linux_test_open.h b/direct/timothy_tests/mirror_tests/linux_test_open.h new file mode 100644 index 0000000..40d3492 --- /dev/null +++ b/direct/timothy_tests/mirror_tests/linux_test_open.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 + * + * 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_open_h__ +#define __linux_test_open_h__ +#include +#include +#include +#include "lib.h" + +int linux_test_open(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 new file mode 100644 index 0000000..319eb93 --- /dev/null +++ b/direct/timothy_tests/mirror_tests/mirror_tests.c @@ -0,0 +1,250 @@ +/* + * 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 + * + * 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 "mirror_tests.h" + +int random_seed; +int simulate_power_failure = 0; + + + + + +typedef struct test_list_temp2{ + char *test_name; + int (*test_pointer)(arg_temp *args_struct); +}test_list_temp; + +typedef struct test_temp2 { + int num_of_tests; + test_list_temp test_list[]; +}test_temp; + +test_temp yaffs_tests={ + 0, + {{"yaffs_test_open",yaffs_test_open} + } +}; + +test_temp linux_tests={ + 0, + {{"linux_test_open",linux_test_open} + } +}; + + +int main(int argc, char *argv[]) +{ + char message[100]; + + yaffs_tests.num_of_tests=(sizeof(yaffs_tests)/sizeof(test_temp)); + linux_tests.num_of_tests=(sizeof(linux_tests)/sizeof(test_temp)); + + init(argc,argv); + print_message(1,"running mirror_tests\n"); + sprintf(message,"linux_root_path: %s\n",linux_struct.root_path); + print_message(3,message); + sprintf(message,"yaffs_root_path: %s\n",yaffs_struct.root_path); + print_message(3,message); + sprintf(message,"linux_num_of_tests: %d\n",linux_tests.num_of_tests); + print_message(3,message); + sprintf(message,"yaffs_num_of_tests: %d\n",yaffs_tests.num_of_tests); + print_message(3,message); + + run_random_test(); + return 0; +} + +void init(int argc, char *argv[]) +{ + char dir[200]; + dir[0]='\0'; + int x=-1; + char message[100]; + linux_struct.type_of_test =LINUX; + yaffs_struct.type_of_test =YAFFS; + + sprintf(message,"current absolute path is: %s\n",getcwd(dir,200)); + print_message(3,message); + strcpy(dir,getcwd(dir,200)); + + strcat(dir,"/test"); + printf("dir: %s\n",dir); + strcpy(linux_struct.root_path,dir); + strcpy(yaffs_struct.root_path,"yaffs2/test/"); + + + for (x=0;xchar1= (rand() % 255); + args_struct->char2= (rand() % 255); + args_struct->int1= (rand() % 100000); + args_struct->int2= (rand() % 100000); + strcpy(args_struct->string1, "apple"); + strcpy(args_struct->string2, "apple"); +} + +void run_yaffs_test(int id,arg_temp *args_struct) +{ + char message[30]; + int output =0; + print_message(2,"\n"); + sprintf(message,"running_test %s\n",yaffs_tests.test_list[id].test_name); + print_message(3,message); + output=yaffs_tests.test_list[id].test_pointer(args_struct); + if (output<0) { + sprintf(message,"test_failed %s\n",yaffs_tests.test_list[id].test_name); + print_message(1,message); + get_error_yaffs(); + } else { + print_message(3,"test_passed\n"); + } +} + +void run_linux_test(int id,arg_temp *args_struct) +{ + char message[30]; + int output =0; + print_message(2,"\n"); + sprintf(message,"running_test %s\n",linux_tests.test_list[id].test_name); + print_message(3,message); + output=linux_tests.test_list[id].test_pointer(args_struct); + if (output<0) { + sprintf(message,"test_failed %s\n",linux_tests.test_list[id].test_name); + print_message(1,message); + get_error_linux(); + } else { + print_message(3,"test_passed\n"); + } +} + +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); +} + diff --git a/direct/timothy_tests/mirror_tests/mirror_tests.h b/direct/timothy_tests/mirror_tests/mirror_tests.h new file mode 100644 index 0000000..8c8b820 --- /dev/null +++ b/direct/timothy_tests/mirror_tests/mirror_tests.h @@ -0,0 +1,48 @@ +/* + * 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 + * + * 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 __mirror_tests_h__ +#define __mirror_tests_h__ + +#include +#include //used for getting the current directory. +#include +#include +#include "yaffsfs.h" +#include "lib.h" + +#include "linux_test_open.h" +#include "yaffs_test_open.h" + + +#define LINUX 1 +#define YAFFS 2 + + + + + +void init(int argc, char *argv[]); +int run_random_test(void); +int compare_linux_and_yaffs(void); +void get_error_yaffs(void); +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 generate_array_of_objects_in_yaffs(void); +//void generate_array_of_objects_in_linux(void); + +#endif diff --git a/direct/timothy_tests/mirror_tests/yaffs_test_open.c b/direct/timothy_tests/mirror_tests/yaffs_test_open.c new file mode 100644 index 0000000..e8b72b4 --- /dev/null +++ b/direct/timothy_tests/mirror_tests/yaffs_test_open.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 + * + * 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_open.h" + +int yaffs_test_open(arg_temp *args_struct) +{ + char path[200]; + char message[100]; + join_paths(yaffs_struct.root_path,args_struct->string1, path ); + sprintf(message,"file path: %s\n",path); + print_message(3,message); + + output=yaffs_open(path,args_struct->char1,args_struct->char2); + if (output>=0){ + output= yaffs_close(output); + if (output<0) { + print_message(1,"failed to close handle\n"); + return -1 + } else { + return 1; + } + } else { + print_message(1,"failed to close handle\n"); + return -1; + } +} diff --git a/direct/timothy_tests/mirror_tests/yaffs_test_open.h b/direct/timothy_tests/mirror_tests/yaffs_test_open.h new file mode 100644 index 0000000..f9e4224 --- /dev/null +++ b/direct/timothy_tests/mirror_tests/yaffs_test_open.h @@ -0,0 +1,26 @@ +/* + * 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 + * + * 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_open_h__ +#define __yaffs_test_open_h__ +#include +#include +#include +#include "yaffsfs.h" +#include "lib.h" + +int yaffs_test_open(arg_temp *args_struct); + +#endif diff --git a/direct/timothy_tests/quick_tests/README.txt b/direct/timothy_tests/quick_tests/README.txt index d757584..1744392 100644 --- a/direct/timothy_tests/quick_tests/README.txt +++ b/direct/timothy_tests/quick_tests/README.txt @@ -246,7 +246,7 @@ test_yaffs_write_EROFS.c Tests to add - + test_yaffs_rename a file over its self. test_yaffs_readlink test_yaffs_readlink_ENOENT diff --git a/direct/timothy_tests/quick_tests/lib.h b/direct/timothy_tests/quick_tests/lib.h index f8b6d74..72376b5 100644 --- a/direct/timothy_tests/quick_tests/lib.h +++ b/direct/timothy_tests/quick_tests/lib.h @@ -45,6 +45,8 @@ #define ELOOP_PATH "/yaffs2/ELOOP" #define ELOOP2_PATH "/yaffs2/ELOOP2" +#define RMDIR_PATH "/yaffs2/RM_DIR" + /* warning do not define anything as FILE because there seems to be a conflict with stdio.h */ #define FILE_PATH "/yaffs2/foo" diff --git a/direct/timothy_tests/quick_tests/quick_tests.c b/direct/timothy_tests/quick_tests/quick_tests.c index 244b8b0..0e34ea7 100644 --- a/direct/timothy_tests/quick_tests/quick_tests.c +++ b/direct/timothy_tests/quick_tests/quick_tests.c @@ -20,69 +20,93 @@ int simulate_power_failure = 0; - +static int number_of_random_tests=0; 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)); -int main(int argc, char *argv[]){ - int output=0; - char message[30]; - message[0]='\0'; - unsigned int x=0; +int main(int argc, char *argv[]) +{ + int x=0; init_quick_tests(argc, argv); + logical_run_of_tests(); + for (x=0;x=0){ - /*test has passed*/ - sprintf(message,"\ttest %s passed\n",test_list[x].name_of_test); - print_message(message,3); - num_of_tests_pass++; - } else { - /*test is assumed to have failed*/ - //printf("test failed\n"); - sprintf(message,"test: %s failed\n",test_list[x].name_of_test); - print_message(message,1); - num_of_tests_failed ++; - - get_error(); - print_message("\n\n",1); - if (get_exit_on_error()){ - quit_quick_tests(1); - } + run_test(x); + } +} +void run_test(int x) +{ + int output=0; + char message[200]; + message[0]='\0'; + + yaffs_set_error(0); /*reset the last error to 0 */ + //printf("foo exists %d\n",test_yaffs_open()); + sprintf(message,"\nrunning test: %s \n",test_list[x].name_of_test); + print_message(message,3); + output=test_list[x].p_function(); /*run test*/ + if (output>=0){ + /*test has passed*/ + sprintf(message,"\ttest %s passed\n",test_list[x].name_of_test); + print_message(message,3); + num_of_tests_pass++; + } else { + /*test is assumed to have failed*/ + //printf("test failed\n"); + sprintf(message,"test: %s failed\n",test_list[x].name_of_test); + print_message(message,1); + num_of_tests_failed ++; + + get_error(); + print_message("\n\n",1); + if (get_exit_on_error()){ + quit_quick_tests(1); } - output=0; - output=test_list[x].p_function_clean(); /*clean the test*/ - if (output <0){ - /* if the test failed to clean it's self then */ - sprintf(message,"test: %s failed to clean\n",test_list[x].name_of_test); - print_message(message,1); - num_of_tests_failed ++; - num_of_tests_pass--; - get_error(); - printf("\n\n"); - if (get_exit_on_error()){ - quit_quick_tests(1); - } - - } else { - sprintf(message,"\ttest clean: %s passed\n",test_list[x].name_of_test); - print_message(message,3); + } + output=0; + output=test_list[x].p_function_clean(); /*clean the test*/ + if (output <0){ + /* if the test failed to clean it's self then */ + sprintf(message,"test: %s failed to clean\n",test_list[x].name_of_test); + print_message(message,1); + num_of_tests_failed ++; + num_of_tests_pass--; + get_error(); + printf("\n\n"); + if (get_exit_on_error()){ + quit_quick_tests(1); } + + } else { + sprintf(message,"\ttest clean: %s passed\n",test_list[x].name_of_test); + print_message(message,3); } - /*this is where the loop should break to*/ - quit_quick_tests(0); } void quit_quick_tests(int exit_code) @@ -122,6 +146,7 @@ void init_quick_tests(int argc, char *argv[]) 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"); exit(0); } else if (0==strcmp(argv[x],"-c")) { set_exit_on_error(0); @@ -131,6 +156,8 @@ void init_quick_tests(int argc, char *argv[]) trace = atoi(argv[x+1]); } else if (0==strcmp(argv[x],"-v")) { set_print_level(5); + } else if (0==strcmp(argv[x],"-r")) { + number_of_random_tests=atoi(argv[x+1]); } } diff --git a/direct/timothy_tests/quick_tests/quick_tests.h b/direct/timothy_tests/quick_tests/quick_tests.h index bee341c..50d17dc 100644 --- a/direct/timothy_tests/quick_tests/quick_tests.h +++ b/direct/timothy_tests/quick_tests/quick_tests.h @@ -510,7 +510,10 @@ test_template test_list[]={ }; +void logical_run_of_tests(void); void init_quick_tests(int argc, char *argv[]); void quit_quick_tests(int exit_code); void get_error(void); +void run_random_test_loop(void); +void run_test(int x); #endif diff --git a/direct/timothy_tests/quick_tests/test_yaffs_read.c b/direct/timothy_tests/quick_tests/test_yaffs_read.c index 48e9826..98e3b3b 100644 --- a/direct/timothy_tests/quick_tests/test_yaffs_read.c +++ b/direct/timothy_tests/quick_tests/test_yaffs_read.c @@ -17,19 +17,14 @@ static int handle=-1; int test_yaffs_read(void) { - char text[20] = "\0"; + char text[2000] = "\0"; int output=0; handle = test_yaffs_open(); if (handle>=0){ output=yaffs_read(handle, text, FILE_TEXT_NBYTES); - if (output>0){ - if (0==memcmp(text,FILE_TEXT,FILE_TEXT_NBYTES)){ - return 1; - } else { - print_message("returned text does not match the the expected text that should be in the file\n", 2); - return -1; - } + if (output>=0){ + return 1; } else{ print_message("error reading file\n", 2); return -1; diff --git a/direct/timothy_tests/quick_tests/test_yaffs_read_EINVAL.c b/direct/timothy_tests/quick_tests/test_yaffs_read_EINVAL.c index c5b5455..873f012 100644 --- a/direct/timothy_tests/quick_tests/test_yaffs_read_EINVAL.c +++ b/direct/timothy_tests/quick_tests/test_yaffs_read_EINVAL.c @@ -113,7 +113,7 @@ int test_yaffs_read_EINVAL_init(void) return -1; } - strcat(file_name,YAFFS_MOUNT_POINT); + strcpy(file_name,YAFFS_MOUNT_POINT); for (x=strlen(YAFFS_MOUNT_POINT); x=0){ - if (FILE_MODE == (FILE_MODE & mode)){ - mode=1; - } else { - print_message("mode did not match expected file mode\n",2); - return -1; - } - } else { - mode =-1; - } - - size=yaffs_test_stat_size(); - if (size >=0){ - if (size==FILE_SIZE){ - size=1; - } else { - sprintf(message,"file size %d, expected file size %d\n",size,FILE_SIZE); - print_message(message,2); - print_message("mode did not match expected file mode\n",2); - return -1; - } - } else { - size =-1; - } - - - if ((mode>0) && (size>0)){ - return 1; - } else { - /* one of the tests failed*/ - return -1; - } + return yaffs_stat(FILE_PATH, &stat); } int test_yaffs_stat_clean(void) diff --git a/direct/timothy_tests/quick_tests/test_yaffs_write_big_file.c b/direct/timothy_tests/quick_tests/test_yaffs_write_big_file.c index 829204c..a17dd89 100644 --- a/direct/timothy_tests/quick_tests/test_yaffs_write_big_file.c +++ b/direct/timothy_tests/quick_tests/test_yaffs_write_big_file.c @@ -38,7 +38,7 @@ int test_yaffs_write_big_file(void) return -1; } - strcat(file_name,YAFFS_MOUNT_POINT); + strcpy(file_name,YAFFS_MOUNT_POINT); for (x=strlen(YAFFS_MOUNT_POINT); x