tests.sh: add [filter] and --pdb (#1092)

pull/1095/head
Disconnect3d 3 years ago committed by GitHub
parent c0b3f88f53
commit 890e314f2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,9 +1,10 @@
import os
import pytest
import sys
print(sys.argv)
use_pdb = os.environ.get('USE_PDB') == '1'
sys._pwndbg_unittest_run = True
CURRENT_DIR = os.path.dirname(os.path.realpath(__file__))
@ -12,9 +13,11 @@ test = os.environ['PWNDBG_LAUNCH_TEST']
test = os.path.join(CURRENT_DIR, test)
# If you want to debug tests locally, add '--pdb' here
args = [test, '-vvv', '-s', '--showlocals', '--color=yes']
if use_pdb:
args.append('--pdb')
print('Launching pytest with args: %s' % args)
return_code = pytest.main(args)

@ -1,5 +1,37 @@
#!/bin/bash
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
;;
*)
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
@ -22,13 +54,13 @@ if [ $? -eq 1 ]; then
exit 1;
fi
TESTS_LIST=$(echo -E "$TESTS_COLLECT_OUTPUT" | grep -o "tests/.*::.*")
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
COVERAGE_PROCESS_START=.coveragerc 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
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=$?
if [ ${exit_status} -eq 0 ]; then

Loading…
Cancel
Save