diff mbox series

[v2,2/5] lib: Add .needs_abi_bits

Message ID 20240521105348.126316-3-pvorel@suse.cz
State Accepted
Headers show
Series .needs_abi_bits + rewrite fork14 to new API | expand

Commit Message

Petr Vorel May 21, 2024, 10:53 a.m. UTC
This allows to force kernel ABI.

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
Changes v1->v2:
* Change from .skip_in_32bit to .needs_abi_bits

 include/tst_kernel.h | 12 ++++++++++++
 include/tst_test.h   |  7 ++++++-
 lib/tst_kernel.c     | 10 ++++++++++
 lib/tst_test.c       |  5 ++++-
 4 files changed, 32 insertions(+), 2 deletions(-)

Comments

Cyril Hrubis May 21, 2024, 3:11 p.m. UTC | #1
Hi!
The tst_test API looks good to me now.

Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
diff mbox series

Patch

diff --git a/include/tst_kernel.h b/include/tst_kernel.h
index e0ce7ce46..5f49952b7 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,15 @@  int tst_kernel_bits(void);
  */
 int tst_is_compat_mode(void);
 
+/**
+ * tst_abi_bits() - Detect if compiled for required kernel ABI.
+ *
+ * @abi: kernel ABI bits (32 or 64).
+ *
+ * Return: true if compiled for required ABI or false otherwise.
+ */
+bool tst_abi_bits(int abi);
+
 /**
  * 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..8dc20d110 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,10 @@  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.
  *
+ * @needs_abi_bits: Skip the test if runs on a different kernel ABI than
+ *                  requested (on 32bit instead of 64bit or vice versa).
+ *                  Possible values: 32, 64.
+ *
  * @needs_hugetlbfs: If set hugetlbfs is mounted at tst_test.mntpoint.
  *
  * @skip_filesystems: A NULL terminated array of unsupported file systems. The
@@ -494,6 +498,7 @@  struct tst_ulimit_val {
 	unsigned int skip_in_lockdown:1;
 	unsigned int skip_in_secureboot:1;
 	unsigned int skip_in_compat:1;
+	int needs_abi_bits;
 
 	unsigned int needs_hugetlbfs:1;
 
diff --git a/lib/tst_kernel.c b/lib/tst_kernel.c
index 7fd1af871..8dabfeba2 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,14 @@  int tst_is_compat_mode(void)
 	return TST_ABI != tst_kernel_bits();
 }
 
+bool tst_abi_bits(int abi)
+{
+	if (abi != 32 && abi != 64)
+		tst_brkm(TBROK | TERRNO, NULL, "abi parameter can be only 32 or 64");
+
+	return abi == TST_ABI;
+}
+
 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..190e8da2a 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->needs_abi_bits && !tst_abi_bits(tst_test->needs_abi_bits))
+		tst_brk(TCONF, "%dbit ABI is not supported", tst_test->needs_abi_bits);
+
 	if (tst_test->needs_cmds) {
 		const char *cmd;
 		int i;