Move tests/ to tests/gdb-tests/

pull/1294/head
Gulshan Singh 3 years ago
parent 295fe29b22
commit e63d289b95

1
.gitignore vendored

@ -73,6 +73,7 @@ tests/**/binaries/*.out
tests/**/binaries/gosample.x*
tests/**/binaries/div_zero_binary/core
tests/**/binaries/div_zero_binary/binary
!tests/**/binaries/*.go
# VS Code files
.vscode/

@ -1,95 +1,4 @@
#!/bin/bash
ROOT_DIR="$(pwd)"
GDB_INIT_PATH="$ROOT_DIR/gdbinit.py"
help_and_exit() {
echo "Usage: ./tests.sh [-p|--pdb] [<test-name-filter>]"
echo " -p, --pdb enable pdb (Python debugger) post mortem debugger on failed tests"
echo " <test-name-filter> run only tests that match the regex"
exit 1
}
if [[ $# -gt 2 ]]; then
help_and_exit
fi
USE_PDB=0
TEST_NAME_FILTER=""
while [[ $# -gt 0 ]]; do
case $1 in
-p | --pdb)
USE_PDB=1
echo "Will run tests with Python debugger"
shift
;;
-h | --help)
help_and_exit
;;
*)
if [[ ! -z "${TEST_NAME_FILTER}" ]]; then
help_and_exit
fi
TEST_NAME_FILTER="$1"
shift
;;
esac
done
if [[ -z "$ZIGPATH" ]]; then
# If ZIGPATH is not set, set it to $pwd/.zig
# In Docker environment this should by default be set to /opt/zig
export ZIGPATH="$ROOT_DIR/.zig"
fi
echo "ZIGPATH set to $ZIGPATH"
cd ./tests/binaries || exit 1
make clean && make all || exit 2
cd ../../
run_gdb() {
gdb --silent --nx --nh "$@" --eval-command quit
}
# NOTE: We run tests under GDB sessions and because of some cleanup/tests dependencies problems
# we decided to run each test in a separate GDB session
gdb_args=(--command $GDB_INIT_PATH --command pytests_collect.py)
TESTS_COLLECT_OUTPUT=$(run_gdb "${gdb_args[@]}")
if [ $? -eq 1 ]; then
echo -E "$TESTS_COLLECT_OUTPUT"
exit 1
fi
TESTS_LIST=$(echo -E "$TESTS_COLLECT_OUTPUT" | grep -o "tests/.*::.*" | grep "${TEST_NAME_FILTER}")
tests_passed_or_skipped=0
tests_failed=0
for test_case in ${TESTS_LIST}; do
gdb_args=(-ex 'py import coverage;coverage.process_startup()' --command $GDB_INIT_PATH --command pytests_launcher.py)
COVERAGE_PROCESS_START=.coveragerc \
USE_PDB="${USE_PDB}" \
PWNDBG_LAUNCH_TEST="${test_case}" \
PWNDBG_DISABLE_COLORS=1 \
run_gdb "${gdb_args[@]}"
exit_status=$?
if [ ${exit_status} -eq 0 ]; then
((++tests_passed_or_skipped))
else
((++tests_failed))
fi
done
echo ""
echo "*********************************"
echo "********* TESTS SUMMARY *********"
echo "*********************************"
echo "Tests passed or skipped: ${tests_passed_or_skipped}"
echo "Tests failed: ${tests_failed}"
if [ "${tests_failed}" -ne 0 ]; then
exit 1
fi
cd tests/gdb-tests
./tests.sh $@

@ -0,0 +1,94 @@
#!/bin/bash
ROOT_DIR="$(readlink -f ../../)"
GDB_INIT_PATH="$ROOT_DIR/gdbinit.py"
COVERAGERC_PATH="$ROOT_DIR/.coveragerc"
help_and_exit() {
echo "Usage: ./tests.sh [-p|--pdb] [<test-name-filter>]"
echo " -p, --pdb enable pdb (Python debugger) post mortem debugger on failed tests"
echo " <test-name-filter> run only tests that match the regex"
exit 1
}
if [[ $# -gt 2 ]]; then
help_and_exit
fi
USE_PDB=0
TEST_NAME_FILTER=""
while [[ $# -gt 0 ]]; do
case $1 in
-p | --pdb)
USE_PDB=1
echo "Will run tests with Python debugger"
shift
;;
-h | --help)
help_and_exit
;;
*)
if [[ ! -z "${TEST_NAME_FILTER}" ]]; then
help_and_exit
fi
TEST_NAME_FILTER="$1"
shift
;;
esac
done
if [[ -z "$ZIGPATH" ]]; then
# If ZIGPATH is not set, set it to $pwd/.zig
# In Docker environment this should by default be set to /opt/zig
export ZIGPATH="$ROOT_DIR/.zig"
fi
echo "ZIGPATH set to $ZIGPATH"
(cd ./tests/binaries && make clean && make all) || exit 1
run_gdb() {
gdb --silent --nx --nh "$@" --eval-command quit
}
# NOTE: We run tests under GDB sessions and because of some cleanup/tests dependencies problems
# we decided to run each test in a separate GDB session
gdb_args=(--command $GDB_INIT_PATH --command pytests_collect.py)
TESTS_COLLECT_OUTPUT=$(run_gdb "${gdb_args[@]}")
if [ $? -eq 1 ]; then
echo -E "$TESTS_COLLECT_OUTPUT"
exit 1
fi
TESTS_LIST=$(echo -E "$TESTS_COLLECT_OUTPUT" | grep -o "tests/.*::.*" | grep "${TEST_NAME_FILTER}")
tests_passed_or_skipped=0
tests_failed=0
for test_case in ${TESTS_LIST}; do
gdb_args=(-ex 'py import coverage;coverage.process_startup()' --command $GDB_INIT_PATH --command pytests_launcher.py)
COVERAGE_PROCESS_START=$COVERAGERC_PATH \
USE_PDB="${USE_PDB}" \
PWNDBG_LAUNCH_TEST="${test_case}" \
PWNDBG_DISABLE_COLORS=1 \
run_gdb "${gdb_args[@]}"
exit_status=$?
if [ ${exit_status} -eq 0 ]; then
((++tests_passed_or_skipped))
else
((++tests_failed))
fi
done
echo ""
echo "*********************************"
echo "********* TESTS SUMMARY *********"
echo "*********************************"
echo "Tests passed or skipped: ${tests_passed_or_skipped}"
echo "Tests failed: ${tests_failed}"
if [ "${tests_failed}" -ne 0 ]; then
exit 1
fi

@ -15,7 +15,7 @@ def get_proc_maps():
Mapped address spaces:
Start Addr End Addr Size Offset objfile
0x400000 0x401000 0x1000 0x0 /opt/pwndbg/tests/binaries/crash_simple.out
0x400000 0x401000 0x1000 0x0 /opt/pwndbg/tests/gdb-tests/tests/binaries/crash_simple.out
0x7ffff7ffa000 0x7ffff7ffd000 0x3000 0x0 [vvar]
0x7ffff7ffd000 0x7ffff7fff000 0x2000 0x0 [vdso]
0x7ffffffde000 0x7ffffffff000 0x21000 0x0 [stack]
@ -42,7 +42,7 @@ def test_command_vmmap_on_coredump_on_crash_simple_binary(start_binary):
"""
Example vmmap when debugging binary:
LEGEND: STACK | HEAP | CODE | DATA | RWX | RODATA
0x400000 0x401000 r-xp 1000 0 /opt/pwndbg/tests/binaries/crash_simple.out
0x400000 0x401000 r-xp 1000 0 /opt/pwndbg/tests/gdb-tests/tests/binaries/crash_simple.out
0x7ffff7ffa000 0x7ffff7ffd000 r--p 3000 0 [vvar]
0x7ffff7ffd000 0x7ffff7fff000 r-xp 2000 0 [vdso]
0x7ffffffde000 0x7ffffffff000 rwxp 21000 0 [stack]
@ -50,7 +50,7 @@ def test_command_vmmap_on_coredump_on_crash_simple_binary(start_binary):
The same vmmap when debugging coredump:
LEGEND: STACK | HEAP | CODE | DATA | RWX | RODATA
0x400000 0x401000 r-xp 1000 0 /opt/pwndbg/tests/binaries/crash_simple.out
0x400000 0x401000 r-xp 1000 0 /opt/pwndbg/tests/gdb-tests/tests/binaries/crash_simple.out
0x7ffff7ffd000 0x7ffff7fff000 r-xp 2000 1158 load2
0x7ffffffde000 0x7ffffffff000 rwxp 21000 3158 [stack]
0xffffffffff600000 0xffffffffff601000 r-xp 1000 24158 [vsyscall]

@ -54,7 +54,9 @@ def test_context_disasm_show_fd_filepath(start_binary):
line_call_read, line_fd, line_buf, line_nbytes, *_rest = lines_after_call_read
line_fd = line_fd.strip()
assert re.match(r"fd:\s+0x3 \([a-z/]*pwndbg/tests/binaries/use-fds.out\)", line_fd)
assert re.match(
r"fd:\s+0x3 \([a-z/]*pwndbg/tests/gdb-tests/tests/binaries/use-fds.out\)", line_fd
)
line_buf = line_buf.strip()
assert re.match(r"buf:\s+0x[0-9a-f]+ ◂— 0x0", line_buf)

@ -19,7 +19,7 @@ def run_gdb_with_script(binary="", core="", pybefore=None, pyafter=None, timeout
for cmd in pybefore:
command += ["--eval-command", cmd]
command += ["--command", "gdbinit.py"]
command += ["--command", "../../gdbinit.py"]
if binary:
command += [binary]
Loading…
Cancel
Save