X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs2.git;a=blobdiff_plain;f=direct%2Ftimothy_tests%2Fquick_tests%2Ftest_yaffs_read_EINVAL.c;h=57f47fb8db34f42aadb3cdb6084c68f1c177e86e;hp=f11e3adbf8b6f4432d44ed54ad761637fdce8548;hb=fc8b640f9637823d87b9582c7edcb87adcd0383a;hpb=4f90d524e3c666c53ae36ad2911e00e5b3741cca 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 f11e3ad..57f47fb 100644 --- a/direct/timothy_tests/quick_tests/test_yaffs_read_EINVAL.c +++ b/direct/timothy_tests/quick_tests/test_yaffs_read_EINVAL.c @@ -13,44 +13,129 @@ #include "test_yaffs_read_EINVAL.h" -static int handle=0; +static int handle = -1; +static char *file_name = NULL; -int test_yaffs_read_EINVAL(void){ - int error_code=0; - handle=test_yaffs_open(); - char text[20]="\0"; - int output=0; +int test_yaffs_read_EINVAL(void) +{ + int error_code = 0; + handle=yaffs_open(FILE_PATH,O_CREAT | O_RDWR, FILE_MODE); + char text[2000000]="\0"; + int output=0; + + if (handle<0){ + print_message("could not open file\n",2); + return -1; + } + + /*there needs a large amout of test in the file in order to trigger EINVAL */ + output=test_yaffs_read_EINVAL_init(); + if (output<0){ + print_message("could not write text to the file\n",2); + return -1; + } if (handle>=0){ output=yaffs_read(handle, text, -1); - if (output<0){ error_code=yaffs_get_error(); if (abs(error_code)== EINVAL){ return 1; + } else { + print_message("different error than expected\n",2); + return -1; } - else { - printf("different error than expected\n"); + } else{ + print_message("read a negative number of bytes (which is a bad thing)\n",2); + return -1; + } + } else { + print_message("error opening file\n",2); + return -1; + } +} + +int test_yaffs_read_EINVAL_clean(void) +{ + int output=0; + if (handle>=0){ + if(file_name){ + free(file_name); + file_name = NULL; + } + + + output= yaffs_truncate(FILE_PATH,FILE_SIZE ); + if (output>=0){ + output=test_yaffs_write(); + if (output<0){ + print_message("failed to write to file\n",2); return -1; + } else { + output=test_yaffs_write_clean(); + if (output<0){ + print_message("failed to clean the write_to_file function\n",2); + } } + } else { + print_message("failed to truncate file\n",2); + return -1; } - else{ - printf("read a non-existing file (which is a bad thing)\n"); + + if(output>=0){ + output=yaffs_close(handle); + if (output>=0){ + return 1; + } else { + print_message("could not close the handle\n",2); + return -1; + } + } else { + print_message("failed to fix the file\n",2); return -1; } + } else { + print_message("no open handle\n",2); + return -1; } - else { - printf("error opening file\n"); +} + +int test_yaffs_read_EINVAL_init(void) +{ + int output=0; + int x=0; + + int file_name_length=1000000; + + file_name = malloc(file_name_length); + if(!file_name){ + print_message("unable to create file text\n",2); return -1; } -} + strcat(file_name,YAFFS_MOUNT_POINT); + for (x=strlen(YAFFS_MOUNT_POINT); x=0){ - return yaffs_close(handle); + output= yaffs_write(handle, file_name, file_name_length-1); + if (output<0){ + print_message("could not write text to file\n",2); + return -1; + } else { + + return 1; + } + + } else { + print_message("error opening file\n",2); + return -1; } - else { - return 1; /* no handle was opened so there is no need to close a handle */ - } + } + +