yaffs Added some more tests to direct/timothy_tests/mirror_tests
[yaffs2.git] / direct / timothy_tests / mirror_tests / lib.c
1 /*
2  * YAFFS: Yet another FFS. A NAND-flash specific file system.
3  *
4  * Copyright (C) 2002-2010 Aleph One Ltd.
5  *   for Toby Churchill Ltd and Brightstar Engineering
6  *
7  * Created by Timothy Manning <timothy@yaffs.net>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 2 as
11  * published by the Free Software Foundation.
12  */
13
14 #include "lib.h"
15
16 static int EXIT_ON_ERROR = 1;
17 static int  PRINT_LEVEL = 2;    //This sets the level of detail which is printed. There are 3 levels 0,1,2 and 3  
18                         //0 just prints the number of tests passed and failed.
19                         //1 is the basic print level. it will print the details of a failed test.
20                         //2 will print if a test passes and cleans. 
21 void set_print_level(int new_level)
22 {
23         PRINT_LEVEL=new_level;
24 }
25 int get_print_level(void)
26 {
27         return PRINT_LEVEL;
28 }
29
30 void set_exit_on_error(int num)
31 {
32         EXIT_ON_ERROR=num;
33 }
34
35 int get_exit_on_error(void)
36 {
37         return EXIT_ON_ERROR;
38 }
39
40 void display_error(void)
41 {
42         
43 }
44
45 void  generate_random_string(char *ptr,int length_of_str){
46         unsigned int x;
47         unsigned int length=((rand() %(length_of_str-3))+3);    /*creates a int with the number of charecters been between 1 and 51*/           
48         char letter='\0';
49         strcpy(ptr,"");
50         //printf("generating string\n");
51         //printf("string length is %d\n",length);
52         for (x=0; x <= (length-2) &&length>2 ; x++)
53         {
54                 //printf("x=%d\n",x);   
55                 /* keep generating a charecter until the charecter is legal*/
56                 while((letter=='\0' )||(letter=='/')||(letter=='\\')){
57                         letter=(rand() % 125-59)+58;    /*generate a number between 32 and 126 and uses it as a charecter (letter) */
58                 }       
59                 ptr[x]=letter;
60                 //printf("charecter generated is %c\n",ptr[x]);
61         }
62         ptr[x+1]='\0';  /*adds NULL charecter to turn it into a string*/
63         
64 }
65
66 void join_paths(char *path1,char *path2,char *new_path )
67 {
68         char message[100];
69         print_message(3,"joining paths\n");
70         sprintf(message,"path1: %s\n",path1);
71         print_message(3,message);
72         sprintf(message,"path2: %s\n",path2);
73         print_message(3,message);
74         strcpy(new_path,"");
75         //strcat(new_path,path1);       /*since all functions have this then pull it out*/
76         if ( (path1[(sizeof(path1)/sizeof(char))-2]=='/') && path2[0]!='/') {
77                 /*paths are compatiable. concatanate them. note -2 is because of \0*/  
78                 strcat(new_path,path1);
79                 strcat(new_path,path2);         
80                 //char new_path[(sizeof(path1)/sizeof(char))+(sizeof(path2)/sizeof(char))];
81                 //strcpy(new_path,strcat(path1,path2)); 
82                 //return new_path;
83         } else if ((path1[(sizeof(path1)/sizeof(char))-2]!='/') && path2[0]=='/') {
84                 /*paths are compatiable. concatanate them*/  
85                 strcat(new_path,path1);
86                 strcat(new_path,path2);         
87
88         } else if ((path1[(sizeof(path1)/sizeof(char))-2]!='/') && path2[0]!='/') {
89                         /*need to add a "/". */  
90                 strcat(new_path,path1);
91                 strcat(new_path,"/");
92                 strcat(new_path,path2);
93
94         } else if ((path1[(sizeof(path1)/sizeof(char))-2]=='/') && path2[0]=='/') {
95                 /*need to remove a "/". */
96                 /*yaffs does not mind the extra slash. */               
97                 strcat(new_path,path1);
98                 strcat(new_path,path2);
99
100         } else {
101                 //error 
102                 //return -1;
103         }
104 }
105
106 void print_message(char print_level,char *message)
107 {
108         if (print_level <= PRINT_LEVEL){
109                 printf(message);
110         }
111 }
112         
113
114