yaffs More tests for quick tests.
[yaffs2.git] / direct / timothy_tests / quick_tests / test_yaffs_read_EINVAL.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 "test_yaffs_read_EINVAL.h"
15
16 static int handle=0;
17
18 static char *file_name = NULL;
19 int test_yaffs_read_EINVAL(void){
20         int error_code=0;
21         handle=test_yaffs_open();
22         char text[2000000]="\0";
23         int output=0;   
24         
25         if (handle<0){
26                 printf("could not open file\n");
27                 return -1;
28         }       
29
30         /*there needs a large amout of test in the file in order to trigger EINVAL */
31         output=test_yaffs_read_EINVAL_init();
32         if (output<0){
33                 printf("could not write text to the file\n");
34                 return -1; 
35         }
36
37         if (handle>=0){
38                 output=yaffs_read(handle, text, -1);
39
40                 if (output<0){ 
41                         error_code=yaffs_get_error();
42                         if (abs(error_code)== EINVAL){
43                                 return 1;
44                         }
45                         else {
46                                 printf("different error than expected\n");
47                                 return -1;
48                         }
49                 }
50                 else{
51                         printf("read a negative number of bytes (which is a bad thing)\n");
52                         return -1;
53                 }
54         }
55         else {
56                 printf("error opening file\n");
57                 return -1;
58         }
59         
60 }
61
62 int test_yaffs_read_EINVAL_clean(void){
63         int output=0;
64         if (handle>=0){
65                 output=test_yaffs_read_EINVAL_init_clean();
66                 if(output>=0){
67                         output=yaffs_close(handle);
68                         if (output>=0){
69                                 return 1;
70                         } else {
71                                 printf("could not close the handle\n");
72                                 return -1;
73                         }
74                 } else {
75                         printf("failed to fix the file\n");
76                         return -1;
77                 }
78         }
79
80 }
81
82 int test_yaffs_read_EINVAL_init(void)
83 {
84         int output=0;
85         int error_code=0;
86         int x=0;
87         
88         int file_name_length=1000000;
89
90         file_name = malloc(file_name_length);
91         if(!file_name){
92                 printf("unable to create file text\n");
93                 return -1;
94         }
95         
96         strcat(file_name,YAFFS_MOUNT_POINT);
97         for (x=strlen(YAFFS_MOUNT_POINT); x<file_name_length -1; x++){
98                 file_name[x]='a';
99         }
100         file_name[file_name_length-2]='\0';
101
102
103
104         if (handle>=0){
105                 output= yaffs_write(handle, file_name, file_name_length-1);
106                 if (output<0){
107                         printf("could not write text to file\n");
108                         return -1;
109                 } else {
110                         
111                         return 1;
112                 }
113
114         } else {
115                 printf("error opening file\n");
116                 return -1;
117         }
118         
119 }
120
121 int test_yaffs_read_EINVAL_init_clean(void)
122 {
123         int output=1;
124         if(file_name){
125                 free(file_name);
126                 file_name = NULL;
127         }
128
129         
130         output= yaffs_truncate(FILE_PATH,FILE_SIZE );   
131         if (output>=0){
132                 output=test_yaffs_write();
133                 if (output>=0){
134                         return 1;
135                 } else {
136                         printf("failed to write to file\n");
137                         return -1;
138                 }
139         } else {
140                 printf("failed to truncate file\n");
141                 return -1;
142         }
143
144 }
145