Add basic floating point register test.
authorTim Newsome <tim@sifive.com>
Mon, 31 Oct 2016 20:30:44 +0000 (13:30 -0700)
committerTim Newsome <tim@sifive.com>
Mon, 31 Oct 2016 20:30:44 +0000 (13:30 -0700)
debug/gdbserver.py
debug/targets.py
debug/testlib.py

index f506640fbbc2d0cac41e8d7db88c19f38d28cb1b..d236a97ede389e4e8fa57da21c1c1882ee6f577d 100755 (executable)
@@ -9,8 +9,8 @@ import time
 
 import targets
 import testlib
 
 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
 
 MSTATUS_UIE = 0x00000001
 MSTATUS_SIE = 0x00000002
@@ -134,6 +134,23 @@ class SimpleT1Test(SimpleRegisterTest):
     def test(self):
         self.check_reg("t1")
 
     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)
 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)
         # 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)
 
             for reg in ('zero', 'ra', 'sp', 'gp', 'tp'):
                 assertIn(reg, output)
 
index 3cf972827a148ce62cafa53fdd0a995c8235f437..ca075ecfcb776682ece1295fec62ade3ae365b02 100644 (file)
@@ -41,6 +41,7 @@ class Target(object):
         testlib.compile(sources +
                 ("programs/entry.S", "programs/init.c",
                     "-I", "../env",
         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",
                     "-T", "targets/%s/link.lds" % (self.directory or self.name),
                     "-nostartfiles",
                     "-mcmodel=medany",
index a38b99b0ea1d4cffe7a918476eb2a787941d0350..b20e2ffca1d69ddd4186a5d579430f3de18f9636 100644 (file)
@@ -238,6 +238,13 @@ class Gdb(object):
         value = int(output.split(':')[1].strip(), 0)
         return value
 
         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)
     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))
 
     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)
 def assertTrue(a):
     if not a:
         raise TestFailed("%r is not True" % a)