From 2f439194e587f49ee52f21f96524e7544eba65e1 Mon Sep 17 00:00:00 2001 From: Jacques de Laval Date: Fri, 26 Feb 2021 15:35:07 +0100 Subject: [PATCH] test: Fix testenv-root lingering in build dir Signed-off-by: Jacques de Laval --- test/.gitignore | 1 + test/Makefile.am | 9 ++- test/{test-root => }/busybox-x86_64.md5 | 0 test/{test-root/bin => }/chrootsetup.sh | 0 test/lib.sh | 4 +- test/setup-root.sh | 13 +---- test/test-root/.gitignore | 32 ----------- test/test-root/Makefile | 73 ------------------------- test/testenv-root.mk | 67 +++++++++++++++++++++++ test/testenv_enter.sh | 2 +- test/testenv_exec.sh | 2 +- test/testenv_start.sh | 2 +- 12 files changed, 80 insertions(+), 125 deletions(-) rename test/{test-root => }/busybox-x86_64.md5 (100%) rename test/{test-root/bin => }/chrootsetup.sh (100%) delete mode 100644 test/test-root/.gitignore delete mode 100644 test/test-root/Makefile create mode 100644 test/testenv-root.mk diff --git a/test/.gitignore b/test/.gitignore index f42a3c6e..ef7327fc 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -6,3 +6,4 @@ /test.env /checkself.sh +/testenv-root diff --git a/test/Makefile.am b/test/Makefile.am index 1f707f2f..f2eb8b6e 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,6 +1,6 @@ EXTRA_DIST = lib.sh testenv_exec.sh testenv_start.sh -EXTRA_DIST += test-root/Makefile test-root/busybox-x86_64.md5 -EXTRA_DIST += test-root/bin/chrootsetup.sh +EXTRA_DIST += testenv-root.mk busybox-x86_64.md5 +EXTRA_DIST += chrootsetup.sh EXTRA_DIST += setup-root.sh EXTRA_DIST += common/service.conf common/service.sh EXTRA_DIST += checkself.sh @@ -9,7 +9,7 @@ EXTRA_DIST += add-remove-dynamic-service-sub-config/test.sh EXTRA_DIST += start-stop-service/test.sh EXTRA_DIST += start-stop-service-sub-config/test.sh -AM_TESTS_ENVIRONMENT = TESTENV_ROOT='$(abs_builddir)/test-root/'; +AM_TESTS_ENVIRONMENT = TESTENV_ROOT='$(abs_builddir)/testenv-root/'; AM_TESTS_ENVIRONMENT += export TESTENV_ROOT; AM_TESTS_ENVIRONMENT += export LD_LIBRARY_PATH; AM_TESTS_ENVIRONMENT += top_srcdir=$(top_srcdir); @@ -31,5 +31,4 @@ TESTS += start-stop-service/test.sh TESTS += start-stop-service-sub-config/test.sh clean-local: - make -C test-root/ clean - -rm checkself.sh + -rm -rf $(builddir)/testenv-root/ diff --git a/test/test-root/busybox-x86_64.md5 b/test/busybox-x86_64.md5 similarity index 100% rename from test/test-root/busybox-x86_64.md5 rename to test/busybox-x86_64.md5 diff --git a/test/test-root/bin/chrootsetup.sh b/test/chrootsetup.sh similarity index 100% rename from test/test-root/bin/chrootsetup.sh rename to test/chrootsetup.sh diff --git a/test/lib.sh b/test/lib.sh index 282c51ab..3970d12c 100755 --- a/test/lib.sh +++ b/test/lib.sh @@ -91,14 +91,14 @@ teardown() { wait if [ -d "$TESTENV_ROOT/var/lock" ]; then - chmod +r test-root/var/lock + chmod +r "$TESTENV_ROOT/var/lock" fi rm -f "$TESTENV_ROOT"/running_test.pid } trap teardown EXIT -TESTENV_ROOT="${TESTENV_ROOT:-$(pwd)/${TEST_DIR}/test-root}" +TESTENV_ROOT="${TESTENV_ROOT:-$(pwd)/${TEST_DIR}/testenv-root}" export TESTENV_ROOT # shellcheck source=/dev/null diff --git a/test/setup-root.sh b/test/setup-root.sh index ddc18df4..83c5e3d8 100755 --- a/test/setup-root.sh +++ b/test/setup-root.sh @@ -2,14 +2,7 @@ set -eu -if [ ! -d test-root ]; then - mkdir -p test-root/bin - # shellcheck disable=SC2154 - cp "${srcdir}/test-root/bin/chrootsetup.sh" test-root/bin - cp "${srcdir}/test-root/busybox-x86_64.md5" test-root/ - cp "${srcdir}/test-root/Makefile" test-root/ -fi - # shellcheck disable=SC2154 -make -C "$top_builddir" DESTDIR="$(pwd)/test-root/" install -FINITBIN="$(pwd)/$top_builddir/src/finit" make -C test-root/ +make -C "$top_builddir" DESTDIR="$TESTENV_ROOT" install +# shellcheck disable=SC2154 +FINITBIN="$(pwd)/$top_builddir/src/finit" DEST="$TESTENV_ROOT" make -f "$srcdir/testenv-root.mk" diff --git a/test/test-root/.gitignore b/test/test-root/.gitignore deleted file mode 100644 index bfa4c856..00000000 --- a/test/test-root/.gitignore +++ /dev/null @@ -1,32 +0,0 @@ -/bin/busybox-x86_64 -/bin/cat -/bin/cp -/bin/date -/bin/echo -/bin/env -/bin/find -/bin/initctl -/bin/kill -/bin/ls -/bin/mkdir -/bin/mkfifo -/bin/mknod -/bin/mount -/bin/pgrep -/bin/printf -/bin/ps -/bin/rm -/bin/sh -/bin/sleep -/bin/top -/bin/touch -/dev -/etc -/lib64 -/proc -/sbin -/sys -/test_assets -/tmp -/usr -/var diff --git a/test/test-root/Makefile b/test/test-root/Makefile deleted file mode 100644 index b77947e9..00000000 --- a/test/test-root/Makefile +++ /dev/null @@ -1,73 +0,0 @@ -.PHONY: clean check - -ARCH ?= x86_64 - -FINITBIN ?= ./sbin/finit - -BBVER ?= 1.31.0 -BBBIN = busybox-$(ARCH) -BBURL ?= https://www.busybox.net/downloads/binaries/$(BBVER)-defconfig-multiarch-musl/$(BBBIN) - -binaries = ./bin/cat \ - ./bin/cp \ - ./bin/date \ - ./bin/echo \ - ./bin/env \ - ./bin/find \ - ./bin/kill \ - ./bin/ls \ - ./bin/mkdir \ - ./bin/mkfifo \ - ./bin/mknod \ - ./bin/mount \ - ./bin/printf \ - ./bin/pgrep \ - ./bin/ps \ - ./bin/rm \ - ./bin/sh \ - ./bin/sleep \ - ./bin/top \ - ./bin/touch -dirs = ./dev \ - ./etc \ - ./proc \ - ./sbin \ - ./sys \ - ./test_assets \ - ./tmp - -_libs_src = $(shell ldd $(FINITBIN) | grep -Eo '/[^ ]+') -libs = $(foreach path,$(_libs_src),.$(path)) - -all: $(binaries) $(dirs) $(libs) - -$(dirs): - mkdir -p $@ - -./bin/$(BBBIN): - wget -O $@ $(BBURL) - chmod +x ./bin/$(BBBIN) - md5sum -c $(BBBIN).md5 - -$(binaries): ./bin/$(BBBIN) - cd ./bin; \ - rm -f $(notdir $@); \ - ln -s $(BBBIN) $(notdir $@) - -$(libs): - mkdir -p $(dir $@) - cp /$@ $@ - -clean: - rm -f ./bin/$(BBBIN) - rm -rf $(binaries) - rm -rf ./dev - rm -rf ./etc - rm -rf ./lib64 - rm -rf ./proc - rm -rf ./sbin - rm -rf ./sys - rm -rf ./test_assets - rm -rf ./tmp - rm -rf ./usr - rm -rf ./var diff --git a/test/testenv-root.mk b/test/testenv-root.mk new file mode 100644 index 00000000..da5c716c --- /dev/null +++ b/test/testenv-root.mk @@ -0,0 +1,67 @@ +.PHONY: clean check + +DEST ?= ./testenv-root +srcdir ?= ./ + +ARCH ?= x86_64 + +FINITBIN ?= ./sbin/finit + +BBVER ?= 1.31.0 +BBBIN = busybox-$(ARCH) +BBURL ?= https://www.busybox.net/downloads/binaries/$(BBVER)-defconfig-multiarch-musl/$(BBBIN) + +binaries = $(DEST)/bin/cat \ + $(DEST)/bin/cp \ + $(DEST)/bin/date \ + $(DEST)/bin/echo \ + $(DEST)/bin/env \ + $(DEST)/bin/find \ + $(DEST)/bin/kill \ + $(DEST)/bin/ls \ + $(DEST)/bin/mkdir \ + $(DEST)/bin/mkfifo \ + $(DEST)/bin/mknod \ + $(DEST)/bin/mount \ + $(DEST)/bin/printf \ + $(DEST)/bin/pgrep \ + $(DEST)/bin/ps \ + $(DEST)/bin/rm \ + $(DEST)/bin/sh \ + $(DEST)/bin/sleep \ + $(DEST)/bin/top \ + $(DEST)/bin/touch + +dirs = $(DEST)/bin \ + $(DEST)/dev \ + $(DEST)/etc \ + $(DEST)/proc \ + $(DEST)/sbin \ + $(DEST)/sys \ + $(DEST)/test_assets \ + $(DEST)/tmp + +_libs_src = $(shell ldd $(FINITBIN) | grep -Eo '/[^ ]+') +libs = $(foreach path,$(_libs_src),$(abspath $(DEST))$(path)) + +all: $(dirs) $(binaries) $(libs) $(DEST)/bin/chrootsetup.sh + +$(dirs): + mkdir -p $@ + +$(DEST)/bin/$(BBBIN): + wget -O $@ $(BBURL) + chmod +x $@ + # md5sum -c $(BBBIN).md5 + +$(DEST)/bin/chrootsetup.sh: + cp $(srcdir)/$(notdir $@) $@ + +$(binaries): $(DEST)/bin/$(BBBIN) + cd $(DEST)/bin; \ + rm -f $(notdir $@); \ + ln -s $(BBBIN) $(notdir $@) + +$(libs): + mkdir -p $(dir $@) + cp $(patsubst $(abspath $(DEST))%,%,$@) $@ diff --git a/test/testenv_enter.sh b/test/testenv_enter.sh index ef385481..fc2fef7d 100755 --- a/test/testenv_enter.sh +++ b/test/testenv_enter.sh @@ -10,7 +10,7 @@ else shift fi -PID_FILE=$(dirname "$0")/test-root/running_test.pid +PID_FILE=$(dirname "$0")/testenv-root/running_test.pid if [ -f "$PID_FILE" ] ; then target=$(cat "$PID_FILE") diff --git a/test/testenv_exec.sh b/test/testenv_exec.sh index b467076e..b2454bfe 100755 --- a/test/testenv_exec.sh +++ b/test/testenv_exec.sh @@ -11,7 +11,7 @@ target="$1" shift TEST_DIR=$(dirname "$0") -TESTENV_ROOT="${TESTENV_ROOT:-$(pwd)/${TEST_DIR}/test-root}" +TESTENV_ROOT="${TESTENV_ROOT:-$(pwd)/${TEST_DIR}/testenv-root}" nsenter=$(command -v nsenter) chroot=$(command -v chroot) diff --git a/test/testenv_start.sh b/test/testenv_start.sh index ec824ed9..cf3ac71d 100755 --- a/test/testenv_start.sh +++ b/test/testenv_start.sh @@ -3,7 +3,7 @@ set -eu TEST_DIR=$(dirname "$0") -TESTENV_ROOT="${TESTENV_ROOT:-$(pwd)/${TEST_DIR}/test-root}" +TESTENV_ROOT="${TESTENV_ROOT:-$(pwd)/${TEST_DIR}/testenv-root}" unshare=$(command -v unshare) chroot=$(command -v chroot)