diff options
author | Tim Newsome <tim@sifive.com> | 2023-05-25 10:05:41 -0700 |
---|---|---|
committer | Tim Newsome <tim@sifive.com> | 2023-05-25 10:05:41 -0700 |
commit | af242299624f602d380985d9850cf7d433e11840 (patch) | |
tree | f4d4d3c88549ea96daa812799f67824476a46afd /debug | |
parent | 557762fc480fdbd2bc06a0b045cf0d6e12dbdfd4 (diff) | |
download | riscv-tests-af242299624f602d380985d9850cf7d433e11840.zip riscv-tests-af242299624f602d380985d9850cf7d433e11840.tar.gz riscv-tests-af242299624f602d380985d9850cf7d433e11840.tar.bz2 |
debug: New pylint => new warnings => new cleanups
- Replace general "Exception" with "GdbServerError" in gdbserver.py for when no
samples are collected
- Replace general "Exception" with "TargetsException" in targets.py for XLEN
mismatch
- Introduce "TestLibError" exception in testlib.py and replace general
exceptions in various locations
- Update pylint.rc to remove overgeneral-exceptions warning
Diffstat (limited to 'debug')
-rwxr-xr-x | debug/gdbserver.py | 29 | ||||
-rw-r--r-- | debug/pylint.rc | 2 | ||||
-rw-r--r-- | debug/targets.py | 5 | ||||
-rw-r--r-- | debug/testlib.py | 22 |
4 files changed, 34 insertions, 24 deletions
diff --git a/debug/gdbserver.py b/debug/gdbserver.py index 3706868..0faebd9 100755 --- a/debug/gdbserver.py +++ b/debug/gdbserver.py @@ -634,18 +634,18 @@ def MCONTROL_DMODE(xlen): def MCONTROL_MASKMAX(xlen): return 0x3<<((xlen)-11) -MCONTROL_SELECT = (1<<19) -MCONTROL_TIMING = (1<<18) -MCONTROL_ACTION = (0x3f<<12) -MCONTROL_CHAIN = (1<<11) -MCONTROL_MATCH = (0xf<<7) -MCONTROL_M = (1<<6) -MCONTROL_H = (1<<5) -MCONTROL_S = (1<<4) -MCONTROL_U = (1<<3) -MCONTROL_EXECUTE = (1<<2) -MCONTROL_STORE = (1<<1) -MCONTROL_LOAD = (1<<0) +MCONTROL_SELECT = 1<<19 +MCONTROL_TIMING = 1<<18 +MCONTROL_ACTION = 0x3f<<12 +MCONTROL_CHAIN = 1<<11 +MCONTROL_MATCH = 0xf<<7 +MCONTROL_M = 1<<6 +MCONTROL_H = 1<<5 +MCONTROL_S = 1<<4 +MCONTROL_U = 1<<3 +MCONTROL_EXECUTE = 1<<2 +MCONTROL_STORE = 1<<1 +MCONTROL_LOAD = 1<<0 MCONTROL_TYPE_NONE = 0 MCONTROL_TYPE_MATCH = 2 @@ -801,6 +801,9 @@ class UserInterrupt(DebugTest): self.gdb.p("i=0") self.exit() +class GdbServerError(Exception): + pass + class MemorySampleTest(DebugTest): def early_applicable(self): return self.target.support_memory_sampling @@ -842,7 +845,7 @@ class MemorySampleTest(DebugTest): samples_per_second = 1000 * end[1] / (end[0] - first_timestamp) print(f"{samples_per_second} samples/second") else: - raise Exception("No samples collected.") + raise GdbServerError("No samples collected.") @staticmethod def check_samples_equal(raw_samples, check_addr, check_value): diff --git a/debug/pylint.rc b/debug/pylint.rc index 49e5af1..79e1d27 100644 --- a/debug/pylint.rc +++ b/debug/pylint.rc @@ -286,4 +286,4 @@ max-public-methods=20 # Exceptions that will emit a warning when being caught. Defaults to # "Exception" -overgeneral-exceptions=Exception +#overgeneral-exceptions=Exception diff --git a/debug/targets.py b/debug/targets.py index ddd39d5..0ba12db 100644 --- a/debug/targets.py +++ b/debug/targets.py @@ -256,6 +256,9 @@ def add_target_options(parser): "the same time. This may make it harder to debug a failure if it " "does occur.") +class TargetsException(Exception): + pass + def target(parsed): directory = os.path.dirname(parsed.target) filename = os.path.basename(parsed.target) @@ -278,7 +281,7 @@ def target(parsed): if h.xlen == 0: h.xlen = parsed.xlen elif h.xlen != parsed.xlen: - raise Exception("The target hart specified an XLEN of " + raise TargetsException("The target hart specified an XLEN of " f"{h.xlen}, but the command line specified an XLEN of " f"{parsed.xlen}. They must match.") diff --git a/debug/testlib.py b/debug/testlib.py index 5137096..26eac60 100644 --- a/debug/testlib.py +++ b/debug/testlib.py @@ -18,6 +18,9 @@ real_stdout = sys.stdout # Note that gdb comes with its own testsuite. I was unable to figure out how to # run that testsuite against the spike simulator. +class TestLibError(Exception): + pass + def find_file(path): for directory in (os.getcwd(), os.path.dirname(__file__)): fullpath = os.path.join(directory, path) @@ -113,7 +116,7 @@ class Spike: time.sleep(0.11) if not self.port: print_log(logname) - raise Exception("Didn't get spike message about bitbang " + raise TestLibError("Didn't get spike message about bitbang " "connection") # pylint: disable=too-many-branches @@ -220,8 +223,9 @@ class MultiSpike: time.sleep(0.11) if not self.port: print_log(self.lognames[-1]) - raise Exception("Didn't get daisy chain message about which port " - "it's listening on.") + raise TestLibError( + "Didn't get daisy chain message about which port " + "it's listening on.") os.environ['REMOTE_BITBANG_HOST'] = 'localhost' os.environ['REMOTE_BITBANG_PORT'] = str(self.port) @@ -281,7 +285,7 @@ class VcsSim: os.environ['JTAG_VPI_PORT'] = str(self.port) if (time.time() - start) > timeout: - raise Exception( + raise TestLibError( "Timed out waiting for VCS to listen for JTAG vpi") def __del__(self): @@ -382,7 +386,7 @@ class Openocd: line = fd.readline() if not line: if not process.poll() is None: - raise Exception("OpenOCD exited early.") + raise TestLibError("OpenOCD exited early.") time.sleep(0.1) continue @@ -398,7 +402,7 @@ class Openocd: messaged = True print("Waiting for OpenOCD to start...") if (time.time() - start) > self.timeout: - raise Exception("Timed out waiting for OpenOCD to " + raise TestLibError("Timed out waiting for OpenOCD to " "listen for gdb") if self.debug_openocd: @@ -533,7 +537,7 @@ def tokenize(text): yield token break else: - raise Exception(repr(text[index:])) + raise TestLibError(repr(text[index:])) def parse_dict(tokens): assert tokens[0] == "{" @@ -579,13 +583,13 @@ def parse_tokens(tokens): return parse_dict_or_list(tokens) if isinstance(tokens[0], str): return tokens.pop(0) - raise Exception(f"Unsupported tokens: {tokens!r}") + raise TestLibError(f"Unsupported tokens: {tokens!r}") def parse_rhs(text): tokens = list(tokenize(text)) result = parse_tokens(tokens) if tokens: - raise Exception(f"Unexpected input: {tokens!r}") + raise TestLibError(f"Unexpected input: {tokens!r}") return result class Gdb: |