diff options
-rw-r--r-- | tests/core/test_indirectbr.in | 21 | ||||
-rw-r--r-- | tests/core/test_indirectbr.out | 2 | ||||
-rw-r--r-- | tests/test_core.py | 24 |
3 files changed, 26 insertions, 21 deletions
diff --git a/tests/core/test_indirectbr.in b/tests/core/test_indirectbr.in new file mode 100644 index 00000000..bdc66b53 --- /dev/null +++ b/tests/core/test_indirectbr.in @@ -0,0 +1,21 @@ + + #include <stdio.h> + int main(void) { + const void *addrs[2] = { &&FOO, &&BAR }; + + // confuse the optimizer so it doesn't hardcode the jump and avoid generating an |indirectbr| instruction + int which = 0; + for (int x = 0; x < 1000; x++) which = (which + x*x) % 7; + which = (which % 2) + 1; + + goto *addrs[which]; + + FOO: + printf("bad\n"); + return 0; + BAR: + printf("good\n"); + const void *addr = &&FOO; + goto *addr; + } +
\ No newline at end of file diff --git a/tests/core/test_indirectbr.out b/tests/core/test_indirectbr.out new file mode 100644 index 00000000..5364b418 --- /dev/null +++ b/tests/core/test_indirectbr.out @@ -0,0 +1,2 @@ +good +bad
\ No newline at end of file diff --git a/tests/test_core.py b/tests/test_core.py index e584df74..c3e76df7 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -2035,28 +2035,10 @@ def process(filename): def test_indirectbr(self): Building.COMPILER_TEST_OPTS = filter(lambda x: x != '-g', Building.COMPILER_TEST_OPTS) - src = ''' - #include <stdio.h> - int main(void) { - const void *addrs[2] = { &&FOO, &&BAR }; - - // confuse the optimizer so it doesn't hardcode the jump and avoid generating an |indirectbr| instruction - int which = 0; - for (int x = 0; x < 1000; x++) which = (which + x*x) % 7; - which = (which % 2) + 1; - - goto *addrs[which]; + test_path = path_from_root('tests', 'core', 'test_indirectbr') + src, output = (test_path + s for s in ('.in', '.out')) - FOO: - printf("bad\\n"); - return 0; - BAR: - printf("good\\n"); - const void *addr = &&FOO; - goto *addr; - } - ''' - self.do_run(src, 'good\nbad') + self.do_run_from_file(src, output) def test_indirectbr_many(self): if Settings.USE_TYPED_ARRAYS != 2: return self.skip('blockaddr > 255 requires ta2') |