diff options
author | Tim Newsome <tim@sifive.com> | 2016-03-19 13:33:58 -0700 |
---|---|---|
committer | Tim Newsome <tim@sifive.com> | 2016-05-23 12:12:10 -0700 |
commit | d1d8863086c57f04236418f21ef8a7fbfc184b0b (patch) | |
tree | 30aaae62cff08366500bd3e29166dd2d8b07a473 /tests | |
parent | c57bdaa03373688f76703d20d6df5e0dc4a21eb5 (diff) | |
download | spike-d1d8863086c57f04236418f21ef8a7fbfc184b0b.zip spike-d1d8863086c57f04236418f21ef8a7fbfc184b0b.tar.gz spike-d1d8863086c57f04236418f21ef8a7fbfc184b0b.tar.bz2 |
Add --gdb-port
It's necessary to be able to run multiple spikes at once on the same
box.
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/gdbserver.py | 8 | ||||
-rw-r--r-- | tests/testlib.py | 16 |
2 files changed, 18 insertions, 6 deletions
diff --git a/tests/gdbserver.py b/tests/gdbserver.py index b5363e6..90ebbe9 100755 --- a/tests/gdbserver.py +++ b/tests/gdbserver.py @@ -9,10 +9,10 @@ import time class DebugTest(unittest.TestCase): def setUp(self): self.binary = testlib.compile("debug.c") - self.spike = testlib.spike(self.binary, halted=False) + self.spike, self.port = 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") + self.gdb.command("target extended-remote localhost:%d" % self.port) self.gdb.command("p i=0"); def tearDown(self): @@ -68,10 +68,10 @@ class DebugTest(unittest.TestCase): class RegsTest(unittest.TestCase): def setUp(self): self.binary = testlib.compile("regs.s") - self.spike = testlib.spike(self.binary, halted=False) + self.spike, self.port = 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") + self.gdb.command("target extended-remote localhost:%d" % self.port) def tearDown(self): self.spike.kill() diff --git a/tests/testlib.py b/tests/testlib.py index 2590f46..2db2549 100644 --- a/tests/testlib.py +++ b/tests/testlib.py @@ -25,13 +25,25 @@ def compile(src): assert result == 0, "%r failed" % cmd return dst +def unused_port(): + # http://stackoverflow.com/questions/2838244/get-open-tcp-port-in-python/2838309#2838309 + import socket + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.bind(("",0)) + port = s.getsockname()[1] + s.close() + return port + def spike(binary, halted=False): + """Launch spike. Return tuple of its process and the port it's running on.""" cmd = [find_file("spike")] if halted: cmd.append('-H') - cmd += ['pk', binary] + port = unused_port() + cmd += ['--gdb-port', str(port), 'pk', binary] logfile = open("spike.log", "w") - return subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=logfile, stderr=logfile) + return subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=logfile, + stderr=logfile), port class Gdb(object): def __init__(self): |