On Thu, Nov 20, 2025 at 09:44:40PM -0800, Bobby Eshleman wrote:
From: Bobby Eshleman <[email protected]>

These functions are reused by the VM tests to collect and compare dmesg
warnings and oops counts. The future VM-specific tests use them heavily.
This patches relies on vm_ssh() already supporting namespaces.

Signed-off-by: Bobby Eshleman <[email protected]>
---
Changes in v11:
- break these out into an earlier patch so that they can be used
 directly in new patches (instead of causing churn by adding this
 later)
---
tools/testing/selftests/vsock/vmtest.sh | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)

Reviewed-by: Stefano Garzarella <[email protected]>


diff --git a/tools/testing/selftests/vsock/vmtest.sh 
b/tools/testing/selftests/vsock/vmtest.sh
index 4da91828a6a0..1623e4da15e2 100755
--- a/tools/testing/selftests/vsock/vmtest.sh
+++ b/tools/testing/selftests/vsock/vmtest.sh
@@ -389,6 +389,17 @@ host_wait_for_listener() {
        fi
}

+vm_dmesg_oops_count() {
+       local ns=$1
+
+       vm_ssh "${ns}" -- dmesg 2>/dev/null | grep -c -i 'Oops'
+}
+
+vm_dmesg_warn_count() {
+       local ns=$1
+
+       vm_ssh "${ns}" -- dmesg --level=warn 2>/dev/null | grep -c -i 'vsock'
+}

vm_vsock_test() {
        local ns=$1
@@ -596,8 +607,8 @@ run_shared_vm_test() {

        host_oops_cnt_before=$(dmesg | grep -c -i 'Oops')
        host_warn_cnt_before=$(dmesg --level=warn | grep -c -i 'vsock')
-       vm_oops_cnt_before=$(vm_ssh -- dmesg | grep -c -i 'Oops')
-       vm_warn_cnt_before=$(vm_ssh -- dmesg --level=warn | grep -c -i 'vsock')
+       vm_oops_cnt_before=$(vm_dmesg_oops_count "init_ns")
+       vm_warn_cnt_before=$(vm_dmesg_warn_count "init_ns")

        name=$(echo "${1}" | awk '{ print $1 }')
        eval test_"${name}"
@@ -615,13 +626,13 @@ run_shared_vm_test() {
                rc=$KSFT_FAIL
        fi

-       vm_oops_cnt_after=$(vm_ssh -- dmesg | grep -i 'Oops' | wc -l)
+       vm_oops_cnt_after=$(vm_dmesg_oops_count "init_ns")
        if [[ ${vm_oops_cnt_after} -gt ${vm_oops_cnt_before} ]]; then
                echo "FAIL: kernel oops detected on vm" | log_host
                rc=$KSFT_FAIL
        fi

-       vm_warn_cnt_after=$(vm_ssh -- dmesg --level=warn | grep -c -i 'vsock')
+       vm_warn_cnt_after=$(vm_dmesg_warn_count "init_ns")
        if [[ ${vm_warn_cnt_after} -gt ${vm_warn_cnt_before} ]]; then
                echo "FAIL: kernel warning detected on vm" | log_host
                rc=$KSFT_FAIL

--
2.47.3



Reply via email to