From 11841ceb5d0be9df7cb2642a326fc2b11a3b8c1c Mon Sep 17 00:00:00 2001 From: Jacques de Laval Date: Mon, 22 Feb 2021 22:07:17 +0100 Subject: [PATCH] test: Clean up Automake integration of tests Signed-off-by: Jacques de Laval --- .travis.yml | 5 +- Makefile.am | 5 +- configure.ac | 3 +- test/.gitignore | 4 +- test/Makefile | 88 ------------------------- test/Makefile.am | 6 ++ test/busybox-x86_64.md5 | 1 - test/checkself.sh | 6 ++ test/test_root/.gitignore | 23 ++++++- test/test_root/Makefile | 79 ++++++++++++++++++++++ test/{ => test_root/bin}/chrootsetup.sh | 0 test/test_root/busybox-x86_64.md5 | 1 + 12 files changed, 123 insertions(+), 98 deletions(-) delete mode 100644 test/Makefile create mode 100644 test/Makefile.am delete mode 100644 test/busybox-x86_64.md5 create mode 100755 test/checkself.sh create mode 100644 test/test_root/Makefile rename test/{ => test_root/bin}/chrootsetup.sh (100%) create mode 100644 test/test_root/busybox-x86_64.md5 diff --git a/.travis.yml b/.travis.yml index 433c487c..2c669b40 100644 --- a/.travis.yml +++ b/.travis.yml @@ -52,6 +52,8 @@ script: - cat config.log - make clean - make V=1 -j5 + - LD_LIBRARY_PATH=/tmp/lib make check + - cat ./test/test-suite.log - make install-strip - tree /tmp - ldd /tmp/sbin/finit @@ -63,5 +65,4 @@ script: - nsenter -V - chroot --version - LD_LIBRARY_PATH=/tmp/lib make check - - cat ./test-suite.log - - make -C test/ clean + - cat ./test/test-suite.log diff --git a/Makefile.am b/Makefile.am index 20ebb66e..a1ccda65 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,5 +1,5 @@ ACLOCAL_AMFLAGS = -I m4 -SUBDIRS = plugins src +SUBDIRS = plugins src test doc_DATA = README.md LICENSE contrib/finit.conf EXTRA_DIST = README.md LICENSE ChangeLog.md contrib/finit.conf @@ -10,9 +10,6 @@ if DOC SUBDIRS += doc endif -AM_TESTS_ENVIRONMENT = make -C $(srcdir)/test test_root; -TESTS = test/test_start_stop_service/test.sh - # Compat hook install-dev: @make -C src install-pkgincludeHEADERS diff --git a/configure.ac b/configure.ac index 6a1c7f85..beeac4e7 100644 --- a/configure.ac +++ b/configure.ac @@ -11,7 +11,8 @@ AC_CONFIG_FILES([Makefile contrib/void/Makefile contrib/void/finit.d/Makefile contrib/void/finit.d/available/Makefile doc/Makefile plugins/Makefile - src/Makefile]) + src/Makefile + test/Makefile]) # Older versions of autoconf (<2.58) do not have AC_CONFIG_MACRO_DIR() #m4_include([m4/plugin.m4]) diff --git a/test/.gitignore b/test/.gitignore index a447bd04..151cdadf 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -1,3 +1,5 @@ -busybox-x86_64 +# GNU configure and build system *.log *.trs +/Makefile +/Makefile.in diff --git a/test/Makefile b/test/Makefile deleted file mode 100644 index 0b047a97..00000000 --- a/test/Makefile +++ /dev/null @@ -1,88 +0,0 @@ -.PHONY: clean check test-check - -ARCH ?= x86_64 - -FINITBIN ?= ../src/finit -INITCTLBIN ?= ../src/initctl - -BBVER ?= 1.31.0 -BBBIN = busybox-$(ARCH) -BBURL ?= https://www.busybox.net/downloads/binaries/$(BBVER)-defconfig-multiarch-musl/$(BBBIN) - -testroot = test_root -testroot_bin = $(testroot)/bin -binaries = $(testroot_bin)/cat \ - $(testroot_bin)/cp \ - $(testroot_bin)/date \ - $(testroot_bin)/echo \ - $(testroot_bin)/env \ - $(testroot_bin)/find \ - $(testroot_bin)/kill \ - $(testroot_bin)/ls \ - $(testroot_bin)/mkdir \ - $(testroot_bin)/mkfifo \ - $(testroot_bin)/mknod \ - $(testroot_bin)/mount \ - $(testroot_bin)/printf \ - $(testroot_bin)/pgrep \ - $(testroot_bin)/ps \ - $(testroot_bin)/rm \ - $(testroot_bin)/sh \ - $(testroot_bin)/sleep \ - $(testroot_bin)/top \ - $(testroot_bin)/touch -dirs = $(testroot)/bin \ - $(testroot)/dev \ - $(testroot)/etc \ - $(testroot)/proc \ - $(testroot)/sbin \ - $(testroot)/sys \ - $(testroot)/tmp - -_libs_src = $(shell ldd $(FINITBIN) | grep -Eo '/[^ ]+') -libs = $(foreach path,$(_libs_src),$(testroot)$(path)) - -all: check - -$(dirs): - mkdir -p $@ - -$(BBBIN): - wget -O $@ $(BBURL) - md5sum -c $@.md5 - -$(testroot): $(binaries) $(testroot_bin)/chrootsetup.sh $(dirs) $(testroot)/sbin/finit $(testroot)/bin/initctl test-check - -$(testroot_bin)/$(BBBIN): $(BBBIN) - mkdir -p $(testroot_bin) - cp $(BBBIN) $(testroot_bin)/ - chmod +x $(testroot_bin)/$(BBBIN) - -$(binaries): $(testroot_bin)/$(BBBIN) - cd $(testroot_bin); \ - ln -s $(BBBIN) $(notdir $@) - -$(testroot_bin)/chrootsetup.sh: chrootsetup.sh - cp $< $@ - -$(testroot)/sbin/finit: $(FINITBIN) $(libs) - cp $< $@ - -$(testroot)/bin/initctl: $(INITCTLBIN) $(libs) - cp $< $@ - -$(libs): - mkdir -p $(dir $@) - cp $(shell echo $@ | sed s/^$(testroot)//) $@ - -check: $(testroot) - ./test_start_stop_service/test.sh - -test-check: - shellcheck $(shell find . -name '*.sh') - -clean: - rm -rf $(testroot)/* - rm -f $(BBBIN) - rm -f ./test_start_stop_service/*.log - rm -f ./test_start_stop_service/*.trs diff --git a/test/Makefile.am b/test/Makefile.am new file mode 100644 index 00000000..29f9741c --- /dev/null +++ b/test/Makefile.am @@ -0,0 +1,6 @@ +AM_TESTS_ENVIRONMENT = make -C test_root/; +TESTS = checkself.sh +TESTS += test_start_stop_service/test.sh + +clean-local: + make -C test_root/ clean diff --git a/test/busybox-x86_64.md5 b/test/busybox-x86_64.md5 deleted file mode 100644 index 0ecfec84..00000000 --- a/test/busybox-x86_64.md5 +++ /dev/null @@ -1 +0,0 @@ -ea7e2353af0067a926d3e021e504290e busybox-x86_64 diff --git a/test/checkself.sh b/test/checkself.sh new file mode 100755 index 00000000..07405ced --- /dev/null +++ b/test/checkself.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +set -eux + +# shellcheck disable=SC2046 +shellcheck $(find ./ -name '*.sh') diff --git a/test/test_root/.gitignore b/test/test_root/.gitignore index 08ad8a05..15385773 100644 --- a/test/test_root/.gitignore +++ b/test/test_root/.gitignore @@ -1,4 +1,25 @@ -/bin +/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 diff --git a/test/test_root/Makefile b/test/test_root/Makefile new file mode 100644 index 00000000..cfb687b1 --- /dev/null +++ b/test/test_root/Makefile @@ -0,0 +1,79 @@ +.PHONY: clean check + +ARCH ?= x86_64 + +FINITBIN ?= ../../src/finit +INITCTLBIN ?= ../../src/initctl + +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 \ + ./tmp + +_libs_src = $(shell ldd $(FINITBIN) | grep -Eo '/[^ ]+') +libs = $(foreach path,$(_libs_src),.$(path)) + +all: $(binaries) $(dirs) ./sbin/finit ./bin/initctl + +$(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 $@) + +./sbin/finit: $(FINITBIN) $(libs) + cp $< $@ + +./bin/initctl: $(INITCTLBIN) $(libs) + cp $< $@ + +$(libs): + mkdir -p $(dir $@) + cp /$@ $@ + +clean: + rm -f ./bin/$(BBBIN) + rm -f ./bin/initctl + rm -rf $(binaries) + rm -rf ./dev + rm -rf ./etc + rm -rf ./lib64 + rm -rf ./proc + rm -rf ./sbin + rm -rf ./sys + rm -rf ./tmp + rm -rf ./usr + rm -rf ./var diff --git a/test/chrootsetup.sh b/test/test_root/bin/chrootsetup.sh similarity index 100% rename from test/chrootsetup.sh rename to test/test_root/bin/chrootsetup.sh diff --git a/test/test_root/busybox-x86_64.md5 b/test/test_root/busybox-x86_64.md5 new file mode 100644 index 00000000..9ad31f90 --- /dev/null +++ b/test/test_root/busybox-x86_64.md5 @@ -0,0 +1 @@ +ea7e2353af0067a926d3e021e504290e bin/busybox-x86_64