X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=debug%2Ftestlib.py;h=b3f8f66a822f8529973fa5a46b89f4beba2da52c;hb=553f2a265fe62b514cb97fdbd80ea1743de6e3cf;hp=f8c8062f2b9c05d9416d90099d3e84611924b2d8;hpb=7ce8ad62d7f1a1e183665418151d7c655c29642a;p=riscv-tests.git diff --git a/debug/testlib.py b/debug/testlib.py index f8c8062..b3f8f66 100644 --- a/debug/testlib.py +++ b/debug/testlib.py @@ -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 @@ -65,6 +62,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) @@ -79,7 +77,7 @@ class Spike(object): return self.process.wait(*args, **kwargs) class Openocd(object): - def __init__(self, cmd=None, config=None, debug=True): + def __init__(self, cmd=None, config=None, debug=False): if cmd: cmd = shlex.split(cmd) else: @@ -89,6 +87,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 @@ -102,10 +101,11 @@ class Openocd(object): pass class Gdb(object): - def __init__(self): - path = os.path.expandvars("$RISCV/bin/riscv64-unknown-elf-gdb") - self.child = pexpect.spawn(path) + def __init__(self, + 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") @@ -153,7 +153,7 @@ class Gdb(object): return output def load(self): - output = self.command("load") + output = self.command("load", timeout=60) assert "failed" not in output assert "Transfer rate" in output @@ -166,5 +166,5 @@ class Gdb(object): def hbreak(self, location): output = self.command("hbreak %s" % location) assert "not defined" not in output - assert "Breakpoint" in output + assert "Hardware assisted breakpoint" in output return output