diff --git a/setup-dev.sh b/setup-dev.sh index 71ab94d11..fe10d24d4 100755 --- a/setup-dev.sh +++ b/setup-dev.sh @@ -33,7 +33,8 @@ install_apt() { libc6-dev \ curl \ build-essential \ - gdb + gdb \ + parallel if [[ "$1" == "22.04" ]]; then sudo apt install shfmt diff --git a/tests/gdb-tests/tests.sh b/tests/gdb-tests/tests.sh index f7b7b35ce..13110dc71 100755 --- a/tests/gdb-tests/tests.sh +++ b/tests/gdb-tests/tests.sh @@ -68,14 +68,11 @@ if [ $? -eq 1 ]; then exit 1 fi -TESTS_LIST=$(echo -E "$TESTS_COLLECT_OUTPUT" | grep -o "tests/.*::.*" | grep "${TEST_NAME_FILTER}") +TESTS_LIST=($(echo -E "$TESTS_COLLECT_OUTPUT" | grep -o "tests/.*::.*" | grep "${TEST_NAME_FILTER}")) -tests_passed_or_skipped=0 -tests_failed=0 +run_test() { + test_case="$1" -declare -a FAILED_TESTS - -for test_case in ${TESTS_LIST}; do gdb_args=(--command $GDB_INIT_PATH --command pytests_launcher.py) if [ ${RUN_CODECOV} -ne 0 ]; then gdb_args=(-ex 'py import coverage;coverage.process_startup()' "${gdb_args[@]}") @@ -88,23 +85,28 @@ for test_case in ${TESTS_LIST}; do PWNDBG_DISABLE_COLORS=1 \ run_gdb "${gdb_args[@]}" - exit_status=$? - if [ ${exit_status} -eq 0 ]; then - ((++tests_passed_or_skipped)) - else - ((++tests_failed)) - FAILED_TESTS+=(${test_case}) - fi -done + exit $? +} +JOBLOG_PATH="$(mktemp)" +echo "Joblog: $JOBLOG_PATH" + +. $(which env_parallel.bash) +env_parallel --joblog $JOBLOG_PATH run_test ::: "${TESTS_LIST[@]}" + +# The seventh column in the joblog is the exit value and the tenth is the test name +FAILED_TESTS=($(awk '$7 == "1" { print $10 }' "${JOBLOG_PATH}")) + +num_tests_failed=${#FAILED_TESTS[@]} +num_tests_passed_or_skipped=$((${#TESTS_LIST[@]} - $num_tests_failed)) echo "" echo "*********************************" echo "********* TESTS SUMMARY *********" echo "*********************************" -echo "Tests passed or skipped: ${tests_passed_or_skipped}" -echo "Tests failed: ${tests_failed}" +echo "Tests passed or skipped: ${num_tests_passed_or_skipped}" +echo "Tests failed: ${num_tests_failed}" -if [ "${tests_failed}" -ne 0 ]; then +if [ "${num_tests_failed}" -ne 0 ]; then echo "" echo "Failing tests: ${FAILED_TESTS[@]}" exit 1 diff --git a/tests/gdb-tests/tests/test_attachp.py b/tests/gdb-tests/tests/test_attachp.py index f1206135b..f48fc581d 100644 --- a/tests/gdb-tests/tests/test_attachp.py +++ b/tests/gdb-tests/tests/test_attachp.py @@ -1,6 +1,7 @@ import os import re import subprocess +import tempfile import pytest @@ -24,7 +25,7 @@ REASON_CANNOT_ATTACH = ( @pytest.fixture def launched_bash_binary(): - path = "/tmp/pwndbg_test_bash" + path = tempfile.mktemp() subprocess.check_output(["cp", "/bin/bash", path]) process = subprocess.Popen([path], stdout=subprocess.PIPE, stdin=subprocess.PIPE) diff --git a/tests/gdb-tests/tests/test_command_vmmap.py b/tests/gdb-tests/tests/test_command_vmmap.py index f279b2589..df1368e78 100644 --- a/tests/gdb-tests/tests/test_command_vmmap.py +++ b/tests/gdb-tests/tests/test_command_vmmap.py @@ -1,3 +1,5 @@ +import tempfile + import gdb import pwndbg @@ -79,7 +81,7 @@ def test_command_vmmap_on_coredump_on_crash_simple_binary(start_binary): assert vmmaps == expected_maps # Now, generate core file, so we can then test coredump vmmap - core = "/tmp/test_command_vmmap_on_coredump_on_crash_simple_binary" + core = tempfile.mktemp() gdb.execute("generate-core-file %s" % core) #### TEST COREDUMP VMMAP diff --git a/tests/gdb-tests/tests/test_context_commands.py b/tests/gdb-tests/tests/test_context_commands.py index eb4a824bb..33b906ace 100644 --- a/tests/gdb-tests/tests/test_context_commands.py +++ b/tests/gdb-tests/tests/test_context_commands.py @@ -32,8 +32,13 @@ def test_context_disasm_show_fd_filepath(start_binary): assert "call read@plt" in line_call_read + # When running tests with GNU Parallel, sometimes the file name looks + # '/tmp/parZ4YC4.par', and occasionally '(deleted)' is present after the + # filename line_fd = line_fd.strip() - assert re.match(r"fd:\s+0x1 \((/dev/pts/\d+|pipe:\[\d+\])\)", line_fd) + assert re.match( + r"fd:\s+0x1 \((/dev/pts/\d+|/tmp/par.+\.par(?: \(deleted\))?|pipe:\[\d+\])\)", line_fd + ) line_buf = line_buf.strip() assert re.match(r"buf:\s+0x[0-9a-f]+ ◂— 0x0", line_buf)