aboutsummaryrefslogtreecommitdiff
path: root/src/tests/utests
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/utests')
-rw-r--r--src/tests/utests/bam.lua37
-rw-r--r--src/tests/utests/chan1/test.c18
-rw-r--r--src/tests/utests/chan2/test.c50
-rw-r--r--src/tests/utests/fs1/test.c18
-rw-r--r--src/tests/utests/fs2/test.c16
-rw-r--r--src/tests/utests/malloc/test.c8
-rwxr-xr-xsrc/tests/utests/run_qemu_test.sh5
-rw-r--r--src/tests/utests/subfs/test.c18
8 files changed, 88 insertions, 82 deletions
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");