[LTP] [PATCH] define TST_MAX_CLOCKS to account MAX_AUX_CLOCKS also

Avinesh Kumar akumar@suse.de
Mon Aug 18 16:06:54 CEST 2025


Starting kernel v6.17, syscall tests clock_adjtime02, clock_gettime02,
clock_settime02 and timer_create02 fails in verifying expected errno
for invalid clock IDs, returning ENODEV instead of expected EINVAL.

clock_gettime02.c:133: TFAIL: clock_gettime(2): clock INVALID/UNKNOWN CLOCK failed unexpectedly: ENODEV (19)
clock_gettime02.c:133: TFAIL: clock_gettime(2): clock INVALID/UNKNOWN CLOCK failed unexpectedly: ENODEV (19)

This started as a result of these commits [1], [2] and [3], which
introduced auxiliary POSIX clocks, so when kernel has POSIX_AUX_CLOCKS
option enabled, invalid IDs being used in tests refer to AUX clock IDs.

To fix the tests, define TST_MAX_CLOCKS to also account MAX_AUX_CLOCKS
when trying invalid clock IDs.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=9094c72c3d81bf2416b7c79d12c8494ab8fbac20
[2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=606424bf4ffd9d27865c45b5707c1edac6b187ed
[3] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=60ecc26ec5af567a55f362ad92c0cac8b894541c

Closes #1255

Signed-off-by: Avinesh Kumar <akumar@suse.de>
---
 include/lapi/common_timers.h                             | 9 +++++++++
 .../kernel/syscalls/clock_adjtime/clock_adjtime02.c      | 4 ++--
 .../kernel/syscalls/clock_gettime/clock_gettime02.c      | 4 ++--
 .../kernel/syscalls/clock_settime/clock_settime02.c      | 4 ++--
 testcases/kernel/syscalls/timer_create/timer_create02.c  | 2 +-
 5 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/include/lapi/common_timers.h b/include/lapi/common_timers.h
index 884c997a1..f68cea811 100644
--- a/include/lapi/common_timers.h
+++ b/include/lapi/common_timers.h
@@ -7,6 +7,7 @@
 #ifndef LAPI_COMMON_TIMERS_H__
 #define LAPI_COMMON_TIMERS_H__
 
+#include <linux/version.h>
 #include "config.h"
 #include "lapi/syscalls.h"
 #include "lapi/posix_clocks.h"
@@ -30,6 +31,14 @@ static const clock_t clock_list[] = {
 /* MAX_CLOCKS is the maximum number of clock sources supported by kernel */
 #define MAX_CLOCKS 16
 
+#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/testcases/kernel/syscalls/clock_adjtime/clock_adjtime02.c b/testcases/kernel/syscalls/clock_adjtime/clock_adjtime02.c
index 2df9099d5..0c5e6ac21 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 = MAX_CLOCKS,
+	 .clktype = TST_MAX_CLOCKS,
 	 .exp_err = EINVAL,
 	},
 	{
-	 .clktype = MAX_CLOCKS + 1,
+	 .clktype = TST_MAX_CLOCKS + 1,
 	 .exp_err = EINVAL,
 	},
 	{
diff --git a/testcases/kernel/syscalls/clock_gettime/clock_gettime02.c b/testcases/kernel/syscalls/clock_gettime/clock_gettime02.c
index 0108bb426..1e1769864 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 = MAX_CLOCKS,
+	 .clktype = TST_MAX_CLOCKS,
 	 .exp_err = EINVAL,
 	 },
 	{
-	 .clktype = MAX_CLOCKS + 1,
+	 .clktype = TST_MAX_CLOCKS + 1,
 	 .exp_err = EINVAL,
 	 },
 	/*
diff --git a/testcases/kernel/syscalls/clock_settime/clock_settime02.c b/testcases/kernel/syscalls/clock_settime/clock_settime02.c
index 5974e79a9..9d703565b 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 = MAX_CLOCKS,
+	 .type = TST_MAX_CLOCKS,
 	 .exp_err = EINVAL,
 	 },
 	{				/* case 07: MAXCLOCK+1		      */
-	 .type = MAX_CLOCKS + 1,
+	 .type = TST_MAX_CLOCKS + 1,
 	 .exp_err = EINVAL,
 	 },
 	/* Linux specific */
diff --git a/testcases/kernel/syscalls/timer_create/timer_create02.c b/testcases/kernel/syscalls/timer_create/timer_create02.c
index 551cf50b9..9f41c683d 100644
--- a/testcases/kernel/syscalls/timer_create/timer_create02.c
+++ b/testcases/kernel/syscalls/timer_create/timer_create02.c
@@ -52,7 +52,7 @@ static struct testcase {
 } tcases[] = {
 	{CLOCK_REALTIME, NULL, &timer_id, EFAULT, "invalid sigevent struct"},
 	{CLOCK_REALTIME, &sig_ev, NULL, EFAULT, "invalid timer ID"},
-	{MAX_CLOCKS, &sig_ev, &timer_id, EINVAL, "invalid clock"},
+	{TST_MAX_CLOCKS, &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"},
 };
-- 
2.43.0



More information about the ltp mailing list