diff --git a/Makefile b/Makefile index aa2419d..c9c5586 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,7 @@ CLEAN_DIRS += clean-$(UNITTEST_DIR) .PHONY: all install uninstall clean check unit .PHONY: $(SUBDIRS) $(BUILD_DIRS) $(INSTALL_DIRS) $(CLEAN_DIRS) .PHONY: integration integration-slow integration-quick +.PHONY: vagrant-integration-slow vagrant-integration-quick vagrant-integration all: $(BUILD_DIRS) @@ -42,5 +43,13 @@ integration-slow: $(INTEGRATION_DIR)/Makefile build-kpatch-build build-kpatch bu integration-quick: $(INTEGRATION_DIR)/Makefile build-kpatch-build build-kpatch build-kmod $(MAKE) -C $(INTEGRATION_DIR) quick +vagrant-integration: vagrant-integration-quick + +vagrant-integration-slow: + $(MAKE) -C $(INTEGRATION_DIR) vagrant-slow + +vagrant-integration-quick: + $(MAKE) -C $(INTEGRATION_DIR) vagrant-quick + check: shellcheck kpatch/kpatch kpatch-build/kpatch-build kpatch-build/kpatch-gcc diff --git a/test/integration/Makefile b/test/integration/Makefile index a1abff6..7ecad9c 100644 --- a/test/integration/Makefile +++ b/test/integration/Makefile @@ -18,6 +18,14 @@ quick: clean cached: ./kpatch-test -d $(PATCH_DIR) --cached $(PATCHES) +vagrant: vagrant_quick + +vagrant-quick: + ./test-vagrant + +vagrant-slow: + ./test-vagrant --slow + clean: rm -f *.ko *.log COMBINED.patch diff --git a/test/integration/lib.sh b/test/integration/lib.sh index 74e4842..ebdb002 100644 --- a/test/integration/lib.sh +++ b/test/integration/lib.sh @@ -248,3 +248,53 @@ kpatch_write_vagrantfile() echo 'end' >>Vagrantfile } + +kpatch_integration_tests_vagrant_distro() +{ + local target_distro=${1} + local test_script=${2} + local slowtest=${3} + + local testdir + local workdir + local logdir + + testdir="$(pwd)" + workdir="${target_distro}.vagrant" + rm -rf "${workdir}" + mkdir -p "${workdir}" + cd "${workdir}" || exit 1 + + kpatch_write_vagrantfile "${target_distro}" + + vagrant up || { vagrant destroy -f; exit 1; } + + local test_cmd="bash /vagrant/runtest.sh" + if [ "${slowtest}" == "1" ]; then + test_cmd="${test_cmd} --slow" + fi + + cp "${test_script}" ./runtest.sh + vagrant ssh -c "${test_cmd}" + local rc=$? + + if [ $rc -eq 0 ]; then + echo "${target_distro} PASS" + else + echo "${target_distro} FAIL" + fi + + logdir="${testdir}/${target_distro}_log" + rm -rf "${logdir}" + mkdir -p "${logdir}" + cp logs/* "${logdir}" + + vagrant destroy -f + + cd "${testdir}" || exit 1 + if [ $rc -eq 0 ]; then + rm -rf "${workdir}" + fi + + return "${rc}" +} diff --git a/test/integration/test-vagrant b/test/integration/test-vagrant new file mode 100755 index 0000000..d946681 --- /dev/null +++ b/test/integration/test-vagrant @@ -0,0 +1,42 @@ +#!/bin/bash + +SCRIPTDIR=$(readlink -f "$(dirname "$(type -p "${0}")")") +ROOTDIR=$(readlink -f "${SCRIPTDIR}/../..") +SLOWTEST=0 + +# shellcheck disable=SC1090 +source "${ROOTDIR}/test/integration/lib.sh" + +usage() +{ + echo "usage: $(basename "${0}") [options]" >&2 + echo "-h, --help This message" >&2 + echo "-s, --slow Run all of the tests" >&2 +} + +options="$(getopt -o hs -l "help,slow" -- "$@")" || "getopt failed" + +eval set -- "${options}" + +while [[ $# -gt 0 ]]; do + case "$1" in + -s|--slow) + SLOWTEST=1 + ;; + -h|--help) + usage + exit 0 + ;; + esac + shift +done + +declare -a distros=("fedora27" "ubuntu1604" "centos7") + +ret=0 +for distro in "${distros[@]}"; do + kpatch_integration_tests_vagrant_distro "${distro}" "${ROOTDIR}/test/integration/vm-integration-run" "${SLOWTEST}" + rc=$? + ret=$((ret + rc)) +done +exit ${ret} diff --git a/test/integration/vm-integration-run b/test/integration/vm-integration-run new file mode 100755 index 0000000..3c905da --- /dev/null +++ b/test/integration/vm-integration-run @@ -0,0 +1,52 @@ +#!/bin/bash + +KPATCH_SLOW=0 +LOGDIR="/vagrant/logs" + +usage() +{ + echo "usage: $(basename "${0}") [options]" >&2 + echo "-h, --help This message" >&2 + echo "-s, --slow Run all of the tests" >&2 +} + +options="$(getopt -o s -l "slow" -- "$@")" || "getopt failed" + +eval set -- "${options}" + +while [[ $# -gt 0 ]]; do + case "$1" in + -s|--slow) + KPATCH_SLOW=1 + ;; + -h|--help) + usage + exit 0 + ;; + esac + shift +done + +git clone https://github.com/dynup/kpatch.git || exit 1 + +cd kpatch || exit 1 + +# shellcheck disable=SC1091 +source test/integration/lib.sh + +kpatch_dependencies +kpatch_separate_disk_cache /dev/vdb /mnt/build +kpatch_set_ccache_max_size 10G + +if [ ${KPATCH_SLOW} -eq 1 ]; then + make integration-slow 2>&1 +else + make integration-quick 2>&1 +fi + +rc=${PIPESTATUS[0]} +rm -rf "${LOGDIR}" +mkdir -p "${LOGDIR}" +cp ./test/integration/*.log "${LOGDIR}" + +exit "${rc}"