From bfa8e501a3c37b4b0cb8a9cda9390ba12e6c86fe Mon Sep 17 00:00:00 2001 From: David Given Date: Fri, 25 Nov 2016 20:28:41 +0100 Subject: [PATCH 01/10] Make pc86 echo console output to the serial port, so qemu can pipe it to stdout. --- plat/pc86/README | 3 +++ plat/pc86/libsys/_sys_rawwrite.s | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/plat/pc86/README b/plat/pc86/README index 689c70844..dcbe0ba27 100644 --- a/plat/pc86/README +++ b/plat/pc86/README @@ -23,6 +23,9 @@ are stubs required to make the demo apps link. File descriptors 0, 1 and 2 represent the console. All reads block. There's enough TTY emulation to allow \n conversion and local echo (but it can't be turned off). +Console output is echoed to the serial port (without any setup). This is used +by qemu for running tests. + Example command line ==================== diff --git a/plat/pc86/libsys/_sys_rawwrite.s b/plat/pc86/libsys/_sys_rawwrite.s index 75f75aae1..ae477c6d2 100644 --- a/plat/pc86/libsys/_sys_rawwrite.s +++ b/plat/pc86/libsys/_sys_rawwrite.s @@ -21,9 +21,18 @@ __sys_rawwrite: push bp mov bp, sp + ! Write to the BIOS console. + movb al, 4(bp) movb ah, 0x0E mov bx, 0x0007 int 0x10 + + ! Also write to the serial port (used by the test suite). + + movb ah, 0x01 + xor dx, dx + int 0x14 + jmp .cret \ No newline at end of file From 5f66f06dc69ee8b89fc3dfce8a7d0ec6f7c8753d Mon Sep 17 00:00:00 2001 From: David Given Date: Fri, 25 Nov 2016 21:02:51 +0100 Subject: [PATCH 02/10] Refactored the tests to make the generic across different plats. --- plat/qemuppc/tests/build.lua | 54 ++---------------- {plat/qemuppc/tests => tests/plat}/_dummy.c | 0 {plat/qemuppc/tests => tests/plat}/brk_c.c | 0 tests/plat/build.lua | 57 +++++++++++++++++++ {plat/qemuppc/tests => tests/plat}/calloc_c.c | 0 {plat/qemuppc/tests => tests/plat}/csa_e.c | 0 {plat/qemuppc/tests => tests/plat}/csb_e.c | 0 .../tests => tests/plat}/doublecmp_e.c | 0 .../tests => tests/plat}/from_d_to_si_e.c | 0 .../tests => tests/plat}/from_d_to_ui_e.c | 0 .../tests => tests/plat}/from_si_to_d_e.c | 0 .../tests => tests/plat}/from_ui_to_d_e.c | 0 {plat/qemuppc/tests => tests/plat}/inn_e.e | 0 {plat/qemuppc/tests => tests/plat}/intadd_e.c | 0 {plat/qemuppc/tests => tests/plat}/intcmp_e.c | 0 {plat/qemuppc/tests => tests/plat}/intdiv_e.c | 0 {plat/qemuppc/tests => tests/plat}/intrem_e.c | 0 .../qemuppc/tests => tests/plat}/intshift_e.c | 0 {plat/qemuppc/tests => tests/plat}/intsub_e.c | 0 .../tests => tests/plat}/lib/build.lua | 0 {plat/qemuppc/tests => tests/plat}/lib/test.c | 0 {plat/qemuppc/tests => tests/plat}/lib/test.h | 0 .../tests => tests/plat}/newdispose_p.p | 0 .../tests => tests/plat}/testdriver.sh | 0 24 files changed, 63 insertions(+), 48 deletions(-) rename {plat/qemuppc/tests => tests/plat}/_dummy.c (100%) rename {plat/qemuppc/tests => tests/plat}/brk_c.c (100%) create mode 100644 tests/plat/build.lua rename {plat/qemuppc/tests => tests/plat}/calloc_c.c (100%) rename {plat/qemuppc/tests => tests/plat}/csa_e.c (100%) rename {plat/qemuppc/tests => tests/plat}/csb_e.c (100%) rename {plat/qemuppc/tests => tests/plat}/doublecmp_e.c (100%) rename {plat/qemuppc/tests => tests/plat}/from_d_to_si_e.c (100%) rename {plat/qemuppc/tests => tests/plat}/from_d_to_ui_e.c (100%) rename {plat/qemuppc/tests => tests/plat}/from_si_to_d_e.c (100%) rename {plat/qemuppc/tests => tests/plat}/from_ui_to_d_e.c (100%) rename {plat/qemuppc/tests => tests/plat}/inn_e.e (100%) rename {plat/qemuppc/tests => tests/plat}/intadd_e.c (100%) rename {plat/qemuppc/tests => tests/plat}/intcmp_e.c (100%) rename {plat/qemuppc/tests => tests/plat}/intdiv_e.c (100%) rename {plat/qemuppc/tests => tests/plat}/intrem_e.c (100%) rename {plat/qemuppc/tests => tests/plat}/intshift_e.c (100%) rename {plat/qemuppc/tests => tests/plat}/intsub_e.c (100%) rename {plat/qemuppc/tests => tests/plat}/lib/build.lua (100%) rename {plat/qemuppc/tests => tests/plat}/lib/test.c (100%) rename {plat/qemuppc/tests => tests/plat}/lib/test.h (100%) rename {plat/qemuppc/tests => tests/plat}/newdispose_p.p (100%) rename {plat/qemuppc/tests => tests/plat}/testdriver.sh (100%) diff --git a/plat/qemuppc/tests/build.lua b/plat/qemuppc/tests/build.lua index f0c2993c4..6581d93ef 100644 --- a/plat/qemuppc/tests/build.lua +++ b/plat/qemuppc/tests/build.lua @@ -1,49 +1,7 @@ -include("plat/build.lua") +include("tests/plat/build.lua") -local qemu = "qemu-system-ppc" -local tests = {} - -if os.execute("which "..qemu.." > /dev/null") ~= 0 then - print("warning: skipping tests which require ", qemu) -else - local testcases = filenamesof("./*.c", "./*.s", "./*.e", "./*.p") - - for _, f in ipairs(testcases) do - local fs = replace(basename(f), "%..$", "") - local _, _, lang = fs:find("_(.)$") - if not lang then - lang = "e" - end - - local bin = ackprogram { - name = fs.."_bin", - srcs = { f }, - deps = { "plat/qemuppc/tests/lib+lib" }, - vars = { - plat = "qemuppc", - lang = lang, - ackcflags = "-O0" - } - } - - tests[#tests+1] = normalrule { - name = fs, - outleaves = { "stamp" }, - ins = { - bin, - "./testdriver.sh" - }, - commands = { - "%{ins[2]} "..qemu.." %{ins[1]} 5", - "touch %{outs}" - } - } - end -end - -normalrule { - name = "tests", - outleaves = { "stamp" }, - ins = tests, - commands = { "touch %{outs}" } -} \ No newline at end of file +plat_testsuite { + name = "tests", + plat = "qemuppc", + method = "qemu-system-ppc" +} diff --git a/plat/qemuppc/tests/_dummy.c b/tests/plat/_dummy.c similarity index 100% rename from plat/qemuppc/tests/_dummy.c rename to tests/plat/_dummy.c diff --git a/plat/qemuppc/tests/brk_c.c b/tests/plat/brk_c.c similarity index 100% rename from plat/qemuppc/tests/brk_c.c rename to tests/plat/brk_c.c diff --git a/tests/plat/build.lua b/tests/plat/build.lua new file mode 100644 index 000000000..23685ba40 --- /dev/null +++ b/tests/plat/build.lua @@ -0,0 +1,57 @@ +include("plat/build.lua") + +definerule("plat_testsuite", + { + plat = { type="string" }, + method = { type="string" }, + }, + function(e) + -- Remember this is executed from the caller's directory; local + -- target names will resolve there. + local testfiles = filenamesof( + "tests/plat/*.c", + "tests/plat/*.e", + "tests/plat/*.p" + ) + + local tests = {} + for _, f in ipairs(testfiles) do + local fs = replace(basename(f), "%..$", "") + local _, _, lang = fs:find("_(.)$") + if not lang then + lang = "e" + end + + local bin = ackprogram { + name = fs.."_bin", + srcs = { f }, + deps = { "tests/plat/lib+lib" }, + vars = { + plat = e.plat, + lang = lang, + ackcflags = "-O0" + } + } + + tests[#tests+1] = normalrule { + name = fs, + outleaves = { "stamp" }, + ins = { + bin, + "tests/plat/testdriver.sh" + }, + commands = { + "%{ins[2]} "..e.method.." %{ins[1]} 5", + "touch %{outs}" + } + } + end + + return normalrule { + name = e.name, + outleaves = { "stamp" }, + ins = tests, + commands = { "touch %{outs}" } + } + end +) \ No newline at end of file diff --git a/plat/qemuppc/tests/calloc_c.c b/tests/plat/calloc_c.c similarity index 100% rename from plat/qemuppc/tests/calloc_c.c rename to tests/plat/calloc_c.c diff --git a/plat/qemuppc/tests/csa_e.c b/tests/plat/csa_e.c similarity index 100% rename from plat/qemuppc/tests/csa_e.c rename to tests/plat/csa_e.c diff --git a/plat/qemuppc/tests/csb_e.c b/tests/plat/csb_e.c similarity index 100% rename from plat/qemuppc/tests/csb_e.c rename to tests/plat/csb_e.c diff --git a/plat/qemuppc/tests/doublecmp_e.c b/tests/plat/doublecmp_e.c similarity index 100% rename from plat/qemuppc/tests/doublecmp_e.c rename to tests/plat/doublecmp_e.c diff --git a/plat/qemuppc/tests/from_d_to_si_e.c b/tests/plat/from_d_to_si_e.c similarity index 100% rename from plat/qemuppc/tests/from_d_to_si_e.c rename to tests/plat/from_d_to_si_e.c diff --git a/plat/qemuppc/tests/from_d_to_ui_e.c b/tests/plat/from_d_to_ui_e.c similarity index 100% rename from plat/qemuppc/tests/from_d_to_ui_e.c rename to tests/plat/from_d_to_ui_e.c diff --git a/plat/qemuppc/tests/from_si_to_d_e.c b/tests/plat/from_si_to_d_e.c similarity index 100% rename from plat/qemuppc/tests/from_si_to_d_e.c rename to tests/plat/from_si_to_d_e.c diff --git a/plat/qemuppc/tests/from_ui_to_d_e.c b/tests/plat/from_ui_to_d_e.c similarity index 100% rename from plat/qemuppc/tests/from_ui_to_d_e.c rename to tests/plat/from_ui_to_d_e.c diff --git a/plat/qemuppc/tests/inn_e.e b/tests/plat/inn_e.e similarity index 100% rename from plat/qemuppc/tests/inn_e.e rename to tests/plat/inn_e.e diff --git a/plat/qemuppc/tests/intadd_e.c b/tests/plat/intadd_e.c similarity index 100% rename from plat/qemuppc/tests/intadd_e.c rename to tests/plat/intadd_e.c diff --git a/plat/qemuppc/tests/intcmp_e.c b/tests/plat/intcmp_e.c similarity index 100% rename from plat/qemuppc/tests/intcmp_e.c rename to tests/plat/intcmp_e.c diff --git a/plat/qemuppc/tests/intdiv_e.c b/tests/plat/intdiv_e.c similarity index 100% rename from plat/qemuppc/tests/intdiv_e.c rename to tests/plat/intdiv_e.c diff --git a/plat/qemuppc/tests/intrem_e.c b/tests/plat/intrem_e.c similarity index 100% rename from plat/qemuppc/tests/intrem_e.c rename to tests/plat/intrem_e.c diff --git a/plat/qemuppc/tests/intshift_e.c b/tests/plat/intshift_e.c similarity index 100% rename from plat/qemuppc/tests/intshift_e.c rename to tests/plat/intshift_e.c diff --git a/plat/qemuppc/tests/intsub_e.c b/tests/plat/intsub_e.c similarity index 100% rename from plat/qemuppc/tests/intsub_e.c rename to tests/plat/intsub_e.c diff --git a/plat/qemuppc/tests/lib/build.lua b/tests/plat/lib/build.lua similarity index 100% rename from plat/qemuppc/tests/lib/build.lua rename to tests/plat/lib/build.lua diff --git a/plat/qemuppc/tests/lib/test.c b/tests/plat/lib/test.c similarity index 100% rename from plat/qemuppc/tests/lib/test.c rename to tests/plat/lib/test.c diff --git a/plat/qemuppc/tests/lib/test.h b/tests/plat/lib/test.h similarity index 100% rename from plat/qemuppc/tests/lib/test.h rename to tests/plat/lib/test.h diff --git a/plat/qemuppc/tests/newdispose_p.p b/tests/plat/newdispose_p.p similarity index 100% rename from plat/qemuppc/tests/newdispose_p.p rename to tests/plat/newdispose_p.p diff --git a/plat/qemuppc/tests/testdriver.sh b/tests/plat/testdriver.sh similarity index 100% rename from plat/qemuppc/tests/testdriver.sh rename to tests/plat/testdriver.sh From 8a58614aefa70c0805186d3c08a80876173c57a2 Mon Sep 17 00:00:00 2001 From: David Given Date: Sat, 26 Nov 2016 11:23:25 +0100 Subject: [PATCH 03/10] Rework the tests to run on pc86; lots of test fixes for the brk() test, which was nearly useless; lots of fixes to qemuppc and pc86 sbrk(), which was broken; change the pc86 console to echo output to the serial port (needed for running tests on qemu). --- .travis.yml | 1 + build.lua | 1 + plat/pc86/boot.s | 11 +++++++---- plat/pc86/include/unistd.h | 1 + plat/pc86/libsys/brk.c | 22 +++++++++++++++++++--- plat/pc86/tests/build.lua | 7 +++++++ plat/qemuppc/libsys/brk.c | 17 +++++++++++++++-- tests/plat/_dummy.c | 1 + tests/plat/brk_c.c | 32 +++++++++++++++++++++++++++----- tests/plat/build.lua | 9 ++++++++- tests/plat/from_d_to_si_e.c | 9 +++++---- tests/plat/from_d_to_ui_e.c | 5 +++-- tests/plat/from_si_to_d_e.c | 9 +++++---- tests/plat/from_ui_to_d_e.c | 5 +++-- tests/plat/inn_e.e | 34 +++++++++++++++++++++------------- tests/plat/intshift_e.c | 9 +++++---- tests/plat/intsub_e.c | 7 ++++--- tests/plat/lib/build.lua | 1 - tests/plat/lib/test.c | 2 +- tests/plat/lib/test.h | 2 +- tests/plat/testdriver.sh | 25 ++++++++++++++++++++----- 21 files changed, 155 insertions(+), 55 deletions(-) create mode 100644 plat/pc86/tests/build.lua diff --git a/.travis.yml b/.travis.yml index c6e2f5913..9db308dea 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,7 @@ addons: packages: - ed - openbios-ppc + - qemu-system-i386 git: depth: 10 diff --git a/build.lua b/build.lua index cc550cb9e..584449834 100644 --- a/build.lua +++ b/build.lua @@ -15,6 +15,7 @@ vars.plats = { } vars.plats_with_tests = { "qemuppc", + "pc86", } local plat_packages = {} diff --git a/plat/pc86/boot.s b/plat/pc86/boot.s index 534809697..51b288e75 100644 --- a/plat/pc86/boot.s +++ b/plat/pc86/boot.s @@ -23,7 +23,7 @@ ! If you ever need to change the boot code, this needs adjusting. I recommend ! a hex editor. -PADDING = 0xB7 +PADDING = 0xB3 ! Some definitions. @@ -271,9 +271,12 @@ finished: ! Push standard parameters onto the stack and go. - push envp ! envp - push argv ! argv - push 1 ! argc + mov ax, envp + push ax + mov ax, argv + push ax + mov ax, 1 + push ax call __m_a_i_n ! fall through into the exit routine. diff --git a/plat/pc86/include/unistd.h b/plat/pc86/include/unistd.h index ea4f51c0f..174c43ad0 100644 --- a/plat/pc86/include/unistd.h +++ b/plat/pc86/include/unistd.h @@ -37,6 +37,7 @@ extern char** environ; extern void _exit(int); extern pid_t getpid(void); +extern int brk(void* addr); extern void* sbrk(int increment); extern int isatty(int d); extern off_t lseek(int fildes, off_t offset, int whence); diff --git a/plat/pc86/libsys/brk.c b/plat/pc86/libsys/brk.c index 952a9c747..293703234 100644 --- a/plat/pc86/libsys/brk.c +++ b/plat/pc86/libsys/brk.c @@ -22,7 +22,10 @@ int brk(void* newend) if ((p > (&dummy - STACK_BUFFER)) || (p < _end)) + { + errno = ENOMEM; return -1; + } current = p; return 0; @@ -31,13 +34,26 @@ int brk(void* newend) void* sbrk(int increment) { char* old; - + char* new; + if (increment == 0) return current; old = current; - if (brk(old + increment) < 0) - return OUT_OF_MEMORY; + + new = old + increment; + + if ((increment > 0) && (new <= old)) + goto out_of_memory; + else if ((increment < 0) && (new >= old)) + goto out_of_memory; + + if (brk(new) < 0) + goto out_of_memory; return old; + +out_of_memory: + errno = ENOMEM; + return OUT_OF_MEMORY; } diff --git a/plat/pc86/tests/build.lua b/plat/pc86/tests/build.lua new file mode 100644 index 000000000..fe871e450 --- /dev/null +++ b/plat/pc86/tests/build.lua @@ -0,0 +1,7 @@ +include("tests/plat/build.lua") + +plat_testsuite { + name = "tests", + plat = "pc86", + method = "qemu-system-i386" +} diff --git a/plat/qemuppc/libsys/brk.c b/plat/qemuppc/libsys/brk.c index 118bda3cf..7d49fa960 100644 --- a/plat/qemuppc/libsys/brk.c +++ b/plat/qemuppc/libsys/brk.c @@ -34,13 +34,26 @@ int brk(void* newend) void* sbrk(int increment) { char* old; + char* new; if (increment == 0) return current; old = current; - if (brk(old + increment) < 0) - return OUT_OF_MEMORY; + + new = old + increment; + + if ((increment > 0) && (new <= old)) + goto out_of_memory; + else if ((increment < 0) && (new >= old)) + goto out_of_memory; + + if (brk(new) < 0) + goto out_of_memory; return old; + +out_of_memory: + errno = ENOMEM; + return OUT_OF_MEMORY; } diff --git a/tests/plat/_dummy.c b/tests/plat/_dummy.c index 48104b5aa..a4693300f 100644 --- a/tests/plat/_dummy.c +++ b/tests/plat/_dummy.c @@ -6,3 +6,4 @@ void _m_a_i_n(void) ASSERT(0 == 0); finished(); } + diff --git a/tests/plat/brk_c.c b/tests/plat/brk_c.c index aa0f7ef99..9a07c7d3b 100644 --- a/tests/plat/brk_c.c +++ b/tests/plat/brk_c.c @@ -7,9 +7,11 @@ int main(int argc, const char* argv[]) { - void* p; + char* o; + char* p; - ASSERT(-1 == (intptr_t)brk((void*)0xffffffff)); + errno = 0; + ASSERT(-1 == brk((void*)-1)); ASSERT(ENOMEM == errno); p = sbrk(0); @@ -19,9 +21,29 @@ int main(int argc, const char* argv[]) ASSERT(p != sbrk(-8)); ASSERT(p == sbrk(0)); - /* We assume the test environment has less than 2GB of RAM. */ - ASSERT(-1 == (intptr_t)sbrk(INT_MAX)); - ASSERT(-1 == (intptr_t)sbrk(INT_MIN)); + errno = 0; + o = sbrk(INT_MAX); + if (o == (char*)-1) + ASSERT(ENOMEM == errno); + else + { + ASSERT(0 == errno); + p = sbrk(0); + ASSERT(p > o); + brk(o); + } + + errno = 0; + o = sbrk(INT_MIN); + if (o == (char*)-1) + ASSERT(ENOMEM == errno); + else + { + ASSERT(0 == errno); + p = sbrk(0); + ASSERT(p < o); + brk(o); + } finished(); } diff --git a/tests/plat/build.lua b/tests/plat/build.lua index 23685ba40..3873ed9a5 100644 --- a/tests/plat/build.lua +++ b/tests/plat/build.lua @@ -14,6 +14,13 @@ definerule("plat_testsuite", "tests/plat/*.p" ) + acklibrary { + name = "lib", + srcs = { "tests/plat/lib/test.c" }, + hdrs = { "tests/plat/lib/test.h" }, + vars = { plat = e.plat }, + } + local tests = {} for _, f in ipairs(testfiles) do local fs = replace(basename(f), "%..$", "") @@ -25,7 +32,7 @@ definerule("plat_testsuite", local bin = ackprogram { name = fs.."_bin", srcs = { f }, - deps = { "tests/plat/lib+lib" }, + deps = { "+lib" }, vars = { plat = e.plat, lang = lang, diff --git a/tests/plat/from_d_to_si_e.c b/tests/plat/from_d_to_si_e.c index 8c7e31c3e..7f51e6c5b 100644 --- a/tests/plat/from_d_to_si_e.c +++ b/tests/plat/from_d_to_si_e.c @@ -1,11 +1,12 @@ +#include #include "test.h" /* Constants in globals to defeat constant folding. */ double one = 1.0; double zero = 0.0; double minusone = -1.0; -double big = 2147483647.0; -double minusbig = -2147483648.0; +double big = (double)INT_MAX; +double minusbig = (double)INT_MIN; /* Bypasses the CRT, so there's no stdio or BSS initialisation. */ void _m_a_i_n(void) @@ -13,8 +14,8 @@ void _m_a_i_n(void) ASSERT((int)zero == 0); ASSERT((int)one == 1); ASSERT((int)minusone == -1); - ASSERT((int)big == 2147483647); - ASSERT((int)minusbig == -2147483648); + ASSERT((int)big == INT_MAX); + ASSERT((int)minusbig == INT_MIN); finished(); } \ No newline at end of file diff --git a/tests/plat/from_d_to_ui_e.c b/tests/plat/from_d_to_ui_e.c index b16667502..811780b87 100644 --- a/tests/plat/from_d_to_ui_e.c +++ b/tests/plat/from_d_to_ui_e.c @@ -1,16 +1,17 @@ +#include #include "test.h" /* Constants in globals to defeat constant folding. */ double one = 1.0; double zero = 0.0; -double big = 4294967295.0; +double big = (double)UINT_MAX; /* Bypasses the CRT, so there's no stdio or BSS initialisation. */ void _m_a_i_n(void) { ASSERT((unsigned int)zero == 0); ASSERT((unsigned int)one == 1); - ASSERT((unsigned int)big == 4294967295); + ASSERT((unsigned int)big == UINT_MAX); finished(); } \ No newline at end of file diff --git a/tests/plat/from_si_to_d_e.c b/tests/plat/from_si_to_d_e.c index e81c2f7c2..b6c7a25ba 100644 --- a/tests/plat/from_si_to_d_e.c +++ b/tests/plat/from_si_to_d_e.c @@ -1,11 +1,12 @@ +#include #include "test.h" /* Constants in globals to defeat constant folding. */ int one = 1; int zero = 0; int minusone = -1; -int big = 0x7fffffff; -int minusbig = -0x8000000; +int big = INT_MAX; +int minusbig = INT_MIN; /* Bypasses the CRT, so there's no stdio or BSS initialisation. */ void _m_a_i_n(void) @@ -13,8 +14,8 @@ void _m_a_i_n(void) ASSERT((double)zero == 0.0); ASSERT((double)one == 1.0); ASSERT((double)minusone == -1.0); - ASSERT((double)big == 2147483647.0); - /* ASSERT((double)minusbig == -2147483648.0); FIXME: fails for now */ + ASSERT((double)big == (double)INT_MAX); + /* ASSERT((double)minusbig == (double)INT_MIN); FIXME: fails for now */ finished(); } \ No newline at end of file diff --git a/tests/plat/from_ui_to_d_e.c b/tests/plat/from_ui_to_d_e.c index a3517b24c..b8e017c99 100644 --- a/tests/plat/from_ui_to_d_e.c +++ b/tests/plat/from_ui_to_d_e.c @@ -1,16 +1,17 @@ +#include #include "test.h" /* Constants in globals to defeat constant folding. */ unsigned int one_u = 1; unsigned int zero_u = 0; -unsigned int big_u = 0xffffffff; +unsigned int big_u = UINT_MAX; /* Bypasses the CRT, so there's no stdio or BSS initialisation. */ void _m_a_i_n(void) { ASSERT((double)zero_u == 0.0); ASSERT((double)one_u == 1.0); - ASSERT((double)big_u == 4294967295.0); + ASSERT((double)big_u == (double)UINT_MAX); finished(); } \ No newline at end of file diff --git a/tests/plat/inn_e.e b/tests/plat/inn_e.e index 4e53b35c5..7d27abf42 100644 --- a/tests/plat/inn_e.e +++ b/tests/plat/inn_e.e @@ -1,5 +1,5 @@ # - mes 2, 4, 4 + mes 2, EM_WSIZE, EM_PSIZE exp $_m_a_i_n pro $_m_a_i_n, 0 @@ -10,12 +10,12 @@ rom 0I1, 0I1, 0I1, 0I1 loe .1 loc 1 /* bit number */ - inn 4 + inn EM_WSIZE zeq *1 loc __LINE__ cal $fail - ass 4 + ass EM_WSIZE 1 /* Test existent bit */ @@ -24,12 +24,12 @@ rom 2I1, 0I1, 0I1, 0I1 loe .2 loc 1 /* bit number */ - inn 4 + inn EM_WSIZE zne *2 loc __LINE__ cal $fail - ass 4 + ass EM_WSIZE 2 /* Test non-existent high bit */ @@ -38,36 +38,44 @@ rom 0I1, 0I1, 0I1, 0I1 rom 0I1, 0I1, 0I1, 0I1 .31 - rom 33 /* to defeat constant folding */ + rom (EM_WSIZE*8)+1 /* to defeat constant folding */ lae .3 - loi 8 + loi EM_WSIZE*2 loe .31 /* bit number */ - inn 8 + inn EM_WSIZE*2 zeq *3 loc __LINE__ cal $fail - ass 4 + ass EM_WSIZE 3 /* Test existent high bit */ .4 +#if EM_WSIZE == 2 + rom 0I1, 0I1 + rom 2I1, 0I1 +#elif EM_WSIZE == 4 rom 0I1, 0I1, 0I1, 0I1 rom 2I1, 0I1, 0I1, 0I1 +#else + #error Unknown word size +#endif + .41 - rom 33 /* to defeat constant folding */ + rom (EM_WSIZE*8)+1 /* to defeat constant folding */ lae .4 - loi 8 + loi EM_WSIZE*2 loe .41 /* bit number */ - inn 8 + inn EM_WSIZE*2 zne *4 loc __LINE__ cal $fail - ass 4 + ass EM_WSIZE 4 cal $finished diff --git a/tests/plat/intshift_e.c b/tests/plat/intshift_e.c index dd280142c..3cc6d52f9 100644 --- a/tests/plat/intshift_e.c +++ b/tests/plat/intshift_e.c @@ -1,3 +1,4 @@ +#include #include "test.h" /* Constants in globals to defeat constant folding. */ @@ -25,8 +26,8 @@ void _m_a_i_n(void) ASSERT(((unsigned int)one >>(unsigned int)zero) == 1); ASSERT(((unsigned int)one >>(unsigned int)one) == 0); - ASSERT(((unsigned int)minusone>>(unsigned int)zero) == 0xffffffff); - ASSERT(((unsigned int)minusone>>(unsigned int)one) == 0x7fffffff); + ASSERT(((unsigned int)minusone>>(unsigned int)zero) == UINT_MAX); + ASSERT(((unsigned int)minusone>>(unsigned int)one) == (UINT_MAX>>1)); ASSERT((one <<0) == 1); ASSERT((one <<1) == 2); @@ -45,8 +46,8 @@ void _m_a_i_n(void) ASSERT(((unsigned int)one >>(unsigned int)0) == 1); ASSERT(((unsigned int)one >>(unsigned int)1) == 0); - ASSERT(((unsigned int)minusone>>(unsigned int)0) == 0xffffffff); - ASSERT(((unsigned int)minusone>>(unsigned int)1) == 0x7fffffff); + ASSERT(((unsigned int)minusone>>(unsigned int)0) == UINT_MAX); + ASSERT(((unsigned int)minusone>>(unsigned int)1) == (UINT_MAX>>1)); finished(); } \ No newline at end of file diff --git a/tests/plat/intsub_e.c b/tests/plat/intsub_e.c index 72ba0ff08..d8f67d3a3 100644 --- a/tests/plat/intsub_e.c +++ b/tests/plat/intsub_e.c @@ -1,3 +1,4 @@ +#include #include "test.h" /* Constants in globals to defeat constant folding. */ @@ -19,13 +20,13 @@ void _m_a_i_n(void) ASSERT((1 - two) == -1); ASSERT(((unsigned int)two - (unsigned int)one) == 1); - ASSERT(((unsigned int)one - (unsigned int)two) == 0xffffffff); + ASSERT(((unsigned int)one - (unsigned int)two) == UINT_MAX); ASSERT(((unsigned int)two - (unsigned int)1) == 1); - ASSERT(((unsigned int)one - (unsigned int)2) == 0xffffffff); + ASSERT(((unsigned int)one - (unsigned int)2) == UINT_MAX); ASSERT(((unsigned int)2 - (unsigned int)one) == 1); - ASSERT(((unsigned int)1 - (unsigned int)two) == 0xffffffff); + ASSERT(((unsigned int)1 - (unsigned int)two) == UINT_MAX); finished(); } \ No newline at end of file diff --git a/tests/plat/lib/build.lua b/tests/plat/lib/build.lua index cb6b5cbea..be9928c84 100644 --- a/tests/plat/lib/build.lua +++ b/tests/plat/lib/build.lua @@ -4,5 +4,4 @@ acklibrary { name = "lib", srcs = { "./test.c" }, hdrs = { "./test.h" }, - vars = { plat = "qemuppc" } } diff --git a/tests/plat/lib/test.c b/tests/plat/lib/test.c index 33d72f3ce..d05417326 100644 --- a/tests/plat/lib/test.c +++ b/tests/plat/lib/test.c @@ -25,7 +25,7 @@ void writehex(uint32_t code) void fail(uint32_t code) { - write(1, "@@FAIL on line 0x", 7); + write(1, "@@FAIL 0x", 10); writehex(code); write(1, "\n", 1); } diff --git a/tests/plat/lib/test.h b/tests/plat/lib/test.h index 96537a2cb..db16506f9 100644 --- a/tests/plat/lib/test.h +++ b/tests/plat/lib/test.h @@ -9,6 +9,6 @@ extern void writehex(uint32_t code); extern void fail(uint32_t code); #define ASSERT(condition) \ - if (!(condition)) fail(__LINE__) + do { if (!(condition)) fail(__LINE__); } while(0) #endif diff --git a/tests/plat/testdriver.sh b/tests/plat/testdriver.sh index 3424e9626..29d9063eb 100755 --- a/tests/plat/testdriver.sh +++ b/tests/plat/testdriver.sh @@ -1,5 +1,5 @@ #!/bin/sh -qemu=$1 +method=$1 img=$2 timeout=$3 @@ -13,10 +13,25 @@ trap "rm -f $result" EXIT pidfile=/tmp/$$.testdriver.pid trap "rm -f $pidfile" EXIT -( $qemu -nographic -kernel $img 2>&1 & echo $! > $pidfile ) \ - | tee $result \ - | ( timeout $timeout grep -l -q @@FINISHED ; echo ) \ - | ( read dummy && kill $(cat $pidfile) ) +case $method in + qemu-system-*) + if ! hash $method 2>/dev/null; then + echo "Warning: $method not installed, skipping test" + exit 0 + fi + + case $method in + qemu-system-i386) img="-drive file=$img,if=floppy,format=raw" ;; + qemu-system-ppc) img="-kernel $img" ;; + esac + + ( $method -nographic $img 2>&1 & echo $! > $pidfile ) \ + | tee $result \ + | ( timeout $timeout grep -l -q @@FINISHED ; echo ) \ + | ( read dummy && kill $(cat $pidfile) ) + + ;; +esac ( grep -q @@FAIL $result || ! grep -q @@FINISHED $result ) && cat $result && exit 1 exit 0 \ No newline at end of file From 90e3d45c696130a99a82a889030079db84edd12b Mon Sep 17 00:00:00 2001 From: David Given Date: Sat, 26 Nov 2016 11:29:57 +0100 Subject: [PATCH 04/10] Travis only whitelists the -x86 version of qemu. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 9db308dea..a73c139d8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ addons: packages: - ed - openbios-ppc - - qemu-system-i386 + - qemu-system-x86 git: depth: 10 From cf33bd6cc46adf0abd6004898305fb87a4e3ed1d Mon Sep 17 00:00:00 2001 From: David Given Date: Sat, 26 Nov 2016 11:56:17 +0100 Subject: [PATCH 05/10] Enable tests for linuxppc via qemu-ppc. --- build.lua | 1 + plat/linux/libsys/sbrk.c | 21 +++++++++++++-------- plat/linuxppc/tests/build.lua | 7 +++++++ tests/plat/brk_c.c | 4 ---- tests/plat/lib/test.c | 1 + tests/plat/testdriver.sh | 14 ++++++++++++++ 6 files changed, 36 insertions(+), 12 deletions(-) create mode 100644 plat/linuxppc/tests/build.lua diff --git a/build.lua b/build.lua index 584449834..2b5ec62a0 100644 --- a/build.lua +++ b/build.lua @@ -14,6 +14,7 @@ vars.plats = { "rpi", } vars.plats_with_tests = { + "linuxppc", "qemuppc", "pc86", } diff --git a/plat/linux/libsys/sbrk.c b/plat/linux/libsys/sbrk.c index 7aeeecb86..f790a17cb 100644 --- a/plat/linux/libsys/sbrk.c +++ b/plat/linux/libsys/sbrk.c @@ -26,7 +26,6 @@ void* sbrk(int increment) { char* old; char* new; - char* actual; if (!current) current = (char*) _syscall(__NR_brk, 0, 0, 0); @@ -35,15 +34,21 @@ void* sbrk(int increment) return current; old = current; + new = old + increment; - actual = (char*) _syscall(__NR_brk, (quad) new, 0, 0); - if (actual < new) - { - errno = ENOMEM; - return OUT_OF_MEMORY; - } + if ((increment > 0) && (new <= old)) + goto out_of_memory; + else if ((increment < 0) && (new >= old)) + goto out_of_memory; + + if (brk(new) < 0) + goto out_of_memory; - current = actual; return old; + +out_of_memory: + errno = ENOMEM; + return OUT_OF_MEMORY; } + diff --git a/plat/linuxppc/tests/build.lua b/plat/linuxppc/tests/build.lua new file mode 100644 index 000000000..7601ab0be --- /dev/null +++ b/plat/linuxppc/tests/build.lua @@ -0,0 +1,7 @@ +include("tests/plat/build.lua") + +plat_testsuite { + name = "tests", + plat = "linuxppc", + method = "qemu-ppc" +} diff --git a/tests/plat/brk_c.c b/tests/plat/brk_c.c index 9a07c7d3b..434cec50b 100644 --- a/tests/plat/brk_c.c +++ b/tests/plat/brk_c.c @@ -10,10 +10,6 @@ int main(int argc, const char* argv[]) char* o; char* p; - errno = 0; - ASSERT(-1 == brk((void*)-1)); - ASSERT(ENOMEM == errno); - p = sbrk(0); ASSERT(p == sbrk(0)); ASSERT(p == sbrk(8)); diff --git a/tests/plat/lib/test.c b/tests/plat/lib/test.c index d05417326..df00e1089 100644 --- a/tests/plat/lib/test.c +++ b/tests/plat/lib/test.c @@ -6,6 +6,7 @@ void finished(void) { static const char s[] = "@@FINISHED\n"; write(1, s, sizeof(s)); + _exit(0); } void writehex(uint32_t code) diff --git a/tests/plat/testdriver.sh b/tests/plat/testdriver.sh index 29d9063eb..f5ca187a3 100755 --- a/tests/plat/testdriver.sh +++ b/tests/plat/testdriver.sh @@ -31,6 +31,20 @@ case $method in | ( read dummy && kill $(cat $pidfile) ) ;; + + qemu-*) + if ! hash $method 2>/dev/null; then + echo "Warning: $method not installed, skipping test" + exit 0 + fi + + $method $img > $result + ;; + + *) + echo "Error: $method not known by testdriver" + exit 1 + ;; esac ( grep -q @@FAIL $result || ! grep -q @@FINISHED $result ) && cat $result && exit 1 From 98c761d5c03ef07aa9fd2611fba090ce50fcb6e3 Mon Sep 17 00:00:00 2001 From: David Given Date: Sat, 26 Nov 2016 11:58:02 +0100 Subject: [PATCH 06/10] Enable tests for linux386 via qemu-i386. --- build.lua | 1 + plat/linux386/tests/build.lua | 7 +++++++ 2 files changed, 8 insertions(+) create mode 100644 plat/linux386/tests/build.lua diff --git a/build.lua b/build.lua index 2b5ec62a0..607a83a3b 100644 --- a/build.lua +++ b/build.lua @@ -14,6 +14,7 @@ vars.plats = { "rpi", } vars.plats_with_tests = { + "linux386", "linuxppc", "qemuppc", "pc86", diff --git a/plat/linux386/tests/build.lua b/plat/linux386/tests/build.lua new file mode 100644 index 000000000..afd12fdce --- /dev/null +++ b/plat/linux386/tests/build.lua @@ -0,0 +1,7 @@ +include("tests/plat/build.lua") + +plat_testsuite { + name = "tests", + plat = "linux386", + method = "qemu-i386" +} From dff67447fed9ae242a60207940921dd3abc1e784 Mon Sep 17 00:00:00 2001 From: David Given Date: Sat, 26 Nov 2016 12:00:59 +0100 Subject: [PATCH 07/10] qmu-system-x86 isn't in Travis' repository? Let's try qemu-user. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a73c139d8..6f2e25efd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ addons: packages: - ed - openbios-ppc - - qemu-system-x86 + - qemu-user git: depth: 10 From a9a0b37b1491ad9691206c01f0c359aeb2751c57 Mon Sep 17 00:00:00 2001 From: David Given Date: Sat, 26 Nov 2016 12:07:08 +0100 Subject: [PATCH 08/10] Plats which use aelflod need to depend on it. --- plat/linux386/build-tools.lua | 1 + plat/linux68k/build-tools.lua | 1 + plat/linuxppc/build-tools.lua | 1 + 3 files changed, 3 insertions(+) diff --git a/plat/linux386/build-tools.lua b/plat/linux386/build-tools.lua index d711f85fd..31b8a7388 100644 --- a/plat/linux386/build-tools.lua +++ b/plat/linux386/build-tools.lua @@ -16,6 +16,7 @@ return installable { ["$(PLATDEP)/linux386/as"] = "+as", ["$(PLATDEP)/linux386/ncg"] = "+ncg", ["$(PLATIND)/descr/linux386"] = "./descr", + "util/amisc+aelflod-pkg", "util/opt+pkg", } } diff --git a/plat/linux68k/build-tools.lua b/plat/linux68k/build-tools.lua index 944e57f47..03d659a15 100644 --- a/plat/linux68k/build-tools.lua +++ b/plat/linux68k/build-tools.lua @@ -16,6 +16,7 @@ return installable { ["$(PLATDEP)/linux68k/as"] = "+as", ["$(PLATDEP)/linux68k/ncg"] = "+ncg", ["$(PLATIND)/descr/linux68k"] = "./descr", + "util/amisc+aelflod-pkg", "util/opt+pkg", } } diff --git a/plat/linuxppc/build-tools.lua b/plat/linuxppc/build-tools.lua index ce1a163d8..e48524cc9 100644 --- a/plat/linuxppc/build-tools.lua +++ b/plat/linuxppc/build-tools.lua @@ -28,6 +28,7 @@ return installable { ["$(PLATDEP)/linuxppc/mcg"] = "+mcg", ["$(PLATDEP)/linuxppc/top"] = "+top", ["$(PLATIND)/descr/linuxppc"] = "./descr", + "util/amisc+aelflod-pkg", "util/opt+pkg", } } From a596973f283ae7abba642ec4e246410fbe6d3442 Mon Sep 17 00:00:00 2001 From: David Given Date: Sat, 26 Nov 2016 12:52:09 +0100 Subject: [PATCH 09/10] OSX doesn't work; let's not bother building it. --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6f2e25efd..765b5cea1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ matrix: include: - os: linux - - os: osx addons: apt: From 2dc083f436cf611f743440982cd45c3080868ba5 Mon Sep 17 00:00:00 2001 From: David Given Date: Sat, 26 Nov 2016 12:53:36 +0100 Subject: [PATCH 10/10] Use command -v rather than hash to detect commands (command is Posix and works on OpenBSD). --- tests/plat/testdriver.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/plat/testdriver.sh b/tests/plat/testdriver.sh index f5ca187a3..1c57ee163 100755 --- a/tests/plat/testdriver.sh +++ b/tests/plat/testdriver.sh @@ -15,7 +15,7 @@ trap "rm -f $pidfile" EXIT case $method in qemu-system-*) - if ! hash $method 2>/dev/null; then + if ! command -v $method 2>/dev/null; then echo "Warning: $method not installed, skipping test" exit 0 fi @@ -33,7 +33,7 @@ case $method in ;; qemu-*) - if ! hash $method 2>/dev/null; then + if ! command -v $method 2>/dev/null; then echo "Warning: $method not installed, skipping test" exit 0 fi @@ -48,4 +48,4 @@ case $method in esac ( grep -q @@FAIL $result || ! grep -q @@FINISHED $result ) && cat $result && exit 1 -exit 0 \ No newline at end of file +exit 0