import random
import binascii
+
MSTATUS_UIE = 0x00000001
MSTATUS_SIE = 0x00000002
MSTATUS_HIE = 0x00000004
# For now gdb has to be told what the architecture is when it's not
# given an ELF file.
self.gdb.command("set arch riscv:rv%d" % target.xlen)
-
+ self.gdb.command("set remotetimeout %d" % target.timeout)
self.gdb.command("target extended-remote localhost:%d" % self.server.port)
-
+
# 0x13 is nop
self.gdb.command("p *((int*) 0x%x)=0x13" % target.ram)
self.gdb.command("p *((int*) 0x%x)=0x13" % (target.ram + 4))
self.server = target.server()
self.gdb = gdb()
self.gdb.command("set arch riscv:rv%d" % target.xlen)
+ self.gdb.command("set remotetimeout %d" % target.timeout)
self.gdb.command("target extended-remote localhost:%d" % self.server.port)
def access_test(self, size, data_type):
self.server = target.server()
self.gdb = gdb()
self.gdb.command("set arch riscv:rv%d" % target.xlen)
+ self.gdb.command("set remotetimeout %d" % target.timeout)
self.gdb.command("target extended-remote localhost:%d" % self.server.port)
-
+
def test_instant_halt(self):
self.assertEqual(target.reset_vector, self.gdb.p("$pc"))
# mcycle and minstret have no defined reset value.
self.server = target.server()
self.gdb = gdb()
self.gdb.command("file %s" % self.binary)
+ self.gdb.command("set remotetimeout %d" % target.timeout)
self.gdb.command("target extended-remote localhost:%d" % self.server.port)
self.gdb.load()
self.gdb.b("_exit")
self.server = target.server()
self.gdb = gdb()
self.gdb.command("file %s" % self.binary)
+ self.gdb.command("set remotetimeout %d" % target.timeout)
self.gdb.command("target extended-remote localhost:%d" % self.server.port)
self.gdb.load()
self.gdb.b("main")
self.server = target.server()
self.gdb = gdb()
self.gdb.command("file %s" % self.binary)
+ self.gdb.command("set remotetimeout %d" % target.timeout)
self.gdb.command("target extended-remote localhost:%d" % self.server.port)
self.gdb.load()
self.gdb.b("main")
self.server = target.server()
self.gdb = gdb()
self.gdb.command("file %s" % self.binary)
+ self.gdb.command("set remotetimeout %d" % target.timeout)
self.gdb.command("target extended-remote localhost:%d" % self.server.port)
-
+
def test_download(self):
output = self.gdb.load()
self.gdb.command("b _exit")
self.server = target.server()
self.gdb = gdb()
self.gdb.command("file %s" % self.binary)
+ self.gdb.command("set remotetimeout %d" % target.timeout)
self.gdb.command("target extended-remote localhost:%d" % self.server.port)
self.gdb.load()
self.server = target.server()
self.gdb = gdb()
self.gdb.command("file %s" % self.binary)
+ self.gdb.command("set remotetimeout %d" % target.timeout)
self.gdb.command("target extended-remote localhost:%d" % self.server.port)
self.gdb.load()
class Target(object):
directory = None
-
+ timeout = 2
+
def server(self):
raise NotImplementedError
return testlib.Openocd(cmd=parsed.cmd,
config="targets/%s/openocd.cfg" % self.name)
+class FreedomE300SimTarget(Target):
+ name = "freedom-e300-sim"
+ xlen = 32
+ timeout = 240
+ ram = 0x80000000
+ ram_size = 256 * 1024 * 1024
+ instruction_hardware_breakpoint_count = 2
+
+ def server(self):
+ sim = testlib.VcsSim(simv=parsed.run)
+ x = testlib.Openocd(cmd=parsed.cmd,
+ config="targets/%s/openocd.cfg" % self.name,
+ keepAlive = sim)
+ time.sleep(20)
+ return x
+
targets = [
Spike32Target,
Spike64Target,
- FreedomE300Target
+ FreedomE300Target,
+ FreedomE300SimTarget
]
def main():
parser = argparse.ArgumentParser(
epilog="""
Example command line from the real world:
- Run all RegsTest cases against a MicroSemi m2gl_m2s board, with custom openocd command:
- ./gdbserver.py --m2gl_m2s --cmd "$HOME/SiFive/openocd/src/openocd -s $HOME/SiFive/openocd/tcl -d" -- -vf RegsTest
+ Run all RegsTest cases against a physical FPGA, with custom openocd command:
+ ./gdbserver.py --freedom-e-300 --cmd "$HOME/SiFive/openocd/src/openocd -s $HOME/SiFive/openocd/tcl -d" -- -vf RegsTest
""")
group = parser.add_mutually_exclusive_group(required=True)
for t in targets:
group.add_argument("--%s" % t.name, action="store_const", const=t,
dest="target")
+ parser.add_argument("--run",
+ help="The command to use to start the actual target (e.g. simulation)")
parser.add_argument("--cmd",
help="The command to use to start the debug server.")
parser.add_argument("--gdb",
import tempfile
import testlib
import unittest
+import time
# Note that gdb comes with its own testsuite. I was unable to figure out how to
# run that testsuite against the spike simulator.
def wait(self, *args, **kwargs):
return self.process.wait(*args, **kwargs)
+class VcsSim(object):
+ def __init__(self, simv=None, debug=False):
+ if simv:
+ cmd = shlex.split(simv)
+ else:
+ cmd = ["simv"]
+ cmd += ["+jtag_vpi_enable"]
+ if debug:
+ cmd[0] = cmd[0] + "-debug"
+ cmd += ["+vcdplusfile=output/gdbserver.vpd"]
+ logfile = open("simv.log", "w")
+ logfile.write("+ %s\n" % " ".join(cmd))
+ logfile.flush()
+ listenfile = open("simv.log", "r")
+ listenfile.seek(0,2)
+ self.process = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=logfile,
+ stderr=logfile)
+ done = False
+ while (not done):
+ line = listenfile.readline()
+ if (not line):
+ time.sleep(1)
+ if ("Listening on port 5555" in line):
+ done = True
+
+ def __del__(self):
+ print "DELETE called for VcsSim"
+ try:
+ self.process.kill()
+ self.process.wait()
+ except OSError:
+ pass
+
+
class Openocd(object):
- def __init__(self, cmd=None, config=None, debug=False):
+ def __init__(self, cmd=None, config=None, debug=False, keepAlive=None):
+
+ # keep handles to other processes -- don't let them be
+ # garbage collected yet.
+
+ self.keepAlive = keepAlive
if cmd:
cmd = shlex.split(cmd)
else: