Move run_test to separate function, update tests.
Now it's a bit closer to multithreading.
This commit is contained in:
parent
d946de1c81
commit
45875d3d9e
@ -184,7 +184,7 @@ s512_xfs_v4_files_b4k_n2b.img:
|
|||||||
fallocate -i -l 4KiB -o 0KiB $(TEMP_DIR)/btree_l1_no_hole ; \
|
fallocate -i -l 4KiB -o 0KiB $(TEMP_DIR)/btree_l1_no_hole ; \
|
||||||
fallocate -z -l 4KiB -o 0KiB $(TEMP_DIR)/btree_l1_no_hole ; \
|
fallocate -z -l 4KiB -o 0KiB $(TEMP_DIR)/btree_l1_no_hole ; \
|
||||||
done
|
done
|
||||||
# $(MKFILEPATTERN) $(TEMP_DIR)/btree_l1_no_hole 134217728
|
$(MKFILEPATTERN) $(TEMP_DIR)/btree_l1_no_hole 8196096
|
||||||
#
|
#
|
||||||
sudo umount $(TEMP_DIR)
|
sudo umount $(TEMP_DIR)
|
||||||
sudo losetup -d $(LOOP_DEV)
|
sudo losetup -d $(LOOP_DEV)
|
||||||
|
80
kofu.c
80
kofu.c
@ -2,6 +2,7 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
#include <limits.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -25,8 +26,7 @@ const char *last_dir = cur_dir;
|
|||||||
bool cur_dir_changed = true;
|
bool cur_dir_changed = true;
|
||||||
|
|
||||||
char cmd_buf[FGETS_BUF_LEN];
|
char cmd_buf[FGETS_BUF_LEN];
|
||||||
bool is_tty;
|
int trace = false;
|
||||||
bool trace = false;
|
|
||||||
|
|
||||||
const char *f70_status_name[] = {
|
const char *f70_status_name[] = {
|
||||||
"success",
|
"success",
|
||||||
@ -141,16 +141,16 @@ void prompt() {
|
|||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool next_line() {
|
int next_line(FILE *file, int is_tty) {
|
||||||
if (is_tty) {
|
if (is_tty) {
|
||||||
prompt();
|
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 split_args(char *s, const char **argv) {
|
||||||
int argc = -1;
|
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;
|
return argc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -331,25 +331,37 @@ func_table_t funcs[] = {
|
|||||||
{ NULL, NULL },
|
{ NULL, NULL },
|
||||||
};
|
};
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
void usage() {
|
||||||
(void)argc;
|
printf("usage: kofu [test_file.t]\n");
|
||||||
(void)argv;
|
}
|
||||||
/*
|
|
||||||
if (argc != 2) {
|
|
||||||
printf("usage: kofu <file.xfs>\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
is_tty = isatty(STDIN_FILENO);
|
|
||||||
|
|
||||||
if (trace) {
|
void *run_test(const char *infile_name) {
|
||||||
trace_begin();
|
FILE *infile, *outfile;
|
||||||
}
|
|
||||||
kos_init();
|
|
||||||
|
|
||||||
//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));
|
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') {
|
if (cmd_buf[0] == '#' || cmd_buf[0] == '\n') {
|
||||||
printf("%s", cmd_buf);
|
printf("%s", cmd_buf);
|
||||||
continue;
|
continue;
|
||||||
@ -358,7 +370,7 @@ int main(int argc, char **argv) {
|
|||||||
if (!is_tty) {
|
if (!is_tty) {
|
||||||
prompt();
|
prompt();
|
||||||
printf("%s", cmd_buf);
|
printf("%s", cmd_buf);
|
||||||
fflush(stdout);
|
fflush(outfile);
|
||||||
}
|
}
|
||||||
int cargc = split_args(cmd_buf, cargv);
|
int cargc = split_args(cmd_buf, cargv);
|
||||||
func_table_t *ft;
|
func_table_t *ft;
|
||||||
@ -375,8 +387,28 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
free(cargv);
|
free(cargv);
|
||||||
|
|
||||||
if (trace) {
|
return NULL;
|
||||||
trace_end();
|
}
|
||||||
|
|
||||||
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
9
makefile
9
makefile
@ -6,10 +6,10 @@ CFLAGS_32=-m32
|
|||||||
LDFLAGS=
|
LDFLAGS=
|
||||||
LDFLAGS_32=-m32
|
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
|
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
|
kofuse: kofuse.o kolibri.o cio.o
|
||||||
$(CC) $(LDFLAGS) $(LDFLAGS_32) $^ -o $@ `pkg-config fuse3 --libs`
|
$(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
|
kolibri.o kolibri.fas: kolibri.asm kolibri.h
|
||||||
INCLUDE="$(KOLIBRI_TRUNK);$(LIBCRASH_X86)" $(FASM) $< $@ -s kolibri.fas
|
INCLUDE="$(KOLIBRI_TRUNK);$(LIBCRASH_X86)" $(FASM) $< $@ -s kolibri.fas
|
||||||
|
|
||||||
|
kolibri.prp: kolibri.fas
|
||||||
|
prepsrc kolibri.fas kolibri.prp
|
||||||
|
|
||||||
kolibri.sym: kolibri.fas
|
kolibri.sym: kolibri.fas
|
||||||
symbols kolibri.fas kolibri.sym
|
symbols kolibri.fas kolibri.sym
|
||||||
|
|
||||||
@ -36,7 +39,7 @@ cio.o: cio.c
|
|||||||
$(CC) $(CFLAGS) $(CFLAGS_32) -c $<
|
$(CC) $(CFLAGS) $(CFLAGS_32) -c $<
|
||||||
|
|
||||||
kofu.o: kofu.c kolibri.h trace.h
|
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
|
kofuse.o: kofuse.c kolibri.h
|
||||||
$(CC) $(CFLAGS) $(CFLAGS_32) `pkg-config fuse3 --cflags` -c $< -std=gnu99
|
$(CC) $(CFLAGS) $(CFLAGS_32) `pkg-config fuse3 --cflags` -c $< -std=gnu99
|
||||||
|
@ -204,3 +204,8 @@ status = 6 end_of_file, count = 0
|
|||||||
/> read /hd0/1/no_hole 0xffffffffffffffff 11 -b
|
/> read /hd0/1/no_hole 0xffffffffffffffff 11 -b
|
||||||
status = 6 end_of_file, count = 0
|
status = 6 end_of_file, count = 0
|
||||||
|
|
||||||
|
|
||||||
|
# btree
|
||||||
|
/> read /hd0/1/btree_l1_no_hole 0x80000 11 -b
|
||||||
|
status = 0 success, count = 11
|
||||||
|
0000080004000800080008
|
||||||
|
@ -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 0x1ffffffff 11 -b
|
||||||
read /hd0/1/no_hole 0xffffffff00000000 11 -b
|
read /hd0/1/no_hole 0xffffffff00000000 11 -b
|
||||||
read /hd0/1/no_hole 0xffffffffffffffff 11 -b
|
read /hd0/1/no_hole 0xffffffffffffffff 11 -b
|
||||||
|
|
||||||
|
# btree
|
||||||
|
read /hd0/1/btree_l1_no_hole 0x80000 11 -b
|
||||||
|
@ -19,4 +19,4 @@ f70s5: $(f70s5_tests)
|
|||||||
%.out: %.ref %.t
|
%.out: %.ref %.t
|
||||||
$(KOFU) < $(word 2, $^) > $@
|
$(KOFU) < $(word 2, $^) > $@
|
||||||
cmp $@ $<
|
cmp $@ $<
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user