diff options
author | Tim Newsome <tim@sifive.com> | 2016-10-19 10:52:59 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-19 10:52:59 -0700 |
commit | 6a64f119fbda35f415d0c8238909aba70acc1654 (patch) | |
tree | 630670b6b48b4963080ba94ad42c969867bb099b /debug/testlib.py | |
parent | 5cd2b39a28c2c77debce4b55c140917c55dc1189 (diff) | |
parent | 2faa3c064a9ac4704976fc06c2ed9c0eda842438 (diff) | |
download | riscv-tests-6a64f119fbda35f415d0c8238909aba70acc1654.zip riscv-tests-6a64f119fbda35f415d0c8238909aba70acc1654.tar.gz riscv-tests-6a64f119fbda35f415d0c8238909aba70acc1654.tar.bz2 |
Merge pull request #34 from richardxia/use-port-randomization
Use port randomization for VCS and OpenOCD
Diffstat (limited to 'debug/testlib.py')
-rw-r--r-- | debug/testlib.py | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/debug/testlib.py b/debug/testlib.py index caf2140..7698980 100644 --- a/debug/testlib.py +++ b/debug/testlib.py @@ -104,8 +104,11 @@ class VcsSim(object): line = listenfile.readline() if not line: time.sleep(1) - if "Listening on port 5555" in line: + match = re.match(r"^Listening on port (\d+)$", line) + if match: done = True + self.port = int(match.group(1)) + print "Using port %d for JTAG VPI" % self.port def __del__(self): try: @@ -126,13 +129,22 @@ class Openocd(object): cmd += ["-f", find_file(config)] if debug: cmd.append("-d") + + # Assign port + self.port = unused_port() + print "Using port %d for gdb server" % self.port + # This command needs to come before any config scripts on the command + # line, since they are executed in order. + cmd[1:1] = ["--command", "gdb_port %d" % self.port] + + env = os.environ.copy() + env['JTAG_VPI_PORT'] = str(otherProcess.port) + logfile = open(Openocd.logname, "w") logfile.write("+ %s\n" % " ".join(cmd)) logfile.flush() self.process = subprocess.Popen(cmd, stdin=subprocess.PIPE, - stdout=logfile, stderr=logfile) - # TODO: Pick a random port - self.port = 3333 + stdout=logfile, stderr=logfile, env=env) # Wait for OpenOCD to have made it through riscv_examine(). When using # OpenOCD to communicate with a simulator this may take a long time, |