From 9c727ed08dca4053cb8d60d40b8bf685ae851e88 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sun, 5 Feb 2023 19:02:06 +0100 Subject: [PATCH] test: namespace cleanup, common -> src, tenv -> lib, etc. Signed-off-by: Joachim Wiberg --- TODO.org | 5 ----- configure.ac | 2 +- test/Makefile.am | 6 +++--- test/add-remove-dynamic-service-sub-config.sh | 6 +++--- test/add-remove-dynamic-service.sh | 6 +++--- test/cond-start-task.sh | 12 ++++++------ test/crashing.sh | 2 +- test/depserv.sh | 2 +- test/devmon.sh | 6 +++--- test/failing-sysv.sh | 2 +- test/global-envs.sh | 2 +- test/initctl-status-subset.sh | 2 +- test/{tenv => lib}/.gitignore | 0 test/lib/Makefile.am | 1 + test/{tenv => lib}/enter.sh | 0 test/{tenv => lib}/exec.sh | 0 test/{tenv/lib.sh => lib/setup.sh} | 6 +++--- test/{tenv => lib}/start.sh | 0 test/{tenv/root.mk => lib/sysroot.mk} | 0 test/notify.sh | 2 +- test/pidfile.sh | 12 ++++++------ test/pre-post-serv.sh | 2 +- test/ready-serv.sh | 2 +- test/restart-self.sh | 2 +- test/runlevel.sh | 2 +- test/{setup-root.sh => setup-sysroot.sh} | 4 ++-- test/signal-service.sh | 6 +++--- test/{common => src}/.gitignore | 0 test/{common => src}/Makefile.am | 0 test/{common => src}/serv.c | 0 test/start-kill-service.sh | 6 +++--- test/start-kill-stop.sh | 6 +++--- test/start-stop-serv.sh | 2 +- test/start-stop-service-sub-config.sh | 6 +++--- test/start-stop-service.sh | 6 +++--- test/start-stop-sysv.sh | 6 +++--- test/tenv/Makefile.am | 1 - test/testserv.sh | 2 +- 38 files changed, 61 insertions(+), 66 deletions(-) rename test/{tenv => lib}/.gitignore (100%) create mode 100644 test/lib/Makefile.am rename test/{tenv => lib}/enter.sh (100%) rename test/{tenv => lib}/exec.sh (100%) rename test/{tenv/lib.sh => lib/setup.sh} (96%) rename test/{tenv => lib}/start.sh (100%) rename test/{tenv/root.mk => lib/sysroot.mk} (100%) rename test/{setup-root.sh => setup-sysroot.sh} (83%) rename test/{common => src}/.gitignore (100%) rename test/{common => src}/Makefile.am (100%) rename test/{common => src}/serv.c (100%) delete mode 100644 test/tenv/Makefile.am diff --git a/TODO.org b/TODO.org index e38dd0b9..8b137891 100644 --- a/TODO.org +++ b/TODO.org @@ -1,6 +1 @@ -* DONE fix pid parser, //run/foo.pid -> /var/run///run/foo.pid -** DONE test framework refactor 'texec sh -c ...' -> 'run ...' -* TODO Clean up tests a bit -* TODO Drop tenv or common and rename sysroot -* TODO rename test/lib.sh to start.sh or sth diff --git a/configure.ac b/configure.ac index abc10b07..a5641382 100644 --- a/configure.ac +++ b/configure.ac @@ -15,7 +15,7 @@ AC_CONFIG_FILES([Makefile plugins/Makefile src/Makefile test/test.env test/Makefile - test/tenv/Makefile test/common/Makefile]) + test/lib/Makefile test/src/Makefile]) # Older versions of autoconf (<2.58) do not have AC_CONFIG_MACRO_DIR() #m4_include([m4/plugin.m4]) diff --git a/test/Makefile.am b/test/Makefile.am index 5aa255c0..701ccaa9 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = common tenv +SUBDIRS = lib src EXTRA_DIST = skel/bin/busybox-x86_64.sha256 skel/sbin/service.sh skel/etc/env \ skel/bin/pre.sh skel/bin/post.sh skel/bin/ready.sh skel/bin/slay \ @@ -17,7 +17,7 @@ EXTRA_DIST = skel/bin/busybox-x86_64.sha256 skel/sbin/service.sh skel/etc/env skel/usr/local/lib/.empty skel/usr/local/bin/.empty \ skel/usr/local/etc/.empty skel/var/.empty -EXTRA_DIST += setup-root.sh +EXTRA_DIST += setup-sysroot.sh EXTRA_DIST += add-remove-dynamic-service.sh EXTRA_DIST += add-remove-dynamic-service-sub-config.sh EXTRA_DIST += cond-start-task.sh @@ -85,7 +85,7 @@ check-recursive: setup-chroot .PHONY: setup-chroot setup-chroot: - @SYSROOT='$(abs_builddir)/sysroot/' srcdir=$(srcdir) top_builddir=$(top_builddir) $(srcdir)/setup-root.sh + @SYSROOT='$(abs_builddir)/sysroot/' srcdir=$(srcdir) top_builddir=$(top_builddir) $(srcdir)/setup-sysroot.sh clean-local: -rm -rf $(builddir)/sysroot/ diff --git a/test/add-remove-dynamic-service-sub-config.sh b/test/add-remove-dynamic-service-sub-config.sh index 81bcc1d7..e35ceb39 100755 --- a/test/add-remove-dynamic-service-sub-config.sh +++ b/test/add-remove-dynamic-service-sub-config.sh @@ -4,9 +4,6 @@ set -eu TEST_DIR=$(dirname "$0") -# shellcheck source=/dev/null -. "$TEST_DIR/tenv/lib.sh" - test_teardown() { say "Test done $(date)" @@ -15,6 +12,9 @@ test_teardown() run "rm -f $FINIT_RCSD/service.conf" } +# shellcheck source=/dev/null +. "$TEST_DIR/lib/setup.sh" + say "Test start $(date)" say "Add a dynamic service in $FINIT_RCSD/service.conf" diff --git a/test/add-remove-dynamic-service.sh b/test/add-remove-dynamic-service.sh index 14a31b2b..29c49296 100755 --- a/test/add-remove-dynamic-service.sh +++ b/test/add-remove-dynamic-service.sh @@ -4,9 +4,6 @@ set -eu TEST_DIR=$(dirname "$0") -# shellcheck source=/dev/null -. "$TEST_DIR/tenv/lib.sh" - test_teardown() { say "Test done $(date)" @@ -15,6 +12,9 @@ test_teardown() run "rm -f $FINIT_CONF" } +# shellcheck source=/dev/null +. "$TEST_DIR/lib/setup.sh" + say "Test start $(date)" say "Add a dynamic service in $FINIT_CONF" diff --git a/test/cond-start-task.sh b/test/cond-start-task.sh index 62bb504d..0aa6e68f 100755 --- a/test/cond-start-task.sh +++ b/test/cond-start-task.sh @@ -7,12 +7,6 @@ set -eu TEST_DIR=$(dirname "$0") -# shellcheck source=/dev/null -. "$TEST_DIR/tenv/lib.sh" - -TEST_CONF=$FINIT_RCSD/cond.conf - - test_setup() { say "Test start $(date)" @@ -88,4 +82,10 @@ test_one() run "initctl reload" } + +# shellcheck source=/dev/null +. "$TEST_DIR/lib/setup.sh" + +TEST_CONF=$FINIT_RCSD/cond.conf + test_one "hello" "task task.sh -- Hello task" diff --git a/test/crashing.sh b/test/crashing.sh index 40af29d4..c54fc813 100755 --- a/test/crashing.sh +++ b/test/crashing.sh @@ -61,7 +61,7 @@ test_one() } # shellcheck source=/dev/null -. "$TEST_DIR/tenv/lib.sh" +. "$TEST_DIR/lib/setup.sh" #run "initctl debug" diff --git a/test/depserv.sh b/test/depserv.sh index 3c9a2af2..7fd6f276 100755 --- a/test/depserv.sh +++ b/test/depserv.sh @@ -28,7 +28,7 @@ test_teardown() } # shellcheck source=/dev/null -. "$TEST_DIR/tenv/lib.sh" +. "$TEST_DIR/lib/setup.sh" #run "initctl debug" #run "ls -l /run/finit/cond/pid/ /lib/finit/plugins/" diff --git a/test/devmon.sh b/test/devmon.sh index 77b08d55..08aa9586 100755 --- a/test/devmon.sh +++ b/test/devmon.sh @@ -7,9 +7,6 @@ set -eu TEST_DIR=$(dirname "$0") -# shellcheck source=/dev/null -. "$TEST_DIR/tenv/lib.sh" - test_setup() { say "Test start $(date)" @@ -60,6 +57,9 @@ test_one() run "initctl reload" } +# shellcheck source=/dev/null +. "$TEST_DIR/lib/setup.sh" + sep test_one "dev/fbsplash" sep diff --git a/test/failing-sysv.sh b/test/failing-sysv.sh index 740d8d1e..4ca8e2dd 100755 --- a/test/failing-sysv.sh +++ b/test/failing-sysv.sh @@ -21,7 +21,7 @@ test_teardown() } # shellcheck source=/dev/null -. "$TEST_DIR/tenv/lib.sh" +. "$TEST_DIR/lib/setup.sh" # This instructs serv to check the environment, and exit # if it cannot find "xyzzy", thus triggering a premature diff --git a/test/global-envs.sh b/test/global-envs.sh index f635b4ef..aac3f209 100755 --- a/test/global-envs.sh +++ b/test/global-envs.sh @@ -17,7 +17,7 @@ test_teardown() } # shellcheck source=/dev/null -. "$TEST_DIR/tenv/lib.sh" +. "$TEST_DIR/lib/setup.sh" #run "initctl debug" say "Add custom envs to $FINIT_CONF ..." diff --git a/test/initctl-status-subset.sh b/test/initctl-status-subset.sh index db851531..cd8a0c36 100755 --- a/test/initctl-status-subset.sh +++ b/test/initctl-status-subset.sh @@ -34,7 +34,7 @@ test_add_one() } # shellcheck source=/dev/null -. "$TEST_DIR/tenv/lib.sh" +. "$TEST_DIR/lib/setup.sh" test_init diff --git a/test/tenv/.gitignore b/test/lib/.gitignore similarity index 100% rename from test/tenv/.gitignore rename to test/lib/.gitignore diff --git a/test/lib/Makefile.am b/test/lib/Makefile.am new file mode 100644 index 00000000..a281a920 --- /dev/null +++ b/test/lib/Makefile.am @@ -0,0 +1 @@ +EXTRA_DIST = exec.sh setup.sh start.sh sysroot.mk diff --git a/test/tenv/enter.sh b/test/lib/enter.sh similarity index 100% rename from test/tenv/enter.sh rename to test/lib/enter.sh diff --git a/test/tenv/exec.sh b/test/lib/exec.sh similarity index 100% rename from test/tenv/exec.sh rename to test/lib/exec.sh diff --git a/test/tenv/lib.sh b/test/lib/setup.sh similarity index 96% rename from test/tenv/lib.sh rename to test/lib/setup.sh index 5b315581..73a7620c 100755 --- a/test/tenv/lib.sh +++ b/test/lib/setup.sh @@ -100,7 +100,7 @@ assert_has_pidfile() # shellcheck disable=SC2154 texec() { - "$TEST_DIR/tenv/exec.sh" "$finit_pid" "$@" + "$TEST_DIR/lib/exec.sh" "$finit_pid" "$@" } run() @@ -263,11 +263,11 @@ else fi # shellcheck disable=2086 -"$TEST_DIR/tenv/start.sh" finit ${FINIT_ARGS:-} & +"$TEST_DIR/lib/start.sh" finit ${FINIT_ARGS:-} & finit_ppid=$! echo "$finit_ppid" > "$SYSROOT"/running_test.pid -#>&2 echo "Hint: Execute 'SYSROOT=$SYSROOT $TEST_DIR/tenv/enter.sh' to enter the test namespace" +#>&2 echo "Hint: Execute 'SYSROOT=$SYSROOT $TEST_DIR/lib/enter.sh' to enter the test namespace" log "$color_reset" 'Setup of test environment done, waiting for Finit ...' '' finit_pid=$(retry "pgrep -P $finit_ppid") diff --git a/test/tenv/start.sh b/test/lib/start.sh similarity index 100% rename from test/tenv/start.sh rename to test/lib/start.sh diff --git a/test/tenv/root.mk b/test/lib/sysroot.mk similarity index 100% rename from test/tenv/root.mk rename to test/lib/sysroot.mk diff --git a/test/notify.sh b/test/notify.sh index 308c7d03..c68e8327 100755 --- a/test/notify.sh +++ b/test/notify.sh @@ -99,7 +99,7 @@ test_one() } # shellcheck source=/dev/null -. "$TEST_DIR/tenv/lib.sh" +. "$TEST_DIR/lib/setup.sh" #run "initctl debug" diff --git a/test/pidfile.sh b/test/pidfile.sh index 013c44b8..9706b6f8 100755 --- a/test/pidfile.sh +++ b/test/pidfile.sh @@ -18,12 +18,6 @@ test_teardown() run "rm -f $FINIT_CONF" "/tmp/post" } -# shellcheck source=/dev/null -. "$TEST_DIR/tenv/lib.sh" - -#run "initctl debug" -#run "ls -l /run/finit/cond/pid/ /lib/finit/plugins/" - test_one() { pidfn=$1 @@ -41,6 +35,12 @@ test_one() run "initctl reload" } +# shellcheck source=/dev/null +. "$TEST_DIR/lib/setup.sh" + +#run "initctl debug" +#run "ls -l /run/finit/cond/pid/ /lib/finit/plugins/" + test_one "/run/serv.pid" "service serv -np" test_one "/run/serv.pid" "service pid:!/run/serv.pid serv" test_one "/run/serv.pid" "service type:forking serv" diff --git a/test/pre-post-serv.sh b/test/pre-post-serv.sh index d4652a11..9e3189fd 100755 --- a/test/pre-post-serv.sh +++ b/test/pre-post-serv.sh @@ -51,7 +51,7 @@ test_one() } # shellcheck source=/dev/null -. "$TEST_DIR/tenv/lib.sh" +. "$TEST_DIR/lib/setup.sh" #run "initctl debug" diff --git a/test/ready-serv.sh b/test/ready-serv.sh index 62b07d3d..7ea29aa8 100755 --- a/test/ready-serv.sh +++ b/test/ready-serv.sh @@ -42,7 +42,7 @@ test_one() } # shellcheck source=/dev/null -. "$TEST_DIR/tenv/lib.sh" +. "$TEST_DIR/lib/setup.sh" #run "initctl debug" diff --git a/test/restart-self.sh b/test/restart-self.sh index e4a7b6cf..751ddb9c 100755 --- a/test/restart-self.sh +++ b/test/restart-self.sh @@ -25,7 +25,7 @@ check_restarts() # shellcheck source=/dev/null -. "$TEST_DIR/tenv/lib.sh" +. "$TEST_DIR/lib/setup.sh" say "Add stanza to $FINIT_CONF" run "echo 'service serv -np -r serv -- Restart self' > $FINIT_CONF" diff --git a/test/runlevel.sh b/test/runlevel.sh index b4062512..d5fb101a 100755 --- a/test/runlevel.sh +++ b/test/runlevel.sh @@ -18,7 +18,7 @@ test_teardown() } # shellcheck source=/dev/null -. "$TEST_DIR/tenv/lib.sh" +. "$TEST_DIR/lib/setup.sh" say 'Check runlevel' lvl=$(run "initctl runlevel | awk '{print \$2;}'") diff --git a/test/setup-root.sh b/test/setup-sysroot.sh similarity index 83% rename from test/setup-root.sh rename to test/setup-sysroot.sh index 6470c506..3434a02c 100755 --- a/test/setup-root.sh +++ b/test/setup-sysroot.sh @@ -6,10 +6,10 @@ set -eu make -C "$top_builddir" DESTDIR="$SYSROOT" install mkdir -p "$SYSROOT/sbin/" -cp "$top_builddir/test/common/serv" "$SYSROOT/sbin/" +cp "$top_builddir/test/src/serv" "$SYSROOT/sbin/" # shellcheck disable=SC2154 -FINITBIN="$(pwd)/$top_builddir/src/finit" DEST="$SYSROOT" make -f "$srcdir/tenv/root.mk" +FINITBIN="$(pwd)/$top_builddir/src/finit" DEST="$SYSROOT" make -f "$srcdir/lib/sysroot.mk" # Drop plugins we don't need in test, only causes confusing FAIL in logs. for plugin in tty.so urandom.so rtc.so modprobe.so hotplug.so; do diff --git a/test/signal-service.sh b/test/signal-service.sh index 6338610a..ad402a46 100755 --- a/test/signal-service.sh +++ b/test/signal-service.sh @@ -5,9 +5,6 @@ set -eu TEST_DIR=$(dirname "$0") -# shellcheck source=/dev/null -. "$TEST_DIR/tenv/lib.sh" - test_teardown() { say "Test done $(date)" @@ -16,6 +13,9 @@ test_teardown() run "rm -f $FINIT_CONF" } +# shellcheck source=/dev/null +. "$TEST_DIR/lib/setup.sh" + say "Test start $(date)" say 'Ensure file system is cleared' diff --git a/test/common/.gitignore b/test/src/.gitignore similarity index 100% rename from test/common/.gitignore rename to test/src/.gitignore diff --git a/test/common/Makefile.am b/test/src/Makefile.am similarity index 100% rename from test/common/Makefile.am rename to test/src/Makefile.am diff --git a/test/common/serv.c b/test/src/serv.c similarity index 100% rename from test/common/serv.c rename to test/src/serv.c diff --git a/test/start-kill-service.sh b/test/start-kill-service.sh index 5d665a5b..90b9a046 100755 --- a/test/start-kill-service.sh +++ b/test/start-kill-service.sh @@ -6,9 +6,6 @@ set -eu TEST_DIR=$(dirname "$0") -# shellcheck source=/dev/null -. "$TEST_DIR/tenv/lib.sh" - test_teardown() { say "Test done $(date)" @@ -17,6 +14,9 @@ test_teardown() run "rm -f $FINIT_CONF" } +# shellcheck source=/dev/null +. "$TEST_DIR/lib/setup.sh" + say "Test start $(date)" rm -f "$SYSROOT"/oldpid diff --git a/test/start-kill-stop.sh b/test/start-kill-stop.sh index 3048e10d..fc5aaafe 100755 --- a/test/start-kill-stop.sh +++ b/test/start-kill-stop.sh @@ -9,9 +9,6 @@ set -eu TEST_DIR=$(dirname "$0") -# shellcheck source=/dev/null -. "$TEST_DIR/tenv/lib.sh" - test_teardown() { # run "initctl status -j serv" @@ -21,6 +18,9 @@ test_teardown() run "rm -f $FINIT_CONF" } +# shellcheck source=/dev/null +. "$TEST_DIR/lib/setup.sh" + say "Check deps ..." check_dep jq diff --git a/test/start-stop-serv.sh b/test/start-stop-serv.sh index 76965c36..a622dd16 100755 --- a/test/start-stop-serv.sh +++ b/test/start-stop-serv.sh @@ -53,7 +53,7 @@ test_one() } # shellcheck source=/dev/null -. "$TEST_DIR/tenv/lib.sh" +. "$TEST_DIR/lib/setup.sh" test_one "/run/serv.pid" "service pid:!/run/serv.pid serv -- Forking service, type 1" test_one "/run/serv.pid" "service type:forking serv -- Forking service, type 2" diff --git a/test/start-stop-service-sub-config.sh b/test/start-stop-service-sub-config.sh index d700d9d3..0472afe7 100755 --- a/test/start-stop-service-sub-config.sh +++ b/test/start-stop-service-sub-config.sh @@ -4,9 +4,6 @@ set -eu TEST_DIR=$(dirname "$0") -# shellcheck source=/dev/null -. "$TEST_DIR/tenv/lib.sh" - test_teardown() { say "Test done $(date)" @@ -15,6 +12,9 @@ test_teardown() run "rm -f $FINIT_RCSD/service.conf" } +# shellcheck source=/dev/null +. "$TEST_DIR/lib/setup.sh" + say "Test start $(date)" say "Add service stanza in $FINIT_RCSD/service.conf" diff --git a/test/start-stop-service.sh b/test/start-stop-service.sh index ca0da31a..01a0f950 100755 --- a/test/start-stop-service.sh +++ b/test/start-stop-service.sh @@ -4,9 +4,6 @@ set -eu TEST_DIR=$(dirname "$0") -# shellcheck source=/dev/null -. "$TEST_DIR/tenv/lib.sh" - test_teardown() { say "Test done $(date)" @@ -15,6 +12,9 @@ test_teardown() run "rm -f $FINIT_CONF" } +# shellcheck source=/dev/null +. "$TEST_DIR/lib/setup.sh" + say "Test start $(date)" say "Add service stanza in $FINIT_CONF" diff --git a/test/start-stop-sysv.sh b/test/start-stop-sysv.sh index a73d7a99..d80eb403 100755 --- a/test/start-stop-sysv.sh +++ b/test/start-stop-sysv.sh @@ -4,9 +4,6 @@ set -eu TEST_DIR=$(dirname "$0") -# shellcheck source=/dev/null -. "$TEST_DIR/tenv/lib.sh" - test_teardown() { say "Test done $(date)" @@ -15,6 +12,9 @@ test_teardown() run "rm -f $FINIT_CONF" } +# shellcheck source=/dev/null +. "$TEST_DIR/lib/setup.sh" + say "Test start $(date)" say "Add sysv stanza in $FINIT_CONF" diff --git a/test/tenv/Makefile.am b/test/tenv/Makefile.am deleted file mode 100644 index 00ddb6ee..00000000 --- a/test/tenv/Makefile.am +++ /dev/null @@ -1 +0,0 @@ -EXTRA_DIST = lib.sh exec.sh start.sh root.mk diff --git a/test/testserv.sh b/test/testserv.sh index 07b967d8..4c3cdc59 100755 --- a/test/testserv.sh +++ b/test/testserv.sh @@ -10,7 +10,7 @@ FINIT_ARGS="finit.cond=testserv" TEST_DIR=$(dirname "$0") # shellcheck source=/dev/null -. "$TEST_DIR/tenv/lib.sh" +. "$TEST_DIR/lib/setup.sh" run "initctl" run "initctl status testserv"