From dfd863ea50c0fcf9b9ac4dfb5ae0e64c529bd767 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Sat, 6 Aug 2016 21:32:36 +0200 Subject: CMake: Switch integration tests and travis over This early support seems a bit hacky, but it's a hard switch: The integration tests do not understand the old build system anymore afterwards. I don't really like that. --- test/CMakeLists.txt | 1 + test/integration/framework | 17 +++++++++-------- test/integration/test-apt-helper-cat-file | 2 +- test/interactive-helper/CMakeLists.txt | 10 ++++++++++ 4 files changed, 21 insertions(+), 9 deletions(-) create mode 100644 test/CMakeLists.txt create mode 100644 test/interactive-helper/CMakeLists.txt (limited to 'test') diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 000000000..599f62aff --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(interactive-helper) diff --git a/test/integration/framework b/test/integration/framework index 7a6b044aa..824bd46b6 100644 --- a/test/integration/framework +++ b/test/integration/framework @@ -180,7 +180,7 @@ aptconfig() { runapt apt-config "$@"; } aptcache() { runapt apt-cache "$@"; } aptcdrom() { runapt apt-cdrom "$@"; } aptget() { runapt apt-get "$@"; } -aptftparchive() { runapt apt-ftparchive "$@"; } +aptftparchive() { runapt "${APTFTPARCHIVEBINDIR}/apt-ftparchive" "$@"; } aptkey() { runapt apt-key "$@"; } aptmark() { runapt apt-mark "$@"; } aptsortpkgs() { runapt apt-sortpkgs "$@"; } @@ -283,14 +283,15 @@ setupenvironment() { TESTDIRECTORY="$(readlink -f "$(dirname $0)")" # allow overriding the default BUILDDIR location SOURCEDIRECTORY="${APT_INTEGRATION_TESTS_SOURCE_DIR:-"${TESTDIRECTORY}/../../"}" - BUILDDIRECTORY="${APT_INTEGRATION_TESTS_BUILD_DIR:-"${TESTDIRECTORY}/../../build/bin"}" - LIBRARYPATH="${APT_INTEGRATION_TESTS_LIBRARY_PATH:-"${BUILDDIRECTORY}"}" - METHODSDIR="${APT_INTEGRATION_TESTS_METHODS_DIR:-"${BUILDDIRECTORY}/methods"}" + BUILDDIRECTORY="${APT_INTEGRATION_TESTS_BUILD_DIR:-"${TESTDIRECTORY}/../../build/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}"}" - APTWEBSERVERBINDIR="${APT_INTEGRATION_TESTS_WEBSERVER_BIN_DIR:-"${BUILDDIRECTORY}"}" - APTINTERNALSOLVER="${APT_INTEGRATION_TESTS_INTERNAL_SOLVER:-"${BUILDDIRECTORY}/apt-internal-solver"}" - APTDUMPSOLVER="${APT_INTEGRATION_TESTS_DUMP_SOLVER:-"${BUILDDIRECTORY}/apt-dump-solver"}" - APTINTERNALPLANNER="${APT_INTEGRATION_TESTS_INTERNAL_PLANNER:-"${BUILDDIRECTORY}/apt-internal-planner"}" + APTWEBSERVERBINDIR="${APT_INTEGRATION_TESTS_WEBSERVER_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"}" test -x "${BUILDDIRECTORY}/apt-get" || msgdie "You need to build tree first" # ----- diff --git a/test/integration/test-apt-helper-cat-file b/test/integration/test-apt-helper-cat-file index 3f509189e..a53a6b4a3 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_fileutl" +TESTTOOL="${BUILDDIRECTORY}/../test/interactive-helper/test_fileutl" msgtest 'Check if we have build the test tool' "$TESTTOOL" if [ -x "$TESTTOOL" ]; then msgpass diff --git a/test/interactive-helper/CMakeLists.txt b/test/interactive-helper/CMakeLists.txt new file mode 100644 index 000000000..fc08d6a8f --- /dev/null +++ b/test/interactive-helper/CMakeLists.txt @@ -0,0 +1,10 @@ +add_executable(mthdcat mthdcat.cc) +target_link_libraries(mthdcat apt-pkg) +add_executable(testdeb testdeb.cc) +target_link_libraries(testdeb apt-pkg apt-inst) +add_executable(extract-control extract-control.cc) +target_link_libraries(extract-control apt-pkg apt-inst) +add_executable(aptwebserver aptwebserver.cc) +target_link_libraries(aptwebserver apt-pkg ${CMAKE_THREAD_LIBS_INIT}) +add_executable(test_fileutl test_fileutl.cc) +target_link_libraries(test_fileutl apt-pkg) -- cgit v1.2.3 From 06c2b40b9b9094f4f6391bd1d17cfc3725313070 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Sun, 7 Aug 2016 18:22:14 +0200 Subject: CMake: Add unit tests Add support for our GTest based unit tests. By default, CMake will look in /usr/src/gtest for the external GTest project, but this can be overriden by defining GTEST_ROOT when invoking cmake. Gbp-Dch: ignore --- test/CMakeLists.txt | 1 + test/libapt/CMakeLists.txt | 22 ++++++++++++++++++++++ test/libapt/fileutl_test.cc | 2 +- test/libapt/hashsums_test.cc | 14 +++++++------- 4 files changed, 31 insertions(+), 8 deletions(-) create mode 100644 test/libapt/CMakeLists.txt (limited to 'test') diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 599f62aff..2f47b5c32 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1 +1,2 @@ +add_subdirectory(libapt) add_subdirectory(interactive-helper) diff --git a/test/libapt/CMakeLists.txt b/test/libapt/CMakeLists.txt new file mode 100644 index 000000000..7f9990526 --- /dev/null +++ b/test/libapt/CMakeLists.txt @@ -0,0 +1,22 @@ +include(ExternalProject) + +set(GTEST_ROOT "/usr/src/gtest" CACHE FILEPATH "Path to GTest CMake project") + +message(STATUS "Found GTest at ${GTEST_ROOT}") + +if (EXISTS ${GTEST_ROOT}) + +ExternalProject_Add(gtest PREFIX ./gtest + SOURCE_DIR ${GTEST_ROOT} + INSTALL_COMMAND true) + +link_directories(${CMAKE_CURRENT_BINARY_DIR}/gtest/src/gtest-build) +FILE(GLOB files gtest_runner.cc *-helpers.cc *_test.cc) +add_executable(libapt_test ${files}) +target_link_libraries(libapt_test -lgtest ${CMAKE_THREAD_LIBS_INIT} apt-private apt-inst) +add_dependencies(libapt_test gtest) +add_test(NAME AptTests + COMMAND libapt_test + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) + +endif() diff --git a/test/libapt/fileutl_test.cc b/test/libapt/fileutl_test.cc index 0a299b51a..67bd850a1 100644 --- a/test/libapt/fileutl_test.cc +++ b/test/libapt/fileutl_test.cc @@ -216,7 +216,7 @@ TEST(FileUtlTest, Glob) { std::vector files; // normal match - files = Glob("*akefile"); + files = Glob("*MakeLists.txt"); EXPECT_EQ(1, files.size()); // not there diff --git a/test/libapt/hashsums_test.cc b/test/libapt/hashsums_test.cc index 705c0297d..fb9a25643 100644 --- a/test/libapt/hashsums_test.cc +++ b/test/libapt/hashsums_test.cc @@ -119,7 +119,7 @@ static void getSummationString(char const * const type, std::string &sum) FileFd fd; ASSERT_TRUE(fd.Open(tempfile, FileFd::WriteOnly | FileFd::Empty, compress)); ASSERT_TRUE(fd.IsOpen()); - FileFd input(__FILE__, FileFd::ReadOnly); + FileFd input("/etc/os-release", FileFd::ReadOnly); ASSERT_TRUE(input.IsOpen()); ASSERT_NE(0, input.FileSize()); ASSERT_TRUE(CopyFile(input, fd)); @@ -161,7 +161,7 @@ TEST(HashSumsTest, FileBased) SHA512SumValue sha512(summation); EXPECT_EQ(sha512.Value(), summation); - FileFd fd(__FILE__, FileFd::ReadOnly); + FileFd fd("/etc/os-release", FileFd::ReadOnly); EXPECT_TRUE(fd.IsOpen()); std::string FileSize; strprintf(FileSize, "%llu", fd.FileSize()); @@ -243,18 +243,18 @@ TEST(HashSumsTest, FileBased) fd.Close(); HashString sha2file("SHA512", sha512.Value()); - EXPECT_TRUE(sha2file.VerifyFile(__FILE__)); + EXPECT_TRUE(sha2file.VerifyFile("/etc/os-release")); HashString sha2wrong("SHA512", "00000000000"); - EXPECT_FALSE(sha2wrong.VerifyFile(__FILE__)); + EXPECT_FALSE(sha2wrong.VerifyFile("/etc/os-release")); EXPECT_EQ(sha2file, sha2file); EXPECT_TRUE(sha2file == sha2file); EXPECT_NE(sha2file, sha2wrong); EXPECT_TRUE(sha2file != sha2wrong); HashString sha2big("SHA256", sha256.Value()); - EXPECT_TRUE(sha2big.VerifyFile(__FILE__)); + EXPECT_TRUE(sha2big.VerifyFile("/etc/os-release")); HashString sha2small("sha256:" + sha256.Value()); - EXPECT_TRUE(sha2small.VerifyFile(__FILE__)); + EXPECT_TRUE(sha2small.VerifyFile("/etc/os-release")); EXPECT_EQ(sha2big, sha2small); EXPECT_TRUE(sha2big == sha2small); EXPECT_FALSE(sha2big != sha2small); @@ -283,7 +283,7 @@ TEST(HashSumsTest, FileBased) EXPECT_EQ(2, hashes.size()); EXPECT_FALSE(hashes.push_back(sha2wrong)); EXPECT_EQ(2, hashes.size()); - EXPECT_TRUE(hashes.VerifyFile(__FILE__)); + EXPECT_TRUE(hashes.VerifyFile("/etc/os-release")); EXPECT_EQ(similar, hashes); EXPECT_TRUE(similar == hashes); -- cgit v1.2.3 From c85c4bed0a4b32ee2dcbd86ea819e39f3d8beb84 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 9 Aug 2016 17:40:01 +0200 Subject: Get rid of the old buildsystem Bye, bye, old friend. --- test/Makefile | 16 -------- test/integration/makefile | 10 ----- test/interactive-helper/makefile | 53 ------------------------- test/libapt/makefile | 84 ---------------------------------------- 4 files changed, 163 deletions(-) delete mode 100644 test/Makefile delete mode 100644 test/integration/makefile delete mode 100644 test/interactive-helper/makefile delete mode 100644 test/libapt/makefile (limited to 'test') diff --git a/test/Makefile b/test/Makefile deleted file mode 100644 index 35a0a51e3..000000000 --- a/test/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -# -*- make -*- - -# This is the top level test makefile for APT, it recurses to each lower -# level make file and runs it with the proper target -ifndef NOISY -.SILENT: -endif - -.PHONY: startup headers library clean veryclean all binary program doc test update-po -startup all clean veryclean binary program dirs test update-po manpages docbook: - $(MAKE) -C libapt $@ - $(MAKE) -C interactive-helper $@ - -# Some very common aliases -.PHONY: maintainer-clean dist-clean distclean pristine sanity -maintainer-clean dist-clean distclean pristine sanity: veryclean diff --git a/test/integration/makefile b/test/integration/makefile deleted file mode 100644 index fb12fe9a8..000000000 --- a/test/integration/makefile +++ /dev/null @@ -1,10 +0,0 @@ -# -*- make -*- -BASE=../.. -SUBDIR=test/integration - -# Bring in the default rules -include ../../buildlib/defaults.mak - -.PHONY: test -test: - ./run-tests diff --git a/test/interactive-helper/makefile b/test/interactive-helper/makefile deleted file mode 100644 index 096767c41..000000000 --- a/test/interactive-helper/makefile +++ /dev/null @@ -1,53 +0,0 @@ -# -*- make -*- -BASE=../.. -SUBDIR=test/interactive-helper -APT_DOMAIN=none - -# Bring in the default rules -include ../../buildlib/defaults.mak - -# Program for testing methods -PROGRAM=mthdcat -SLIBS = -SOURCE = mthdcat.cc -include $(PROGRAM_H) - -# Program for testing the tar/deb extractor -PROGRAM=testdeb -SLIBS = -lapt-pkg -lapt-inst -LIB_MAKES = apt-pkg/makefile apt-inst/makefile -SOURCE = testdeb.cc -include $(PROGRAM_H) - -# Program for testing tar extraction -PROGRAM=extract-control -SLIBS = -lapt-pkg -lapt-inst -LIB_MAKES = apt-pkg/makefile apt-inst/makefile -SOURCE = extract-control.cc -include $(PROGRAM_H) - -# Program for testing udevcdrom -PROGRAM=test_udevcdrom -SLIBS = -lapt-pkg -LIB_MAKES = apt-pkg/makefile -SOURCE = test_udevcdrom.cc -include $(PROGRAM_H) - -PROGRAM=test_fileutl -SLIBS = -lapt-pkg -LIB_MAKES = apt-pkg/makefile -SOURCE = test_fileutl.cc -include $(PROGRAM_H) - -# Program for checking rpm versions -#PROGRAM=rpmver -#SLIBS = -lapt-pkg -lrpm -#SOURCE = rpmver.cc -#include $(PROGRAM_H) - -# very simple webserver for APT testing -PROGRAM=aptwebserver -SLIBS = -lapt-pkg -lpthread -LIB_MAKES = apt-pkg/makefile -SOURCE = aptwebserver.cc -include $(PROGRAM_H) diff --git a/test/libapt/makefile b/test/libapt/makefile deleted file mode 100644 index 5ff9cf68a..000000000 --- a/test/libapt/makefile +++ /dev/null @@ -1,84 +0,0 @@ -# -*- make -*- -BASE=../.. -SUBDIR=test/libapt -BASENAME=_libapt_test -APT_DOMAIN=none - -# Bring in the default rules -include ../../buildlib/defaults.mak - -.PHONY: test -ifeq (file-okay,$(shell $(CC) -I $(BASE)/build/include -M gtest_runner.cc >/dev/null 2>&1 && echo 'file-okay')) -test: $(BIN)/gtest$(BASENAME) - MALLOC_PERTURB_=21 MALLOC_CHECK_=2 LD_LIBRARY_PATH=$(LIB) $(BIN)/gtest$(BASENAME) - -$(BIN)/gtest$(BASENAME): $(LIB)/gtest.a - -PROGRAM = gtest${BASENAME} -SLIBS = -lapt-pkg -lapt-private -lapt-inst -pthread $(LIB)/gtest.a -LIB_MAKES = apt-pkg/makefile apt-private/makefile apt-inst/makefile -SOURCE = gtest_runner.cc $(wildcard *-helpers.cc *_test.cc) -include $(PROGRAM_H) - - -MKDIRS += $(OBJ) $(LIB) -LOCAL=gtest -SOURCE=gtest-all -gtest-OBJS := $(addprefix $(OBJ)/,$(addsuffix .o,$(SOURCE))) - -# The rest of the file is based on the example found in -# /usr/share/doc/libgtest-dev/examples/make/Makefile -GTEST_DIR = /usr/src/gtest - -# Flags passed to the preprocessor. -# Set Google Test's header directory as a system directory, such that -# the compiler doesn't generate warnings in Google Test headers. -#CPPFLAGS += -isystem $(GTEST_DIR)/include - -# Flags passed to the C++ compiler. -CXXFLAGS += -pthread -# disable some flags for gtest again -CXXFLAGS+= -Wno-missing-declarations -CXXFLAGS+= -Wno-missing-field-initializers -CXXFLAGS+= -Wno-suggest-attribute=pure -Wno-suggest-attribute=const -Wno-suggest-attribute=noreturn -CXXFLAGS+= -Wno-undef - -# All Google Test headers. Usually you shouldn't change this definition. -GTEST_HEADERS = /usr/include/gtest/*.h \ - /usr/include/gtest/internal/*.h - -# House-keeping build targets. -.PHONY: clean/gtest veryclean/gtest -clean: clean/gtest -clean/gtest: - rm -f $(gtest-OBJS) -veryclean: veryclean/gtest -veryclean/gtest: clean/gtest - rm -f $(LIB)/gtest.a - -# Usually you shouldn't tweak such internal variables, indicated by a -# trailing _. -GTEST_SRCS_ = $(GTEST_DIR)/src/*.cc $(GTEST_DIR)/src/*.h $(GTEST_HEADERS) - -# Builds gtest.a -# For simplicity and to avoid depending on Google Test's -# implementation details, the dependencies specified below are -# conservative and not optimized. This is fine as Google Test -# compiles fast and for ordinary users its source rarely changes. -$(gtest-OBJS): $(GTEST_SRCS_) - echo Compiling $@ - $(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c -o $@ $(GTEST_DIR)/src/$(notdir $(basename $@)).cc - -$(LIB)/gtest.a: $(OBJ)/gtest-all.o - echo Building static library $@ - -rm -f $@ - $(AR) $(ARFLAGS) $@ $^ - -else -test: - @echo "APT uses Googles C++ testing framework for its unit tests" - @echo "On Debian systems this is available in the 'libgtest-dev' package." - @echo "Please install it before attempting to run the unit tests." - $(CC) -I $(BASE)/build/include -M gtest_runner.cc - exit 100 -endif -- cgit v1.2.3 From 61fef4ddbec8f70bb9e213ac0491d4e6cfefab30 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Wed, 10 Aug 2016 14:16:52 +0200 Subject: test: Automatically discover CMake build directory Look at the project root, and all directories directly below it and pick the directory with the newest CMakeCache.txt file. Gbp-Dch: ignore --- test/integration/framework | 22 +++++++++++++++++++++- test/integration/run-tests | 6 ++++++ 2 files changed, 27 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/integration/framework b/test/integration/framework index 824bd46b6..0f442dff4 100644 --- a/test/integration/framework +++ b/test/integration/framework @@ -257,6 +257,24 @@ escape_shell() { echo "$@" | sed -e "s#'#'\"'\"'#g" } +find_project_binary_dir() { + local TESTDIRECTORY="$(readlink -f "$(dirname $0)")" + if [ -z "$PROJECT_BINARY_DIR" ]; then + PROJECT_BINARY_DIR= + for dir in ${TESTDIRECTORY}/../../ ${TESTDIRECTORY}/../../*; do + test -e "$dir/CMakeCache.txt" || continue + if [ -z "$PROJECT_BINARY_DIR" ] || + [ "$dir/CMakeCache.txt" -nt "$PROJECT_BINARY_DIR/CMakeCache.txt" ]; then + PROJECT_BINARY_DIR="$dir" + fi + done + if [ -z "$PROJECT_BINARY_DIR" ]; then + echo "Cannot find build directory, you might want to set PROJECT_BINARY_DIR" >&2 + exit 1 + fi + export PROJECT_BINARY_DIR + fi +} setupenvironment() { # privilege dropping and testing doesn't work if /tmp isn't world-writeable (as e.g. with libpam-tmpdir) if [ -n "$TMPDIR" ] && [ "$(id -u)" = '0' ] && [ "$(stat --format '%a' "$TMPDIR")" != '1777' ]; then @@ -281,9 +299,11 @@ setupenvironment() { fi TESTDIRECTORY="$(readlink -f "$(dirname $0)")" + # Find the newest build directory (sets PROJECT_BINARY_DIR) + find_project_binary_dir # allow overriding the default BUILDDIR location SOURCEDIRECTORY="${APT_INTEGRATION_TESTS_SOURCE_DIR:-"${TESTDIRECTORY}/../../"}" - BUILDDIRECTORY="${APT_INTEGRATION_TESTS_BUILD_DIR:-"${TESTDIRECTORY}/../../build/cmdline"}" + 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}"}" diff --git a/test/integration/run-tests b/test/integration/run-tests index 78f24fbaf..e90b4b755 100755 --- a/test/integration/run-tests +++ b/test/integration/run-tests @@ -1,4 +1,10 @@ #!/bin/sh + +TESTDIR="$(readlink -f "$(dirname "$0")")" +. "$TESTDIR/framework" + +find_project_binary_dir + set -e TESTTORUN='' -- cgit v1.2.3