aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTim Newsome <tim@sifive.com>2016-03-14 11:54:29 -0700
committerTim Newsome <tim@sifive.com>2016-05-23 12:12:10 -0700
commitdaa39a220492433a138ce359f2afcf91f2ff48b6 (patch)
treef117304a5527264a42d0b9daca1952eefd618adc /tests
parent0ba84e9c8ecd025af5e084d66de02df0e016ac40 (diff)
downloadspike-daa39a220492433a138ce359f2afcf91f2ff48b6.zip
spike-daa39a220492433a138ce359f2afcf91f2ff48b6.tar.gz
spike-daa39a220492433a138ce359f2afcf91f2ff48b6.tar.bz2
Implement register writes.
Diffstat (limited to 'tests')
-rwxr-xr-xtests/gdbserver-smoke.py41
-rw-r--r--tests/testlib.py14
2 files changed, 48 insertions, 7 deletions
diff --git a/tests/gdbserver-smoke.py b/tests/gdbserver-smoke.py
index 770e77a..9d04915 100755
--- a/tests/gdbserver-smoke.py
+++ b/tests/gdbserver-smoke.py
@@ -6,13 +6,12 @@ import unittest
import tempfile
import time
-class SmokeTest(unittest.TestCase):
+class DebugTest(unittest.TestCase):
def setUp(self):
- self.tmpf = tempfile.NamedTemporaryFile()
- testlib.compile("debug.c", self.tmpf.name)
- self.spike = testlib.spike(self.tmpf.name, halted=False)
+ self.binary = testlib.compile("debug.c")
+ self.spike = testlib.spike(self.binary, halted=False)
self.gdb = testlib.Gdb()
- self.gdb.command("file %s" % self.tmpf.name)
+ self.gdb.command("file %s" % self.binary)
self.gdb.command("target extended-remote localhost:9824")
self.gdb.command("p i=0");
@@ -62,5 +61,37 @@ class SmokeTest(unittest.TestCase):
last_time = time
self.gdb.command("stepi")
+class RegsTest(unittest.TestCase):
+ def setUp(self):
+ self.binary = testlib.compile("regs.s")
+ self.spike = testlib.spike(self.binary, halted=False)
+ self.gdb = testlib.Gdb()
+ self.gdb.command("file %s" % self.binary)
+ self.gdb.command("target extended-remote localhost:9824")
+
+ def tearDown(self):
+ self.spike.kill()
+ self.spike.wait()
+
+ def test_write_gprs(self):
+ # Note a0 is missing from this list since it's used to hold the
+ # address.
+ regs = ("ra", "sp", "gp", "tp", "t0", "t1", "t2", "fp", "s1",
+ "a1", "a2", "a3", "a4", "a5", "a6", "a7", "s2", "s3", "s4",
+ "s5", "s6", "s7", "s8", "s9", "s10", "s11", "t3", "t4", "t5",
+ "t6")
+
+ self.gdb.command("p $pc=write_regs")
+ for i, r in enumerate(regs):
+ self.gdb.command("p $%s=%d" % (r, i*0xdeadbeef+17))
+ self.gdb.command("p $a0=data")
+ self.gdb.command("b all_done")
+ output = self.gdb.command("c")
+ self.assertIn("Breakpoint 1", output)
+
+ for n in range(len(regs)):
+ self.assertEqual(self.gdb.x("data+%d" % (8*n), 'g'),
+ n*0xdeadbeef+17)
+
if __name__ == '__main__':
unittest.main()
diff --git a/tests/testlib.py b/tests/testlib.py
index 04acbfc..0c1713c 100644
--- a/tests/testlib.py
+++ b/tests/testlib.py
@@ -15,10 +15,15 @@ def find_file(path):
return fullpath
raise ValueError("Couldn't find %r." % path)
-def compile(src, dst):
+def compile(src):
"""Compile a single .c file into a binary."""
+ src = find_file(src)
+ dst = os.path.splitext(src)[0]
cc = os.path.expandvars("$RISCV/bin/riscv64-unknown-elf-gcc")
- return os.system("%s -g -o %s %s" % (cc, dst, find_file(src)))
+ cmd = "%s -g -o %s %s" % (cc, dst, src)
+ result = os.system(cmd)
+ assert result == 0, "%r failed" % cmd
+ return dst
def spike(binary, halted=False):
cmd = [find_file("spike")]
@@ -46,3 +51,8 @@ class Gdb(object):
self.child.expect("\n")
self.child.expect("\(gdb\)")
return self.child.before.strip()
+
+ def x(self, address, size='w'):
+ output = self.command("x/%s %s" % (size, address))
+ value = int(output.split(':')[1].strip())
+ return value