]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
KVM: selftests: Add wrapper macro to handle and assert on expected SIGBUS
authorSean Christopherson <seanjc@google.com>
Fri, 3 Oct 2025 23:26:04 +0000 (16:26 -0700)
committerSean Christopherson <seanjc@google.com>
Fri, 10 Oct 2025 21:25:29 +0000 (14:25 -0700)
commitf91187c0ecc6358ccecf533c5fcc6b7dbb4735cb
tree3e3261c6d7ba163b2c699fad26b115391e6cf6a2
parent505c953009ec8260870d41ef8109bb4c7e208e6f
KVM: selftests: Add wrapper macro to handle and assert on expected SIGBUS

Extract the guest_memfd test's SIGBUS handling functionality into a common
TEST_EXPECT_SIGBUS() macro in anticipation of adding more SIGBUS testcases.
Eating a SIGBUS isn't terrible difficult, but it requires a non-trivial
amount of boilerplate code, and using a macro allows selftests to print
out the exact action that failed to generate a SIGBUS without the developer
needing to remember to add a useful error message.

Explicitly mark the SIGBUS handler as "used", as gcc-14 at least likes to
discard the function before linking.

Opportunistically use TEST_FAIL(...) instead of TEST_ASSERT(false, ...),
and fix the write path of the guest_memfd test to use the local "val"
instead of hardcoding the literal value a second time.

Suggested-by: Ackerley Tng <ackerleytng@google.com>
Reviewed-by: Ackerley Tng <ackerleytng@google.com>
Tested-by: Ackerley Tng <ackerleytng@google.com>
Reviewed-by: Lisa Wang <wyihan@google.com>
Tested-by: Lisa Wang <wyihan@google.com>
Link: https://lore.kernel.org/r/20251003232606.4070510-12-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
tools/testing/selftests/kvm/guest_memfd_test.c
tools/testing/selftests/kvm/include/test_util.h
tools/testing/selftests/kvm/lib/test_util.c