diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/integration/framework | 63 | ||||
-rwxr-xr-x | test/integration/test-bug-992993-marked-cycles | 30 | ||||
-rw-r--r-- | test/interactive-helper/CMakeLists.txt | 3 | ||||
-rw-r--r-- | test/interactive-helper/longest-dependency-chain.cc | 72 |
4 files changed, 165 insertions, 3 deletions
diff --git a/test/integration/framework b/test/integration/framework index 8c9abfbe4..1f942d162 100644 --- a/test/integration/framework +++ b/test/integration/framework @@ -307,6 +307,13 @@ find_project_binary_dir() { export PROJECT_BINARY_DIR fi } +_removetmpworkingdirectory() { + cd / + if [ -n "$TMPWORKINGDIRECTORY" -a -d "$TMPWORKINGDIRECTORY" ]; then + rm -rf "$TMPWORKINGDIRECTORY" + fi + TMPWORKINGDIRECTORY='' +} setupenvironment() { # Next check needs a gnu stat, let's figure that out early. stat=stat @@ -317,8 +324,10 @@ setupenvironment() { if [ -n "$TMPDIR" ] && [ "$(id -u)" = '0' ] && [ "$($stat --format '%a' "$TMPDIR")" != '1777' ]; then unset TMPDIR fi - TMPWORKINGDIRECTORY="$(mktemp -d)" - addtrap "cd /; rm -rf '$(escape_shell "$TMPWORKINGDIRECTORY")';" + if [ -z "$TMPWORKINGDIRECTORY" ]; then + addtrap '_removetmpworkingdirectory;' + TMPWORKINGDIRECTORY="$(mktemp -d)" + fi if [ -n "$TMPDIR_ADD" ]; then TMPWORKINGDIRECTORY="${TMPWORKINGDIRECTORY}/${TMPDIR_ADD}" mkdir -p "$TMPWORKINGDIRECTORY" @@ -361,6 +370,7 @@ setupenvironment() { 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"}" + ARTIFACTSDIR="${APT_INTEGRATION_TESTS_ARTIFACTS_DIR:-"${BUILDDIRECTORY}/artifacts"}" test -x "${BUILDDIRECTORY}/apt-get" || msgdie "You need to build tree first" # ----- @@ -1778,6 +1788,52 @@ msgfailoutput() { ls -l fi catfile "$OUTPUT" + if [ "$CMD" != 'echo' ] && tail -n 1 "$OUTPUT" | grep -q '(core dumped)$'; then + local COREDUMP="${TMPWORKINGDIRECTORY}/rootdir/tmp/core.dump" + local COREEXE='' + for CORENAME in 'core' 'core.pid'; do + if [ -s "$CORENAME" ]; then + cp -a ${CORENAME} "$COREDUMP" + elif [ -s "${TMPWORKINGDIRECTORY}/${CORENAME}" ]; then + cp -a "${TMPWORKINGDIRECTORY}/${CORENAME}" "$COREDUMP" + else + continue + fi + break + done + if [ -s "$COREDUMP" ]; then + true # found already as a file + elif dpkg-checkbuilddeps -d 'systemd-coredump' /dev/null >/dev/null 2>&1; then + COREEXE="$(coredumpctl -1 --no-legend list | sed -e 's#^.* \([^ ]\+\)$#\1#')" + coredumpctl -1 dump "$COREEXE" -o "$COREDUMP" 2>/dev/null >&2 || true + else + echo '### core dump not found ###' + cat /proc/sys/kernel/core_pattern + fi + if [ -s "$COREDUMP" ]; then + if [ -z "$COREEXE" ]; then + case "$CMD" in + apt) COREEXE="${BUILDDIRECTORY}/${CMD}";; + aptftparchive) COREEXE="${APTFTPARCHIVEBINDIR}/apt-ftparchive";; + apthelper) COREEXE="${APTHELPERBINDIR}/apt-helper";; + aptwebserver) COREEXE="${APTTESTHELPERSBINDIR}/aptwebserver";; + apt*) COREEXE="${BUILDDIRECTORY}/apt-${CMD##*apt}";; + *) COREEXE="${BUILDDIRECTORY}/${CMD}";; + esac + fi + + if [ -d "${ARTIFACTSDIR}" ]; then + local ARTIFACT_COREDUMP="$(mktemp --suffix=.coredump -p "${ARTIFACTSDIR}" "${COREEXE##*/}-XXXXXX")" + cp -a "$COREDUMP" "$ARTIFACT_COREDUMP" + echo "#### coredump in $ARTIFACT_COREDUMP for $COREEXE ####" + fi + if [ -n "$COREEXE" -a -s "$COREEXE" ] && dpkg-checkbuilddeps -d 'gdb' /dev/null >/dev/null 2>&1; then + echo "#### gdb backtrace ####" + command gdb --batch -n -ex 'set pagination off' --ex 'thread apply all bt full' "$COREEXE" "$COREDUMP" || true + fi + fi + rm -f "$COREDUMP" + fi msgfail "$MSG" } @@ -1801,6 +1857,9 @@ testsuccesswithglobalerror() { if echo 'E: Can not write log (Is /dev/pts mounted?) - posix_openpt (2: No such file or directory)' \ | cmp - "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" >/dev/null 2>&1; then msgpass + elif echo 'E: Can not write log (Is /dev/pts mounted?) - posix_openpt (13: Permission denied)' \ + | cmp - "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" >/dev/null 2>&1; then + msgpass else msgfailoutput 'successful run, but output contains warnings/errors' "$OUTPUT" "$@" fi diff --git a/test/integration/test-bug-992993-marked-cycles b/test/integration/test-bug-992993-marked-cycles new file mode 100755 index 000000000..a569040cf --- /dev/null +++ b/test/integration/test-bug-992993-marked-cycles @@ -0,0 +1,30 @@ +#!/bin/sh +set -e + +TESTDIR="$(readlink -f "$(dirname "$0")")" +. "$TESTDIR/framework" +setupenvironment +configarchitecture 'amd64' + +insertinstalledpackage 'librust-nom-4-dev' 'all' '4.2.3-3' 'Provides: librust-nom-dev (= 4.2.3-3)' +insertinstalledpackage 'librust-nom-dev' 'all' '5.0.1-4' 'Depends: librust-nom+default-dev (= 5.0.1-4)' +insertinstalledpackage 'librust-nom+default-dev ' 'all' '5.0.1-4' 'Depends: librust-nom-dev (= 5.0.1-4)' +insertinstalledpackage 'librust-nom-4+std-dev' 'all' '4.2.3-3' 'Provides: librust-nom+default-dev (= 4.2.3-3)' + +insertinstalledpackage 'foo' 'all' '1' 'Depends: librust-nom-4-dev, librust-nom-dev, librust-nom-4+std-dev' + +for AUTO in '' 'librust-nom-4-dev' 'librust*' 'foo' '.*'; do + msgmsg 'Running test with these packages marked auto:' "$AUTO" + testsuccess aptmark manual '.*' + if [ -n "$AUTO" ]; then + testsuccess aptmark auto "$AUTO" + fi + + testsuccess aptget check + testsuccess aptget autoremove -s + + testsuccess aptget upgrade + testsuccess aptget full-upgrade + + testsuccess apt show foo +done diff --git a/test/interactive-helper/CMakeLists.txt b/test/interactive-helper/CMakeLists.txt index 565474afd..fff47300b 100644 --- a/test/interactive-helper/CMakeLists.txt +++ b/test/interactive-helper/CMakeLists.txt @@ -11,7 +11,8 @@ target_link_libraries(aptdropprivs apt-pkg) add_executable(test_fileutl test_fileutl.cc) target_link_libraries(test_fileutl apt-pkg) 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) add_library(noprofile SHARED libnoprofile.c) target_link_libraries(noprofile ${CMAKE_DL_LIBS}) diff --git a/test/interactive-helper/longest-dependency-chain.cc b/test/interactive-helper/longest-dependency-chain.cc new file mode 100644 index 000000000..3da722a5b --- /dev/null +++ b/test/interactive-helper/longest-dependency-chain.cc @@ -0,0 +1,72 @@ +#include <config.h> + +#include <apt-pkg/cachefile.h> +#include <apt-pkg/pkgsystem.h> +#include <apt-private/private-cmndline.h> + +#include <iostream> + +static bool ShowHelp(CommandLine &) /*{{{*/ +{ + std::cout << + "Usage: longest-dependecy-chain [options]\n" + "\n" + "Tries to find the longest dependency chain available in the data\n" + "assuming an empty status file, no conflicts, all or-group members\n" + "are followed and discovery order matters. In other words:\n" + "The found length might very well be too short and not realistic.\n" + "It is also not implemented very intelligently, so it runs forever.\n"; + return true; +} + /*}}}*/ +static std::vector<aptDispatchWithHelp> GetCommands() /*{{{*/ +{ + return { + {nullptr, nullptr, nullptr} + }; +} + /*}}}*/ +static size_t findLongestInstallChain(pkgDepCache &Cache, pkgCache::PkgIterator const &Pkg, std::vector<bool> &installed)/*{{{*/ +{ + if (installed[Pkg->ID]) + return 0; + installed[Pkg->ID] = true; + + auto const Ver = Cache.GetCandidateVersion(Pkg); + if (Ver.end()) + return 0; + + size_t maxdepth = 0; + for (auto D = Ver.DependsList(); not D.end(); ++D) + if (D->Type == pkgCache::Dep::Depends || + D->Type == pkgCache::Dep::PreDepends || + D->Type == pkgCache::Dep::Recommends || + D->Type == pkgCache::Dep::Suggests) + maxdepth = std::max(maxdepth, findLongestInstallChain(Cache, D.TargetPkg(), installed)); + return maxdepth + 1; +} + /*}}}*/ +int main(int argc,const char *argv[]) /*{{{*/ +{ + CommandLine CmdL; + auto const Cmds = ParseCommandLine(CmdL, APT_CMD::APT_SORTPKG, &_config, &_system, argc, argv, &ShowHelp, &GetCommands); + _config->Set("dir::state::status", "/dev/null"); + + pkgCacheFile CacheFile; + CacheFile.InhibitActionGroups(true); + pkgDepCache * const Cache = CacheFile.GetDepCache(); + if (unlikely(Cache == nullptr)) + return DispatchCommandLine(CmdL, Cmds); + + size_t maxdepth = 0; + for (auto P = Cache->PkgBegin(); not P.end(); ++P) + { + std::vector<bool> installed(Cache->Head().PackageCount, false); + auto const depth = findLongestInstallChain(*Cache, P, installed); + std::cout << depth << ' ' << P.FullName() << '\n'; + maxdepth = std::max(maxdepth, depth); + } + + return 0; +} + /*}}}*/ |