From 2d483fcb12c505fb2b954095b410d3294d550ea1 Mon Sep 17 00:00:00 2001 From: Gulshan Singh Date: Thu, 1 Sep 2022 18:35:28 -0700 Subject: [PATCH] Add smoke test (#1113) --- pwndbg/commands/shell.py | 4 +-- tests/conftest.py | 1 + tests/test_commands.py | 55 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 tests/test_commands.py diff --git a/pwndbg/commands/shell.py b/pwndbg/commands/shell.py index 5304a9a1e..36ec1997d 100644 --- a/pwndbg/commands/shell.py +++ b/pwndbg/commands/shell.py @@ -10,7 +10,7 @@ import pwndbg.commands import pwndbg.which pwncmds = ["asm", "constgrep", "cyclic", "disasm", "pwn", "unhex"] -shellcmds = [ +shellcmd_names = [ "awk", "bash", "cat", @@ -63,7 +63,7 @@ shellcmds = [ ] pwncmds = filter(pwndbg.which.which, pwncmds) -shellcmds = filter(pwndbg.which.which, shellcmds) +shellcmds = filter(pwndbg.which.which, shellcmd_names) def register_shell_function(cmd, deprecated=False): diff --git a/tests/conftest.py b/tests/conftest.py index fc83744d3..9f8feb76b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -16,6 +16,7 @@ def start_binary(): def _start_binary(path, *args): gdb.execute("file " + path) + gdb.execute("set exception-verbose on") gdb.execute("starti " + " ".join(args)) global _start_binary_called diff --git a/tests/test_commands.py b/tests/test_commands.py new file mode 100644 index 000000000..684fad292 --- /dev/null +++ b/tests/test_commands.py @@ -0,0 +1,55 @@ +import gdb +import pytest + +import tests +from pwndbg.commands import command_names +from pwndbg.commands import commands +from pwndbg.commands.shell import shellcmd_names + +BINARY = tests.binaries.get("heap_bins.out") + +# TODO: See if we can reduce the number of commands we need to skip +blacklisted_commands = set( + [ + "disasm", + "unhex", + "bugreport", + "try_free", + "errno", + "nextproginstr", + ] +) + +# Don't run any shell commands +blacklisted_commands.update(shellcmd_names) + +# TODO: Figure out why these are being thrown and then remove this +whitelisted_exceptions = [ + "Cannot access memory at address", + "Cannot insert breakpoint", + "Warning:", + "The program is not being run", +] + + +@pytest.mark.skip(reason="flaky test") +def test_commands(start_binary): + for name in command_names: + print("Running command", name) + try: + start_binary(BINARY) + + if name in blacklisted_commands: + continue + + gdb.execute(name) + except gdb.error as e: + ignore = False + for ex in whitelisted_exceptions: + if ex in str(e): + ignore = True + print("Ignoring exception in command", name) + break + + if not ignore: + raise e