All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: selftests: Use TEST_REQUIRE() in nx_huge_pages_test
@ 2022-08-12 17:53 Oliver Upton
  2022-08-12 18:04 ` David Matlack
  0 siblings, 1 reply; 5+ messages in thread
From: Oliver Upton @ 2022-08-12 17:53 UTC (permalink / raw)
  To: kvm
  Cc: Paolo Bonzini, Ben Gardon, David Matlack, Sean Christopherson,
	Oliver Upton

Avoid boilerplate for checking test preconditions by using
TEST_REQUIRE(). While at it, add a precondition for
KVM_CAP_VM_DISABLE_NX_HUGE_PAGES to skip (instead of silently pass) on
older kernels.

Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
---
 .../selftests/kvm/x86_64/nx_huge_pages_test.c | 24 +++++--------------
 1 file changed, 6 insertions(+), 18 deletions(-)

diff --git a/tools/testing/selftests/kvm/x86_64/nx_huge_pages_test.c b/tools/testing/selftests/kvm/x86_64/nx_huge_pages_test.c
index cc6421716400..e19933ea34ca 100644
--- a/tools/testing/selftests/kvm/x86_64/nx_huge_pages_test.c
+++ b/tools/testing/selftests/kvm/x86_64/nx_huge_pages_test.c
@@ -118,13 +118,6 @@ void run_test(int reclaim_period_ms, bool disable_nx_huge_pages,
 	vm = vm_create(1);
 
 	if (disable_nx_huge_pages) {
-		/*
-		 * Cannot run the test without NX huge pages if the kernel
-		 * does not support it.
-		 */
-		if (!kvm_check_cap(KVM_CAP_VM_DISABLE_NX_HUGE_PAGES))
-			return;
-
 		r = __vm_disable_nx_huge_pages(vm);
 		if (reboot_permissions) {
 			TEST_ASSERT(!r, "Disabling NX huge pages should succeed if process has reboot permissions");
@@ -248,18 +241,13 @@ int main(int argc, char **argv)
 		}
 	}
 
-	if (token != MAGIC_TOKEN) {
-		print_skip("This test must be run with the magic token %d.\n"
-			   "This is done by nx_huge_pages_test.sh, which\n"
-			   "also handles environment setup for the test.",
-			   MAGIC_TOKEN);
-		exit(KSFT_SKIP);
-	}
+	TEST_REQUIRE(kvm_has_cap(KVM_CAP_VM_DISABLE_NX_HUGE_PAGES));
+	TEST_REQUIRE(reclaim_period_ms > 0);
 
-	if (!reclaim_period_ms) {
-		print_skip("The NX reclaim period must be specified and non-zero");
-		exit(KSFT_SKIP);
-	}
+	__TEST_REQUIRE(token == MAGIC_TOKEN,
+		       "This test must be run with the magic token %d.\n"
+		       "This is done by nx_huge_pages_test.sh, which\n"
+		       "also handles environment setup for the test.");
 
 	run_test(reclaim_period_ms, false, reboot_permissions);
 	run_test(reclaim_period_ms, true, reboot_permissions);

base-commit: 93472b79715378a2386598d6632c654a2223267b
-- 
2.37.1.595.g718a3a8f04-goog


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-09-08 19:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-12 17:53 [PATCH] KVM: selftests: Use TEST_REQUIRE() in nx_huge_pages_test Oliver Upton
2022-08-12 18:04 ` David Matlack
2022-08-12 19:16   ` Oliver Upton
2022-08-15 23:22     ` David Matlack
2022-09-08 19:30       ` Sean Christopherson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.