From 7e7c47f20992495a051d1e57859fff08a95dd476 Mon Sep 17 00:00:00 2001 From: patryk4815 Date: Mon, 21 Jul 2025 22:30:55 +0900 Subject: [PATCH] fix relative imports in tests (#3163) * fix relative imports --- .dockerignore | 14 +++++++------- tests/host/gdb/__init__.py | 2 +- tests/library/qemu_system/system-tests.sh | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.dockerignore b/.dockerignore index a65331d91..8c490aa7e 100644 --- a/.dockerignore +++ b/.dockerignore @@ -5,12 +5,12 @@ # E.g. the binary could reference source code on the host system # this is a problem because inside docker we won't have access to # the host system -tests/**/binaries/*.o -tests/**/binaries/*.out -tests/**/binaries/gosample.x* -tests/**/binaries/div_zero_binary/core -tests/**/binaries/div_zero_binary/binary -!tests/**/binaries/*.go +tests/binaries/**/*.o +tests/binaries/**/*.out +tests/binaries/**/gosample.x* +tests/binaries/**/div_zero_binary/core +tests/binaries/**/div_zero_binary/binary +!tests/binaries/**/*.go # ignore QEMU test images (could also be tainted) -tests/library/qemu-*/kimages +tests/library/qemu_system/kimages diff --git a/tests/host/gdb/__init__.py b/tests/host/gdb/__init__.py index ecda177e8..19fdf251c 100644 --- a/tests/host/gdb/__init__.py +++ b/tests/host/gdb/__init__.py @@ -36,7 +36,7 @@ class GDBTestHost(TestHost): env = os.environ if env is None else env # Prepare the GDB command line. - gdb_args = ["-ex", f"py import sys,os; sys.path.append(os.getcwd()); import {target}"] + gdb_args = ["-ex", f"py import sys,os; sys.path.insert(0, os.getcwd()); import {target}"] return subprocess.run( [str(self._gdb_path), "--silent", "--nx"] diff --git a/tests/library/qemu_system/system-tests.sh b/tests/library/qemu_system/system-tests.sh index 58667ff47..97904fa27 100755 --- a/tests/library/qemu_system/system-tests.sh +++ b/tests/library/qemu_system/system-tests.sh @@ -146,15 +146,15 @@ run_gdb() { echo "$GDB --nx ${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_TEST $GDB --silent --nx "${gdb_load_pwndbg[@]}" \ - -ex "set exception-verbose on" "$@" -ex "quit" 2> /dev/null + (cd $PWNDBG_ABS_PATH && $UV_RUN_TEST $GDB --silent --nx "${gdb_load_pwndbg[@]}" \ + -ex "set exception-verbose on" "$@" -ex "quit" 2> /dev/null) fi return $? } # 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=("-ex" "py import sys,os; sys.path.append(os.getcwd()); import tests.host.gdb.pytests_collect") +gdb_args=("-ex" "py import sys,os; sys.path.insert(0, os.getcwd()); import tests.host.gdb.pytests_collect") TESTS_COLLECT_OUTPUT=$(TESTS_PATH="$ROOT_DIR/tests/library/qemu_system/tests/" run_gdb "x86_64" 0 "${gdb_args[@]}") if [ $? -eq 1 ]; then @@ -187,7 +187,7 @@ run_test() { 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_args=("${gdb_connect_qemu[@]}" "-ex" "py import sys,os; sys.path.append(os.getcwd()); import tests.host.gdb.pytests_launcher") + gdb_args=("${gdb_connect_qemu[@]}" "-ex" "py import sys,os; sys.path.insert(0, os.getcwd()); import tests.host.gdb.pytests_launcher") if [ ${RUN_CODECOV} -ne 0 ]; then gdb_args=(-ex 'py import coverage;coverage.process_startup()' "${gdb_args[@]}") fi