diff mbox series

[2/3] lib: Add .skip_in_32bit

Message ID 20240516005558.253199-3-pvorel@suse.cz
State Changes Requested
Headers show
Series .skip_in_32bit + rewrite fork14 to new API | expand

Commit Message

Petr Vorel May 16, 2024, 12:55 a.m. UTC
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 include/tst_kernel.h | 13 +++++++++++++
 include/tst_test.h   |  6 +++++-
 lib/tst_kernel.c     | 11 +++++++++++
 lib/tst_test.c       |  5 ++++-
 4 files changed, 33 insertions(+), 2 deletions(-)

Comments

Cyril Hrubis May 20, 2024, 3:38 p.m. UTC | #1
Hi!
> @@ -494,6 +497,7 @@ struct tst_ulimit_val {
>  	unsigned int skip_in_lockdown:1;
>  	unsigned int skip_in_secureboot:1;
>  	unsigned int skip_in_compat:1;
> +	unsigned int skip_in_32bit:1;

I was thinking about this and maybe it would make more sense to make
this more generic. If we ever need to add flags for a test to be skipped
on 64bit ABI we would have to add another flag. One example would be an
EOVERFLOW error from mmap() that can happen only on 32bit.

So maybe it would make sense to change this to be .needs_abi_bits and
the possible values would be 32 and 64.
Petr Vorel May 21, 2024, 7:51 a.m. UTC | #2
> Hi!
> > @@ -494,6 +497,7 @@ struct tst_ulimit_val {
> >  	unsigned int skip_in_lockdown:1;
> >  	unsigned int skip_in_secureboot:1;
> >  	unsigned int skip_in_compat:1;
> > +	unsigned int skip_in_32bit:1;

> I was thinking about this and maybe it would make more sense to make
> this more generic. If we ever need to add flags for a test to be skipped
> on 64bit ABI we would have to add another flag. One example would be an
> EOVERFLOW error from mmap() that can happen only on 32bit.

> So maybe it would make sense to change this to be .needs_abi_bits and
> the possible values would be 32 and 64.

.needs_abi_bits sounds good, I'll send v2.

Kind regards,
Petr
diff mbox series

Patch

diff --git a/include/tst_kernel.h b/include/tst_kernel.h
index e0ce7ce46..e3fadbeb0 100644
--- a/include/tst_kernel.h
+++ b/include/tst_kernel.h
@@ -1,10 +1,13 @@ 
 /* SPDX-License-Identifier: GPL-2.0-or-later
  * Copyright (c) 2017 Cyril Hrubis <chrubis@suse.cz>
+ * Copyright (c) Linux Test Project, 2018-2024
  */
 
 #ifndef TST_KERNEL_H__
 #define TST_KERNEL_H__
 
+#include <stdbool.h>
+
 /**
  * tst_kernel_bits() - Detect if running on 32bit or 64bit kernel.
  *
@@ -23,6 +26,16 @@  int tst_kernel_bits(void);
  */
 int tst_is_compat_mode(void);
 
+/**
+ * tst_is_32bit() - Detect if compiled for 32bit target.
+ *
+ * Detect if compiled for 32bit target (regardless if the test process is
+ * running on 32bit or 64bit kernel).
+ *
+ * Return: true if compiled for 32bit target or false otherwise.
+ */
+bool tst_is_32bit(void);
+
 /**
  * tst_check_builtin_driver() - Check if the kernel module is built-in.
  *
diff --git a/include/tst_test.h b/include/tst_test.h
index 69587917f..018249503 100644
--- a/include/tst_test.h
+++ b/include/tst_test.h
@@ -1,7 +1,7 @@ 
 /* SPDX-License-Identifier: GPL-2.0-or-later */
 /*
  * Copyright (c) 2015-2016 Cyril Hrubis <chrubis@suse.cz>
- * Copyright (c) Linux Test Project, 2016-2019
+ * Copyright (c) Linux Test Project, 2016-2024
  */
 
 #ifndef TST_TEST_H__
@@ -328,6 +328,9 @@  struct tst_ulimit_val {
  * @skip_in_compat: Skip the test if we are executing 32bit binary on a 64bit
  *                  kernel, i.e. we are testing the kernel compat layer.
  *
+ * @skip_in_32bit: Skip the test if compiled for 32bit target (regardless if
+ *                 the test process is running on 32bit or 64bit kernel).
+ *
  * @needs_hugetlbfs: If set hugetlbfs is mounted at tst_test.mntpoint.
  *
  * @skip_filesystems: A NULL terminated array of unsupported file systems. The
@@ -494,6 +497,7 @@  struct tst_ulimit_val {
 	unsigned int skip_in_lockdown:1;
 	unsigned int skip_in_secureboot:1;
 	unsigned int skip_in_compat:1;
+	unsigned int skip_in_32bit:1;
 
 	unsigned int needs_hugetlbfs:1;
 
diff --git a/lib/tst_kernel.c b/lib/tst_kernel.c
index 7fd1af871..ada8d104b 100644
--- a/lib/tst_kernel.c
+++ b/lib/tst_kernel.c
@@ -1,6 +1,7 @@ 
 /*
  * Copyright (c) 2017 Cyril Hrubis <chrubis@suse.cz>
  * Copyright (c) 2020-2021 Petr Vorel <pvorel@suse.cz>
+ * Copyright (c) Linux Test Project, 2017-2024
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -18,6 +19,7 @@ 
 
 #include <sys/personality.h>
 #include <sys/utsname.h>
+#include <stdbool.h>
 #include <limits.h>
 
 #include "test.h"
@@ -96,6 +98,15 @@  int tst_is_compat_mode(void)
 	return TST_ABI != tst_kernel_bits();
 }
 
+bool tst_is_32bit(void)
+{
+#ifdef TST_ABI32
+	return true;
+#else
+	return false;
+#endif
+}
+
 static int tst_search_driver_(const char *driver, const char *file)
 {
 	struct stat st;
diff --git a/lib/tst_test.c b/lib/tst_test.c
index 686ee428d..c35dc12b3 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -1,7 +1,7 @@ 
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2015-2016 Cyril Hrubis <chrubis@suse.cz>
- * Copyright (c) Linux Test Project, 2016-2021
+ * Copyright (c) Linux Test Project, 2016-2024
  */
 
 #include <limits.h>
@@ -1209,6 +1209,9 @@  static void do_setup(int argc, char *argv[])
 	if (tst_test->skip_in_compat && tst_is_compat_mode())
 		tst_brk(TCONF, "Not supported in 32-bit compat mode");
 
+	if (tst_test->skip_in_32bit && tst_is_32bit())
+		tst_brk(TCONF, "Not supported in 32-bit");
+
 	if (tst_test->needs_cmds) {
 		const char *cmd;
 		int i;