The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=cfc595f4a05ed6fc690b17adee967e652b8636b3
commit cfc595f4a05ed6fc690b17adee967e652b8636b3 Author: Kyle Evans <kev...@freebsd.org> AuthorDate: 2025-07-26 03:13:40 +0000 Commit: Kyle Evans <kev...@freebsd.org> CommitDate: 2025-07-26 03:13:40 +0000 jail: tests: cleanup the commands test a bit We shouldn't be doing setup in a head() function, as this can cause various problems. For instance, in this case, it caused test listing to fail in some cases if we didn't get to execute the cleanup properly by complaining to stderr if the directory could not be created. Switch to using atf_check for sanity checking stdout; most of these expressions are self-explanatory and will make it clear what the problem is. commands.jail.conf contains a hard-coded path that we can avoid, which is probably good to avoid weird conflicts if other tests try to copy it and do the same. Just make a copy of our jail.conf and add the test's $PWD to it to get a generally unique jail root. Finally, simplify the cleanup handler a bit. Reviewed by: jamie Differential Revision: https://reviews.freebsd.org/D51501 --- usr.sbin/jail/tests/commands.jail.conf | 2 -- usr.sbin/jail/tests/jail_basic_test.sh | 35 +++++++++++++++++++--------------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/usr.sbin/jail/tests/commands.jail.conf b/usr.sbin/jail/tests/commands.jail.conf index afd56d1fa5d6..ad152a28b7fe 100644 --- a/usr.sbin/jail/tests/commands.jail.conf +++ b/usr.sbin/jail/tests/commands.jail.conf @@ -4,6 +4,4 @@ exec.prestart = "echo START"; exec.poststart = "env"; persist; -path = "/tmp/test_${name}_root"; - basejail {} diff --git a/usr.sbin/jail/tests/jail_basic_test.sh b/usr.sbin/jail/tests/jail_basic_test.sh index 6498eb1c1fdc..f3c8be4a6595 100755 --- a/usr.sbin/jail/tests/jail_basic_test.sh +++ b/usr.sbin/jail/tests/jail_basic_test.sh @@ -129,38 +129,43 @@ commands_head() { atf_set descr 'Commands jail test' atf_set require.user root - mkdir /tmp/test_basejail_root } commands_body() { + cp "$(atf_get_srcdir)/commands.jail.conf" jail.conf + echo "path = \"$PWD\";" >> jail.conf + # exec.prestart (START) and exec.poststart (env) - atf_check -s exit:0 -o save:stdout -e empty \ - jail -f $(atf_get_srcdir)/commands.jail.conf -qc basejail - grep -E '^START$' stdout || atf_fail "exec.prestart output not found" - grep -E '^JID=[0-9]+' stdout || atf_fail "JID not found in exec.poststart env output" - grep -E '^JNAME=basejail$' stdout || atf_fail "JNAME not found in exec.poststart env output" - grep -E '^JPATH=/tmp/test_basejail_root$' stdout || atf_fail "JPATH not found in exec.poststart env output" + atf_check -o save:stdout -e empty \ + jail -f jail.conf -qc basejail + + # exec.prestart output is missing + atf_check grep -qE '^START$' stdout + # JID was not set in the exec.poststart env + atf_check grep -qE '^JID=[0-9]+' stdout + # JNAME was not set in the exec.poststart env + atf_check grep -qE '^JNAME=basejail$' stdout + # JPATH was not set in the exec.poststart env + atf_check grep -qE "^JPATH=$PWD$" stdout # exec.prestop by jailname atf_check -s exit:0 -o inline:"STOP\n" \ - jail -f $(atf_get_srcdir)/commands.jail.conf -qr basejail + jail -f jail.conf -qr basejail # exec.prestop by jid - jail -f $(atf_get_srcdir)/commands.jail.conf -qc basejail + jail -f jail.conf -qc basejail atf_check -s exit:0 -o inline:"STOP\n" \ - jail -f $(atf_get_srcdir)/commands.jail.conf -qr `jls -j basejail jid` + jail -f jail.conf -qr `jls -j basejail jid` } -commands_cleanup() +commands_cleanup() { - jls -j basejail > /dev/null 2>&1 - if [ $? -e 0 ] - then + if jls -j basejail > /dev/null 2>&1; then jail -r basejail fi - rmdir /tmp/test_basejail_root } + atf_init_test_cases() { atf_add_test_case "basic"