Update timothy test Makefile
[yaffs2.git] / direct / timothy_tests / quick_tests / test_yaffs_write_big_file.c
1 /*
2  * YAFFS: Yet another FFS. A NAND-flash specific file system.
3  *
4  * Copyright (C) 2002-2011 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_write_big_file.h"
15
16 static int handle=-1;
17 static char *file_name = NULL;
18 int test_yaffs_write_big_file(void)
19 {
20         int output=0;
21         int error_code=0;
22         handle=test_yaffs_open();
23         int x=0;
24         
25         int file_name_length=20000;
26         if (handle<0){
27                 printf("failed to open file\n");
28                 return -1;
29         }
30         output=yaffs_lseek(handle,0x7FFFFF00, SEEK_SET);
31         if (output<0){
32                 printf("failed to seek\n");
33                 return -1;
34         }
35         file_name = malloc(file_name_length);
36         if(!file_name){
37                 printf("unable to create file text\n");
38                 return -1;
39         }
40         
41         strcpy(file_name,YAFFS_MOUNT_POINT);
42         for (x=strlen(YAFFS_MOUNT_POINT); x<file_name_length -1; x++){
43                 file_name[x]='a';
44         }
45         file_name[file_name_length-2]='\0';
46
47
48
49         if (handle>=0){
50                 output= yaffs_write(handle, file_name, file_name_length-1);
51                 if (output<0){
52                         error_code=yaffs_get_error();
53                         //printf("EISDIR def %d, Error code %d\n", ENOTDIR,error_code);
54                         if (abs(error_code)==EINVAL){
55                                 return 1;
56                         } else {
57                                 printf("different error than expected\n");
58                                 return -1;
59                         }
60                 } else {
61                         printf("wrote a large amount of text to a file.(which is a bad thing)\n");
62                         return -1;
63                 }
64
65         } else {
66                 printf("error opening file\n");
67                 return -1;
68         }
69         
70 }
71
72 int test_yaffs_write_big_file_clean(void)
73 {
74         int output=1;
75         if(file_name){
76                 free(file_name);
77                 file_name = NULL;
78         }
79
80         if (handle>=0){ 
81                 output=yaffs_close(handle);
82         }
83
84         
85         output= yaffs_truncate(FILE_PATH,FILE_SIZE );   
86         if (output>=0){
87                 output=test_yaffs_write();
88                 if (output>=0){
89                         return test_yaffs_write_clean();
90                 } else {
91                         printf("failed to write to file\n");
92                         return -1;
93                 }
94         } else {
95                 printf("failed to truncate file\n");
96                 return -1;
97         }
98
99 }