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
-//#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;
}
--- /dev/null
+#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;
+}