X-Git-Url: https://yaffs.net/gitweb/?p=yaffs2.git;a=blobdiff_plain;f=direct%2Ftest-framework%2Funit_tests%2F64_and_32_bit_time%2Fshared%2Fshared.c;fp=direct%2Ftest-framework%2Funit_tests%2F64_and_32_bit_time%2Fshared%2Fshared.c;h=0e0dd8b91b48a490d5cbbe72ab0783e3f2f6d4e0;hp=0000000000000000000000000000000000000000;hb=5758b7a95a391ac8e4d631fbea9fd409d1130a62;hpb=0137051a94e1e688479aa916574894d150d71625 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 index 0000000..0e0dd8b --- /dev/null +++ b/direct/test-framework/unit_tests/64_and_32_bit_time/shared/shared.c @@ -0,0 +1,75 @@ +#include +#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; +}