From a7592b2ca2f9c50c83bc7ee7bfdd1d97ba656430 Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Thu, 25 Apr 2024 03:19:59 +0200 Subject: [PATCH] all: enhance tests --- .github/workflows/ci.yml | 3 +++ CMakeLists.txt | 21 +++++++++++++++- misc/make/Makefile-extra.mk | 1 + misc/testsuite/mimic_ctest.sh | 42 +++++++++++++++++++++++-------- misc/testsuite/test_symlinks.sh | 3 +-- misc/testsuite/upx_testsuite_1.sh | 2 +- src/packer.cpp | 2 -- 7 files changed, 58 insertions(+), 16 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7f9adc34..dd7e3c72 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -162,6 +162,7 @@ jobs: run: | if command -v valgrind >/dev/null; then export upx_exe_runner="valgrind --leak-check=no --error-exitcode=1 --quiet --gen-suppressions=all" + export UPX_CONFIG_DISABLE_EXHAUSTIVE_TEST=ON # valgrind is SLOW env -C build/extra/gcc/debug bash "$PWD"/misc/testsuite/mimic_ctest.sh env -C build/extra/gcc/release bash "$PWD"/misc/testsuite/mimic_ctest.sh # clang/debug does not work before valgrind-3.20, see https://bugs.kde.org/show_bug.cgi?id=452758 @@ -173,6 +174,7 @@ jobs: run: | if command -v valgrind >/dev/null; then export upx_exe_runner="valgrind --leak-check=no --error-exitcode=1 --quiet --gen-suppressions=all" + export UPX_CONFIG_DISABLE_EXHAUSTIVE_TEST=ON # valgrind is SLOW env -C build/extra/gcc-m32/debug bash "$PWD"/misc/testsuite/mimic_ctest.sh env -C build/extra/gcc-m32/release bash "$PWD"/misc/testsuite/mimic_ctest.sh fi @@ -597,5 +599,6 @@ jobs: apk add coreutils valgrind export upx_exe_runner="valgrind --leak-check=no --error-exitcode=1 --quiet --gen-suppressions=all" upx_exe_runner="$upx_exe_runner --suppressions=$PWD/misc/valgrind/musl.supp" + export UPX_CONFIG_DISABLE_EXHAUSTIVE_TEST=ON # valgrind is SLOW env -C build/zig/${ZIG_TARGET}${ZIG_PIC}/debug bash "$PWD"/misc/testsuite/mimic_ctest.sh env -C build/zig/${ZIG_TARGET}${ZIG_PIC}/release bash "$PWD"/misc/testsuite/mimic_ctest.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index fe7ada3f..72bae098 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,7 +52,8 @@ endif() # test config options (see below) # IMPORTANT NOTE: self-pack test can only work if the host executable format is supported by UPX! -option(UPX_CONFIG_DISABLE_SELF_PACK_TEST "Do not test packing UPX with itself" OFF) +option(UPX_CONFIG_DISABLE_SELF_PACK_TEST "Do not test packing UPX with itself" OFF) +option(UPX_CONFIG_DISABLE_EXHAUSTIVE_TEST "Do not run exhaustive test" OFF) #*********************************************************************** # init @@ -501,6 +502,24 @@ if(NOT UPX_CONFIG_DISABLE_SELF_PACK_TEST) upx_add_serial_test(upx-run-packed-nrv2e ${emu} ./upx-packed-nrv2e${exe} --version-short) upx_add_serial_test(upx-run-packed-lzma ${emu} ./upx-packed-lzma${exe} --version-short) endif() + + # TODO later: check if we can somehow run these tests in parallel groups + if(NOT UPX_CONFIG_DISABLE_EXHAUSTIVE_TEST) + foreach(method IN ITEMS nrv2b nrv2d nrv2e lzma) + foreach(level IN ITEMS 1 2 3 4 5 6 7 ) + set(s "${method}-${level}") + upx_add_serial_test(upx-self-pack-${s} upx --${method} -${level} --debug-use-random-filter "${upx_self_exe}" ${fo} -o upx-packed-${s}${exe}) + upx_add_serial_test(upx-list-${s} upx -l upx-packed-${s}${exe}) + upx_add_serial_test(upx-fileinfo-${s} upx --fileinfo upx-packed-${s}${exe}) + upx_add_serial_test(upx-test-${s} upx -t upx-packed-${s}${exe}) + upx_add_serial_test(upx-unpack-pack-${s} upx -d upx-packed-${s}${exe} ${fo} -o upx-unpacked-${s}${exe}) + upx_add_serial_test(upx-compare-${s} "${CMAKE_COMMAND}" -E compare_files upx-unpacked${exe} upx-unpacked-${s}${exe}) + if(NOT UPX_CONFIG_DISABLE_RUN_PACKED_TEST) + upx_add_serial_test(upx-run-packed-${s} ${emu} ./upx-packed-${s}${exe} --version-short) + endif() + endforeach() + endforeach() + endif () # UPX_CONFIG_DISABLE_EXHAUSTIVE_TEST endif() # UPX_CONFIG_DISABLE_SELF_PACK_TEST endif() # CMAKE_CROSSCOMPILING diff --git a/misc/make/Makefile-extra.mk b/misc/make/Makefile-extra.mk index 236dfd8d..23477a1d 100644 --- a/misc/make/Makefile-extra.mk +++ b/misc/make/Makefile-extra.mk @@ -310,6 +310,7 @@ UPX_CMAKE_CONFIG_FLAGS += $(call __add_cmake_config,UPX_CONFIG_DISABLE_SANITIZE) UPX_CMAKE_CONFIG_FLAGS += $(call __add_cmake_config,UPX_CONFIG_DISABLE_WSTRICT) UPX_CMAKE_CONFIG_FLAGS += $(call __add_cmake_config,UPX_CONFIG_DISABLE_WERROR) UPX_CMAKE_CONFIG_FLAGS += $(call __add_cmake_config,UPX_CONFIG_DISABLE_SELF_PACK_TEST) +UPX_CMAKE_CONFIG_FLAGS += $(call __add_cmake_config,UPX_CONFIG_DISABLE_EXHAUSTIVE_TEST) # pass UPX extra compile options; see CMakeLists.txt UPX_CMAKE_CONFIG_FLAGS += $(call __add_cmake_config,UPX_CONFIG_EXTRA_COMPILE_OPTIONS_BZIP2) UPX_CMAKE_CONFIG_FLAGS += $(call __add_cmake_config,UPX_CONFIG_EXTRA_COMPILE_OPTIONS_UCL) diff --git a/misc/testsuite/mimic_ctest.sh b/misc/testsuite/mimic_ctest.sh index c978dca8..0d0f890a 100755 --- a/misc/testsuite/mimic_ctest.sh +++ b/misc/testsuite/mimic_ctest.sh @@ -61,10 +61,13 @@ set_on_off() { set -x set_on_off UPX_CONFIG_DISABLE_SELF_PACK_TEST +set_on_off UPX_CONFIG_DISABLE_EXHAUSTIVE_TEST set_on_off UPX_CONFIG_DISABLE_RUN_UNPACKED_TEST set_on_off UPX_CONFIG_DISABLE_RUN_PACKED_TEST -export UPX="--no-color --no-progress" +export UPX="--prefer-ucl --no-color --no-progress" +export UPX_DEBUG_DISABLE_GITREV_WARNING=1 +export UPX_DEBUG_DOCTEST_DISABLE=1 # already checked above "${run_upx[@]}" --version "${run_upx[@]}" --version-short @@ -116,18 +119,37 @@ cmp -s upx-unpacked${exe} upx-unpacked-nrv2e${exe} cmp -s upx-unpacked${exe} upx-unpacked-lzma${exe} if [[ $UPX_CONFIG_DISABLE_RUN_UNPACKED_TEST == OFF ]]; then -"${emu[@]}" ./upx-unpacked${exe} --version-short + "${emu[@]}" ./upx-unpacked${exe} --version-short fi if [[ $UPX_CONFIG_DISABLE_RUN_PACKED_TEST == OFF ]]; then -"${emu[@]}" ./upx-packed${exe} --version-short -"${emu[@]}" ./upx-packed-fa${exe} --version-short -"${emu[@]}" ./upx-packed-fn${exe} --version-short -"${emu[@]}" ./upx-packed-fr${exe} --version-short -"${emu[@]}" ./upx-packed-nrv2b${exe} --version-short -"${emu[@]}" ./upx-packed-nrv2d${exe} --version-short -"${emu[@]}" ./upx-packed-nrv2e${exe} --version-short -"${emu[@]}" ./upx-packed-lzma${exe} --version-short + "${emu[@]}" ./upx-packed${exe} --version-short + "${emu[@]}" ./upx-packed-fa${exe} --version-short + "${emu[@]}" ./upx-packed-fn${exe} --version-short + "${emu[@]}" ./upx-packed-fr${exe} --version-short + "${emu[@]}" ./upx-packed-nrv2b${exe} --version-short + "${emu[@]}" ./upx-packed-nrv2d${exe} --version-short + "${emu[@]}" ./upx-packed-nrv2e${exe} --version-short + "${emu[@]}" ./upx-packed-lzma${exe} --version-short +fi + +if [[ $UPX_CONFIG_DISABLE_EXHAUSTIVE_TEST == OFF ]]; then + set +x + for method in nrv2b nrv2d nrv2e lzma; do + for level in 1 2 3 4 5 6 7; do + s="${method}-${level}" + echo "========== $s ==========" + "${run_upx[@]}" -qq --${method} -${level} --debug-use-random-filter "${upx_self_exe}" ${fo} -o upx-packed-${s}${exe} + "${run_upx[@]}" -qq -l upx-packed-${s}${exe} + "${run_upx[@]}" -qq --fileinfo upx-packed-${s}${exe} + "${run_upx[@]}" -qq -t upx-packed-${s}${exe} + "${run_upx[@]}" -qq -d upx-packed-${s}${exe} ${fo} -o upx-unpacked-${s}${exe} + cmp -s upx-unpacked${exe} upx-unpacked-${s}${exe} + if [[ $UPX_CONFIG_DISABLE_RUN_PACKED_TEST == OFF ]]; then + "${emu[@]}" ./upx-packed-${s}${exe} --version-short + fi + done + done fi echo "All done." diff --git a/misc/testsuite/test_symlinks.sh b/misc/testsuite/test_symlinks.sh index 7a318d47..9063a14e 100755 --- a/misc/testsuite/test_symlinks.sh +++ b/misc/testsuite/test_symlinks.sh @@ -170,8 +170,7 @@ create_files() { export UPX="--prefer-ucl --no-color --no-progress" export UPX_DEBUG_DISABLE_GITREV_WARNING=1 -export UPX_DEBUG_DOCTEST_VERBOSE=0 -export NO_COLOR=1 +export UPX_DEBUG_DOCTEST_DISABLE=1 # already checked above testsuite_header() { local x='==========='; x="$x$x$x$x$x$x$x" diff --git a/misc/testsuite/upx_testsuite_1.sh b/misc/testsuite/upx_testsuite_1.sh index 038d9387..54644db2 100755 --- a/misc/testsuite/upx_testsuite_1.sh +++ b/misc/testsuite/upx_testsuite_1.sh @@ -99,7 +99,7 @@ all_errors= export UPX="--prefer-ucl --no-color --no-progress" export UPX_DEBUG_DISABLE_GITREV_WARNING=1 -export UPX_DEBUG_DOCTEST_VERBOSE=0 +export UPX_DEBUG_DOCTEST_DISABLE=1 # already checked above case $UPX_TESTSUITE_LEVEL in [0-8]) ;; diff --git a/src/packer.cpp b/src/packer.cpp index c7203ea6..c6342063 100644 --- a/src/packer.cpp +++ b/src/packer.cpp @@ -60,8 +60,6 @@ void Packer::assertPacker() const { // info: 36 is the limit for show_all_packers() in help.cpp, but 32 should be enough for now assert(strlen(getFullName(nullptr)) <= 32); assert(strlen(getFullName(opt)) <= 32); - assert(getCompressionMethods(M_ALL, 10) != nullptr); - (void) getFilters(); if (bele == nullptr) fprintf(stderr, "%s\n", getName()); assert(bele != nullptr);