Linux Test Project
 help / color / mirror / Atom feed
From: Avinesh Kumar <akumar@suse.de>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH] Add tst_get_max_clocks() routine based on tst_kconfig_check()
Date: Fri,  5 Sep 2025 10:46:07 +0200	[thread overview]
Message-ID: <20250905084608.11958-1-akumar@suse.de> (raw)

current logic for defining TST_MAX_CLOCKS is based on checking the kernel
version provided by glibc headers which is not right as there are
mismatches possible between kernel version being tested and version
provided by headers.
Instead use tst_kconfig_check() routine for checking if the
CONFIG_POSIX_AUX_CLOCKS config option is set and define max clocks
accordingly in the tests for invalid clock types.

Fixes: da6b61438 ("define TST_MAX_CLOCKS to account MAX_AUX_CLOCKS also")
Suggested-by: Cyril Hrubis <chrubis@suse.cz>
Suggested-by: Petr Vorel <pvorel@suse.cz>
Signed-off-by: Avinesh Kumar <akumar@suse.de>
---
 include/lapi/common_timers.h                         |  6 ------
 include/tst_clocks.h                                 |  2 ++
 lib/tst_clocks.c                                     | 12 ++++++++++++
 .../kernel/syscalls/clock_adjtime/clock_adjtime02.c  |  7 +++++--
 .../kernel/syscalls/clock_gettime/clock_gettime02.c  |  7 +++++--
 .../kernel/syscalls/clock_settime/clock_settime02.c  |  7 +++++--
 .../kernel/syscalls/timer_create/timer_create02.c    |  5 ++++-
 7 files changed, 33 insertions(+), 13 deletions(-)

diff --git a/include/lapi/common_timers.h b/include/lapi/common_timers.h
index f68cea811..6a615c3f4 100644
--- a/include/lapi/common_timers.h
+++ b/include/lapi/common_timers.h
@@ -33,12 +33,6 @@ static const clock_t clock_list[] = {
 
 #define MAX_AUX_CLOCKS 8
 
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 17, 0)
-#define TST_MAX_CLOCKS (MAX_CLOCKS + MAX_AUX_CLOCKS)
-#else
-#define TST_MAX_CLOCKS (MAX_CLOCKS)
-#endif
-
 #define CLOCK_TO_STR(def_name)	\
 	case def_name:		\
 		return #def_name;
diff --git a/include/tst_clocks.h b/include/tst_clocks.h
index 8b7f33d4f..69251d5d4 100644
--- a/include/tst_clocks.h
+++ b/include/tst_clocks.h
@@ -48,4 +48,6 @@ time_t tst_fs_timestamp_start(void);
  */
 time_t tst_fs_timestamp_end(void);
 
+int tst_get_max_clocks(void);
+
 #endif /* TST_CLOCKS__ */
diff --git a/lib/tst_clocks.c b/lib/tst_clocks.c
index fba4a4f7b..704ce9551 100644
--- a/lib/tst_clocks.c
+++ b/lib/tst_clocks.c
@@ -11,6 +11,8 @@
 #include "tst_clocks.h"
 #include "lapi/syscalls.h"
 #include "lapi/posix_clocks.h"
+#include "lapi/common_timers.h"
+#include "tst_kconfig.h"
 
 typedef int (*mysyscall)(clockid_t clk_id, void *ts);
 
@@ -168,3 +170,13 @@ time_t tst_fs_timestamp_end(void)
 {
 	return tst_clock_get_timestamp(CLOCK_REALTIME);
 }
+
+int tst_get_max_clocks(void)
+{
+	static const char * const kconf_aux[] = {"CONFIG_POSIX_AUX_CLOCKS=y", NULL};
+
+	if (!tst_kconfig_check(kconf_aux))
+		return MAX_CLOCKS + MAX_AUX_CLOCKS;
+	else
+		return MAX_CLOCKS;
+}
diff --git a/testcases/kernel/syscalls/clock_adjtime/clock_adjtime02.c b/testcases/kernel/syscalls/clock_adjtime/clock_adjtime02.c
index 0c5e6ac21..ba62bf716 100644
--- a/testcases/kernel/syscalls/clock_adjtime/clock_adjtime02.c
+++ b/testcases/kernel/syscalls/clock_adjtime/clock_adjtime02.c
@@ -76,11 +76,11 @@ struct test_case {
 
 struct test_case tc[] = {
 	{
-	 .clktype = TST_MAX_CLOCKS,
+	 .clktype = 0,
 	 .exp_err = EINVAL,
 	},
 	{
-	 .clktype = TST_MAX_CLOCKS + 1,
+	 .clktype = 0,
 	 .exp_err = EINVAL,
 	},
 	{
@@ -223,6 +223,9 @@ static void setup(void)
 			tc[i].lowlimit /= hz;
 		}
 	}
+
+	tc[0].clktype = tst_get_max_clocks();
+	tc[1].clktype = tst_get_max_clocks() + 1;
 }
 
 static void cleanup(void)
