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
*.so
!tests/binaries/glibcs/**/*.so
!tests/**/binaries/glibcs/**/*.so
# Distribution / packaging
.Python
@ -66,12 +66,11 @@ venv/
# PyTest files
.pytest_cache/
tests/.pytest_cache/
tests/binaries/*.o
tests/binaries/*.out
tests/binaries/gosample.x*
/tests/binaries/div_zero_binary/core
/tests/binaries/div_zero_binary/binary
tests/**/binaries/*.o
tests/**/binaries/*.out
tests/**/binaries/gosample.x*
tests/**/binaries/div_zero_binary/core
tests/**/binaries/div_zero_binary/binary
# VS Code files
.vscode/

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

@ -1,41 +1,44 @@
#!/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 " -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;
exit 1
}
if [[ $# -gt 2 ]]; then
help_and_exit
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
;;
*)
if [[ ! -z "${TEST_NAME_FILTER}" ]]; then
help_and_exit
fi
TEST_NAME_FILTER="$1"
shift
;;
esac
case $1 in
-p|--pdb)
USE_PDB=1
echo "Will run tests with Python debugger"
shift
;;
*)
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="$(pwd)/.zig"
export ZIGPATH="$ROOT_DIR/.zig"
fi
echo "ZIGPATH set to $ZIGPATH"
@ -44,14 +47,18 @@ 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
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
echo -E "$TESTS_COLLECT_OUTPUT";
exit 1;
echo -E "$TESTS_COLLECT_OUTPUT"
exit 1
fi
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
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
exit_status=$?
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

@ -93,7 +93,7 @@ heap_bugs.out: heap_bugs.c
# https://sourceware.org/bugzilla/show_bug.cgi?id=24548
heap_vis.out: heap_vis.c
@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 :
@echo "[+] Cleaning stuff"

@ -17,7 +17,9 @@ if os.getuid() == 0:
else:
# see `man ptrace`
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'

Loading…
Cancel
Save