From 1beedca590e3ba7cdb494d87860be7007f7ff8be Mon Sep 17 00:00:00 2001 From: David Given Date: Sat, 31 Dec 2016 17:38:52 +0000 Subject: [PATCH] Add support for B tests; add a test for the B operators (finding several compiler bugs in the process). --- tests/plat/b/operators_b.b | 57 ++++++++++++++++++++++++++++++++++++++ tests/plat/build.lua | 12 +++++--- tests/plat/lib/test_b.c | 34 +++++++++++++++++++++++ 3 files changed, 99 insertions(+), 4 deletions(-) create mode 100644 tests/plat/b/operators_b.b create mode 100644 tests/plat/lib/test_b.c diff --git a/tests/plat/b/operators_b.b b/tests/plat/b/operators_b.b new file mode 100644 index 000000000..5a4c1d91f --- /dev/null +++ b/tests/plat/b/operators_b.b @@ -0,0 +1,57 @@ +# +zero 0; +one 1; +two 2; + +main() +{ + extrn zero, one, two; + auto i; + + if (!((two + two) == 4)) fail(__LINE__); + if (!((two - two) == 0)) fail(__LINE__); + if (!((two * two) == 4)) fail(__LINE__); + if (!((two / two) == 1)) fail(__LINE__); + if (!((two % two) == 0)) fail(__LINE__); + + if (!(zero == zero)) fail(__LINE__); + if (!(zero != one)) fail(__LINE__); + if (!(zero < one)) fail(__LINE__); + if (!(zero <= one)) fail(__LINE__); + if (!(zero <= zero)) fail(__LINE__); + if (!(one > zero)) fail(__LINE__); + if (!(one >= zero)) fail(__LINE__); + if (!(one >= one)) fail(__LINE__); + + if (!((one << 1) == 2)) fail(__LINE__); + if (!((two >> 1) == 1)) fail(__LINE__); + + if (!((two & 1) == 0)) fail(__LINE__); + if (!((two | 1) == 3)) fail(__LINE__); + if (!((two ^ 2) == 0)) fail(__LINE__); + + i = 2; i =+ two; if (!(i == 4)) fail(__LINE__); + i = 2; i =- two; if (!(i == 0)) fail(__LINE__); + i = 2; i =* two; if (!(i == 4)) fail(__LINE__); + i = 2; i =/ two; if (!(i == 1)) fail(__LINE__); + i = 2; i =% two; if (!(i == 0)) fail(__LINE__); + + i = zero; i === zero; if (!i) fail(__LINE__); + i = zero; i =!= one; if (!i) fail(__LINE__); + i = zero; i =< one; if (!i) fail(__LINE__); + i = zero; i =<= one; if (!i) fail(__LINE__); + i = zero; i =<= zero; if (!i) fail(__LINE__); + i = one; i => zero; if (!i) fail(__LINE__); + i = one; i =>= zero; if (!i) fail(__LINE__); + i = one; i =>= one; if (!i) fail(__LINE__); + + i = one; i =<< one; if (!(i == 2)) fail(__LINE__); + i = two; i =>> one; if (!(i == 1)) fail(__LINE__); + + i = two; i =& 1; if (!(i == 0)) fail(__LINE__); + i = two; i =| 1; if (!(i == 3)) fail(__LINE__); + i = two; i =^ 2; if (!(i == 0)) fail(__LINE__); + + finished(); +} + diff --git a/tests/plat/build.lua b/tests/plat/build.lua index 3f43fb95b..b689ea5f6 100644 --- a/tests/plat/build.lua +++ b/tests/plat/build.lua @@ -12,12 +12,16 @@ definerule("plat_testsuite", "tests/plat/*.c", "tests/plat/*.e", "tests/plat/*.p", + "tests/plat/b/*.b", "tests/plat/bugs/*.mod" ) acklibrary { name = "lib", - srcs = { "tests/plat/lib/test.c" }, + srcs = { + "tests/plat/lib/test.c", + "tests/plat/lib/test_b.c", + }, hdrs = { "tests/plat/lib/test.h", "tests/plat/lib/Test.def" @@ -40,7 +44,7 @@ definerule("plat_testsuite", vars = { plat = e.plat, lang = lang, - ackcflags = "-O0" + ackcflags = "-O0 -Bmain" } } @@ -53,7 +57,7 @@ definerule("plat_testsuite", "util/build+testrunner" }, commands = { - "(%{ins[2]} "..e.method.." %{ins[1]} 5 %{ins[3]} || echo FAILED) > %{outs}", + "(%{ins[2]} "..e.method.." %{ins[1]} 5 %{ins[3]} || echo @@FAIL) > %{outs}", } } end @@ -63,4 +67,4 @@ definerule("plat_testsuite", srcs = tests, } end -) \ No newline at end of file +) diff --git a/tests/plat/lib/test_b.c b/tests/plat/lib/test_b.c new file mode 100644 index 000000000..b2173b4f3 --- /dev/null +++ b/tests/plat/lib/test_b.c @@ -0,0 +1,34 @@ +#include +#include "test.h" + +extern void patch_addresses(uintptr_t* module); +extern uintptr_t* bmodule_main; + +static void i_writehex(intptr_t code) +{ + writehex(code); +} + +static void i_fail(intptr_t code) +{ + fail(code); +} + +uintptr_t b_finished = (uintptr_t)&finished; +uintptr_t b_writehex = (uintptr_t)&i_writehex; +uintptr_t b_fail = (uintptr_t)&i_fail; + +static uintptr_t* bmodule_test[] = +{ + &b_finished, + &b_writehex, + &b_fail, + 0 +}; + +void binit(void) +{ + patch_addresses(&bmodule_test); + patch_addresses(&bmodule_main); +} +