Skip to contentSkip to conversation

selftests: drivers/s390x: Use SKIP() during FIXTURE_SETUP

PATCH In review Kees Cook 2 participants 2 messages May 18, 2024 – Jun 4, 2024

Subsystems (3)
lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 selftests: drivers/s390x: Use SKIP() during FIXTURE_SETUP

Instead of mixing selftest harness and ksft helpers, perform SKIP testing from the FIXTURE_SETUPs. This also means TEST_HARNESS_MAIN does not need to be open-coded.

---
Cc: Christian Borntraeger <[email protected]>
Cc: Janosch Frank <[email protected]>
Cc: Claudio Imbrenda <[email protected]>
Cc: David Hildenbrand <[email protected]>
Cc: Shuah Khan <[email protected]>
Cc: Masahiro Yamada <[email protected]>
Cc: [email protected]
Cc: [email protected]
---
I wasn't able to build or run test this, since it's very s390 specific, it seems?

---
 .../drivers/s390x/uvdevice/test_uvdevice.c    | 32 ++++++++-----------
 1 file changed, 13 insertions(+), 19 deletions(-)
tools/testing/selftests/drivers/s390x/uvdevice/test_uvdevice.c +13 -19
index ea0cdc37b44f..9622fac42597 100644
@@ -18,6 +18,16 @@
 
 #define UV_PATH  "/dev/uv"
 #define BUFFER_SIZE 0x200
+
+#define open_uv() \
+do { \
+	self->uv_fd = open(UV_PATH, O_ACCMODE);	\
+	if (self->uv_fd < 0) \
+		SKIP(return, "No uv-device or cannot access " UV_PATH  "\n" \
+			     "Enable CONFIG_S390_UV_UAPI and check the access rights on " \
+			     UV_PATH ".\n"); \
+} while (0)
+
 FIXTURE(uvio_fixture) {
 	int uv_fd;
 	struct uvio_ioctl_cb uvio_ioctl;
@@ -37,7 +47,7 @@ FIXTURE_VARIANT_ADD(uvio_fixture, att) {
 
 FIXTURE_SETUP(uvio_fixture)
 {
-	self->uv_fd = open(UV_PATH, O_ACCMODE);
+	open_uv();
 
 	self->uvio_ioctl.argument_addr = (__u64)self->buffer;
 	self->uvio_ioctl.argument_len = variant->arg_size;
@@ -159,7 +169,7 @@ FIXTURE(attest_fixture) {
 
 FIXTURE_SETUP(attest_fixture)
 {
-	self->uv_fd = open(UV_PATH, O_ACCMODE);
+	open_uv();
 
 	self->uvio_ioctl.argument_addr = (__u64)&self->uvio_attest;
 	self->uvio_ioctl.argument_len = sizeof(self->uvio_attest);
@@ -257,20 +267,4 @@ TEST_F(attest_fixture, att_inval_addr)
 	att_inval_addr_test(&self->uvio_attest.meas_addr, _metadata, self);
 }
 
-static void __attribute__((constructor)) __constructor_order_last(void)
-{
-	if (!__constructor_order)
-		__constructor_order = _CONSTRUCTOR_ORDER_BACKWARD;
-}
-
-int main(int argc, char **argv)
-{
-	int fd = open(UV_PATH, O_ACCMODE);
-
-	if (fd < 0)
-		ksft_exit_skip("No uv-device or cannot access " UV_PATH  "\n"
-			       "Enable CONFIG_S390_UV_UAPI and check the access rights on "
-			       UV_PATH ".\n");
-	close(fd);
-	return test_harness_run(argc, argv);
-}
+TEST_HARNESS_MAIN
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 6 lines · Kees Cook

Instead of mixing selftest harness and ksft helpers, perform SKIP testing from the FIXTURE_SETUPs. This also means TEST_HARNESS_MAIN does not need to be open-coded.

---

Adding the author in CC.

This changes the skip behavior from one single skip to a skip per test. Not an issue, but a change.

But also we're generating invalid TAP AFAIK which we also have been before but we can fix that in this patch.

From what I understand this line should have a "#" prefix to show that it's a comment:
Enable CONFIG_S390_UV_UAPI and check the access rights on /dev/uv.