From 45875d3d9e7eecd75fcf4bdff439ac06594f448d Mon Sep 17 00:00:00 2001 From: Ivan Baravy Date: Thu, 31 Oct 2019 00:54:12 +0300 Subject: [PATCH] Move run_test to separate function, update tests. Now it's a bit closer to multithreading. --- img/makefile | 2 +- kofu.c | 80 +++++++++++++++++++-------- makefile | 9 ++- test/003_f70s0_read_without_holes.ref | 5 ++ test/003_f70s0_read_without_holes.t | 3 + test/makefile | 2 +- 6 files changed, 72 insertions(+), 29 deletions(-) diff --git a/img/makefile b/img/makefile index df82abc..2a9d3b5 100644 --- a/img/makefile +++ b/img/makefile @@ -184,7 +184,7 @@ s512_xfs_v4_files_b4k_n2b.img: fallocate -i -l 4KiB -o 0KiB $(TEMP_DIR)/btree_l1_no_hole ; \ fallocate -z -l 4KiB -o 0KiB $(TEMP_DIR)/btree_l1_no_hole ; \ done -# $(MKFILEPATTERN) $(TEMP_DIR)/btree_l1_no_hole 134217728 + $(MKFILEPATTERN) $(TEMP_DIR)/btree_l1_no_hole 8196096 # sudo umount $(TEMP_DIR) sudo losetup -d $(LOOP_DEV) diff --git a/kofu.c b/kofu.c index 25a830c..71a0ed0 100644 --- a/kofu.c +++ b/kofu.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -25,8 +26,7 @@ const char *last_dir = cur_dir; bool cur_dir_changed = true; char cmd_buf[FGETS_BUF_LEN]; -bool is_tty; -bool trace = false; +int trace = false; const char *f70_status_name[] = { "success", @@ -141,16 +141,16 @@ void prompt() { fflush(stdout); } -bool next_line() { +int next_line(FILE *file, int is_tty) { if (is_tty) { prompt(); } - return fgets(cmd_buf, FGETS_BUF_LEN, stdin) != NULL; + return fgets(cmd_buf, FGETS_BUF_LEN, file) != NULL; } int split_args(char *s, const char **argv) { int argc = -1; - for ( ; (argv[++argc] = strtok(s, " \t\n")) != NULL; s = NULL ); + for (; (argv[++argc] = strtok(s, " \t\n")) != NULL; s = NULL); return argc; } @@ -331,25 +331,37 @@ func_table_t funcs[] = { { NULL, NULL }, }; -int main(int argc, char **argv) { - (void)argc; - (void)argv; -/* - if (argc != 2) { - printf("usage: kofu \n"); - exit(1); - } -*/ - is_tty = isatty(STDIN_FILENO); +void usage() { + printf("usage: kofu [test_file.t]\n"); +} - if (trace) { - trace_begin(); - } - kos_init(); +void *run_test(const char *infile_name) { + FILE *infile, *outfile; -//msg_file_not_found db 'file not found: ' + if (!infile_name) { + infile = stdin; + outfile = stdout; + } else { + char outfile_name[PATH_MAX]; + strncpy(outfile_name, infile_name, PATH_MAX-2); // ".t" is shorter that ".out" + char *last_dot = strrchr(outfile_name, '.'); + if (!last_dot) { + printf("test file must have '.t' suffix\n"); + usage(); + return NULL; + } + strcpy(last_dot, ".out"); + infile = fopen(infile_name, "r"); + outfile = fopen(outfile_name, "w"); + if (!infile || !outfile) { + printf("can't open in/out files\n"); + return NULL; + } + } + + int is_tty = isatty(fileno(infile)); const char **cargv = (const char**)malloc(sizeof(const char*) * (MAX_COMMAND_ARGS + 1)); - while(next_line()) { + while(next_line(infile, is_tty)) { if (cmd_buf[0] == '#' || cmd_buf[0] == '\n') { printf("%s", cmd_buf); continue; @@ -358,7 +370,7 @@ int main(int argc, char **argv) { if (!is_tty) { prompt(); printf("%s", cmd_buf); - fflush(stdout); + fflush(outfile); } int cargc = split_args(cmd_buf, cargv); func_table_t *ft; @@ -375,8 +387,28 @@ int main(int argc, char **argv) { } free(cargv); - if (trace) { - trace_end(); + return NULL; +} + +int main(int argc, char **argv) { + if (trace) + trace_begin(); + kos_init(); + + switch (argc) { + case 1: + run_test(NULL); + break; + case 2: { + run_test(argv[1]); + break; } + default: + usage(); + } + + if (trace) + trace_end(); + return 0; } diff --git a/makefile b/makefile index bb95b72..6f026f4 100644 --- a/makefile +++ b/makefile @@ -6,10 +6,10 @@ CFLAGS_32=-m32 LDFLAGS= LDFLAGS_32=-m32 -all: kofu kofuse kolibri.sym kolibri.lst tools/mkdirrange tools/mkfilepattern +all: kofu kofuse kolibri.sym kolibri.prp kolibri.lst tools/mkdirrange tools/mkfilepattern kofu: kofu.o kolibri.o trace.o trace_lbr.o trace_lwp.o cio.o - $(CC) $(LDFLAGS) $(LDFLAGS_32) $^ -o $@ -static + $(CC) $(LDFLAGS) $(LDFLAGS_32) $^ -o $@ kofuse: kofuse.o kolibri.o cio.o $(CC) $(LDFLAGS) $(LDFLAGS_32) $^ -o $@ `pkg-config fuse3 --libs` @@ -17,6 +17,9 @@ kofuse: kofuse.o kolibri.o cio.o kolibri.o kolibri.fas: kolibri.asm kolibri.h INCLUDE="$(KOLIBRI_TRUNK);$(LIBCRASH_X86)" $(FASM) $< $@ -s kolibri.fas +kolibri.prp: kolibri.fas + prepsrc kolibri.fas kolibri.prp + kolibri.sym: kolibri.fas symbols kolibri.fas kolibri.sym @@ -36,7 +39,7 @@ cio.o: cio.c $(CC) $(CFLAGS) $(CFLAGS_32) -c $< kofu.o: kofu.c kolibri.h trace.h - $(CC) $(CFLAGS) $(CFLAGS_32) -c $< -std=c99 + $(CC) $(CFLAGS) $(CFLAGS_32) -c $< -std=c99 -D_POSIX_C_SOURCE kofuse.o: kofuse.c kolibri.h $(CC) $(CFLAGS) $(CFLAGS_32) `pkg-config fuse3 --cflags` -c $< -std=gnu99 diff --git a/test/003_f70s0_read_without_holes.ref b/test/003_f70s0_read_without_holes.ref index b0ff816..0a6b37f 100644 --- a/test/003_f70s0_read_without_holes.ref +++ b/test/003_f70s0_read_without_holes.ref @@ -204,3 +204,8 @@ status = 6 end_of_file, count = 0 /> read /hd0/1/no_hole 0xffffffffffffffff 11 -b status = 6 end_of_file, count = 0 + +# btree +/> read /hd0/1/btree_l1_no_hole 0x80000 11 -b +status = 0 success, count = 11 +0000080004000800080008 diff --git a/test/003_f70s0_read_without_holes.t b/test/003_f70s0_read_without_holes.t index cc5960f..564f0eb 100644 --- a/test/003_f70s0_read_without_holes.t +++ b/test/003_f70s0_read_without_holes.t @@ -69,3 +69,6 @@ read /hd0/1/no_hole 0x100000001 11 -b read /hd0/1/no_hole 0x1ffffffff 11 -b read /hd0/1/no_hole 0xffffffff00000000 11 -b read /hd0/1/no_hole 0xffffffffffffffff 11 -b + +# btree +read /hd0/1/btree_l1_no_hole 0x80000 11 -b diff --git a/test/makefile b/test/makefile index 12674d6..ba13f69 100644 --- a/test/makefile +++ b/test/makefile @@ -19,4 +19,4 @@ f70s5: $(f70s5_tests) %.out: %.ref %.t $(KOFU) < $(word 2, $^) > $@ cmp $@ $< - +