Add requirements.txt and reorder imports by type.
[riscv-tests.git] / debug / gdbserver.py
index 263dbd6e82bc5542d0ba724397af43c15cd5182f..de8241ce33fb6c503308971090b8929f5369b8f2 100755 (executable)
@@ -1,15 +1,16 @@
-#!/usr/bin/python
+#!/usr/bin/env python
 
 import os
 import sys
 import argparse
-import testlib
 import unittest
 import tempfile
 import time
 import random
 import binascii
 
+import .testlib
+
 
 MSTATUS_UIE = 0x00000001
 MSTATUS_SIE = 0x00000002
@@ -224,9 +225,8 @@ class DebugTest(DeleteServer):
     def test_function_call(self):
         self.gdb.b("main:start")
         self.gdb.c()
-        text = "Howdy, Earth!"
-        gdb_length = self.gdb.p('strlen("%s")' % text)
-        self.assertEqual(gdb_length, len(text))
+        self.assertEqual(self.gdb.p('fib(6)'), 8)
+        self.assertEqual(self.gdb.p('fib(7)'), 13)
         self.exit()
 
     def test_change_string(self):
@@ -238,6 +238,8 @@ class DebugTest(DeleteServer):
 
     def test_turbostep(self):
         """Single step a bunch of times."""
+        self.gdb.b("main:start")
+        self.gdb.c()
         self.gdb.command("p i=0");
         last_pc = None
         advances = 0
@@ -389,8 +391,8 @@ class RegsTest(DeleteServer):
 
         self.gdb.p("$pc=write_regs")
         for i, r in enumerate(regs):
-            self.gdb.command("p $%s=%d" % (r, (0xdeadbeef<<i)+17))
-        self.gdb.command("p $x1=data")
+            self.gdb.p("$%s=%d" % (r, (0xdeadbeef<<i)+17))
+        self.gdb.p("$x1=data")
         self.gdb.command("b all_done")
         output = self.gdb.c()
         self.assertIn("Breakpoint ", output)
@@ -527,9 +529,10 @@ class Target(object):
         raise NotImplementedError
 
     def compile(self, *sources):
-        binary_name = "%s_%s" % (
+        binary_name = "%s_%s-%d" % (
                 self.name,
-                os.path.basename(os.path.splitext(sources[0])[0]))
+                os.path.basename(os.path.splitext(sources[0])[0]),
+                self.xlen)
         if parsed.isolate:
             self.temporary_binary = tempfile.NamedTemporaryFile(
                     prefix=binary_name + "_")
@@ -644,16 +647,28 @@ def main():
             help="The command to use to start the debug server.")
     parser.add_argument("--gdb",
             help="The command to use to start gdb.")
+
+    xlen_group = parser.add_mutually_exclusive_group()
+    xlen_group.add_argument("--32", action="store_const", const=32, dest="xlen",
+            help="Force the target to be 32-bit.")
+    xlen_group.add_argument("--64", action="store_const", const=64, dest="xlen",
+            help="Force the target to be 64-bit.")
+
     parser.add_argument("--isolate", action="store_true",
             help="Try to run in such a way that multiple instances can run at "
             "the same time. This may make it harder to debug a failure if it "
             "does occur.")
+
     parser.add_argument("unittest", nargs="*")
     global parsed
     parsed = parser.parse_args()
 
     global target
     target = parsed.target()
+
+    if parsed.xlen:
+        target.xlen = parsed.xlen
+
     unittest.main(argv=[sys.argv[0]] + parsed.unittest)
 
 # TROUBLESHOOTING TIPS