diff options
author | Alex Auvolat <alex@adnab.me> | 2016-07-30 23:17:12 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2016-07-30 23:17:12 +0200 |
commit | f58f65c30de315d4419f69a92a708cbed797ff37 (patch) | |
tree | efaaa82089523dc0f7a3b9a6ab4c963550f9b241 /src/tests | |
parent | fa5327d4cc5e47656326b8c0c55d23cd71b04462 (diff) | |
download | kogata-f58f65c30de315d4419f69a92a708cbed797ff37.tar.gz kogata-f58f65c30de315d4419f69a92a708cbed797ff37.zip |
Release mode (enables some optimizations) ; fix tests.
Diffstat (limited to 'src/tests')
-rw-r--r-- | src/tests/ktests/bam.lua | 61 | ||||
-rwxr-xr-x | src/tests/ktests/run_qemu_test.sh | 3 | ||||
-rw-r--r-- | src/tests/slab_test/bam.lua | 19 | ||||
-rw-r--r-- | src/tests/slab_test/slab_test.c | 2 | ||||
-rw-r--r-- | src/tests/utests/bam.lua | 37 | ||||
-rw-r--r-- | src/tests/utests/chan1/test.c | 18 | ||||
-rw-r--r-- | src/tests/utests/chan2/test.c | 50 | ||||
-rw-r--r-- | src/tests/utests/fs1/test.c | 18 | ||||
-rw-r--r-- | src/tests/utests/fs2/test.c | 16 | ||||
-rw-r--r-- | src/tests/utests/malloc/test.c | 8 | ||||
-rwxr-xr-x | src/tests/utests/run_qemu_test.sh | 5 | ||||
-rw-r--r-- | src/tests/utests/subfs/test.c | 18 |
12 files changed, 133 insertions, 122 deletions
diff --git a/src/tests/ktests/bam.lua b/src/tests/ktests/bam.lua index b721a8b..c1be337 100644 --- a/src/tests/ktests/bam.lua +++ b/src/tests/ktests/bam.lua @@ -1,35 +1,38 @@ -local obj_nokmain = {} -for name in TableWalk(kernel_obj) do - if not name:find('kmain') then - table.insert(obj_nokmain, name) +return function(s, common, kernel_obj) + local tests = {} + + local obj_nokmain = {} + for name in TableWalk(kernel_obj) do + if not name:find('kmain') then + table.insert(obj_nokmain, name) + end end -end -for _, name in pairs({ - "breakpoint", - "btree1", "btree2", - "cmdline", - "hashtbl1", "hashtbl2", - "kmalloc", - "region1" -}) do - local map = "build/tests/ktest_" .. name .. ".map" + for _, name in pairs({ + "breakpoint", + "btree1", "btree2", + "cmdline", + "hashtbl1", "hashtbl2", + "kmalloc", + "region1" + }) do + local test_config = TableDeepCopy(s.common_settings) + test_config.cc.includes:Add("src/kernel/include", + "src/common/include/kogata", + "src/tests/ktests/"..name) + test_config.cc.flags:Add('-DBUILD_KERNEL_TEST') + test_config.link.flags:Add("-T src/kernel/linker.ld") + test_config.cc.extension = ".ktest_" .. name .. ".o" - local test_config = TableDeepCopy(common_settings) - test_config.cc.includes:Add("src/kernel/include", - "src/tests/ktests/"..name) - test_config.cc.flags:Add('-DBUILD_KERNEL_TEST') - test_config.link.flags:Add("-T src/kernel/linker.ld", - "-Xlinker -Map=" .. map) - test_config.cc.extension = ".ktest_" .. name .. ".o" + local kmain = Compile(test_config, "src/kernel/core/kmain.c") + local bin = Link(test_config, "tests/ktest_"..name, + {obj_nokmain, kmain, common.libkogata, common.libc, common.libalgo}) - local kmain = Compile(test_config, "src/kernel/core/kmain.c") - local bin = Link(test_config, "tests/ktest_"..name, - {obj_nokmain, kmain, common_libkogata, common_libc, common_libalgo}) + local out = bin .. ".log" + AddJob(out, "ktest " .. name, "./src/tests/ktests/run_qemu_test.sh " .. bin .. " " .. out) + AddDependency(out, bin) + table.insert(tests, out) + end - local out = "build/tests/ktest_"..name..".log" - AddJob(out, "ktest " .. name, "./src/tests/ktests/run_qemu_test.sh " .. bin .. " " .. out .. " " .. map) - AddDependency(out, bin) - table.insert(tests, out) + return tests end - diff --git a/src/tests/ktests/run_qemu_test.sh b/src/tests/ktests/run_qemu_test.sh index 4249a96..bc86f12 100755 --- a/src/tests/ktests/run_qemu_test.sh +++ b/src/tests/ktests/run_qemu_test.sh @@ -2,12 +2,11 @@ BINFILE=$1 LOGFILE=$2 -MAPFILE=$3 RESULTFILE=`mktemp` PIDFILE=`mktemp` -(timeout 3s qemu-system-i386 -kernel $BINFILE -initrd $MAPFILE -serial stdio -m 16 -display none 2>/dev/null \ +(timeout 3s qemu-system-i386 -kernel $BINFILE -serial stdio -m 16 -display none 2>/dev/null \ & echo $! >$PIDFILE) \ | tee >(grep -m 1 "TEST-" >$RESULTFILE; kill -INT `cat $PIDFILE`) > $LOGFILE diff --git a/src/tests/slab_test/bam.lua b/src/tests/slab_test/bam.lua index 87c6666..cd5ad2d 100644 --- a/src/tests/slab_test/bam.lua +++ b/src/tests/slab_test/bam.lua @@ -1,11 +1,14 @@ -local source = {"src/common/libkogata/slab_alloc.c", - "src/tests/slab_test/slab_test.c"} -local obj = Compile(host_settings, source) +return function(s) + local source = {"src/common/libkogata/slab_alloc.c", + "src/tests/slab_test/slab_test.c"} + local obj = Compile(s.host_settings, source) -local bin = Link(host_settings, "build/tests/slab_test", obj) + local f = s.host_settings.cc.Output(s.host_settings, "tests/slab_test") + local bin = Link(s.host_settings, f, obj) -local slab_test = "build/tests/slab_test.log" -AddJob(slab_test, "slab_test", "./" .. bin .. " > " .. slab_test) -AddDependency(slab_test, bin) + local slab_test = f .. ".log" + AddJob(slab_test, "slab_test", "./" .. bin .. " > " .. slab_test) + AddDependency(slab_test, bin) -table.insert(tests, slab_test) + return slab_test +end diff --git a/src/tests/slab_test/slab_test.c b/src/tests/slab_test/slab_test.c index 747c785..31af03d 100644 --- a/src/tests/slab_test/slab_test.c +++ b/src/tests/slab_test/slab_test.c @@ -1,4 +1,4 @@ -#include <slab_alloc.h> +#include <kogata/slab_alloc.h> #include <stdlib.h> #include <stdio.h> diff --git a/src/tests/utests/bam.lua b/src/tests/utests/bam.lua index 6137399..abbce88 100644 --- a/src/tests/utests/bam.lua +++ b/src/tests/utests/bam.lua @@ -1,21 +1,24 @@ -for _, name in pairs({ - "chan1", "chan2", - "fs1", "fs2", - "malloc", - "subfs" -}) do - local map = "build/tests/utest_" .. name .. ".map" +return function(s, kernel, lib) + local tests = {} - local config = TableDeepCopy(user_settings) - config.link.flags:Add( '-Xlinker -Map=' .. map, - '-T src/sysbin/linker.ld') + for _, name in pairs({ + "chan1", "chan2", + "fs1", "fs2", + "malloc", + "subfs" + }) do + local config = TableDeepCopy(s.user_settings) + config.link.flags:Add('-T src/lib/linker.ld') - local obj = Compile(config, 'src/tests/utests/' .. name .. '/test.c') - local bin = Link(config, 'tests/utest_' .. name, {obj, libkogata}) + local obj = Compile(config, 'src/tests/utests/' .. name .. '/test.c') + local bin = Link(config, 'tests/utest_' .. name, {obj, lib.libkogata}) - local out = "build/tests/utest_"..name..".log" - AddJob(out, "utest " .. name, "./src/tests/utests/run_qemu_test.sh " .. bin .. " " .. out .. " " .. map) - AddDependency(out, bin) - AddDependency(out, kernel) - table.insert(tests, out) + local out = bin .. ".log" + AddJob(out, "utest " .. name, "./src/tests/utests/run_qemu_test.sh " .. bin .. " " .. out .. " " .. kernel) + AddDependency(out, bin) + AddDependency(out, kernel) + table.insert(tests, out) + end + + return tests end diff --git a/src/tests/utests/chan1/test.c b/src/tests/utests/chan1/test.c index 1b89255..0c4e61a 100644 --- a/src/tests/utests/chan1/test.c +++ b/src/tests/utests/chan1/test.c @@ -1,26 +1,26 @@ #include <string.h> -#include <malloc.h> +#include <kogata/malloc.h> -#include <syscall.h> -#include <debug.h> +#include <kogata/syscall.h> +#include <kogata/debug.h> int main(int argc, char **argv) { - fd_pair_t ch = make_channel(false); + fd_pair_t ch = sc_make_channel(false); char* s = "Hello, world!"; - ASSERT(write(ch.a, 0, strlen(s), s) == strlen(s)); + ASSERT(sc_write(ch.a, 0, strlen(s), s) == strlen(s)); char buf[128]; - ASSERT(read(ch.b, 0, 128, buf) == strlen(s)); + ASSERT(sc_read(ch.b, 0, 128, buf) == strlen(s)); ASSERT(strncmp(s, buf, strlen(s)) == 0); - close(ch.a); + sc_close(ch.a); sel_fd_t sel = { .fd = ch.b, .req_flags = SEL_ERROR }; - ASSERT(select(&sel, 1, 0)); + ASSERT(sc_select(&sel, 1, 0)); ASSERT(sel.got_flags & SEL_ERROR); - close(ch.b); + sc_close(ch.b); dbg_printf("(TEST-OK)\n"); diff --git a/src/tests/utests/chan2/test.c b/src/tests/utests/chan2/test.c index a2f8b3f..c972e79 100644 --- a/src/tests/utests/chan2/test.c +++ b/src/tests/utests/chan2/test.c @@ -1,9 +1,9 @@ #include <string.h> -#include <malloc.h> +#include <kogata/malloc.h> -#include <syscall.h> -#include <debug.h> +#include <kogata/syscall.h> +#include <kogata/debug.h> volatile int step = 0; // volatile because thread-shared @@ -15,6 +15,8 @@ const char* msg_d = "hello world"; void listen_thread(fd_t c1, fd_t c2) { dbg_printf("listen_thread started\n"); + dbg_printf("Got args: %d, %d\n", c1, c2); + sel_fd_t sel[2]; sel[0].fd = c1; sel[1].fd = c2; @@ -23,49 +25,49 @@ void listen_thread(fd_t c1, fd_t c2) { char buf[128]; dbg_printf("Doing first select...\n"); - ASSERT(select(sel, 2, -1)); + ASSERT(sc_select(sel, 2, -1)); dbg_printf("%x %x\n", sel[0].got_flags, sel[1].got_flags); ASSERT(sel[0].got_flags & SEL_READ); ASSERT(!(sel[1].got_flags & SEL_READ)); - ASSERT(read(c1, 0, strlen(msg_a), buf) == strlen(msg_a)); + ASSERT(sc_read(c1, 0, strlen(msg_a), buf) == strlen(msg_a)); ASSERT(strncmp(buf, msg_a, strlen(msg_a)) == 0); - ASSERT(write(c1, 0, strlen(msg_c), msg_c) == strlen(msg_c)); + ASSERT(sc_write(c1, 0, strlen(msg_c), msg_c) == strlen(msg_c)); step = 1; dbg_printf("Doing second select...\n"); - ASSERT(select(sel, 2, -1)); + ASSERT(sc_select(sel, 2, -1)); dbg_printf("%x %x\n", sel[0].got_flags, sel[1].got_flags); ASSERT(sel[1].got_flags & SEL_READ); ASSERT(!(sel[0].got_flags & SEL_READ)); - ASSERT(read(c2, 0, strlen(msg_b), buf) == strlen(msg_b)); + ASSERT(sc_read(c2, 0, strlen(msg_b), buf) == strlen(msg_b)); ASSERT(strncmp(buf, msg_b, strlen(msg_b)) == 0); - ASSERT(write(c2, 0, strlen(msg_d), msg_d) == strlen(msg_d)); + ASSERT(sc_write(c2, 0, strlen(msg_d), msg_d) == strlen(msg_d)); step = 2; dbg_printf("Doing third select...\n"); - ASSERT(select(sel, 2, -1)); + ASSERT(sc_select(sel, 2, -1)); dbg_printf("%x %x\n", sel[0].got_flags, sel[1].got_flags); ASSERT(sel[0].got_flags & SEL_ERROR); ASSERT(!(sel[1].got_flags & SEL_ERROR)); - close(c1); + sc_close(c1); step = 3; dbg_printf("Doing fourth select...\n"); - ASSERT(select(sel + 1, 1, -1)); + ASSERT(sc_select(sel + 1, 1, -1)); dbg_printf("%x\n", sel[1].got_flags); ASSERT(sel[1].got_flags & SEL_ERROR); - close(c2); + sc_close(c2); step = 4; - exit_thread(); + sc_exit_thread(); } int main(int argc, char **argv) { - fd_pair_t ch1 = make_channel(false); + fd_pair_t ch1 = sc_make_channel(false); ASSERT(ch1.a != 0 && ch1.b != 0); - fd_pair_t ch2 = make_channel(false); + fd_pair_t ch2 = sc_make_channel(false); ASSERT(ch2.a != 0 && ch2.b != 0); void* stack = malloc(0x1000); @@ -77,42 +79,42 @@ int main(int argc, char **argv) { *(--esp) = ch2.a; *(--esp) = ch1.a; *(--esp) = 0; // false return address - dbg_printf("launching waiter thread\n"); - ASSERT(sys_new_thread(listen_thread, esp)); + dbg_printf("launching waiter thread (args: %d, %d)\n", ch1.a, ch2.a); + ASSERT(sc_sys_new_thread(listen_thread, esp)); fd_t c1 = ch1.b, c2 = ch2.b; // -- the test on the first channel - ASSERT(write(c1, 0, strlen(msg_a), msg_a) == strlen(msg_a)); + ASSERT(sc_write(c1, 0, strlen(msg_a), msg_a) == strlen(msg_a)); dbg_printf("wait for step1 signal\n"); while(step != 1); dbg_printf("got step1 signal, proceeding\n"); - ASSERT(read(c1, 0, strlen(msg_c), buf) == strlen(msg_c)); + ASSERT(sc_read(c1, 0, strlen(msg_c), buf) == strlen(msg_c)); ASSERT(strncmp(msg_c, buf, strlen(msg_c)) == 0); // -- the test on the second channel - ASSERT(write(c2, 0, strlen(msg_b), msg_b) == strlen(msg_b)); + ASSERT(sc_write(c2, 0, strlen(msg_b), msg_b) == strlen(msg_b)); dbg_printf("wait for step2 signal\n"); while(step != 2); dbg_printf("got step2 signal, proceeding\n"); - ASSERT(read(c2, 0, strlen(msg_d), buf) == strlen(msg_d)); + ASSERT(sc_read(c2, 0, strlen(msg_d), buf) == strlen(msg_d)); ASSERT(strncmp(msg_d, buf, strlen(msg_d)) == 0); // -- closing stuff - close(c1); + sc_close(c1); dbg_printf("waiting for step3 signal\n"); while(step != 3); dbg_printf("got step3 signal, proceeding\n"); - close(c2); + sc_close(c2); dbg_printf("waiting for step4 signal\n"); while(step != 4); diff --git a/src/tests/utests/fs1/test.c b/src/tests/utests/fs1/test.c index 79db13b..7356c14 100644 --- a/src/tests/utests/fs1/test.c +++ b/src/tests/utests/fs1/test.c @@ -1,37 +1,37 @@ #include <string.h> -#include <malloc.h> +#include <kogata/malloc.h> -#include <syscall.h> -#include <debug.h> +#include <kogata/syscall.h> +#include <kogata/debug.h> int main(int argc, char **argv) { dbg_print("Hello, world! from user process.\n"); - fd_t f = open("io:/", FM_READDIR); + fd_t f = sc_open("io:/", FM_READDIR); dbg_printf("openned /: %d\n", f); ASSERT(f != 0); dirent_t x; size_t ent_no = 0; - while (readdir(f, ent_no++, &x)) { + while (sc_readdir(f, ent_no++, &x)) { dbg_printf("- '%s' %p %d\n", x.name, x.st.type, x.st.size); if (x.st.type == FT_REGULAR) { char buf[256]; strcpy(buf, "io:/"); strcpy(buf+4, x.name); dbg_printf("trying to open %s...\n", buf); - fd_t ff = open(buf, FM_READ); + fd_t ff = sc_open(buf, FM_READ); ASSERT(ff != 0); dbg_printf("ok, open as %d\n", ff); char* cont = malloc(x.st.size + 1); - ASSERT(read(ff, 0, x.st.size, cont) == x.st.size); + ASSERT(sc_read(ff, 0, x.st.size, cont) == x.st.size); cont[x.st.size] = 0; dbg_printf("> '%s'\n", cont); - close(ff); + sc_close(ff); } } - close(f); + sc_close(f); dbg_printf("(TEST-OK)\n"); diff --git a/src/tests/utests/fs2/test.c b/src/tests/utests/fs2/test.c index 0acf11d..1b72eb7 100644 --- a/src/tests/utests/fs2/test.c +++ b/src/tests/utests/fs2/test.c @@ -1,28 +1,28 @@ #include <string.h> -#include <malloc.h> +#include <kogata/malloc.h> -#include <syscall.h> -#include <debug.h> +#include <kogata/syscall.h> +#include <kogata/debug.h> int main(int argc, char **argv) { dbg_print("Hello, world! from user process.\n"); - fd_t f = open("io:/mod", FM_READDIR); + fd_t f = sc_open("io:/mod", FM_READDIR); dbg_printf("openned io:/mod as %d\n", f); ASSERT(f != 0); dirent_t x; size_t ent_no = 0; - while (ent_no < 2) { - ASSERT (readdir(f, ent_no++, &x)); + while (ent_no < 1) { + ASSERT (sc_readdir(f, ent_no++, &x)); ASSERT((!strcmp(x.name, "utest_fs2.bin")) || (!strcmp(x.name, "kernel.map"))); ASSERT(x.st.type == FT_REGULAR); } - ASSERT(!readdir(f, ent_no++, &x)); - close(f); + ASSERT(!sc_readdir(f, ent_no++, &x)); + sc_close(f); dbg_printf("(TEST-OK)\n"); diff --git a/src/tests/utests/malloc/test.c b/src/tests/utests/malloc/test.c index fb2f3b9..9a937aa 100644 --- a/src/tests/utests/malloc/test.c +++ b/src/tests/utests/malloc/test.c @@ -1,10 +1,10 @@ #include <string.h> -#include <malloc.h> +#include <kogata/malloc.h> -#include <syscall.h> -#include <debug.h> -#include <region_alloc.h> +#include <kogata/syscall.h> +#include <kogata/debug.h> +#include <kogata/region_alloc.h> int main(int argc, char **argv) { dbg_print("(BEGIN-USER-TEST malloc-test)\n"); diff --git a/src/tests/utests/run_qemu_test.sh b/src/tests/utests/run_qemu_test.sh index e806501..b9f3c36 100755 --- a/src/tests/utests/run_qemu_test.sh +++ b/src/tests/utests/run_qemu_test.sh @@ -2,12 +2,13 @@ BINFILE=$1 LOGFILE=$2 +KERNEL=$3 RESULTFILE=`mktemp` PIDFILE=`mktemp` -(timeout 3s qemu-system-i386 -kernel build/kernel.bin -append "init=io:/mod/`basename $BINFILE`" \ - -initrd "$BINFILE,build/kernel.map" -serial stdio -m 16 -display none 2>/dev/null \ +(timeout 3s qemu-system-i386 -kernel $KERNEL -append "init=io:/mod/`basename $BINFILE`" \ + -initrd "$BINFILE" -serial stdio -m 16 -display none 2>/dev/null \ & echo $! >$PIDFILE) \ | tee >(grep -m 1 "TEST-" >$RESULTFILE; kill -INT `cat $PIDFILE`) >$LOGFILE diff --git a/src/tests/utests/subfs/test.c b/src/tests/utests/subfs/test.c index 52c1025..b237181 100644 --- a/src/tests/utests/subfs/test.c +++ b/src/tests/utests/subfs/test.c @@ -1,30 +1,30 @@ #include <string.h> -#include <malloc.h> +#include <kogata/malloc.h> -#include <syscall.h> -#include <debug.h> +#include <kogata/syscall.h> +#include <kogata/debug.h> int main(int argc, char **argv) { dbg_print("Hello, world! from user process.\n"); - ASSERT(fs_subfs("mod", "io", "/mod", FM_READ | FM_READDIR)); + ASSERT(sc_fs_subfs("mod", "io", "/mod", FM_READ | FM_READDIR)); - fd_t f = open("mod:/", FM_READDIR); + fd_t f = sc_open("mod:/", FM_READDIR); dbg_printf("openned mod:/ as %d\n", f); ASSERT(f != 0); dirent_t x; size_t ent_no = 0; - while (ent_no < 2) { - ASSERT (readdir(f, ent_no++, &x)); + while (ent_no < 1) { + ASSERT (sc_readdir(f, ent_no++, &x)); ASSERT((!strcmp(x.name, "utest_subfs.bin")) || (!strcmp(x.name, "kernel.map"))); ASSERT(x.st.type == FT_REGULAR); } - ASSERT(!readdir(f, ent_no++, &x)); - close(f); + ASSERT(!sc_readdir(f, ent_no++, &x)); + sc_close(f); dbg_printf("(TEST-OK)\n"); |