Fix unmatched temporary buffer allocations
[yaffs2.git] / direct / test-framework / unit_tests / is_yaffs_working_tests / test_1_yaffs_mount.c
1 /*
2  * YAFFS: Yet another FFS. A NAND-flash specific file system.
3  *
4  * Copyright (C) 2002-2018 Aleph One Ltd.
5  *
6  * Created by Timothy Manning <timothy@yaffs.net>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as
10  * published by the Free Software Foundation.
11  */
12
13
14 #include "yaffsfs.h"
15 #define YAFFS_MOUNT_POINT "/yflash2/"
16 #define FILE_PATH "/yflash2/foo.txt"
17
18 int random_seed;
19 int simulate_power_failure = 0;
20
21
22 int main()
23 {
24         int output = 0;
25         int output2 = 0;
26         yaffs_start_up();
27
28         printf("\n\n starting test\n");
29         yaffs_set_trace(0);
30         output = yaffs_mount(YAFFS_MOUNT_POINT);
31
32         if (output>=0){  
33                 printf("yaffs correctly mounted: %s\n",YAFFS_MOUNT_POINT);
34         } else {
35                 printf("error\n yaffs failed to mount: %s\n with error code %d\n",YAFFS_MOUNT_POINT, yaffs_get_error());
36
37                 return (-1);
38         }
39         //now create a file.
40         output = yaffs_open(FILE_PATH,O_CREAT | O_RDWR, S_IREAD | S_IWRITE);
41         if (output>=0){  
42                 printf("yaffs correctly created a the file: %s\n",FILE_PATH);
43         } else {
44                 printf("error\n yaffs failed to create the file: %s\nerror\n",FILE_PATH);
45                 return (-1);
46         }
47         output2 = yaffs_close(output);
48         if (output2>=0){  
49                 printf("yaffs correctly closed the file: %s\n",FILE_PATH);
50         } else {
51                 printf("error\n yaffs failed to close the file: %s\nerror\n",FILE_PATH);
52                 return (-1);
53         }
54         //unmount and remount the mount point.
55         output = yaffs_unmount(YAFFS_MOUNT_POINT);
56         if (output>=0){  
57                 printf("yaffs correctly unmounted: %s\n",YAFFS_MOUNT_POINT);
58         } else {
59                 printf("error\n yaffs failed to unmount: %s\nerror\n",YAFFS_MOUNT_POINT);
60                 return (-1);
61         }
62         output = yaffs_mount(YAFFS_MOUNT_POINT);
63         if (output>=0){  
64                 printf("yaffs correctly mounted: %s\n",YAFFS_MOUNT_POINT);
65         } else {
66                 printf("error\n yaffs failed to mount: %s\nerror\n",YAFFS_MOUNT_POINT);
67                 return (-1);
68         }
69         //now open the existing file.
70         output = yaffs_open(FILE_PATH, O_RDWR, S_IREAD | S_IWRITE);
71         if (output>=0){  
72                 printf("yaffs correctly opened the file: %s\n",FILE_PATH);
73         } else {
74                 printf("error\n yaffs failed to create the file: %s\nerror\n",FILE_PATH);
75                 return (-1);
76         }
77         //close the file.
78         output2 = yaffs_close(output);
79         if (output2>=0){  
80                 printf("yaffs correctly closed the file: %s\n",FILE_PATH);
81         } else {
82                 printf("error\n yaffs failed to close the file: %s\nerror\n",FILE_PATH);
83                 return (-1);
84         }
85
86         //unmount the mount point.
87         output = yaffs_unmount(YAFFS_MOUNT_POINT);
88         if (output>=0){  
89                 printf("yaffs correctly unmounted: %s\n",YAFFS_MOUNT_POINT);
90         } else {
91                 printf("error\n yaffs failed to unmount: %s\nerror\n",YAFFS_MOUNT_POINT);
92                 return (-1);
93         }
94
95         printf("test passed. yay!\n");
96         
97         return(0);
98 }