diff --git a/testcases/kernel/syscalls/clock_gettime/clock_gettime02.c b/testcases/kernel/syscalls/clock_gettime/clock_gettime02.c
index 1e1769864..091188d8a 100644
--- a/testcases/kernel/syscalls/clock_gettime/clock_gettime02.c
+++ b/testcases/kernel/syscalls/clock_gettime/clock_gettime02.c
@@ -34,11 +34,11 @@ struct test_case {
 
 static struct test_case tc[] = {
 	{
-	 .clktype = TST_MAX_CLOCKS,
+	 .clktype = 0,
 	 .exp_err = EINVAL,
 	 },
 	{
-	 .clktype = TST_MAX_CLOCKS + 1,
+	 .clktype = 0,
 	 .exp_err = EINVAL,
 	 },
 	/*
@@ -103,6 +103,9 @@ static void setup(void)
 	tst_res(TINFO, "Testing variant: %d: %s", tst_variant, variants[tst_variant].desc);
 
 	bad_addr = tst_get_bad_addr(NULL);
+
+	tc[0].clktype = tst_get_max_clocks();
+	tc[1].clktype = tst_get_max_clocks() + 1;
 }
 
 static void verify_clock_gettime(unsigned int i)
diff --git a/testcases/kernel/syscalls/clock_settime/clock_settime02.c b/testcases/kernel/syscalls/clock_settime/clock_settime02.c
index 9d703565b..cf002b30e 100644
--- a/testcases/kernel/syscalls/clock_settime/clock_settime02.c
+++ b/testcases/kernel/syscalls/clock_settime/clock_settime02.c
@@ -59,11 +59,11 @@ struct test_case tc[] = {
 	 .exp_err = EINVAL,
 	 },
 	{				/* case 06: MAXCLOCK		      */
-	 .type = TST_MAX_CLOCKS,
+	 .type = 0,
 	 .exp_err = EINVAL,
 	 },
 	{				/* case 07: MAXCLOCK+1		      */
-	 .type = TST_MAX_CLOCKS + 1,
+	 .type = 0,
 	 .exp_err = EINVAL,
 	 },
 	/* Linux specific */
@@ -106,6 +106,9 @@ static void setup(void)
 	tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
 
 	bad_addr = tst_get_bad_addr(NULL);
+
+	tc[5].type = tst_get_max_clocks();
+	tc[6].type = tst_get_max_clocks() + 1;
 }
 
 static void verify_clock_settime(unsigned int i)
diff --git a/testcases/kernel/syscalls/timer_create/timer_create02.c b/testcases/kernel/syscalls/timer_create/timer_create02.c
index af3a5203e..cc7b6d0d0 100644
--- a/testcases/kernel/syscalls/timer_create/timer_create02.c
+++ b/testcases/kernel/syscalls/timer_create/timer_create02.c
@@ -25,6 +25,7 @@
 #include <signal.h>
 #include "tst_test.h"
 #include "lapi/common_timers.h"
+#include "tst_safe_clocks.h"
 
 static struct sigevent sig_ev = {
 	.sigev_notify = SIGEV_NONE,
@@ -52,7 +53,7 @@ static struct testcase {
 } tcases[] = {
 	{CLOCK_REALTIME, NULL, &timer_id, EFAULT, "invalid sigevent struct"},
 	{CLOCK_REALTIME, &sig_ev, NULL, EFAULT, "invalid timer ID"},
-	{TST_MAX_CLOCKS, &sig_ev, &timer_id, EINVAL, "invalid clock"},
+	{0, &sig_ev, &timer_id, EINVAL, "invalid clock"},
 	{CLOCK_REALTIME, &sig_ev_inv_not, &timer_id, EINVAL, "wrong sigev_notify"},
 	{CLOCK_REALTIME, &sig_ev_inv_sig, &timer_id, EINVAL, "wrong sigev_signo"},
 };
@@ -84,6 +85,8 @@ static void setup(void)
 		if (!tcases[i].kt_ptr)
 			tcases[i].kt_ptr = tst_get_bad_addr(NULL);
 	}
+
+    tcases[2].clock = tst_get_max_clocks();
 }
 
 static struct tst_test test = {
-- 
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

             reply	other threads:[~2025-09-05  8:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-05  8:46 Avinesh Kumar [this message]
2025-09-05 11:12 ` [LTP] [PATCH] Add tst_get_max_clocks() routine based on tst_kconfig_check() Cyril Hrubis
2025-09-05 14:58   ` Avinesh Kumar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250905084608.11958-1-akumar@suse.de \
    --to=akumar@suse.de \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox