Minor test cleanup (#1099)

* Silence nonnull warning when building heap_vis.c

* Fix checking ptrace_scope in test_attachp.py

* Fix .gitignore

* tests.sh cleanup

* Fixed coverage generation
pull/1100/head
Gulshan Singh 3 years ago committed by GitHub
parent 5d358585b1
commit 7c53bdeaa8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

13
.gitignore vendored

@ -4,7 +4,7 @@ __pycache__/
# C extensions # C extensions
*.so *.so
!tests/binaries/glibcs/**/*.so !tests/**/binaries/glibcs/**/*.so
# Distribution / packaging # Distribution / packaging
.Python .Python
@ -66,12 +66,11 @@ venv/
# PyTest files # PyTest files
.pytest_cache/ .pytest_cache/
tests/.pytest_cache/ tests/**/binaries/*.o
tests/binaries/*.o tests/**/binaries/*.out
tests/binaries/*.out tests/**/binaries/gosample.x*
tests/binaries/gosample.x* tests/**/binaries/div_zero_binary/core
/tests/binaries/div_zero_binary/core tests/**/binaries/div_zero_binary/binary
/tests/binaries/div_zero_binary/binary
# VS Code files # VS Code files
.vscode/ .vscode/

@ -1,7 +1,6 @@
import os import os
import pytest import pytest
import sys import sys
print(sys.argv)
use_pdb = os.environ.get('USE_PDB') == '1' use_pdb = os.environ.get('USE_PDB') == '1'

@ -1,10 +1,13 @@
#!/bin/bash #!/bin/bash
ROOT_DIR="$(pwd)"
GDB_INIT_PATH="$ROOT_DIR/gdbinit.py"
help_and_exit() { help_and_exit() {
echo "Usage: ./tests.sh [-p|--pdb] [<test-name-filter>]" echo "Usage: ./tests.sh [-p|--pdb] [<test-name-filter>]"
echo " -p, --pdb enable pdb (Python debugger) post mortem debugger on failed tests" echo " -p, --pdb enable pdb (Python debugger) post mortem debugger on failed tests"
echo " <test-name-filter> run only tests that match the regex" echo " <test-name-filter> run only tests that match the regex"
exit 1; exit 1
} }
if [[ $# -gt 2 ]]; then if [[ $# -gt 2 ]]; then
@ -35,7 +38,7 @@ done
if [[ -z "$ZIGPATH" ]]; then if [[ -z "$ZIGPATH" ]]; then
# If ZIGPATH is not set, set it to $pwd/.zig # If ZIGPATH is not set, set it to $pwd/.zig
# In Docker environment this should by default be set to /opt/zig # In Docker environment this should by default be set to /opt/zig
export ZIGPATH="$(pwd)/.zig" export ZIGPATH="$ROOT_DIR/.zig"
fi fi
echo "ZIGPATH set to $ZIGPATH" echo "ZIGPATH set to $ZIGPATH"
@ -44,14 +47,18 @@ cd ./tests/binaries || exit 1
make clean && make all || exit 2 make clean && make all || exit 2
cd ../../ 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 # 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 # we decided to run each test in a separate GDB session
TESTS_COLLECT_OUTPUT=$(gdb --silent --nx --nh --command gdbinit.py --command pytests_collect.py --eval-command quit) gdb_args=(--command $GDB_INIT_PATH --command pytests_collect.py)
TESTS_COLLECT_OUTPUT=$(run_gdb "${gdb_args[@]}")
if [ $? -eq 1 ]; then if [ $? -eq 1 ]; then
echo -E "$TESTS_COLLECT_OUTPUT"; echo -E "$TESTS_COLLECT_OUTPUT"
exit 1; exit 1
fi 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}")
@ -60,9 +67,14 @@ tests_passed_or_skipped=0
tests_failed=0 tests_failed=0
for test_case in ${TESTS_LIST}; do for test_case in ${TESTS_LIST}; do
COVERAGE_PROCESS_START=.coveragerc USE_PDB="${USE_PDB}" PWNDBG_LAUNCH_TEST="${test_case}" PWNDBG_DISABLE_COLORS=1 gdb --silent --nx --nh -ex 'py import coverage;coverage.process_startup()' --command gdbinit.py --command pytests_launcher.py --eval-command quit gdb_args=(-ex 'py import coverage;coverage.process_startup()' --command $GDB_INIT_PATH --command pytests_launcher.py)
exit_status=$? 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 if [ ${exit_status} -eq 0 ]; then
(( ++tests_passed_or_skipped )) (( ++tests_passed_or_skipped ))
else else

@ -93,7 +93,7 @@ heap_bugs.out: heap_bugs.c
# https://sourceware.org/bugzilla/show_bug.cgi?id=24548 # https://sourceware.org/bugzilla/show_bug.cgi?id=24548
heap_vis.out: heap_vis.c heap_vis.out: heap_vis.c
@echo "[+] Building heap_vis.out" @echo "[+] Building heap_vis.out"
${CC} -g -O0 -o heap_vis.out heap_vis.c -pthread -lpthread ${CC} -g -O0 -Wno-nonnull -o heap_vis.out heap_vis.c -pthread -lpthread
clean : clean :
@echo "[+] Cleaning stuff" @echo "[+] Cleaning stuff"

@ -17,7 +17,9 @@ if os.getuid() == 0:
else: else:
# see `man ptrace` # see `man ptrace`
with open('/proc/sys/kernel/yama/ptrace_scope') as f: with open('/proc/sys/kernel/yama/ptrace_scope') as f:
can_attach = f.read() == '0' result = f.read()
if len(result) >= 1 and result[0] == '0':
can_attach = True
REASON_CANNOT_ATTACH = 'Test skipped due to inability to attach (needs sudo or sysctl -w kernel.yama.ptrace_scope=0' REASON_CANNOT_ATTACH = 'Test skipped due to inability to attach (needs sudo or sysctl -w kernel.yama.ptrace_scope=0'

Loading…
Cancel
Save