void print_message(char *message,char print_level)
{
if (print_level <= PRINT_LEVEL){
- printf(message);
+ printf("%s",message);
}
}
-
+/*same as forcing the rmdir of a directory*/
+int delete_dir(char *dir_name)
+{
+ yaffs_DIR *d;
+ struct yaffs_dirent *de;
+ struct yaffs_stat s;
+ char str[100];
+ d = yaffs_opendir(dir_name);
+ printf("%s\n",dir_name);
+ if(!d)
+ {
+ printf("%s\n",dir_name);
+ print_message("failed to open dir\n",2);
+ get_error();
+ return -1;
+ }
+
+ while((de = yaffs_readdir(d)) != NULL) {
+ //stats the file
+ sprintf(str,"%s/%s",dir_name,de->d_name);
+ yaffs_lstat(str,&s);
+
+ if ((s.st_mode & S_IFMT) == S_IFDIR){
+ //it is a directory. call the function recursivly.
+ delete_dir(str);
+ yaffs_rmdir(str);
+ }else{
+ yaffs_unlink(str);
+ }
+ }
+ yaffs_rmdir(dir_name);
+ yaffs_closedir(d);
+ return 1;
+}
+
+void get_error(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(message,1);
+ sprintf(message,"error is : %s\n",yaffs_error_to_str(error_code));
+ print_message(message,1);
+}
#define YAFFS_MOUNT_POINT "/yaffs2/"
-#define FILE_NAME "foo"
+#define FILE_NAME "test_dir/foo"
#define FILE_SIZE 10
#define FILE_MODE (S_IREAD | S_IWRITE)
#define FILE_SIZE_TRUNCATED 100
#define FILE_TEXT "file foo " /* keep space at end of string */
#define FILE_TEXT_NBYTES 10
+#define TEST_DIR "/yaffs2/test_dir"
+#define DIR_PATH "/yaffs2/test_dir/new_directory"
-#define DIR_PATH "/yaffs2/new_directory"
+#define SYMLINK_PATH "/yaffs2/test_dir/sym_foo"
-#define SYMLINK_PATH "/yaffs2/sym_foo"
+#define HARD_LINK_PATH "/yaffs2/test_dir/hard_link"
-#define HARD_LINK_PATH "/yaffs2/hard_link"
+#define NODE_PATH "/yaffs2/test_dir/node"
-#define NODE_PATH "/yaffs2/node"
+#define RENAME_PATH "/yaffs2/test_dir/foo2"
-#define RENAME_PATH "/yaffs2/foo2"
+#define RENAME_DIR_PATH "/yaffs2/test_dir/dir2"
-#define RENAME_DIR_PATH "/yaffs2/dir2"
+#define ELOOP_PATH "/yaffs2/test_dir/ELOOP"
+#define ELOOP2_PATH "/yaffs2/test_dir/ELOOP2"
-#define ELOOP_PATH "/yaffs2/ELOOP"
-#define ELOOP2_PATH "/yaffs2/ELOOP2"
-
-#define RMDIR_PATH "/yaffs2/RM_DIR"
+#define RMDIR_PATH "/yaffs2/test_dir/RM_DIR"
/* warning do not define anything as FILE because there seems to be a conflict with stdio.h */
-#define FILE_PATH "/yaffs2/foo"
+#define FILE_PATH "/yaffs2/test_dir/foo"
void join_paths(char *path1,char *path2,char *new_path );
void print_message(char *message,char print_level);
int set_up_ELOOP(void);
int EROFS_setup(void);
int EROFS_clean(void);
+int delete_dir(char *dir_name);
+void get_error(void);
#endif
}
/*this is where the loop should break to*/
quit_quick_tests(0);
+
}
void run_random_test_loop(void)
{
int id=0;
- int x=0;
- int run_list[total_number_of_tests];
+ unsigned int x=0;
+ //int run_list[total_number_of_tests];
for (x=0;x<total_number_of_tests;x++){
id = (rand() % (total_number_of_tests-1));
run_test(id);
void run_test(int x)
{
int output=0;
+ int y= 0;
char message[200];
message[0]='\0';
+ printf ("making test dir %d\n",yaffs_mkdir(TEST_DIR,S_IWRITE | S_IREAD));
yaffs_set_error(0); /*reset the last error to 0 */
//printf("foo exists %d\n",test_yaffs_open());
sprintf(message,"\ttest clean: %s passed\n",test_list[x].name_of_test);
print_message(message,3);
}
+ /* close all open handles */
+ for (y=0; y<100;y++){
+ yaffs_close(y);
+ }
+ delete_dir(TEST_DIR);
}
void quit_quick_tests(int exit_code)
{
- char message[30];
- message[0]='\0';
+ /*char message[30];
+ message[0]='\0';
+ */
if (num_of_tests_pass==total_number_of_tests && num_of_tests_failed==0){
printf("\t OK --all tests passed\n");
}
exit(exit_code);
}
-void get_error(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(message,1);
- sprintf(message,"error is : %s\n",yaffs_error_to_str(error_code));
- print_message(message,1);
-}
void init_quick_tests(int argc, char *argv[])
{
int trace=0;
int new_option;
- int x=0;
+ //int x=0;
do{
new_option=getopt_long(argc,argv,short_options,long_options,NULL);
if (new_option=='h'){
int error_code=0;
int output =-1;
if (yaffs_access(FILE_PATH,0)!=0){
- output=yaffs_close(test_yaffs_open());
+
+ handle = yaffs_open(FILE_PATH, O_CREAT | O_RDWR, FILE_MODE);
+
+ output=yaffs_close(handle);
if (output<0){
print_message("failed to open file\n",2);
return -1;
int test_yaffs_open_EEXIST(void)
{
int error_code = 0;
+ handle = yaffs_open(FILE_PATH, O_CREAT | O_EXCL | O_TRUNC| O_RDWR ,FILE_MODE );
handle = yaffs_open(FILE_PATH, O_CREAT | O_EXCL | O_TRUNC| O_RDWR ,FILE_MODE );
if (handle == -1){
int test_yaffs_open_EINVAL(void)
{
int error_code = 0;
+ handle = yaffs_open(FILE_PATH, O_CREAT | O_RDWR, FILE_MODE);
handle=yaffs_open(FILE_PATH, 255,FILE_MODE);
if (handle == -1){
int test_yaffs_open_ENOTDIR(void)
{
int error_code=0;
+ handle = yaffs_open(FILE_PATH,O_CREAT | O_RDWR, FILE_MODE);
- handle=yaffs_open("/yaffs2/foo/file", O_TRUNC| O_RDWR,FILE_MODE );
+ handle=yaffs_open("/yaffs2/test_dir/foo/file", O_TRUNC| O_RDWR,FILE_MODE );
if (handle <0){
error_code=yaffs_get_error();
if (abs(error_code)==ENOTDIR){
#include "test_yaffs_rename_dir.h"
-
+/*creates a new directory and renames it*/
int test_yaffs_rename_dir(void)
{
int output=0;
#include "test_yaffs_rename_dir_ENOENT.h"
-
+/*tries to rename a nonexisting directory */
int test_yaffs_rename_dir_ENOENT(void)
{
int output=0;
#include "test_yaffs_rename_dir.h"
-
+/*tests renaming a non empty file */
int test_yaffs_rename_dir(void)
{
int output=0;
#include "test_yaffs_rename_dir_to_file.h"
-
+/*tries to rename a directory over an existing file */
int test_yaffs_rename_dir_to_file(void)
{
int output=0;
if (0 != yaffs_access(DIR_PATH,0)) {
output= yaffs_mkdir(DIR_PATH,(S_IREAD | S_IWRITE));
if (output<0) {
- print_message("failed to remove directory\n",2);
+ print_message("failed to create directory\n",2);
return -1;
}
}
}
}
}
+ if (0 != yaffs_access(RENAME_DIR_PATH,0)) {
+ output = yaffs_mkdir(RENAME_DIR_PATH,S_IWRITE | S_IREAD);
+ if (output < 0) {
+ print_message("failed to create directory\n",2);
+ return -1;
+ }
+ }
output = yaffs_rename( "/yaffs2/foo" , RENAME_DIR_PATH);
if (output<0){
print_message("failed to rename a file over an empty directory\n",2);