Finished the 32 and 64 bit tests.
[yaffs2.git] / direct / test-framework / unit_tests / 64_and_32_bit_time / shared / shared.c
1 #include <stdlib.h>
2 #include "yaffsfs.h"
3 #include "shared.h"
4
5 void assert_exit_yaffs(char *fun_name, int fun_return_value){
6         if (fun_return_value < 0) {
7                 printf("yaffs command: %s failed with error code %d \n", fun_name, fun_return_value);
8                 int error_code = yaffsfs_GetLastError();
9                 printf("error code is: %d, which is %s\n", error_code, yaffs_error_to_str(error_code));
10                 printf("exiting program now\n");
11                 exit(-1);
12         }
13 }
14
15 void setup_yaffs() {
16         yaffs_start_up();
17         yaffs_set_trace(0);
18         assert_exit_yaffs("yaffs_mount", yaffs_mount(YAFFS_MOUNT_POINT));
19 }
20
21
22
23 int shared_create(int argc, char *argv[]){
24         printf("YTIME_T size is %lu bits\n", sizeof(YTIME_T) *8);
25         #ifdef CONFIG_YAFFS_USE_32_BIT_TIME_T
26                 if (sizeof(YTIME_T)*8 != 32) {
27                         printf("YTIME_T size is incorrect. it is %lu and should be 32\n", sizeof(YTIME_T));
28                 } 
29         #endif
30         if (argc != 3) {
31                 printf("wrong number of arguments\n");
32                 printf("requires $ create file_name time\n");
33                 return TEST_FAIL;
34         }
35         
36         setup_yaffs();  
37         char *file_path = argv[1];
38         int handle = yaffs_open(file_path, O_CREAT | O_RDWR, S_IREAD |S_IWRITE);
39         assert_exit_yaffs ( "yaffs_open", handle);
40
41         assert_exit_yaffs ( "yaffs_close", yaffs_close(handle));
42         
43         
44         //set the time.
45         uint time = atoi(argv[2]);
46
47         struct yaffs_utimbuf new_times;
48         new_times.actime = time;
49         int ret = yaffs_utime(file_path, &new_times);
50         assert_exit_yaffs("yaffs_utime", ret);
51
52         assert_exit_yaffs("yaffs_unmount", yaffs_unmount(YAFFS_MOUNT_POINT));
53         return 0;
54 }
55
56 int shared_validate_file(int argc, char *argv[]){
57         
58         if (argc != 3) {
59                 printf("wrong number of arguments\n");
60                 printf("requires $ create file_name time\n");
61                 return TEST_FAIL;
62         }
63         
64         setup_yaffs();  
65         char *file_path = argv[1];
66         int handle = yaffs_open(file_path, O_RDWR, S_IREAD |S_IWRITE);
67         assert_exit_yaffs ( "yaffs_open", handle);
68
69         //assert the file is the correct size and has the correct time.
70         uint expected_time = atoi(argv[2]);     
71         struct yaffs_stat stat;
72         assert_exit_yaffs ( "yaffs_stat", yaffs_stat(file_path, &stat));
73         assert_exit_yaffs ( "yaffs_close", yaffs_close(handle));
74         if (stat.yst_atime != expected_time) {
75                 printf("stat time is different from expected time\n");
76                 exit(0);
77         }
78         assert_exit_yaffs("yaffs_unmount", yaffs_unmount(YAFFS_MOUNT_POINT));
79         return 0;
80 }