Fix archlinux ci tests (#1411)

* Fix Arch CI: install missing netcat (#1400)

The arch linux test_command_procinfo was failing bcoz the netcat was not
installed on arch build. This commit fixes it by:
1) installing gnu-netcat for arch linux setup-dev.sh
2) asserting that nc is available in the test itself, to prevent similar
   regressions from happening on future/newer images

* Fix Arch CI: the load binary tests (#1400)

Before this commit we asserted whether the loaded binary in tests report
to find or not find debug symbols but this is irrelevant for the thing
we want to test there which is: pwndbg loading. What eventually cares is
whether Pwndbg got loaded and didn't raise an exception.

This commit fixes those tests so they should now work also on ArchLinux
CI and on all CI builds.

Additionally, it removes the `compile_binary` test utility function
which was redundant as we compile all test binaries via a makefile.

* fix lint

* cleanup tests/binaries/div_zero_binary
pull/1413/head
Disconnect3d 3 years ago committed by GitHub
parent 1c609eba15
commit f78e3250c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -129,7 +129,8 @@ EOF
curl \
base-devel \
gdb \
parallel
parallel \
gnu-netcat
test -f /usr/bin/go || sudo pacman -S --noconfirm go

@ -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
;;

@ -1,7 +1,5 @@
import os
from . import div_zero_binary
path = os.path.dirname(__file__)

@ -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

@ -1,7 +0,0 @@
import os
path = os.path.dirname(__file__)
def get(x):
return os.path.join(path, x)

@ -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")

@ -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)

@ -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])

Loading…
Cancel
Save