Made by Timothy Manning <timothy@yaffs.net> on 04/11/2010
+the yaffs_open function has been covered by tests
+the yaffs_close function has been covered by tests
+
+
+
+tests to add
+ test_yaffs_open_EACCES
+ test_yaffs_open_ENOSPC
+ test_yaffs_open_ELOOP Too many symbolic links were encountered in resolving pathname
+ test_yaffs_close
+ test yaffs_open_running_out_of_handles error
+ check to see if an error code is generated when there isn't an error
How to add a test
#include <string.h>
#define YAFFS_MOUNT_POINT "/yaffs2/"
#define FILE_NAME "foo"
-#define FILE_SIZE 9
+#define FILE_SIZE 10
#define FILE_MODE (S_IREAD | S_IWRITE)
#define FILE_SIZE_TRUNCATED 100
-#define FILE_TEXT "file foo"
-#define FILE_TEXT_NBYTES 9
+#define FILE_TEXT "file foo " /* keep space at end of string */
+#define FILE_TEXT_NBYTES 10
/* warning do not define anything as FILE because there seems to be a conflict with stdio.h */
#define FILE_PATH "/yaffs2/foo"
//printf("len function %d",(sizeof(test_list)/sizeof(test_template)));
for (x=0;x<total_number_of_tests;x++){
//printf("x %d\n",x);
+ yaffs_set_error(0); /*reset the last error to 0 */
output=test_list[x].p_function(); /*run test*/
if (output>=0){
/*test has passed*/
{test_yaffs_open,test_yaffs_open_clean,"test_yaffs_open"},
{test_yaffs_open_EISDIR,test_yaffs_open_EISDIR_clean,"test_yaffs_open_EISDIR"},
{test_yaffs_open_EEXIST,test_yaffs_open_EEXIST_clean,"test_yaffs_open_EEXIST"},
-// {test_yaffs_open_ENOTDIR,test_yaffs_open_ENOTDIR_clean,"test_yaffs_open_ENOTDIR"},
-// {test_yaffs_open_ENOENT,test_yaffs_open_ENOENT_clean,"test_yaffs_open_ENOENT"},
+ {test_yaffs_open_ENOTDIR,test_yaffs_open_ENOTDIR_clean,"test_yaffs_open_ENOTDIR"},
+ {test_yaffs_open_ENOENT,test_yaffs_open_ENOENT_clean,"test_yaffs_open_ENOENT"},
{test_yaffs_close_EBADF,test_yaffs_close_EBADF_clean,"test_yaffs_close_EBADF"},
if (output<0){
/*error has happened */
error_code=yaffs_get_error();
- printf("EEXIST def %d, Error code %d\n",(- EBADF),error_code);
+ //printf("EBADF def %d, Error code %d\n",(- EBADF),error_code);
if (abs(error_code)== EBADF){
return 1;
}
int test_yaffs_open(void){
- handle=yaffs_open(FILE_PATH,O_CREAT | O_TRUNC| O_RDWR, FILE_MODE);
+ handle=yaffs_open(FILE_PATH,O_CREAT | O_RDWR, FILE_MODE);
return handle;
}
handle=yaffs_open(FILE_PATH, O_CREAT | O_EXCL | O_TRUNC| O_RDWR ,FILE_MODE );
if (handle==-1){
error_code=yaffs_get_error();
- printf("EEXIST def %d, Error code %d\n",(- EEXIST),error_code);
+ //printf("EEXIST def %d, Error code %d\n",(- EEXIST),error_code);
if (abs(error_code)== EEXIST){
return 1;
}
handle=yaffs_open(YAFFS_MOUNT_POINT, O_CREAT | O_TRUNC| O_RDWR ,FILE_MODE );
if (handle==-1){
error_code=yaffs_get_error();
- printf("EISDIR def %d, Error code %d\n", EISDIR,error_code);
+ //printf("EISDIR def %d, Error code %d\n", EISDIR,error_code);
if (abs(error_code)== EISDIR){
return 1;
}
handle=yaffs_open("/nonexisting_dir/foo", O_TRUNC| O_RDWR,FILE_MODE );
if (handle==-1){
error_code=yaffs_get_error();
- printf("EISDIR def %d, Error code %d\n", ENOTDIR,error_code);
+ //printf("EISDIR def %d, Error code %d\n", ENOTDIR,error_code);
if (abs(error_code)==ENOTDIR){
return 1;
}
handle=test_yaffs_open();
char text[20]="\0";
int output=0;
- printf("handle %d\n",handle);
+ //printf("handle %d\n",handle);
if (handle>=0){
output=yaffs_read(handle, text, FILE_TEXT_NBYTES);
- printf("yaffs_test_read output: %d\n",output);
- printf("text in file is: %s\n",text);
+ //printf("yaffs_test_read output: %d\n",output);
+ //printf("text in file is: '%s' expected text is '%s'\n",text,FILE_TEXT);
if (output>0){
- if (text==FILE_TEXT){
+ if (0==memcmp(text,FILE_TEXT,FILE_TEXT_NBYTES)){
return 1;
}
else {
int mode=0;
int size=0;
mode =yaffs_test_stat_mode();
- printf("\nmode %o\n",mode);
+/* printf("\nmode %o\n",mode);
printf("expected mode %o \n",FILE_MODE);
printf("anding together %o\n",FILE_MODE & mode);
printf("%d\n",FILE_MODE == (FILE_MODE & mode));
- if (FILE_MODE == (FILE_MODE & mode)){
+*/ if (FILE_MODE == (FILE_MODE & mode)){
mode=1;
}
else {
printf("mode did not match expected file mode\n");
return -1;
}
- if (yaffs_test_stat_size()==FILE_SIZE){
+ size=yaffs_test_stat_size();
+ if (size==FILE_SIZE){
size=1;
}
else {
+ printf("file size %d, expected file size %d\n",size,FILE_SIZE);
printf("mode did not match expected file mode\n");
return -1;
}
struct yaffs_stat stat;
int output=0;
output=yaffs_stat(FILE_PATH, &stat);
- printf("output: %d\n",output);
+ //printf("output: %d\n",output);
if (output>=0){
return stat.st_mode;
}