From 6e8abe36e3190664d26161ace6948c57f9ffda94 Mon Sep 17 00:00:00 2001 From: Timothy Manning Date: Fri, 17 Dec 2010 09:21:32 +1300 Subject: [PATCH] yaffs Added some more tests to direct/timothy_tests/mirror_tests Signed-off-by: Timothy Manning --- direct/timothy_tests/mirror_tests/Makefile | 3 +- direct/timothy_tests/mirror_tests/lib.c | 4 +++ direct/timothy_tests/mirror_tests/lib.h | 1 + .../mirror_tests/linux_test_write.c | 35 +++++++++++++++++++ .../mirror_tests/linux_test_write.h | 27 ++++++++++++++ .../timothy_tests/mirror_tests/mirror_tests.c | 21 +++++++---- .../timothy_tests/mirror_tests/mirror_tests.h | 2 ++ .../mirror_tests/yaffs_test_write.c | 35 +++++++++++++++++++ .../mirror_tests/yaffs_test_write.h | 27 ++++++++++++++ 9 files changed, 147 insertions(+), 8 deletions(-) create mode 100644 direct/timothy_tests/mirror_tests/linux_test_write.c create mode 100644 direct/timothy_tests/mirror_tests/linux_test_write.h create mode 100644 direct/timothy_tests/mirror_tests/yaffs_test_write.c create mode 100644 direct/timothy_tests/mirror_tests/yaffs_test_write.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/lib.c b/direct/timothy_tests/mirror_tests/lib.c index 1a9d6ac..558de9a 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) { diff --git a/direct/timothy_tests/mirror_tests/lib.h b/direct/timothy_tests/mirror_tests/lib.h index 99c2763..c77e2f6 100644 --- a/direct/timothy_tests/mirror_tests/lib.h +++ b/direct/timothy_tests/mirror_tests/lib.h @@ -44,6 +44,7 @@ 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); 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..9695953 --- /dev/null +++ b/direct/timothy_tests/mirror_tests/linux_test_write.c @@ -0,0 +1,35 @@ +/* + * 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_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); + handle=open(path,args_struct->char1 &(O_TRUNC|O_EXCL|O_CREAT|O_APPEND),args_struct->char2&(S_IREAD|S_IWRITE)); + 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 + * + * 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 +#include +#include +#include +#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 28b88b5..758b0a9 100644 --- a/direct/timothy_tests/mirror_tests/mirror_tests.c +++ b/direct/timothy_tests/mirror_tests/mirror_tests.c @@ -31,18 +31,20 @@ 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} } }; @@ -165,7 +167,7 @@ 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; + int num_of_tests_before_check=1; char message[200]; arg_temp args_struct; for (y=0;(y*num_of_tests_before_check)=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(); @@ -295,7 +302,7 @@ int compare_linux_and_yaffs(void) sprintf(message,"searching for yaffs file: %s\n",yaffs_file_list[x]); print_message(3,message); for (y=0;y + * + * 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; + int handle; + 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); + handle=yaffs_open(path,args_struct->char1 &(O_TRUNC|O_EXCL|O_CREAT|O_APPEND),args_struct->char2&(S_IREAD|S_IWRITE)); + 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=yaffs_write(handle,args_struct->string2,strlen(args_struct->string2)); + yaffs_close(handle); + 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 + * + * 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 +#include +#include +#include +#include "yaffsfs.h" +#include "lib.h" + +int yaffs_test_write(arg_temp *args_struct); + +#endif -- 2.30.2