Added create and validate tests.
[yaffs2.git] / direct / test-framework / unit_tests / 64_and_32_bit_time / shared / shared.c
diff --git a/direct/test-framework/unit_tests/64_and_32_bit_time/shared/shared.c b/direct/test-framework/unit_tests/64_and_32_bit_time/shared/shared.c
new file mode 100644 (file)
index 0000000..0e0dd8b
--- /dev/null
@@ -0,0 +1,75 @@
+#include <stdlib.h>
+#include "yaffsfs.h"
+#include "shared.h"
+
+void assert_exit_yaffs(char *fun_name, int fun_return_value){
+       if (fun_return_value < 0) {
+               printf("yaffs command: %s failed with error code %d \n", fun_name, fun_return_value);
+               int error_code = yaffsfs_GetLastError();
+               printf("error code is: %d, which is %s\n", error_code, yaffs_error_to_str(error_code));
+               printf("exiting program now\n");
+               exit(-1);
+       }
+}
+
+void setup_yaffs() {
+       yaffs_start_up();
+       yaffs_set_trace(0);
+       assert_exit_yaffs("yaffs_mount", yaffs_mount(YAFFS_MOUNT_POINT));
+}
+
+
+
+int shared_create(int argc, char *argv[]){
+       
+       if (argc != 3) {
+               printf("wrong number of arguments\n");
+               printf("requires $ create file_name time\n");
+               return TEST_FAIL;
+       }
+       
+       setup_yaffs();  
+       char *file_path = argv[1];
+       int handle = yaffs_open(file_path, O_CREAT | O_RDWR, S_IREAD |S_IWRITE);
+       assert_exit_yaffs ( "yaffs_open", handle);
+
+       assert_exit_yaffs ( "yaffs_close", yaffs_close(handle));
+       
+       
+       //set the time.
+       uint time = atoi(argv[2]);
+
+       struct yaffs_utimbuf new_times;
+       new_times.actime = time;
+       int ret = yaffs_utime(file_path, &new_times);
+       assert_exit_yaffs("yaffs_utime", ret);
+
+       assert_exit_yaffs("yaffs_unmount", yaffs_unmount(YAFFS_MOUNT_POINT));
+       return TEST_FAIL;
+}
+
+int shared_validate_file(int argc, char *argv[]){
+       
+       if (argc != 3) {
+               printf("wrong number of arguments\n");
+               printf("requires $ create file_name time\n");
+               return TEST_FAIL;
+       }
+       
+       setup_yaffs();  
+       char *file_path = argv[1];
+       int handle = yaffs_open(file_path, O_RDWR, S_IREAD |S_IWRITE);
+       assert_exit_yaffs ( "yaffs_open", handle);
+
+       //assert the file is the correct size and has the correct time.
+       uint expected_time = atoi(argv[2]);     
+       struct yaffs_stat stat;
+       assert_exit_yaffs ( "yaffs_stat", yaffs_stat(file_path, &stat));
+       assert_exit_yaffs ( "yaffs_close", yaffs_close(handle));
+       if (stat.yst_atime != expected_time) {
+               printf("stat time is different from expected time\n");
+               exit(0);
+       }
+       assert_exit_yaffs("yaffs_unmount", yaffs_unmount(YAFFS_MOUNT_POINT));
+       return TEST_FAIL;
+}