X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=debug%2Ftestlib.py;h=d6044f5eba79adeecdf507d2f43e826155b37feb;hb=1d9383f6a7b1a31406dd86adc0975775eb1442a1;hp=e749a1a7919bbf2827559e098fc187657ee7aa69;hpb=36b305709080d84b5d4516ab344acb09349ae6d8;p=riscv-tests.git diff --git a/debug/testlib.py b/debug/testlib.py index e749a1a..d6044f5 100644 --- a/debug/testlib.py +++ b/debug/testlib.py @@ -5,6 +5,7 @@ import subprocess 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. @@ -17,10 +18,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 +29,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 @@ -65,6 +63,7 @@ class Spike(object): cmd.append(binary) logfile = open("spike.log", "w") logfile.write("+ %s\n" % " ".join(cmd)) + logfile.flush() self.process = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=logfile, stderr=logfile) @@ -78,8 +77,47 @@ class Spike(object): 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=True): + 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: @@ -89,6 +127,7 @@ class Openocd(object): if debug: cmd.append("-d") logfile = open("openocd.log", "w") + logfile.write("+ %s\n" % " ".join(cmd)) self.process = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=logfile, stderr=logfile) # TODO: Pick a random port @@ -103,9 +142,10 @@ class Openocd(object): class Gdb(object): def __init__(self, - path=os.path.expandvars("$RISCV/bin/riscv64-unknown-elf-gdb")): - self.child = pexpect.spawn(path) + cmd=os.path.expandvars("$RISCV/bin/riscv64-unknown-elf-gdb")): + self.child = pexpect.spawn(cmd) self.child.logfile = file("gdb.log", "w") + self.child.logfile.write("+ %s\n" % cmd) self.wait() self.command("set confirm off") self.command("set width 0")