From 8a856751eedac2d6d6ca8ceaec285ad0cf873478 Mon Sep 17 00:00:00 2001 From: Ajax Date: Mon, 16 Nov 2015 10:54:12 +0100 Subject: Test/TestALL: add QEMU tests --- test/test_all.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'test/test_all.py') diff --git a/test/test_all.py b/test/test_all.py index 28da3d5a..95c880e3 100644 --- a/test/test_all.py +++ b/test/test_all.py @@ -51,6 +51,38 @@ for script in ["x86/sem.py", ]: testset += RegressionTest([script], base_dir="arch") +### QEMU regression tests +class QEMUTest(RegressionTest): + """Test against QEMU regression tests + An expected output is provided, computed on a x86 host""" + + SCRIPT_NAME = "testqemu.py" + SAMPLE_NAME = "test-i386" + EXPECTED_PATH = "expected" + + def __init__(self, name, *args, **kwargs): + super(QEMUTest, self).__init__([self.SCRIPT_NAME], *args, **kwargs) + self.base_dir = os.path.join(self.base_dir, "arch", "x86", "qemu") + test_name = "test_%s" % name + expected_output = os.path.join(self.EXPECTED_PATH, test_name) + ".exp" + self.command_line += [self.SAMPLE_NAME, + test_name, + expected_output, + ] + +for test_name in ( + # Operations + "btr", "bts", "bt", "shrd", "shld", "rcl", "rcr", "ror", + "rol", "sar", "shr", "shl", "not", "neg", "dec", "inc", + "sbb", "adc", "cmp", "or", "and", "xor", "sub", "add", + # Specifics + "bsx", "mul", "lea", "conv" + # Unsupported + # "jcc", "loop", "floats", "bcd", "xchg", "string", "misc", + # "segs", "code16", "exceptions", "self_modifying_code", "single_step", +): + testset += QEMUTest(test_name) + ## Semantic class SemanticTestAsm(RegressionTest): -- cgit 1.4.1 From a014d17db74a0de84efbf7a8a21ea58739dbb39d Mon Sep 17 00:00:00 2001 From: Ajax Date: Mon, 16 Nov 2015 11:04:51 +0100 Subject: Test/QEMU: test the python jitter too --- test/test_all.py | 63 ++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 48 insertions(+), 15 deletions(-) (limited to 'test/test_all.py') diff --git a/test/test_all.py b/test/test_all.py index 95c880e3..4dff7ed7 100644 --- a/test/test_all.py +++ b/test/test_all.py @@ -60,28 +60,61 @@ class QEMUTest(RegressionTest): SAMPLE_NAME = "test-i386" EXPECTED_PATH = "expected" - def __init__(self, name, *args, **kwargs): + def __init__(self, name, jitter, *args, **kwargs): super(QEMUTest, self).__init__([self.SCRIPT_NAME], *args, **kwargs) self.base_dir = os.path.join(self.base_dir, "arch", "x86", "qemu") test_name = "test_%s" % name expected_output = os.path.join(self.EXPECTED_PATH, test_name) + ".exp" self.command_line += [self.SAMPLE_NAME, - test_name, - expected_output, + test_name, + expected_output, + "--jitter", + jitter, ] -for test_name in ( - # Operations - "btr", "bts", "bt", "shrd", "shld", "rcl", "rcr", "ror", - "rol", "sar", "shr", "shl", "not", "neg", "dec", "inc", - "sbb", "adc", "cmp", "or", "and", "xor", "sub", "add", - # Specifics - "bsx", "mul", "lea", "conv" - # Unsupported - # "jcc", "loop", "floats", "bcd", "xchg", "string", "misc", - # "segs", "code16", "exceptions", "self_modifying_code", "single_step", -): - testset += QEMUTest(test_name) +# Test name -> supported jitter engines +QEMU_TESTS = { + # Operations + "btr": ("tcc", "python"), + "bts": ("tcc", "python"), + "bt": ("tcc", "python"), + "shrd": ("tcc", "python"), + "shld": ("tcc", "python"), + "rcl": ("tcc", "python"), + "rcr": ("tcc", "python"), + "ror": ("tcc", "python"), + "rol": ("tcc", "python"), + "sar": ("tcc", "python"), + "shr": ("tcc", "python"), + "shl": ("tcc", "python"), + "not": ("tcc", "python"), + "neg": ("tcc", "python"), + "dec": ("tcc", "python"), + "inc": ("tcc", "python"), + "sbb": ("tcc", "python"), + "adc": ("tcc", "python"), + "cmp": ("tcc", "python"), + "or": ("tcc", "python"), + "and": ("tcc", "python"), + "xor": ("tcc", "python"), + "sub": ("tcc", "python"), + "add": ("tcc", "python"), + # Specifics + "bsx": ("tcc", "python"), + "mul": ("tcc", "python"), + "jcc": ("tcc", "python"), + "loop": ("tcc", "python"), + "lea": ("tcc", "python"), + "conv": ("tcc", "python"), + # Unsupported + # "floats", "bcd", "xchg", "string", "misc", "segs", "code16", "exceptions", + # "self_modifying_code", "single_step" +} + + +for test_name, jitters in QEMU_TESTS.iteritems(): + for jitter_engine in jitters: + testset += QEMUTest(test_name, jitter_engine) ## Semantic -- cgit 1.4.1 From 35822fc551ce0c881c7e5216e2a2119cbed0a162 Mon Sep 17 00:00:00 2001 From: Ajax Date: Mon, 16 Nov 2015 12:46:42 +0100 Subject: Test/QEMU: emulate puts, enabling test_self_modifying_code --- test/arch/x86/qemu/testqemu.py | 16 ++++++++++++++++ test/test_all.py | 3 ++- 2 files changed, 18 insertions(+), 1 deletion(-) (limited to 'test/test_all.py') diff --git a/test/arch/x86/qemu/testqemu.py b/test/arch/x86/qemu/testqemu.py index d04308e4..7cf2ab75 100644 --- a/test/arch/x86/qemu/testqemu.py +++ b/test/arch/x86/qemu/testqemu.py @@ -84,6 +84,22 @@ def xxx___printf_chk(jitter): nb_tests += 1 jitter.func_ret_cdecl(ret_ad, 0) +def xxx_puts(jitter): + ''' + #include + int puts(const char *s); + + writes the string s and a trailing newline to stdout. + ''' + ret_addr, args = jitter.func_args_cdecl(['target']) + output = jitter.get_str_ansi(args.target) + # Check with expected result + line = expected.next() + if output != line.rstrip(): + print "Expected:", line + print "Obtained:", output + raise RuntimeError("Bad semantic") + return jitter.func_ret_cdecl(ret_addr, 1) # Parse arguments parser = Sandbox_Linux_x86_32.parser(description="ELF sandboxer") diff --git a/test/test_all.py b/test/test_all.py index 4dff7ed7..6288466a 100644 --- a/test/test_all.py +++ b/test/test_all.py @@ -105,10 +105,11 @@ QEMU_TESTS = { "jcc": ("tcc", "python"), "loop": ("tcc", "python"), "lea": ("tcc", "python"), + "self_modifying_code": ("tcc", "python"), "conv": ("tcc", "python"), # Unsupported # "floats", "bcd", "xchg", "string", "misc", "segs", "code16", "exceptions", - # "self_modifying_code", "single_step" + # "single_step" } -- cgit 1.4.1