Add test case for `riscv expose_custom`.
authorTim Newsome <tim@sifive.com>
Mon, 27 Aug 2018 20:17:51 +0000 (13:17 -0700)
committerTim Newsome <tim@sifive.com>
Wed, 29 Aug 2018 22:00:23 +0000 (15:00 -0700)
Only works against spike, where I've implemented some custom debug
registers to test against.

12 files changed:
debug/gdbserver.py
debug/targets.py
debug/targets/RISC-V/spike-1.cfg
debug/targets/RISC-V/spike-2.cfg
debug/targets/RISC-V/spike-rtos.cfg
debug/targets/RISC-V/spike32-2-rtos.py
debug/targets/RISC-V/spike32-2.py
debug/targets/RISC-V/spike32.py
debug/targets/RISC-V/spike64-2-rtos.py
debug/targets/RISC-V/spike64-2.py
debug/targets/RISC-V/spike64.py
debug/testlib.py

index 8761cf695bea732fa8c9d9e7421267546e2b8c02..c362e1dc03dea441af582c093cbf490eba36101e 100755 (executable)
@@ -137,6 +137,36 @@ class SimpleF18Test(SimpleRegisterTest):
     def test(self):
         self.check_reg("f18", "fs2")
 
+class CustomRegisterTest(SimpleRegisterTest):
+    def early_applicable(self):
+        return self.target.implements_custom_test
+
+    def check_custom(self, magic):
+        regs = self.gdb.info_registers("custom")
+        assertEqual(set(regs.keys()),
+                set(("custom1",
+                    "custom12345",
+                    "custom12346",
+                    "custom12347",
+                    "custom12348")))
+        for name, value in regs.iteritems():
+            number = int(name[6:])
+            if number % 2:
+                expect = number + magic
+                assertIn(value, (expect, expect + (1<<32)))
+            else:
+                assertIn("Could not fetch register", value)
+
+    def test(self):
+        self.check_custom(0)
+
+        # Now test writing
+        magic = 6667
+        self.gdb.p("$custom12345=%d" % (12345 + magic))
+        self.gdb.stepi()
+
+        self.check_custom(magic)
+
 class SimpleNoExistTest(GdbTest):
     def test(self):
         try:
index 2cdbb33454270663b701f549c004624b8f4f326e..63994db87cd252b98839c23ade1597a198b839ae 100644 (file)
@@ -75,6 +75,10 @@ class Target(object):
     # Supports mtime at 0x2004000
     supports_clint_mtime = True
 
+    # Implements custom debug registers like spike does. It seems unlikely any
+    # hardware will every do that.
+    implements_custom_test = False
+
     # Internal variables:
     directory = None
     temporary_files = []
index 083794fc14906a9fd9b133810371ba373bc20fbe..6f7da7426a79caa71b2024e11a0028be3e59a587 100644 (file)
@@ -16,6 +16,7 @@ gdb_report_register_access_error enable
 # Expose an unimplemented CSR so we can test non-existent register access
 # behavior.
 riscv expose_csrs 2288
+riscv expose_custom 1,12345-12348
 
 init
 
index ef8bab10bff9d2c204638b60ab3f1065a5f100e1..9dbbfe30911923bdd1b11599f8be8dff6d601b7d 100644 (file)
@@ -19,6 +19,7 @@ gdb_report_register_access_error enable
 # Expose an unimplemented CSR so we can test non-existent register access
 # behavior.
 riscv expose_csrs 2288
+riscv expose_custom 1,12345-12348
 
 init
 
index d8bd27e903aa333b4bf7b5d2cf970fd367404b64..e26ca8a43c4d8b37141ff05158fb8bc0239e5b2f 100644 (file)
@@ -17,6 +17,7 @@ gdb_report_register_access_error enable
 # Expose an unimplemented CSR so we can test non-existent register access
 # behavior.
 riscv expose_csrs 2288
+riscv expose_custom 1,12345-12348
 
 init
 
index 79105d5f3a64ef1644843f1bdca0c598890edb85..c45013f0402a69cf1868225c3643b8c508362ae3 100644 (file)
@@ -7,6 +7,7 @@ class spike32_2(targets.Target):
     harts = [spike32.spike32_hart(), spike32.spike32_hart()]
     openocd_config_path = "spike-rtos.cfg"
     timeout_sec = 30
+    implements_custom_test = True
 
     def create(self):
         return testlib.Spike(self, progbufsize=0)
index 89d3c2a3602bbc59bd96f92bdeda052df81d167d..6c90b7c87f808d9b2a229072417365e3a67357b1 100644 (file)
@@ -7,6 +7,7 @@ class spike32_2(targets.Target):
     harts = [spike32.spike32_hart(), spike32.spike32_hart()]
     openocd_config_path = "spike-2.cfg"
     timeout_sec = 30
+    implements_custom_test = True
 
     def create(self):
         return testlib.Spike(self, isa="RV32IMAFC", progbufsize=0)
index dfcfc0134dc26a67dedbc1ee79fd4e0d3d1c38c2..a831ecbb2af2ae63d9e5a0cbcfbe870885cefa0b 100644 (file)
@@ -13,6 +13,7 @@ class spike32(targets.Target):
     harts = [spike32_hart()]
     openocd_config_path = "spike-1.cfg"
     timeout_sec = 30
+    implements_custom_test = True
 
     def create(self):
         # 64-bit FPRs on 32-bit target
index 7e3fc7e2748b5a8ddeb1d75b63ac14a0e24b8260..9cb3a448fe49878c4286c08446dde053b932c7ff 100644 (file)
@@ -7,6 +7,7 @@ class spike64_2_rtos(targets.Target):
     harts = [spike64.spike64_hart(), spike64.spike64_hart()]
     openocd_config_path = "spike-rtos.cfg"
     timeout_sec = 60
+    implements_custom_test = True
 
     def create(self):
         return testlib.Spike(self)
index a2082b41b7d9e68174267d6b3be79add87f9f1e6..23ae06b6b1dce5b97030cd538f318965952c6ac8 100644 (file)
@@ -7,6 +7,7 @@ class spike64_2(targets.Target):
     harts = [spike64.spike64_hart(), spike64.spike64_hart()]
     openocd_config_path = "spike-2.cfg"
     timeout_sec = 60
+    implements_custom_test = True
 
     def create(self):
         return testlib.Spike(self, isa="RV64IMAFD")
index d5802b5714c9e7443ec3e09151e981a95b917bc3..d0eaf5ce301e1b6340b175938e3d800b4841ef0a 100644 (file)
@@ -13,6 +13,7 @@ class spike64(targets.Target):
     harts = [spike64_hart()]
     openocd_config_path = "spike-1.cfg"
     timeout_sec = 30
+    implements_custom_test = True
 
     def create(self):
         # 32-bit FPRs only
index 1d46b6c4a59cd93279595bba63a8115b780007d9..6adc43ad6586ad8e11f14fb9e7d549e2d8f21cf0 100644 (file)
@@ -552,6 +552,18 @@ class Gdb(object):
         value = shlex.split(output.split('=')[-1].strip())[1]
         return value
 
+    def info_registers(self, group):
+        output = self.command("info registers %s" % group)
+        result = {}
+        for line in output.splitlines():
+            if "Could not fetch" in line:
+                name, value = line.split(None, 1)
+            else:
+                name, hex_value, _ = line.split(None, 2)
+                value = int(hex_value, 0)
+            result[name] = value
+        return result
+
     def stepi(self):
         output = self.command("stepi", ops=10)
         return output