diff mbox series

syscalls/shmget02: Handle missing hugepage support in HW

Message ID 20210923110453.14038-1-mdoucha@suse.cz
State Accepted
Headers show
Series syscalls/shmget02: Handle missing hugepage support in HW | expand

Commit Message

Martin Doucha Sept. 23, 2021, 11:04 a.m. UTC
When hugepage support is enabled in kernel but hardware support is missing,
the last two test cases in shmget02 will fail because kernel will return
ENOENT. Check hardware support and update expected errnos accordingly.

Signed-off-by: Martin Doucha <mdoucha@suse.cz>
---
 .../kernel/syscalls/ipc/shmget/shmget02.c     | 33 +++++++++++++------
 1 file changed, 23 insertions(+), 10 deletions(-)

Comments

Cyril Hrubis Sept. 23, 2021, 12:18 p.m. UTC | #1
Hi!
Applied, thanks.
diff mbox series

Patch

diff --git a/testcases/kernel/syscalls/ipc/shmget/shmget02.c b/testcases/kernel/syscalls/ipc/shmget/shmget02.c
index effd33799..165a34456 100644
--- a/testcases/kernel/syscalls/ipc/shmget/shmget02.c
+++ b/testcases/kernel/syscalls/ipc/shmget/shmget02.c
@@ -63,15 +63,27 @@  static struct tcase {
 	{&shmkey1, SHM_SIZE, IPC_CREAT | SHM_HUGETLB, 0, 0, ENOMEM}
 };
 
-static int hugetlbfs_supported(void)
+static int get_hugetlb_exp_error(void)
 {
+	long tmp;
 	struct tst_kconfig_var kconfig = {
 		.id = CONFIG_HUGETLBFS,
 		.id_len = sizeof(CONFIG_HUGETLBFS)-1,
 	};
 
 	tst_kconfig_read(&kconfig, 1);
-	return kconfig.choice == 'y';
+
+	if (kconfig.choice != 'y') {
+		tst_res(TINFO, "SHM_HUGETLB not supported by kernel");
+		return EINVAL;
+	}
+
+	if (FILE_LINES_SCANF("/proc/meminfo", "Hugepagesize: %ld", &tmp)) {
+		tst_res(TINFO, "Huge pages not supported by hardware");
+		return ENOENT;
+	}
+
+	return 0;
 }
 
 static void do_test(unsigned int n)
@@ -102,22 +114,23 @@  static void do_test(unsigned int n)
 static void setup(void)
 {
 	struct rlimit rl = { 0, 0 };
+	int hugetlb_errno;
+	unsigned int i;
+
 	shmkey = GETIPCKEY();
 	shmkey1 = GETIPCKEY();
 
 	SAFE_SETRLIMIT(RLIMIT_MEMLOCK, &rl);
 	shm_id = SAFE_SHMGET(shmkey, SHM_SIZE, IPC_CREAT | IPC_EXCL);
 	pw = SAFE_GETPWNAM("nobody");
+	hugetlb_errno = get_hugetlb_exp_error();
 
-	if (!hugetlbfs_supported()) {
-		unsigned int i;
-
-		tst_res(TINFO, "SHM_HUGETLB not supported by kernel");
+	if (!hugetlb_errno)
+		return;
 
-		for (i = 0; i < ARRAY_SIZE(tcases); i++) {
-			if (tcases[i].flags & SHM_HUGETLB)
-				tcases[i].exp_err = EINVAL;
-		}
+	for (i = 0; i < ARRAY_SIZE(tcases); i++) {
+		if (tcases[i].flags & SHM_HUGETLB)
+			tcases[i].exp_err = hugetlb_errno;
 	}
 }