Added create and validate tests.
authorTimothy Manning <codedraftsman@gmail.com>
Fri, 10 Sep 2021 04:03:13 +0000 (16:03 +1200)
committerTimothy Manning <codedraftsman@gmail.com>
Fri, 10 Sep 2021 04:03:13 +0000 (16:03 +1200)
Signed-off-by: Timothy Manning <codedraftsman@gmail.com>
direct/test-framework/unit_tests/64_and_32_bit_time/64_bit/Makefile
direct/test-framework/unit_tests/64_and_32_bit_time/64_bit/create_64_bit.c
direct/test-framework/unit_tests/64_and_32_bit_time/64_bit/shared.c [new symlink]
direct/test-framework/unit_tests/64_and_32_bit_time/64_bit/shared.h [new symlink]
direct/test-framework/unit_tests/64_and_32_bit_time/64_bit/validate_64_bit.c [new file with mode: 0644]
direct/test-framework/unit_tests/64_and_32_bit_time/shared/shared.c [new file with mode: 0644]
direct/test-framework/unit_tests/64_and_32_bit_time/shared/shared.h [new file with mode: 0644]

index deff539e07ff28b4620b8d3ef6b1d33a63a781db..179ec07e1d165eec8d6839ac7c9460bd82fa9080 100644 (file)
 YDI_DIR = ../../../../
 YDI_FRAMEWORK_DIR = ../../../
 
-MAINFILES = time_64_tests create_64_bit
-CLEAN_OBJS = $(MAINFILES) 
+MAINFILES = time_64_tests create_64_bit validate_64_bit
+MAIN_OBJS = $(addsuffix .o,$(MAINFILES))
 
-all: $(MAINFILES) 
+EXTRA_OBJS = shared.o
 
-YAFFS_TEST_OBJS = $(COMMONTESTOBJS) 
+CLEAN_OBJS = $(MAINFILES) 
 
+YAFFS_TEST_OBJS = $(COMMONTESTOBJS) $(EXTRA_OBJS)
+ALL_UNSORTED_OBJS += $(YAFFS_TEST_OBJS) $(MAIN_OBJS)
 
-ALL_UNSORTED_OBJS += $(YAFFS_TEST_OBJS) $(FUZZER_OBJS)
+all: $(MAINFILES) 
 
 include $(YDI_FRAMEWORK_DIR)/FrameworkRules.mk
 
 phony. test: time_64_tests
        ./time_64_tests
-$(MAINFILES): $(FRAMEWORK_SOURCES) $(YAFFS_TEST_OBJS)
+
+$(MAINFILES): $(FRAMEWORK_SOURCES) $(YAFFS_TEST_OBJS) $(MAIN_OBJS) 
        gcc $(CFLAGS) -o $@ $(YAFFS_TEST_OBJS) $@.o -lpthread
 
index 1b8f03e89c7b518f5b36cd19b99ea90a884122b7..85c29bd2acef6699519147122784f02171377bea 100644 (file)
@@ -1,45 +1,10 @@
-//#include <stdio.h>
-#include <stdlib.h>
-#include "yaffsfs.h"
-
-#define TEST_PASS 0
-#define TEST_FAIL 1
-
-#define YAFFS_MOUNT_POINT "/yflash2/"
-#define FILE_PATH "/yflash2/foo.txt"
+#include "shared.h"
 
 int random_seed;
 int simulate_power_failure = 0;
 
-
-int setup_yaffs() {
-       yaffs_start_up();
-       yaffs_set_trace(0);
-       if (yaffs_mount(YAFFS_MOUNT_POINT) < 0) {
-               printf("failed to mount %s/n", YAFFS_MOUNT_POINT);
-               return TEST_FAIL;
-       }       
-       
-       return TEST_PASS;
-}
-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();  
-       uint time = atoi(argv[2]);
-       char *file_path = argv[1];
-       if (yaffs_open(FILE_PATH, O_CREAT | O_RDWR, S_IREAD |S_IWRITE)) {
-               printf("failed to open the file %s/n", FILE_PATH);
-               return TEST_FAIL;
-       }
-       printf("created file: %s,  with  time: %d\n", file_path, time);
-       return TEST_PASS;
-}
 int main(int argc, char *argv[] ){
-       return shared_create(argc, argv);
+       int ret = shared_create(argc, argv);
+       ret = ret && shared_validate_file(argc, argv);
+       return ret;
 }
diff --git a/direct/test-framework/unit_tests/64_and_32_bit_time/64_bit/shared.c b/direct/test-framework/unit_tests/64_and_32_bit_time/64_bit/shared.c
new file mode 120000 (symlink)
index 0000000..e4b04bb
--- /dev/null
@@ -0,0 +1 @@
+../shared/shared.c
\ No newline at end of file
diff --git a/direct/test-framework/unit_tests/64_and_32_bit_time/64_bit/shared.h b/direct/test-framework/unit_tests/64_and_32_bit_time/64_bit/shared.h
new file mode 120000 (symlink)
index 0000000..ae87f9e
--- /dev/null
@@ -0,0 +1 @@
+../shared/shared.h
\ No newline at end of file
diff --git a/direct/test-framework/unit_tests/64_and_32_bit_time/64_bit/validate_64_bit.c b/direct/test-framework/unit_tests/64_and_32_bit_time/64_bit/validate_64_bit.c
new file mode 100644 (file)
index 0000000..df1fcdb
--- /dev/null
@@ -0,0 +1,8 @@
+#include "shared.h"
+
+int random_seed;
+int simulate_power_failure = 0;
+
+int main(int argc, char *argv[] ){
+       return shared_validate_file(argc, argv);
+}
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;
+}
diff --git a/direct/test-framework/unit_tests/64_and_32_bit_time/shared/shared.h b/direct/test-framework/unit_tests/64_and_32_bit_time/shared/shared.h
new file mode 100644 (file)
index 0000000..31b64b8
--- /dev/null
@@ -0,0 +1,13 @@
+#ifndef __SHARED_H__
+#define __SHARED_H__
+
+#define TEST_PASS 0
+#define TEST_FAIL 1
+
+#define YAFFS_MOUNT_POINT "/yflash2/"
+#define FILE_PATH "/yflash2/foo.txt"
+
+void setup_yaffs();
+int shared_create();
+int shared_validate_file();
+#endif