From 8d8b45a96ceceb015f7836cf25b99279c2f377b9 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 21 Apr 2022 01:45:45 +0200 Subject: Link interactive helpers against system libapt for autopkgtest Building the library just so we can build the helpers against it is not only wasteful but as we are supposed to test the system we can use that as an additional simple smoke test before the real testing starts. --- test/integration/create-test-data | 2 - test/integration/framework | 51 ++++++++++------------ test/integration/test-apt-helper-cat-file | 2 +- .../test-no-fds-leaked-to-maintainer-scripts | 6 +-- test/interactive-helper/CMakeLists.txt | 27 +++++++++--- 5 files changed, 48 insertions(+), 40 deletions(-) (limited to 'test') diff --git a/test/integration/create-test-data b/test/integration/create-test-data index eff2ba530..0eca3998c 100755 --- a/test/integration/create-test-data +++ b/test/integration/create-test-data @@ -9,8 +9,6 @@ fi CHECK_ARGS='no' TESTDIR="$(readlink -f "$(dirname "$0")")" . "$TESTDIR/framework" -find_project_binary_dir -BUILDDIRECTORY="${APT_INTEGRATION_TESTS_BUILD_DIR:-"${PROJECT_BINARY_DIR}/cmdline"}" GENERATE="$1" CODENAME="$2" diff --git a/test/integration/framework b/test/integration/framework index c9559a7ba..8bb8c00d6 100644 --- a/test/integration/framework +++ b/test/integration/framework @@ -175,7 +175,7 @@ runapt() { shift case "$CMD" in sh|aptitude|*/*|command) ;; - *) CMD="${BUILDDIRECTORY}/$CMD";; + *) CMD="${APTCMDLINEBINDIR}/$CMD";; esac if [ "$CMD" = 'aptitude' ]; then MALLOC_PERTURB_=21 MALLOC_CHECK_=2 APT_CONFIG="$(getaptconfig)" LD_LIBRARY_PATH="${LIBRARYPATH}:${LD_LIBRARY_PATH}" command "$CMD" "$@" @@ -228,7 +228,7 @@ gdb() { esac shift if [ "${CMD##*/}" = "$CMD" ]; then - CMD="${BUILDDIRECTORY}/${CMD}" + CMD="${APTCMDLINEBINDIR}/${CMD}" fi runapt command gdb --quiet -ex "directory '$SOURCEDIRECTORY'" -ex run "$CMD" --args "$CMD" "$@" } @@ -248,7 +248,7 @@ valgrind() { esac shift if [ "${CMD##*/}" = "$CMD" ]; then - CMD="${BUILDDIRECTORY}/${CMD}" + CMD="${APTCMDLINEBINDIR}/${CMD}" fi runapt command valgrind "$CMD" "$@" } @@ -373,9 +373,6 @@ setupenvironment() { fi mkdir -p 'rootdir/usr/bin' 'rootdir/var/cache' 'rootdir/var/lib' 'rootdir/var/log' 'rootdir/var/crash' 'rootdir/tmp' - # Find the newest build directory (sets PROJECT_BINARY_DIR) - find_project_binary_dir - _setupprojectenvironment # create some files in /tmp and look at user/group to get what this means @@ -383,9 +380,6 @@ setupenvironment() { touch "${TMPWORKINGDIRECTORY}/test-file" TEST_DEFAULT_GROUP=$(stat --format '%G' "${TMPWORKINGDIRECTORY}/test-file") - # prefer our apt binaries over the system apt binaries - export PATH="${BUILDDIRECTORY}:${PATH}:/usr/local/sbin:/usr/sbin:/sbin" - if [ -r "${TESTDIRECTORY}/extra-environment" ]; then . "${TESTDIRECTORY}/extra-environment" fi @@ -393,19 +387,20 @@ setupenvironment() { msgdone "info" } _setupprojectenvironment() { - # allow overriding the default BUILDDIR location + # allow overriding the default BUILDDIR locations SOURCEDIRECTORY="${APT_INTEGRATION_TESTS_SOURCE_DIR:-"${TESTDIRECTORY}/../../"}" - BUILDDIRECTORY="${APT_INTEGRATION_TESTS_BUILD_DIR:-"${PROJECT_BINARY_DIR}/cmdline"}" - LIBRARYPATH="${APT_INTEGRATION_TESTS_LIBRARY_PATH:-"${BUILDDIRECTORY}/../apt-pkg"}" - METHODSDIR="${APT_INTEGRATION_TESTS_METHODS_DIR:-"${BUILDDIRECTORY}/../methods"}" - APTHELPERBINDIR="${APT_INTEGRATION_TESTS_LIBEXEC_DIR:-"${BUILDDIRECTORY}"}" - APTTESTHELPERSBINDIR="${APT_INTEGRATION_TESTS_HELPERS_BIN_DIR:-"${BUILDDIRECTORY}/../test/interactive-helper"}" - APTFTPARCHIVEBINDIR="${APT_INTEGRATION_TESTS_FTPARCHIVE_BIN_DIR:-"${BUILDDIRECTORY}/../ftparchive"}" - APTINTERNALSOLVER="${APT_INTEGRATION_TESTS_INTERNAL_SOLVER:-"${BUILDDIRECTORY}/solvers/apt"}" - APTDUMPSOLVER="${APT_INTEGRATION_TESTS_DUMP_SOLVER:-"${BUILDDIRECTORY}/solvers/dump"}" - APTINTERNALPLANNER="${APT_INTEGRATION_TESTS_INTERNAL_PLANNER:-"${BUILDDIRECTORY}/planners/apt"}" + BUILDDIRECTORY="${APT_INTEGRATION_TESTS_BUILD_DIR:-"$(find_project_binary_dir; printf '%s' "$PROJECT_BINARY_DIR")"}" + LIBRARYPATH="${APT_INTEGRATION_TESTS_LIBRARY_PATH:-"${BUILDDIRECTORY}/apt-pkg"}" + METHODSDIR="${APT_INTEGRATION_TESTS_METHODS_DIR:-"${BUILDDIRECTORY}/methods"}" + APTHELPERBINDIR="${APT_INTEGRATION_TESTS_LIBEXEC_DIR:-"${BUILDDIRECTORY}/cmdline"}" + APTTESTHELPERSBINDIR="${APT_INTEGRATION_TESTS_HELPERS_BIN_DIR:-"${BUILDDIRECTORY}/test/interactive-helper"}" + APTFTPARCHIVEBINDIR="${APT_INTEGRATION_TESTS_FTPARCHIVE_BIN_DIR:-"${BUILDDIRECTORY}/ftparchive"}" + APTCMDLINEBINDIR="${APT_INTEGRATION_TESTS_CMDLINE_BIN_DIR:-"${BUILDDIRECTORY}/cmdline"}" + APTINTERNALSOLVER="${APT_INTEGRATION_TESTS_INTERNAL_SOLVER:-"${APTCMDLINEBINDIR}/solvers/apt"}" + APTDUMPSOLVER="${APT_INTEGRATION_TESTS_DUMP_SOLVER:-"${APTCMDLINEBINDIR}/solvers/dump"}" + APTINTERNALPLANNER="${APT_INTEGRATION_TESTS_INTERNAL_PLANNER:-"${APTCMDLINEBINDIR}/planners/apt"}" ARTIFACTSDIR="${APT_INTEGRATION_TESTS_ARTIFACTS_DIR:-"${BUILDDIRECTORY}/artifacts"}" - test -x "${BUILDDIRECTORY}/apt-get" || msgdie "You need to build tree first" + test -x "${APTCMDLINEBINDIR}/apt-get" || msgdie 'You need to build tree first' echo "#x-apt-configure-index \"${SOURCEDIRECTORY}/doc/examples/configure-index\";" > aptconfig.conf mkdir aptarchive keys @@ -422,8 +417,7 @@ _setupprojectenvironment() { ln -s "${APTINTERNALPLANNER}" usr/lib/apt/planners/apt echo "Dir::Bin::Solvers \"${TMPWORKINGDIRECTORY}/rootdir/usr/lib/apt/solvers\";" >> ../aptconfig.conf echo "Dir::Bin::Planners \"${TMPWORKINGDIRECTORY}/rootdir/usr/lib/apt/planners\";" >> ../aptconfig.conf - # use the autoremove from the BUILDDIRECTORY if its there, otherwise - # system + # use the autoremove from the BUILDDIRECTORY if its there, otherwise system if [ -z "${APT_INTEGRATION_TESTS_SOURCE_DIR}" ]; then ln -s "${SOURCEDIRECTORY}/debian/apt.conf.autoremove" etc/apt/apt.conf.d/01autoremove else @@ -452,11 +446,11 @@ _setupprojectenvironment() { echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf echo "Dir::Bin::Methods \"${TMPWORKINGDIRECTORY}/rootdir/usr/lib/apt/methods\";" >> aptconfig.conf # either store apt-key were we can access it, even if we run it as a different user - #cp "${BUILDDIRECTORY}/apt-key" "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/" + #cp "${APTCMDLINEBINDIR}/apt-key" "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/" #chmod o+rx "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key" #echo "Dir::Bin::apt-key \"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key\";" >> aptconfig.conf # destroys coverage reporting though, so we disable changing user for the calling gpgv - echo "Dir::Bin::apt-key \"${BUILDDIRECTORY}/apt-key\";" >> aptconfig.conf + echo "Dir::Bin::apt-key \"${APTCMDLINEBINDIR}/apt-key\";" >> aptconfig.conf if [ "$(id -u)" = '0' ]; then echo 'Binary::gpgv::APT::Sandbox::User "root";' >> aptconfig.conf # same for the solver executables @@ -542,6 +536,9 @@ EOF # most tests just need one signed Release file, not both export APT_DONT_SIGN='Release.gpg' + + # prefer our apt binaries over the system apt binaries + export PATH="${APTCMDLINEBINDIR}:${PATH}:/usr/sbin:/sbin" } getarchitecture() { @@ -1831,12 +1828,12 @@ msgfailoutput() { if [ -s "$COREDUMP" ]; then if [ -z "$COREEXE" ]; then case "$CMD" in - apt) COREEXE="${BUILDDIRECTORY}/${CMD}";; + apt) COREEXE="${APTCMDLINEBINDIR}/${CMD}";; aptftparchive) COREEXE="${APTFTPARCHIVEBINDIR}/apt-ftparchive";; apthelper) COREEXE="${APTHELPERBINDIR}/apt-helper";; aptwebserver) COREEXE="${APTTESTHELPERSBINDIR}/aptwebserver";; - apt*) COREEXE="${BUILDDIRECTORY}/apt-${CMD##*apt}";; - *) COREEXE="${BUILDDIRECTORY}/${CMD}";; + apt*) COREEXE="${APTCMDLINEBINDIR}/apt-${CMD##*apt}";; + *) COREEXE="${APTCMDLINEBINDIR}/${CMD}";; esac fi diff --git a/test/integration/test-apt-helper-cat-file b/test/integration/test-apt-helper-cat-file index a53a6b4a3..064760c9e 100755 --- a/test/integration/test-apt-helper-cat-file +++ b/test/integration/test-apt-helper-cat-file @@ -5,7 +5,7 @@ TESTDIR="$(readlink -f "$(dirname "$0")")" . "$TESTDIR/framework" setupenvironment -TESTTOOL="${BUILDDIRECTORY}/../test/interactive-helper/test_fileutl" +TESTTOOL="${APTTESTHELPERSBINDIR}/test_fileutl" msgtest 'Check if we have build the test tool' "$TESTTOOL" if [ -x "$TESTTOOL" ]; then msgpass diff --git a/test/integration/test-no-fds-leaked-to-maintainer-scripts b/test/integration/test-no-fds-leaked-to-maintainer-scripts index 4606408fc..2b165520e 100755 --- a/test/integration/test-no-fds-leaked-to-maintainer-scripts +++ b/test/integration/test-no-fds-leaked-to-maintainer-scripts @@ -159,11 +159,11 @@ else fi rm -f rootdir/var/log/dpkg.log rootdir/var/log/apt/term.log -testsuccess runapt command setsid -w "${BUILDDIRECTORY}/apt-get" install -y fdleaks -qq < /dev/null +testsuccess runapt command setsid -w "${APTCMDLINEBINDIR}/apt-get" install -y fdleaks -qq < /dev/null checkinstall rm -f rootdir/var/log/dpkg.log rootdir/var/log/apt/term.log -testsuccess runapt command setsid -w "${BUILDDIRECTORY}/apt-get" purge -y fdleaks -qq +testsuccess runapt command setsid -w "${APTCMDLINEBINDIR}/apt-get" purge -y fdleaks -qq checkpurge touch rootdir/tmp/read_stdin @@ -174,6 +174,6 @@ checkinstall testequal '2' grep -c '^STDIN: ' rootdir/var/log/apt/term.log rm -f rootdir/var/log/dpkg.log rootdir/var/log/apt/term.log -yes '' | testsuccess runapt command setsid -w "${BUILDDIRECTORY}/apt-get" purge -y fdleaks -qq +yes '' | testsuccess runapt command setsid -w "${APTCMDLINEBINDIR}/apt-get" purge -y fdleaks -qq checkpurge testequal '3' grep -c '^STDIN: ' rootdir/var/log/apt/term.log diff --git a/test/interactive-helper/CMakeLists.txt b/test/interactive-helper/CMakeLists.txt index fff47300b..8e8764353 100644 --- a/test/interactive-helper/CMakeLists.txt +++ b/test/interactive-helper/CMakeLists.txt @@ -1,18 +1,31 @@ +if(USE_SYSTEM_APTPKG) + find_library(aptpkg NAMES apt-pkg NO_PACKAGE_ROOT_PATH REQUIRED) + set(APTPKG_LIB "${aptpkg}") + # it isn't easy to link against -private, but that is by design + set(APTPRIVATE_LIB "/usr/lib/${CMAKE_LIBRARY_ARCHITECTURE}/libapt-private.so.0.0") + set(APTPRIVATE_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}") +else() + set(APTPKG_LIB "apt-pkg") + set(APTPRIVATE_LIB "apt-private") + set(APTPRIVATE_INCLUDE_DIRS "") +endif() + add_executable(mthdcat mthdcat.cc) -target_link_libraries(mthdcat apt-pkg) +target_link_libraries(mthdcat ${APTPKG_LIB}) add_executable(testdeb testdeb.cc) -target_link_libraries(testdeb apt-pkg) +target_link_libraries(testdeb ${APTPKG_LIB}) add_executable(extract-control extract-control.cc) -target_link_libraries(extract-control apt-pkg) +target_link_libraries(extract-control ${APTPKG_LIB}) add_executable(aptwebserver aptwebserver.cc) -target_link_libraries(aptwebserver apt-pkg ${CMAKE_THREAD_LIBS_INIT}) +target_link_libraries(aptwebserver ${APTPKG_LIB} ${CMAKE_THREAD_LIBS_INIT}) add_executable(aptdropprivs aptdropprivs.cc) -target_link_libraries(aptdropprivs apt-pkg) +target_link_libraries(aptdropprivs ${APTPKG_LIB}) add_executable(test_fileutl test_fileutl.cc) -target_link_libraries(test_fileutl apt-pkg) +target_link_libraries(test_fileutl ${APTPKG_LIB}) add_executable(createdeb-cve-2020-27350 createdeb-cve-2020-27350.cc) add_executable(longest-dependency-chain longest-dependency-chain.cc) -target_link_libraries(longest-dependency-chain apt-pkg apt-private) +target_link_libraries(longest-dependency-chain ${APTPKG_LIB} ${APTPRIVATE_LIB}) +target_include_directories(longest-dependency-chain PRIVATE ${APTPRIVATE_INCLUDE_DIRS}) add_library(noprofile SHARED libnoprofile.c) target_link_libraries(noprofile ${CMAKE_DL_LIBS}) -- cgit v1.2.3-70-g09d2 From e5aa5c04ecbd3cdab611794cebf9eb3aa8cbddd4 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 21 Apr 2022 12:51:20 +0200 Subject: Ignore stty failures in testcases MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We use 'stty sane' to combat against stepped output and co caused by (especially) failed tests, but it does so many things that it occasionally fails to reset some bits in the parallel interaction we have with it which fails the tests without a real problem in apt… Ideally we would be better at stitching the output together, but for the time being lets ignore these failures instead to stabilize the tests. --- test/integration/run-tests | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/integration/run-tests b/test/integration/run-tests index f5a39f244..c1cc780f0 100755 --- a/test/integration/run-tests +++ b/test/integration/run-tests @@ -80,9 +80,9 @@ if [ -n "$TESTTORUN" ]; then fi } >"$OUTPUT" 2>&1 # without we end up getting stepped output 'randomly' - stty sane + stty sane || true cat >&2 "$OUTPUT" - stty sane + stty sane || true if [ "$FAIL" = 'yes' ]; then exit 1 else -- cgit v1.2.3-70-g09d2 From 320245536a7ad21606286d9dcf54acf3bdf096c6 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 22 Apr 2022 17:05:36 +0200 Subject: Include our config.h in all C++ files to avoid ODR violations Some of our headers use APT_COMPILING_APT trickery to avoid exposing too broadly details we don't want external clients to know and make use of. The flip-side is that this can lead to different compilation units seeing different definitions if they aren't all using the same config. --- apt-pkg/contrib/proxy.cc | 2 ++ apt-pkg/metaindex.cc | 2 ++ apt-pkg/statechanges.cc | 2 ++ apt-private/private-json-hooks.cc | 1 + ftparchive/sources.cc | 2 ++ prepare-release | 5 +++++ test/interactive-helper/createdeb-cve-2020-27350.cc | 2 ++ test/interactive-helper/test_fileutl.cc | 2 ++ test/libapt/extracttar_test.cc | 2 ++ test/libapt/file-helpers.cc | 2 ++ test/libapt/gtest_runner.cc | 4 +++- 11 files changed, 25 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/apt-pkg/contrib/proxy.cc b/apt-pkg/contrib/proxy.cc index 6dc3b0686..a99f44f49 100644 --- a/apt-pkg/contrib/proxy.cc +++ b/apt-pkg/contrib/proxy.cc @@ -7,6 +7,8 @@ ##################################################################### */ /*}}}*/ // Include Files /*{{{*/ +#include + #include #include #include diff --git a/apt-pkg/metaindex.cc b/apt-pkg/metaindex.cc index fc03f3db0..97996b3f1 100644 --- a/apt-pkg/metaindex.cc +++ b/apt-pkg/metaindex.cc @@ -1,4 +1,6 @@ // Include Files /*{{{*/ +#include + #include #include #include diff --git a/apt-pkg/statechanges.cc b/apt-pkg/statechanges.cc index 45468e462..bbcde71d3 100644 --- a/apt-pkg/statechanges.cc +++ b/apt-pkg/statechanges.cc @@ -1,3 +1,5 @@ +#include + #include #include #include diff --git a/apt-private/private-json-hooks.cc b/apt-private/private-json-hooks.cc index a17204dda..ddf1c89d6 100644 --- a/apt-private/private-json-hooks.cc +++ b/apt-private/private-json-hooks.cc @@ -5,6 +5,7 @@ * * SPDX-License-Identifier: GPL-2.0+ */ +#include #include #include diff --git a/ftparchive/sources.cc b/ftparchive/sources.cc index ee6efda05..a59224395 100644 --- a/ftparchive/sources.cc +++ b/ftparchive/sources.cc @@ -1,3 +1,5 @@ +#include + #include #include diff --git a/prepare-release b/prepare-release index 39e2250bc..988ccabad 100755 --- a/prepare-release +++ b/prepare-release @@ -142,6 +142,11 @@ elif [ "$1" = 'post-build' ]; then FAILED=true fi + if [ "$(find -name '*.cc' ! -name 'tagfile-keys.cc' -exec grep --files-without-match '^#include $' '{}' \+ | wc -l)" != '0' ]; then + echo >&2 'WARNING: C++ files not including our config.h can cause ODR violations!' + find -name '*.cc' ! -name 'tagfile-keys.cc' -exec grep --files-without-match '^#include $' '{}' \+ >&2 + FAILED=true + fi if $REPORT_FAILURE && $FAILED; then exit 1 fi diff --git a/test/interactive-helper/createdeb-cve-2020-27350.cc b/test/interactive-helper/createdeb-cve-2020-27350.cc index 7fc9b0e55..57c53ae91 100644 --- a/test/interactive-helper/createdeb-cve-2020-27350.cc +++ b/test/interactive-helper/createdeb-cve-2020-27350.cc @@ -1,3 +1,5 @@ +#include + #include #include #include diff --git a/test/interactive-helper/test_fileutl.cc b/test/interactive-helper/test_fileutl.cc index 6c29b748f..5569af1bf 100644 --- a/test/interactive-helper/test_fileutl.cc +++ b/test/interactive-helper/test_fileutl.cc @@ -1,3 +1,5 @@ +#include + #include #include #include diff --git a/test/libapt/extracttar_test.cc b/test/libapt/extracttar_test.cc index ae74341e6..c945a0c68 100644 --- a/test/libapt/extracttar_test.cc +++ b/test/libapt/extracttar_test.cc @@ -1,3 +1,5 @@ +#include + #include #include #include diff --git a/test/libapt/file-helpers.cc b/test/libapt/file-helpers.cc index 85fc6838e..bb7052b2a 100644 --- a/test/libapt/file-helpers.cc +++ b/test/libapt/file-helpers.cc @@ -1,3 +1,5 @@ +#include + #include #include diff --git a/test/libapt/gtest_runner.cc b/test/libapt/gtest_runner.cc index 5620aa0bd..09fc55d92 100644 --- a/test/libapt/gtest_runner.cc +++ b/test/libapt/gtest_runner.cc @@ -1,10 +1,12 @@ -#include +#include #include #include #include #include +#include + int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); if (pkgInitSystem(*_config, _system) == false) -- cgit v1.2.3-70-g09d2