From 7bcd5472362887151e3029f197f7ee012f9c1f14 Mon Sep 17 00:00:00 2001 From: Timothy Manning Date: Wed, 17 Nov 2010 13:09:36 +1300 Subject: [PATCH] yaffs Chasing a bug in yaffsfs. Signed-off-by: Timothy Manning --- direct/timothy_tests/quick_tests/Makefile | 4 +- direct/timothy_tests/quick_tests/README.txt | 6 ++- direct/timothy_tests/quick_tests/lib.h | 2 + .../timothy_tests/quick_tests/quick_tests.c | 4 +- .../timothy_tests/quick_tests/quick_tests.h | 11 ++++- .../quick_tests/test_yaffs_mknode.c | 33 +++++++++++++ .../quick_tests/test_yaffs_mknode.h | 25 ++++++++++ .../quick_tests/test_yaffs_mount2.c | 33 +++++++++++++ .../quick_tests/test_yaffs_mount2.h | 26 ++++++++++ .../quick_tests/test_yaffs_symlink_ENOENT.c | 47 +++++++++++++++++++ .../quick_tests/test_yaffs_symlink_ENOENT.h | 25 ++++++++++ .../quick_tests/test_yaffs_truncate_EINVAL.c | 30 +++++------- .../quick_tests/test_yaffs_truncate_EISDIR.c | 30 +++++------- .../quick_tests/test_yaffs_truncate_ENOENT.c | 32 ++++++------- .../quick_tests/test_yaffs_truncate_ENOTDIR.c | 29 +++++------- .../test_yaffs_truncate_big_file.c | 30 +++++------- .../quick_tests/test_yaffs_unlink.c | 2 +- 17 files changed, 276 insertions(+), 93 deletions(-) create mode 100644 direct/timothy_tests/quick_tests/test_yaffs_mknode.c create mode 100644 direct/timothy_tests/quick_tests/test_yaffs_mknode.h create mode 100644 direct/timothy_tests/quick_tests/test_yaffs_mount2.c create mode 100644 direct/timothy_tests/quick_tests/test_yaffs_mount2.h create mode 100644 direct/timothy_tests/quick_tests/test_yaffs_symlink_ENOENT.c create mode 100644 direct/timothy_tests/quick_tests/test_yaffs_symlink_ENOENT.h diff --git a/direct/timothy_tests/quick_tests/Makefile b/direct/timothy_tests/quick_tests/Makefile index 00ef9f1..94614fb 100644 --- a/direct/timothy_tests/quick_tests/Makefile +++ b/direct/timothy_tests/quick_tests/Makefile @@ -66,7 +66,9 @@ TESTFILES = quick_tests.o lib.o \ test_yaffs_fdatasync.o test_yaffs_fdatasync_EBADF.o \ test_yaffs_mkdir.o test_yaffs_mkdir_EEXIST.o test_yaffs_mkdir_ENOTDIR.o \ test_yaffs_fchmod.o test_yaffs_fchmod_EBADF.o test_yaffs_fchmod_EINVAL.o \ - test_yaffs_symlink.o test_yaffs_symlink_ENOTDIR.o test_yaffs_symlink_EEXIST.o + test_yaffs_symlink.o test_yaffs_symlink_ENOTDIR.o test_yaffs_symlink_EEXIST.o test_yaffs_symlink_ENOENT.o \ + test_yaffs_mount2.o + diff --git a/direct/timothy_tests/quick_tests/README.txt b/direct/timothy_tests/quick_tests/README.txt index a1cb4b7..41efeee 100644 --- a/direct/timothy_tests/quick_tests/README.txt +++ b/direct/timothy_tests/quick_tests/README.txt @@ -62,6 +62,8 @@ Tests made test_yaffs_symlink test_yaffs_symlink_ENOTDIR + test_yaffs_symlink_EEXISTS + test_yaffs_symlink_ENOENT //if there is a slash on the end of new path test_yaffs_fstat test_yaffs_fstat_EBADF @@ -117,12 +119,12 @@ Tests to add test_yaffs_symlink_EACCES - test_yaffs_symlink_EEXISTS test_yaffs_symlink_ELOOP test_yaffs_symlink_ENAMETOOLONG - test_yaffs_symlink_ENOENT //if there is a slash on the end test_yaffs_symlink_EROFS + + //the yaffs_mknod function does not exist in yaffsfs, so these tests will be ignored. test_yaffs_mknod test_yaffs_mknod_EACCES test_yaffs_mknod_EEXIST diff --git a/direct/timothy_tests/quick_tests/lib.h b/direct/timothy_tests/quick_tests/lib.h index b12c04f..2906312 100644 --- a/direct/timothy_tests/quick_tests/lib.h +++ b/direct/timothy_tests/quick_tests/lib.h @@ -34,6 +34,8 @@ #define SYMLINK_PATH "/yaffs2/sym_foo" +#define NODE_PATH "/yaffs2/node" + /* 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 d74714d..f127be7 100644 --- a/direct/timothy_tests/quick_tests/quick_tests.c +++ b/direct/timothy_tests/quick_tests/quick_tests.c @@ -35,7 +35,9 @@ int main(int argc, char *argv[]){ print_message("\n\nrunning quick tests for yaffs\n\n", 0); for (x=0;x + * + * 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_yaffs_mknode.h" + +static int output = 0; + +int test_yaffs_mknode(void) +{ + output = yaffs_mknod(NODE_PATH,S_IREAD | S_IWRITE); + return output; +} + + +int test_yaffs_mknode_clean(void) +{ + if (output >= 0){ + return yaffs_unlink(NODE_PATH); + } else { + return 1; /* the file failed to open so there is no need to close it */ + } +} + diff --git a/direct/timothy_tests/quick_tests/test_yaffs_mknode.h b/direct/timothy_tests/quick_tests/test_yaffs_mknode.h new file mode 100644 index 0000000..7699141 --- /dev/null +++ b/direct/timothy_tests/quick_tests/test_yaffs_mknode.h @@ -0,0 +1,25 @@ +/* + * 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 __test_yaffs_mknode_h__ +#define __test_yaffs_mknode_h__ + +#include "lib.h" +#include "yaffsfs.h" + +int test_yaffs_mknode(void); +int test_yaffs_mknode_clean(void); + +#endif diff --git a/direct/timothy_tests/quick_tests/test_yaffs_mount2.c b/direct/timothy_tests/quick_tests/test_yaffs_mount2.c new file mode 100644 index 0000000..52728b7 --- /dev/null +++ b/direct/timothy_tests/quick_tests/test_yaffs_mount2.c @@ -0,0 +1,33 @@ +/* + * 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 "test_yaffs_mount2.h" + +int test_yaffs_mount2(void) +{ + int output = -1; + printf("closing handle again %d\n",yaffs_close(0)); + output= yaffs_unmount(YAFFS_MOUNT_POINT); + if (output < 0) { + print_message("failed to unmount current_mountpoint\n",2); + return -1; + } + + output = yaffs_mount2(YAFFS_MOUNT_POINT,255); + return output; +} + +int test_yaffs_mount2_clean(void) +{ + return 1; +} diff --git a/direct/timothy_tests/quick_tests/test_yaffs_mount2.h b/direct/timothy_tests/quick_tests/test_yaffs_mount2.h new file mode 100644 index 0000000..4db4342 --- /dev/null +++ b/direct/timothy_tests/quick_tests/test_yaffs_mount2.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 __test_yaffs_mount2__ +#define __test_yaffs_mount2__ + +#include "yaffsfs.h" +#include "lib.h" +#include "test_yaffs_unmount.h" + +int test_yaffs_mount2(void); +int test_yaffs_mount2_clean(void); + +#endif diff --git a/direct/timothy_tests/quick_tests/test_yaffs_symlink_ENOENT.c b/direct/timothy_tests/quick_tests/test_yaffs_symlink_ENOENT.c new file mode 100644 index 0000000..64129b1 --- /dev/null +++ b/direct/timothy_tests/quick_tests/test_yaffs_symlink_ENOENT.c @@ -0,0 +1,47 @@ +/* + * 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 "test_yaffs_symlink_ENOENT.h" + +static int output = 0; + +int test_yaffs_symlink_ENOENT(void) +{ + int error_code = 0; + output = yaffs_symlink(FILE_PATH,"/yaffs2//"); + if (output<0){ + error_code=yaffs_get_error(); + if (abs(error_code)==ENOENT){ + return 1; + } else { + print_message("returned error does not match the the expected error\n",2); + return -1; + } + } else { + print_message("created a symlink in a non-existing directory (which is a bad thing)\n",2); + return -1; + } + +} + +int test_yaffs_symlink_ENOENT_clean(void) +{ + if (output >= 0){ + return yaffs_unlink(SYMLINK_PATH); + } else { + return 1; /* the file failed to open so there is no need to close it */ + } +} + + + diff --git a/direct/timothy_tests/quick_tests/test_yaffs_symlink_ENOENT.h b/direct/timothy_tests/quick_tests/test_yaffs_symlink_ENOENT.h new file mode 100644 index 0000000..b6dc53d --- /dev/null +++ b/direct/timothy_tests/quick_tests/test_yaffs_symlink_ENOENT.h @@ -0,0 +1,25 @@ +/* + * 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 __test_yaffs_symlink_ENOENT_h__ +#define __test_yaffs_symlink_ENOENT_h__ + +#include "lib.h" +#include "yaffsfs.h" + +int test_yaffs_symlink_ENOENT(void); +int test_yaffs_symlink_ENOENT_clean(void); + +#endif diff --git a/direct/timothy_tests/quick_tests/test_yaffs_truncate_EINVAL.c b/direct/timothy_tests/quick_tests/test_yaffs_truncate_EINVAL.c index f56045a..26c70a1 100644 --- a/direct/timothy_tests/quick_tests/test_yaffs_truncate_EINVAL.c +++ b/direct/timothy_tests/quick_tests/test_yaffs_truncate_EINVAL.c @@ -12,32 +12,28 @@ */ #include "test_yaffs_truncate_EINVAL.h" -static int handle=-1; + int test_yaffs_truncate_EINVAL(void) { int error=0; int output=0; - handle=test_yaffs_open(); - if (handle>=0){ - output= yaffs_truncate("/yaffs2/foo",-1 ); - if (output<0){ - error=yaffs_get_error(); - if (abs(error)==EINVAL){ - return 1; - } else { - print_message("received a different error than expected\n",2); - return -1; - } - } else{ - print_message("truncated a file with a bad mode set.\n",2); + + output= yaffs_truncate("/yaffs2/foo",-1 ); + if (output<0){ + error=yaffs_get_error(); + if (abs(error)==EINVAL){ + return 1; + } else { + print_message("received a different error than expected\n",2); return -1; } - - } else { - print_message("error opening file",2); + } else{ + print_message("truncated a file with a bad mode set.\n",2); return -1; } + + } int test_yaffs_truncate_EINVAL_clean(void) diff --git a/direct/timothy_tests/quick_tests/test_yaffs_truncate_EISDIR.c b/direct/timothy_tests/quick_tests/test_yaffs_truncate_EISDIR.c index cfd1d82..b6bd10f 100644 --- a/direct/timothy_tests/quick_tests/test_yaffs_truncate_EISDIR.c +++ b/direct/timothy_tests/quick_tests/test_yaffs_truncate_EISDIR.c @@ -18,26 +18,22 @@ int test_yaffs_truncate_EISDIR(void) { int error = 0; int output = 0; - handle = test_yaffs_open(); - if (handle>=0){ - output = yaffs_truncate("/yaffs2/",10); - if (output < 0){ - error = yaffs_get_error(); - if (abs(error) == EISDIR){ - return 1; - } else { - print_message("received a different error than expected\n",2); - return -1; - } - } else{ - print_message("truncated a directory\n",2); + + + output = yaffs_truncate("/yaffs2/",10); + if (output < 0){ + error = yaffs_get_error(); + if (abs(error) == EISDIR){ + return 1; + } else { + print_message("received a different error than expected\n",2); return -1; } - - } else { - print_message("error opening file\n",2); - return 1; + } else{ + print_message("truncated a directory\n",2); + return -1; } + } int test_yaffs_truncate_EISDIR_clean(void) diff --git a/direct/timothy_tests/quick_tests/test_yaffs_truncate_ENOENT.c b/direct/timothy_tests/quick_tests/test_yaffs_truncate_ENOENT.c index 72d7314..21b2873 100644 --- a/direct/timothy_tests/quick_tests/test_yaffs_truncate_ENOENT.c +++ b/direct/timothy_tests/quick_tests/test_yaffs_truncate_ENOENT.c @@ -12,32 +12,28 @@ */ #include "test_yaffs_truncate_ENOENT.h" -static int handle = -1; + int test_yaffs_truncate_ENOENT(void) { int error=0; int output=0; - handle=test_yaffs_open(); - if (handle>=0){ - output= yaffs_truncate("/yaffs2/non_existing_file",FILE_SIZE_TRUNCATED ); - if (output<0){ - error=yaffs_get_error(); - if (abs(error)==ENOENT){ - return 1; - } else { - print_message("received a different error than expected\n",2); - return -1; - } - } else{ - print_message("truncated a nonexisting file\n",2); + + output= yaffs_truncate("/yaffs2/non_existing_file",FILE_SIZE_TRUNCATED ); + if (output<0){ + error=yaffs_get_error(); + if (abs(error)==ENOENT){ + return 1; + } else { + print_message("received a different error than expected\n",2); return -1; - } - } else { - print_message("error opening file",2); + } + } else{ + print_message("truncated a nonexisting file\n",2); return -1; - } + } + } int test_yaffs_truncate_ENOENT_clean(void) diff --git a/direct/timothy_tests/quick_tests/test_yaffs_truncate_ENOTDIR.c b/direct/timothy_tests/quick_tests/test_yaffs_truncate_ENOTDIR.c index c2414db..d8ef155 100644 --- a/direct/timothy_tests/quick_tests/test_yaffs_truncate_ENOTDIR.c +++ b/direct/timothy_tests/quick_tests/test_yaffs_truncate_ENOTDIR.c @@ -13,30 +13,25 @@ #include "test_yaffs_truncate_ENOTDIR.h" -static int handle = -1; + int test_yaffs_truncate_ENOTDIR(void) { int error=0; int output=0; - handle=test_yaffs_open(); - if (handle>=0){ - output= yaffs_truncate("/non_existing_dir/foo",FILE_SIZE_TRUNCATED ); - if (output<0){ - error=yaffs_get_error(); - if (abs(error)==ENOTDIR){ - return 1; - } else { - print_message("received a different error than expected\n",2); - return -1; - } - } else{ - print_message("truncated a nonexisting file\n",2); + + + output= yaffs_truncate("/non_existing_dir/foo",FILE_SIZE_TRUNCATED ); + if (output<0){ + error=yaffs_get_error(); + if (abs(error)==ENOTDIR){ + return 1; + } else { + print_message("received a different error than expected\n",2); return -1; } - - } else { - print_message("error opening file\n",2); + } else{ + print_message("truncated a nonexisting file\n",2); return -1; } } diff --git a/direct/timothy_tests/quick_tests/test_yaffs_truncate_big_file.c b/direct/timothy_tests/quick_tests/test_yaffs_truncate_big_file.c index 270bf49..7ec30cf 100644 --- a/direct/timothy_tests/quick_tests/test_yaffs_truncate_big_file.c +++ b/direct/timothy_tests/quick_tests/test_yaffs_truncate_big_file.c @@ -12,32 +12,28 @@ */ #include "test_yaffs_truncate_big_file.h" -static int handle = -1; + int test_yaffs_truncate_big_file(void) { int error=0; int output=0; - handle=test_yaffs_open(); - if (handle>=0){ - output= yaffs_truncate("/yaffs2/foo",10000000000000000000000000000000000000000000 ); - if (output<0){ - error=yaffs_get_error(); - if (abs(error)==EINVAL){ /*in yaffs EINVAL is used instead of big_file */ - return 1; - } else { - print_message("received a different error than expected\n",2); - return -1; - } - } else{ - print_message("truncated a file to a massive size\n",2); + + output= yaffs_truncate("/yaffs2/foo",10000000000000000000000000000000000000000000 ); + if (output<0){ + error=yaffs_get_error(); + if (abs(error)==EINVAL){ /*in yaffs EINVAL is used instead of big_file */ + return 1; + } else { + print_message("received a different error than expected\n",2); return -1; } - - } else { - print_message("error opening file\n",2); + } else{ + print_message("truncated a file to a massive size\n",2); return -1; } + + } int test_yaffs_truncate_big_file_clean(void) diff --git a/direct/timothy_tests/quick_tests/test_yaffs_unlink.c b/direct/timothy_tests/quick_tests/test_yaffs_unlink.c index 75cf7c0..4436da6 100644 --- a/direct/timothy_tests/quick_tests/test_yaffs_unlink.c +++ b/direct/timothy_tests/quick_tests/test_yaffs_unlink.c @@ -26,5 +26,5 @@ int test_yaffs_unlink(void) int test_yaffs_unlink_clean(void) { - return test_yaffs_open(); + return test_yaffs_open()||test_yaffs_open_clean(); } -- 2.30.2