From ce405b436277a52f764aa15551603e6dce3f568f Mon Sep 17 00:00:00 2001 From: Tim Newsome Date: Mon, 31 Oct 2016 13:30:44 -0700 Subject: [PATCH] Add basic floating point register test. --- debug/gdbserver.py | 22 +++++++++++++++++++--- debug/targets.py | 1 + debug/testlib.py | 11 +++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/debug/gdbserver.py b/debug/gdbserver.py index f506640..d236a97 100755 --- a/debug/gdbserver.py +++ b/debug/gdbserver.py @@ -9,8 +9,8 @@ import time import targets import testlib -from testlib import assertEqual, assertNotEqual, assertIn, assertNotIn -from testlib import assertGreater, assertTrue, assertRegexpMatches +from testlib import assertEqual, assertNotEqual, assertIn +from testlib import assertGreater, assertTrue, assertRegexpMatches, assertLess MSTATUS_UIE = 0x00000001 MSTATUS_SIE = 0x00000002 @@ -134,6 +134,23 @@ class SimpleT1Test(SimpleRegisterTest): def test(self): self.check_reg("t1") +class SimpleF18Test(SimpleRegisterTest): + def check_reg(self, name): + a = random.random() + b = random.random() + self.gdb.p_raw("$%s=%f" % (name, a)) + self.gdb.stepi() + assertLess(abs(float(self.gdb.p_raw("$%s" % name)) - a), .001) + self.gdb.p_raw("$%s=%f" % (name, b)) + self.gdb.stepi() + assertLess(abs(float(self.gdb.p_raw("$%s" % name)) - b), .001) + + def test(self): + misa = self.gdb.p("$misa") + if not misa & (1<<(ord('F')-ord('A'))): + return 'not_applicable' + self.check_reg("f18") + class SimpleMemoryTest(GdbTest): def access_test(self, size, data_type): assertEqual(self.gdb.p("sizeof(%s)" % data_type), size) @@ -367,7 +384,6 @@ class Registers(DebugTest): # Try both forms to test gdb. for cmd in ("info all-registers", "info registers all"): output = self.gdb.command(cmd) - assertNotIn("Could not", output) for reg in ('zero', 'ra', 'sp', 'gp', 'tp'): assertIn(reg, output) diff --git a/debug/targets.py b/debug/targets.py index 3cf9728..ca075ec 100644 --- a/debug/targets.py +++ b/debug/targets.py @@ -41,6 +41,7 @@ class Target(object): testlib.compile(sources + ("programs/entry.S", "programs/init.c", "-I", "../env", + "-march=RV%dIMAF" % self.xlen, "-T", "targets/%s/link.lds" % (self.directory or self.name), "-nostartfiles", "-mcmodel=medany", diff --git a/debug/testlib.py b/debug/testlib.py index a38b99b..b20e2ff 100644 --- a/debug/testlib.py +++ b/debug/testlib.py @@ -238,6 +238,13 @@ class Gdb(object): value = int(output.split(':')[1].strip(), 0) return value + def p_raw(self, obj): + output = self.command("p %s" % obj) + m = re.search("Cannot access memory at address (0x[0-9a-f]+)", output) + if m: + raise CannotAccess(int(m.group(1), 0)) + return output.split('=')[-1].strip() + def p(self, obj): output = self.command("p/x %s" % obj) m = re.search("Cannot access memory at address (0x[0-9a-f]+)", output) @@ -444,6 +451,10 @@ def assertGreater(a, b): if not a > b: raise TestFailed("%r not greater than %r" % (a, b)) +def assertLess(a, b): + if not a < b: + raise TestFailed("%r not less than %r" % (a, b)) + def assertTrue(a): if not a: raise TestFailed("%r is not True" % a) -- 2.30.2