diff --git a/setup-dev.sh b/setup-dev.sh index e1ba1dd85..d68b037ca 100755 --- a/setup-dev.sh +++ b/setup-dev.sh @@ -129,7 +129,8 @@ EOF curl \ base-devel \ gdb \ - parallel + parallel \ + gnu-netcat test -f /usr/bin/go || sudo pacman -S --noconfirm go diff --git a/tests/gdb-tests/tests.sh b/tests/gdb-tests/tests.sh index b07f27fd8..2b506aca4 100755 --- a/tests/gdb-tests/tests.sh +++ b/tests/gdb-tests/tests.sh @@ -32,7 +32,7 @@ while [[ $# -gt 0 ]]; do case $1 in -p | --pdb) USE_PDB=1 - SERIAL=1 + SERIAL=1 echo "Will run tests in serial and with Python debugger" shift ;; diff --git a/tests/gdb-tests/tests/binaries/__init__.py b/tests/gdb-tests/tests/binaries/__init__.py index 9a73e3e6f..f61cd10c0 100644 --- a/tests/gdb-tests/tests/binaries/__init__.py +++ b/tests/gdb-tests/tests/binaries/__init__.py @@ -1,7 +1,5 @@ import os -from . import div_zero_binary - path = os.path.dirname(__file__) diff --git a/tests/gdb-tests/tests/binaries/div_zero_binary/binary.c b/tests/gdb-tests/tests/binaries/div_zero.c similarity index 100% rename from tests/gdb-tests/tests/binaries/div_zero_binary/binary.c rename to tests/gdb-tests/tests/binaries/div_zero.c diff --git a/tests/gdb-tests/tests/binaries/div_zero_binary/Makefile b/tests/gdb-tests/tests/binaries/div_zero_binary/Makefile deleted file mode 100644 index f3b10f0c6..000000000 --- a/tests/gdb-tests/tests/binaries/div_zero_binary/Makefile +++ /dev/null @@ -1,6 +0,0 @@ - -all: - gcc binary.c -o binary - -core: - gdb binary --nx --nh -ex run -ex 'generate-core-file core' -ex 'set confirm off' -ex quit diff --git a/tests/gdb-tests/tests/binaries/div_zero_binary/__init__.py b/tests/gdb-tests/tests/binaries/div_zero_binary/__init__.py deleted file mode 100644 index f61cd10c0..000000000 --- a/tests/gdb-tests/tests/binaries/div_zero_binary/__init__.py +++ /dev/null @@ -1,7 +0,0 @@ -import os - -path = os.path.dirname(__file__) - - -def get(x): - return os.path.join(path, x) diff --git a/tests/gdb-tests/tests/test_command_procinfo.py b/tests/gdb-tests/tests/test_command_procinfo.py index 80edaf929..02c61a47e 100644 --- a/tests/gdb-tests/tests/test_command_procinfo.py +++ b/tests/gdb-tests/tests/test_command_procinfo.py @@ -1,4 +1,5 @@ import os +import shutil import gdb @@ -10,6 +11,8 @@ REFERENCE_BINARY_NET = tests.binaries.get("reference-binary-net.out") def test_command_procinfo(start_binary): start_binary(REFERENCE_BINARY_NET) + # Sanity check, netcat must exist at this point + assert shutil.which("nc") is not None os.system("nc -l -p 31337 2>/dev/null 1>&2 &") bin_path = gdb.execute("pi pwndbg.gdblib.proc.exe", to_string=True).strip("\n") diff --git a/tests/gdb-tests/tests/test_loads.py b/tests/gdb-tests/tests/test_loads.py index 980e50880..6cea18c77 100644 --- a/tests/gdb-tests/tests/test_loads.py +++ b/tests/gdb-tests/tests/test_loads.py @@ -3,7 +3,6 @@ import re import tests -from .utils import compile_binary from .utils import run_gdb_with_script HELLO = [ @@ -11,9 +10,8 @@ HELLO = [ "pwndbg: created $rebase, $ida gdb functions (can be used with print/break)", ] -BINARY_SOURCE = tests.binaries.div_zero_binary.get("binary.c") -BINARY = tests.binaries.div_zero_binary.get("binary") -CORE = tests.binaries.div_zero_binary.get("core") +BINARY = tests.binaries.get("div_zero.out") +CORE = "/tmp/pwndbg-tests-div-zero-core" def test_loads_pure_gdb_without_crashing(): @@ -22,21 +20,15 @@ def test_loads_pure_gdb_without_crashing(): def test_loads_binary_without_crashing(): - if not os.path.isfile(BINARY): - compile_binary(BINARY_SOURCE, BINARY) output = run_gdb_with_script(binary=BINARY).splitlines() for h in HELLO: assert h in output assert any("Reading symbols from %s..." % BINARY in line for line in output) - # Old GDB says f"(no debugging symbols found)" - # New GDB says f"(No debugging symbols found in ${BINARY})" - assert any("(no debugging symbols found" in line.lower() for line in output) + assert any("pwndbg: loaded" in line for line in output) def test_loads_binary_with_core_without_crashing(): - if not os.path.isfile(BINARY): - compile_binary(BINARY_SOURCE, BINARY) if not os.path.isfile(CORE): create_coredump = ["run", f"generate-core-file {CORE}"] run_gdb_with_script(binary=BINARY, pyafter=create_coredump) @@ -44,9 +36,7 @@ def test_loads_binary_with_core_without_crashing(): output = run_gdb_with_script(binary=BINARY, core=CORE).splitlines() assert any("Reading symbols from %s..." % BINARY in line for line in output) - # Old GDB says f"(no debugging symbols found)" - # New GDB says f"(No debugging symbols found in ${BINARY})" - assert any("(no debugging symbols found" in line.lower() for line in output) + assert any("pwndbg: loaded" in line for line in output) assert "Program terminated with signal SIGFPE, Arithmetic exception." in output for h in HELLO: assert h in output @@ -57,13 +47,11 @@ def test_loads_binary_with_core_without_crashing(): binary_line = re.compile("^Core was generated by .+$") assert any([binary_line.match(line) for line in output]) - crash_address_line = re.compile(r"^#0 0x[0-9a-fA-F]+ in main \(\)$") + crash_address_line = re.compile(r"^#0 0x[0-9a-fA-F]+ in main .*$") assert any([crash_address_line.match(line) for line in output]) def test_loads_core_without_crashing(): - if not os.path.isfile(BINARY): - compile_binary(BINARY_SOURCE, BINARY) if not os.path.isfile(CORE): create_coredump = ["run", f"generate-core-file {CORE}"] run_gdb_with_script(binary=BINARY, pyafter=create_coredump) diff --git a/tests/gdb-tests/tests/utils.py b/tests/gdb-tests/tests/utils.py index 06d87ad28..412c50ead 100644 --- a/tests/gdb-tests/tests/utils.py +++ b/tests/gdb-tests/tests/utils.py @@ -47,9 +47,3 @@ def run_gdb_with_script(binary="", core="", pybefore=None, pyafter=None, timeout ) return output - - -def compile_binary(binary_source, binary_out): - assert os.path.isfile(binary_source) - - subprocess.check_call(["gcc", binary_source, "-o", binary_out])