Fixing an issue that occurs when a qemu-system test fails and the `--pdb` option is specified (#3063)

* fixing the issue that the script does not drop to a pdb shell when a test fails and the pdb option is specified

* allowing to manually connect to gdb

* changed to pdb
revert-3020-kernel-vmmap
jxuanli 6 months ago committed by GitHub
parent dd01498159
commit 74bf01e707
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -58,7 +58,7 @@ if [[ $# -gt 3 ]]; then
help_and_exit help_and_exit
fi fi
USE_PDB=0 PDB=0
TEST_NAME_FILTER="" TEST_NAME_FILTER=""
RUN_CODECOV=0 RUN_CODECOV=0
VERBOSE=0 VERBOSE=0
@ -70,7 +70,7 @@ RUN_IN_NIX=0
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
case $1 in case $1 in
-p | --pdb) -p | --pdb)
USE_PDB=1 PDB=1
echo "Will run tests with Python debugger" echo "Will run tests with Python debugger"
;; ;;
-c | --cov) -c | --cov)
@ -123,7 +123,8 @@ fi
run_gdb() { run_gdb() {
local arch="$1" local arch="$1"
shift local should_drop_to_pdb=$2
shift 2
if [ $RUN_IN_NIX -eq 1 ]; then if [ $RUN_IN_NIX -eq 1 ]; then
gdb_load_pwndbg=() gdb_load_pwndbg=()
@ -143,15 +144,23 @@ run_gdb() {
fi fi
fi fi
$UV_RUN $GDB --silent --nx --nh "${gdb_load_pwndbg[@]}" \ if [ $should_drop_to_pdb -eq 1 ]; then
-ex "set exception-verbose on" "$@" -ex "quit" 2> /dev/null # $GDB --nx --nh "${gdb_load_pwndbg[@]}" \
# -ex "set exception-verbose on" "$@"
echo "Run: "
echo "$GDB --nx --nh ${gdb_load_pwndbg[@]} -ex \"set exception-debugger on\" -ex \"file ${TESTING_KERNEL_IMAGES_DIR}/vmlinux-${kernel_type}-${kernel_version}-${arch}\" -ex \"target remote :${GDB_PORT}\""
read -p "Press enter to continue"
else
$UV_RUN $GDB --silent --nx --nh "${gdb_load_pwndbg[@]}" \
-ex "set exception-verbose on" "$@" -ex "quit" 2> /dev/null
fi
return $? return $?
} }
# 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
gdb_args=(--command ../pytests_collect.py) gdb_args=(--command ../pytests_collect.py)
TESTS_COLLECT_OUTPUT=$(TESTS_PATH="$ROOT_DIR/tests/qemu-tests/tests/system" run_gdb "x86_64" "${gdb_args[@]}") TESTS_COLLECT_OUTPUT=$(TESTS_PATH="$ROOT_DIR/tests/qemu-tests/tests/system" run_gdb "x86_64" 0 "${gdb_args[@]}")
if [ $? -eq 1 ]; then if [ $? -eq 1 ]; then
echo -E "$TESTS_COLLECT_OUTPUT" echo -E "$TESTS_COLLECT_OUTPUT"
@ -172,7 +181,7 @@ init_gdb() {
# using 'rest_init' instead of 'start_kernel' to make sure that kernel # using 'rest_init' instead of 'start_kernel' to make sure that kernel
# initialization has progressed sufficiently for testing purposes # initialization has progressed sufficiently for testing purposes
gdb_args=("${gdb_connect_qemu[@]}" -ex 'break *rest_init' -ex 'continue') gdb_args=("${gdb_connect_qemu[@]}" -ex 'break *rest_init' -ex 'continue')
run_gdb "${arch}" "${gdb_args[@]}" > /dev/null 2>&1 run_gdb "${arch}" 0 "${gdb_args[@]}" > /dev/null 2>&1
} }
run_test() { run_test() {
@ -180,6 +189,7 @@ run_test() {
local kernel_type="$2" local kernel_type="$2"
local kernel_version="$3" local kernel_version="$3"
local arch="$4" local arch="$4"
local should_drop_to_pdb=$5
gdb_connect_qemu=(-ex "file ${TESTING_KERNEL_IMAGES_DIR}/vmlinux-${kernel_type}-${kernel_version}-${arch}" -ex "target remote :${GDB_PORT}") gdb_connect_qemu=(-ex "file ${TESTING_KERNEL_IMAGES_DIR}/vmlinux-${kernel_type}-${kernel_version}-${arch}" -ex "target remote :${GDB_PORT}")
gdb_args=("${gdb_connect_qemu[@]}" --command ../pytests_launcher.py) gdb_args=("${gdb_connect_qemu[@]}" --command ../pytests_launcher.py)
@ -190,13 +200,13 @@ run_test() {
SRC_DIR=$ROOT_DIR \ SRC_DIR=$ROOT_DIR \
COVERAGE_FILE=$ROOT_DIR/.cov/coverage \ COVERAGE_FILE=$ROOT_DIR/.cov/coverage \
COVERAGE_PROCESS_START=$COVERAGERC_PATH \ COVERAGE_PROCESS_START=$COVERAGERC_PATH \
USE_PDB="${USE_PDB}" \ USE_PDB="$should_drop_to_pdb" \
PWNDBG_LAUNCH_TEST="qemu-tests/${test_case}" \ PWNDBG_LAUNCH_TEST="qemu-tests/${test_case}" \
PWNDBG_DISABLE_COLORS=1 \ PWNDBG_DISABLE_COLORS=1 \
PWNDBG_ARCH="${arch}" \ PWNDBG_ARCH="${arch}" \
PWNDBG_KERNEL_TYPE="${kernel_type}" \ PWNDBG_KERNEL_TYPE="${kernel_type}" \
PWNDBG_KERNEL_VERSION="${kernel_version}" \ PWNDBG_KERNEL_VERSION="${kernel_version}" \
run_gdb "${arch}" "${gdb_args[@]}" run_gdb "${arch}" $should_drop_to_pdb "${gdb_args[@]}"
return $? return $?
} }
@ -216,16 +226,19 @@ process_output() {
printf '%-70s %s\n' $testname $result printf '%-70s %s\n' $testname $result
if [[ "$result" =~ FAIL ]]; then
FAILED_TESTS+=("$testname")
fi
# Only show the output of failed tests unless the verbose flag was used # Only show the output of failed tests unless the verbose flag was used
if [[ $VERBOSE -eq 1 || "$result" =~ FAIL ]]; then if [[ $VERBOSE -eq 1 || "$result" =~ FAIL ]]; then
echo "" echo ""
echo "$output" echo "$output"
echo "" echo ""
fi fi
if [[ "$result" =~ FAIL ]]; then
FAILED_TESTS+=("$testname")
return 1
fi
return 0
} }
test_system() { test_system() {
@ -251,8 +264,11 @@ test_system() {
start=$(date +%s) start=$(date +%s)
for t in "${TESTS_LIST[@]}"; do for t in "${TESTS_LIST[@]}"; do
output=$(run_test "$t" "${kernel_type}" "${kernel_version}" "${arch}") output=$(run_test "$t" "${kernel_type}" "${kernel_version}" "${arch}" 0)
process_output "$output" process_output "$output"
if [ $? -eq 1 ] && [ $PDB -eq 1 ]; then
run_test "$t" "${kernel_type}" "${kernel_version}" "${arch}" 1
fi
done done
end=$(date +%s) end=$(date +%s)

Loading…
Cancel
Save