Add Makefile.
authorTim Newsome <tim@sifive.com>
Mon, 18 Jul 2016 16:57:37 +0000 (09:57 -0700)
committerTim Newsome <tim@sifive.com>
Tue, 19 Jul 2016 18:24:25 +0000 (11:24 -0700)
Add --isolate argument which enables the 32- and 64-bit spikes to be
tested simultaneously.

debug/Makefile [new file with mode: 0644]
debug/gdbserver.py
debug/testlib.py

diff --git a/debug/Makefile b/debug/Makefile
new file mode 100644 (file)
index 0000000..a138f25
--- /dev/null
@@ -0,0 +1,12 @@
+RISCV_SIM ?= spike
+
+all:   spike32.log spike64.log
+
+spike32.log:
+       ./gdbserver.py --isolate --spike32 --cmd $(RISCV_SIM) > $@ 2>&1
+
+spike64.log:
+       ./gdbserver.py --isolate --spike --cmd $(RISCV_SIM) > $@ 2>&1
+
+clean:
+       rm -f *.log
index 6b7ac030b3f78239ff5ed324aa253036cbe1b25f..bafd7ac5e413b60915f60570e633f241b4e68f6e 100755 (executable)
@@ -409,28 +409,28 @@ class RegsTest(DeleteServer):
 class DownloadTest(DeleteServer):
     def setUp(self):
         length = min(2**20, target.ram_size - 2048)
-        fd = file("download.c", "w")
-        fd.write("#include <stdint.h>\n")
-        fd.write("unsigned int crc32a(uint8_t *message, unsigned int size);\n")
-        fd.write("uint32_t length = %d;\n" % length)
-        fd.write("uint8_t d[%d] = {\n" % length)
+        download_c = tempfile.NamedTemporaryFile(prefix="download_", suffix=".c")
+        download_c.write("#include <stdint.h>\n")
+        download_c.write("unsigned int crc32a(uint8_t *message, unsigned int size);\n")
+        download_c.write("uint32_t length = %d;\n" % length)
+        download_c.write("uint8_t d[%d] = {\n" % length)
         self.crc = 0
         for i in range(length / 16):
-            fd.write("  /* 0x%04x */ " % (i * 16));
+            download_c.write("  /* 0x%04x */ " % (i * 16));
             for _ in range(16):
                 value = random.randrange(1<<8)
-                fd.write("%d, " % value)
+                download_c.write("%d, " % value)
                 self.crc = binascii.crc32("%c" % value, self.crc)
-            fd.write("\n");
-        fd.write("};\n");
-        fd.write("uint8_t *data = &d[0];\n");
-        fd.write("uint32_t main() { return crc32a(data, length); }\n")
-        fd.close()
+            download_c.write("\n");
+        download_c.write("};\n");
+        download_c.write("uint8_t *data = &d[0];\n");
+        download_c.write("uint32_t main() { return crc32a(data, length); }\n")
+        download_c.flush()
 
         if self.crc < 0:
             self.crc += 2**32
 
-        self.binary = target.compile("download.c", "programs/checksum.c")
+        self.binary = target.compile(download_c.name, "programs/checksum.c")
         self.server = target.server()
         self.gdb = testlib.Gdb()
         self.gdb.command("file %s" % self.binary)
@@ -466,12 +466,22 @@ class Target(object):
         raise NotImplementedError
 
     def compile(self, *sources):
-        return testlib.compile(sources +
+        binary_name = "%s_%s" % (
+                self.name,
+                os.path.basename(os.path.splitext(sources[0])[0]))
+        if parsed.isolate:
+            self.temporary_binary = tempfile.NamedTemporaryFile(
+                    prefix=binary_name + "_")
+            binary_name = self.temporary_binary.name
+        testlib.compile(sources +
                 ("programs/entry.S", "programs/init.c",
                     "-I", "../env",
                     "-T", "targets/%s/link.lds" % (self.directory or self.name),
                     "-nostartfiles",
-                    "-mcmodel=medany"), xlen=self.xlen)
+                    "-mcmodel=medany",
+                    "-o", binary_name),
+                xlen=self.xlen)
+        return binary_name
 
 class Spike64Target(Target):
     name = "spike"
@@ -526,6 +536,10 @@ def main():
                 dest="target")
     parser.add_argument("--cmd",
             help="The command to use to start the debug server.")
+    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()
index e9b17d0283bdeb253cab412a24c31907f567f455..5e7f36690f5d57e1779949b1d2ff8f3bdeb3fac6 100644 (file)
@@ -17,10 +17,8 @@ def find_file(path):
     return None
 
 def compile(args, xlen=32):
-    """Compile a single .c file into a binary."""
-    dst = os.path.splitext(args[0])[0]
     cc = os.path.expandvars("$RISCV/bin/riscv%d-unknown-elf-gcc" % xlen)
-    cmd = [cc, "-g", "-o", dst]
+    cmd = [cc, "-g"]
     for arg in args:
         found = find_file(arg)
         if found:
@@ -30,7 +28,6 @@ def compile(args, xlen=32):
     cmd = " ".join(cmd)
     result = os.system(cmd)
     assert result == 0, "%r failed" % cmd
-    return dst
 
 def unused_port():
     # http://stackoverflow.com/questions/2838244/get-open-tcp-port-in-python/2838309#2838309