git: 4826406b30f9 - main - pf tests: log additional information when a test ends

From: Kristof Provost <kp_at_FreeBSD.org>
Date: Mon, 13 Dec 2021 14:54:26 UTC
The branch main has been updated by kp:

URL: https://cgit.FreeBSD.org/src/commit/?id=4826406b30f9756102a1443273aeb9d7dd5d80c7

commit 4826406b30f9756102a1443273aeb9d7dd5d80c7
Author:     Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2021-12-13 12:01:27 +0000
Commit:     Kristof Provost <kp@FreeBSD.org>
CommitDate: 2021-12-13 14:54:03 +0000

    pf tests: log additional information when a test ends
    
    Log information from the running jails (routing, interfaces and pf) as
    well as interfaces on the host.
    
    This information is expected to be useful in debugging test failures.
    
    MFC after:      2 weeks
    Sponsored by:   Rubicon Communications, LLC ("Netgate")
---
 tests/sys/netpfil/pf/utils.subr | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/tests/sys/netpfil/pf/utils.subr b/tests/sys/netpfil/pf/utils.subr
index c9a404c8012e..9afd6280707e 100644
--- a/tests/sys/netpfil/pf/utils.subr
+++ b/tests/sys/netpfil/pf/utils.subr
@@ -28,8 +28,39 @@
 
 . $(atf_get_srcdir)/../../common/vnet.subr
 
+pft_onerror()
+{
+	status=$?
+
+	echo "Debug log."
+	echo "=========="
+	echo "Test exit status: $?"
+	echo
+
+	if [ -f created_jails.lst ]; then
+		for jailname in `cat created_jails.lst`
+		do
+			echo "Jail ${jailname}"
+			echo "----------------"
+			jexec ${jailname} ifconfig
+			jexec ${jailname} netstat -rn
+			jexec ${jailname} pfctl -sa -v
+		done
+	fi
+
+	echo "Created interfaces:"
+	echo "-------------------"
+	cat created_interfaces.lst
+
+	echo "Host interfaces:"
+	echo "----------------"
+	ifconfig
+}
+
 pft_init()
 {
+	trap pft_onerror EXIT
+
 	vnet_init
 
 	if [ ! -c /dev/pf ]; then