Skip to contentSkip to conversation

syscalls/clock_*(): Add support for time64 variants

PATCH Superseded Viresh Kumar 2 participants 15 messages Apr 22, 2020 – Apr 28, 2020

lore
Share & tools
lore
#0 lore raw

v4 cover syscalls/clock_*(): Add support for time64 variants

Hello,

Here is the fourth version of this series and here are the changes since v3.

V3->V4:
- Dropped the first patch, it is already applied by Cyril.
- Update clock_gettime() patch (1/5), according to the changes Cyril made.
- Rest four patches (2-5/5) are posted for the first time here.

--
Viresh

Viresh Kumar (5):
syscalls/clock_gettime: Add support for time64 tests syscalls/clock_settime: Add support for time64 tests syscalls/clock_getres: Add support for time64 tests syscalls/clock_nanosleep: Add support for time64 tests syscalls/clock_adjtime: Add support for time64 tests

 include/tst_timer.h                           | 122 +++++++++-
 runtest/syscalls                              |   2 +-
 .../syscalls/clock_adjtime/clock_adjtime.h    | 220 +++++++++++++++---
 .../syscalls/clock_adjtime/clock_adjtime01.c  | 124 ++++++----
 .../syscalls/clock_adjtime/clock_adjtime02.c  |  90 +++++--
 .../syscalls/clock_getres/clock_getres01.c    |  58 +++--
 .../syscalls/clock_gettime/clock_gettime01.c  | 116 +++++----
 .../syscalls/clock_gettime/clock_gettime02.c  |  72 +++---
 .../syscalls/clock_gettime/clock_gettime03.c  |  58 ++++-
 .../syscalls/clock_nanosleep/.gitignore       |   1 +
 .../clock_nanosleep/clock_nanosleep01.c       | 102 ++++++--
 .../clock_nanosleep/clock_nanosleep03.c       |  68 +++++-
 .../clock_nanosleep/clock_nanosleep04.c       |  90 +++++++
 .../syscalls/clock_nanosleep2/.gitignore      |   1 -
 .../kernel/syscalls/clock_nanosleep2/Makefile |  10 -
 .../clock_nanosleep2/clock_nanosleep2_01.c    |  45 ----
 .../syscalls/clock_settime/clock_settime01.c  |  87 +++++--
 .../syscalls/clock_settime/clock_settime02.c  |  95 +++++---
 18 files changed, 993 insertions(+), 368 deletions(-)
 create mode 100644 testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep04.c
 delete mode 100644 testcases/kernel/syscalls/clock_nanosleep2/.gitignore
 delete mode 100644 testcases/kernel/syscalls/clock_nanosleep2/Makefile
 delete mode 100644 testcases/kernel/syscalls/clock_nanosleep2/clock_nanosleep2_01.c
Signature · 1 line
2.25.0.rc1.19.g042ed3e048af
#1 lore raw

PATCH v4 1/5 syscalls/clock_gettime: Add support for time64 tests

This adds support for time64 tests to the existing clock_gettime() syscall tests.

---
 include/tst_timer.h                           |  65 +++++++++-
 .../syscalls/clock_gettime/clock_gettime01.c  | 116 ++++++++----------
 .../syscalls/clock_gettime/clock_gettime02.c  |  72 ++++++-----
 .../syscalls/clock_gettime/clock_gettime03.c  |  58 +++++++--
 4 files changed, 206 insertions(+), 105 deletions(-)
include/tst_timer.h +64 -1
index 4f97acd165b8..f40b93a624b3 100644
@@ -15,6 +15,7 @@
 #include <sys/time.h>
 #include <time.h>
 #include "tst_test.h"
+#include "lapi/syscalls.h"
 
 /*
  * Converts timeval to microseconds.
@@ -116,7 +117,9 @@ struct __kernel_timespec {
 enum tst_ts_type {
 	TST_LIBC_TIMESPEC,
 	TST_KERN_OLD_TIMESPEC,
-	TST_KERN_TIMESPEC
+	TST_KERN_TIMESPEC,
+	/* Used for indicating failure test with bad address */
+	TST_KERN_BAD_ADDR
 };
 
 struct tst_ts {
@@ -128,6 +131,66 @@ struct tst_ts {
 	};
 };
 
+static inline void *tst_get_ts(struct tst_ts *t)
+{
+	switch (t->type) {
+	case TST_LIBC_TIMESPEC:
+		return &t->libc_ts;
+	case TST_KERN_OLD_TIMESPEC:
+		return &t->kern_old_ts;
+	case TST_KERN_TIMESPEC:
+		return &t->kern_ts;
+	case TST_KERN_BAD_ADDR:
+		return tst_get_bad_addr(NULL);
+	default:
+		tst_brk(TBROK, "Invalid type: %d", t->type);
+		return NULL;
+	}
+}
+
+static inline int libc_clock_gettime(clockid_t clk_id, struct tst_ts *t)
+{
+	return clock_gettime(clk_id, tst_get_ts(t));
+}
+
+static inline int sys_clock_gettime(clockid_t clk_id, struct tst_ts *t)
+{
+	return tst_syscall(__NR_clock_gettime, clk_id, tst_get_ts(t));
+}
+
+static inline int sys_clock_gettime64(clockid_t clk_id, struct tst_ts *t)
+{
+	return tst_syscall(__NR_clock_gettime64, clk_id, tst_get_ts(t));
+}
+
+/*
+ * tst_ts_nonzero return:
+ * 0: On success, i.e. timespec updated correctly.
+ * -1: Error, timespec not updated.
+ * -2: Error, tv_nsec is corrupted.
+ */
+static inline int tst_ts_nonzero(struct tst_ts *t)
+{
+	switch (t->type) {
+	case TST_LIBC_TIMESPEC:
+		return (t->libc_ts.tv_nsec == 0 && t->libc_ts.tv_sec == 0) ? -1 : 0;
+	case TST_KERN_OLD_TIMESPEC:
+		return (t->kern_old_ts.tv_nsec == 0 && t->kern_old_ts.tv_sec == 0) ? -1 : 0;
+	case TST_KERN_TIMESPEC:
+		if (t->kern_ts.tv_nsec == 0 && t->kern_ts.tv_sec == 0)
+			return -1;
+
+		/* Upper 32 bits of tv_nsec should be cleared */
+		if (t->kern_ts.tv_nsec >> 32)
+			return -2;
+		else
+			return 0;
+	default:
+		tst_brk(TBROK, "Invalid type: %d", t->type);
+		return -1;
+	}
+}
+
 /*
  * Returns tst_ts seconds.
  */
testcases/kernel/syscalls/clock_gettime/clock_gettime01.c +52 -64

150 lines not on this page · raw message

testcases/kernel/syscalls/clock_gettime/clock_gettime02.c +43 -29

112 lines not on this page · raw message

testcases/kernel/syscalls/clock_gettime/clock_gettime03.c +47 -11

109 lines not on this page · raw message

Signature · 1 line
2.25.0.rc1.19.g042ed3e048af
#5 lore raw

PATCH v4 2/5 syscalls/clock_settime: Add support for time64 tests

In reply to Viresh Kumar

This adds support for time64 tests to the existing clock_settime() syscall tests.

---
 include/tst_timer.h                           | 15 +++
 .../syscalls/clock_settime/clock_settime01.c  | 87 ++++++++++++++---
 .../syscalls/clock_settime/clock_settime02.c  | 95 ++++++++++++-------
 3 files changed, 146 insertions(+), 51 deletions(-)
include/tst_timer.h +15 -0
index f40b93a624b3..fef201ee04df 100644
@@ -163,6 +163,21 @@ static inline int sys_clock_gettime64(clockid_t clk_id, struct tst_ts *t)
 	return tst_syscall(__NR_clock_gettime64, clk_id, tst_get_ts(t));
 }
 
+static inline int libc_clock_settime(clockid_t clk_id, struct tst_ts *t)
+{
+	return clock_settime(clk_id, tst_get_ts(t));
+}
+
+static inline int sys_clock_settime(clockid_t clk_id, struct tst_ts *t)
+{
+	return tst_syscall(__NR_clock_settime, clk_id, tst_get_ts(t));
+}
+
+static inline int sys_clock_settime64(clockid_t clk_id, struct tst_ts *t)
+{
+	return tst_syscall(__NR_clock_settime64, clk_id, tst_get_ts(t));
+}
+
 /*
  * tst_ts_nonzero return:
  * 0: On success, i.e. timespec updated correctly.
testcases/kernel/syscalls/clock_settime/clock_settime01.c +72 -15

125 lines not on this page · raw message

testcases/kernel/syscalls/clock_settime/clock_settime02.c +59 -36

166 lines not on this page · raw message

Signature · 1 line
2.25.0.rc1.19.g042ed3e048af
#7 lore raw

PATCH v4 3/5 syscalls/clock_getres: Add support for time64 tests

In reply to Viresh Kumar

This adds support for time64 tests to the existing clock_getres() syscall tests.

---
 include/tst_timer.h                           | 18 ++++++
 .../syscalls/clock_getres/clock_getres01.c    | 58 ++++++++++++-------
 2 files changed, 54 insertions(+), 22 deletions(-)
include/tst_timer.h +18 -0
index fef201ee04df..df59c6aac0a5 100644
@@ -133,6 +133,9 @@ struct tst_ts {
 
 static inline void *tst_get_ts(struct tst_ts *t)
 {
+	if (!t)
+		return NULL;
+
 	switch (t->type) {
 	case TST_LIBC_TIMESPEC:
 		return &t->libc_ts;
@@ -148,6 +151,21 @@ static inline void *tst_get_ts(struct tst_ts *t)
 	}
 }
 
+static inline int libc_clock_getres(clockid_t clk_id, struct tst_ts *t)
+{
+	return clock_getres(clk_id, tst_get_ts(t));
+}
+
+static inline int sys_clock_getres(clockid_t clk_id, struct tst_ts *t)
+{
+	return tst_syscall(__NR_clock_getres, clk_id, tst_get_ts(t));
+}
+
+static inline int sys_clock_getres64(clockid_t clk_id, struct tst_ts *t)
+{
+	return tst_syscall(__NR_clock_getres_time64, clk_id, tst_get_ts(t));
+}
+
 static inline int libc_clock_gettime(clockid_t clk_id, struct tst_ts *t)
 {
 	return clock_gettime(clk_id, tst_get_ts(t));
testcases/kernel/syscalls/clock_getres/clock_getres01.c +36 -22

86 lines not on this page · raw message

Signature · 1 line
2.25.0.rc1.19.g042ed3e048af
#8 lore raw

PATCH v4 4/5 syscalls/clock_nanosleep: Add support for time64 tests

In reply to Viresh Kumar

This adds support for time64 tests to the existing clock_nanosleep() syscall tests.

This also moves the tests from clock_nanosleep2/ directory to clock_nanosleep/ directory as it was added mistakenly there, as there is no clock_nanosleep2() syscall.

Also note that this patch doesn't update clock_nanosleep02.c test as that uses the sample test pattern and will result in many other changes to core libraries of LTP test suite.

---
 include/tst_timer.h                           |  24 +++++
 runtest/syscalls                              |   2 +-
 .../syscalls/clock_nanosleep/.gitignore       |   1 +
 .../clock_nanosleep/clock_nanosleep01.c       | 102 +++++++++++++-----
 .../clock_nanosleep/clock_nanosleep03.c       |  68 ++++++++++--
 .../clock_nanosleep/clock_nanosleep04.c       |  90 ++++++++++++++++
 .../syscalls/clock_nanosleep2/.gitignore      |   1 -
 .../kernel/syscalls/clock_nanosleep2/Makefile |  10 --
 .../clock_nanosleep2/clock_nanosleep2_01.c    |  45 --------
 9 files changed, 253 insertions(+), 90 deletions(-)
 create mode 100644 testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep04.c
 delete mode 100644 testcases/kernel/syscalls/clock_nanosleep2/.gitignore
 delete mode 100644 testcases/kernel/syscalls/clock_nanosleep2/Makefile
 delete mode 100644 testcases/kernel/syscalls/clock_nanosleep2/clock_nanosleep2_01.c
include/tst_timer.h +24 -0
index df59c6aac0a5..ab7d65f73b7b 100644
@@ -196,6 +196,30 @@ static inline int sys_clock_settime64(clockid_t clk_id, struct tst_ts *t)
 	return tst_syscall(__NR_clock_settime64, clk_id, tst_get_ts(t));
 }
 
+static inline int libc_clock_nanosleep(clockid_t clk_id, int flags,
+				       struct tst_ts *request,
+				       struct tst_ts *remain)
+{
+	return clock_nanosleep(clk_id, flags, tst_get_ts(request),
+			       tst_get_ts(remain));
+}
+
+static inline int sys_clock_nanosleep(clockid_t clk_id, int flags,
+				      struct tst_ts *request,
+				      struct tst_ts *remain)
+{
+	return tst_syscall(__NR_clock_nanosleep, clk_id, flags,
+			   tst_get_ts(request), tst_get_ts(remain));
+}
+
+static inline int sys_clock_nanosleep64(clockid_t clk_id, int flags,
+				        struct tst_ts *request,
+					struct tst_ts *remain)
+{
+	return tst_syscall(__NR_clock_nanosleep_time64, clk_id, flags,
+			   tst_get_ts(request), tst_get_ts(remain));
+}
+
 /*
  * tst_ts_nonzero return:
  * 0: On success, i.e. timespec updated correctly.
runtest/syscalls +1 -1
index 9bb72beb2287..bfd8d3dc32f2 100644
@@ -90,8 +90,8 @@ clock_adjtime02 clock_adjtime02
 clock_getres01 clock_getres01
 clock_nanosleep01 clock_nanosleep01
 clock_nanosleep02 clock_nanosleep02
-clock_nanosleep2_01 clock_nanosleep2_01
 clock_nanosleep03 clock_nanosleep03
+clock_nanosleep04 clock_nanosleep04
 
 clock_gettime01 clock_gettime01
 clock_gettime02 clock_gettime02
testcases/kernel/syscalls/clock_nanosleep/.gitignore +1 -0
index 406897cded6d..1ab03a335f37 100644
@@ -1,3 +1,4 @@
 /clock_nanosleep01
 /clock_nanosleep02
 /clock_nanosleep03
+/clock_nanosleep04
testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep01.c +77 -25

178 lines not on this page · raw message

testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep03.c +60 -8

104 lines not on this page · raw message

testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep04.c new file +90 -0

90 lines not on this page · raw message

testcases/kernel/syscalls/clock_nanosleep2/.gitignore deleted +0 -1
deleted file mode 100644
index 5be9cd0e8a8d..000000000000
@@ -1 +0,0 @@
-/clock_nanosleep2_01
testcases/kernel/syscalls/clock_nanosleep2/Makefile deleted +0 -10
deleted file mode 100644
index 262eef71b02b..000000000000
@@ -1,10 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0-or-later
-# Copyright (c) International Business Machines  Corp., 2009
-
-top_srcdir		?= ../../../..
-
-include $(top_srcdir)/include/mk/testcases.mk
-
-LDLIBS			+= -lpthread -lrt
-
-include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/clock_nanosleep2/clock_nanosleep2_01.c deleted +0 -45

45 lines not on this page · raw message

Signature · 1 line
2.25.0.rc1.19.g042ed3e048af
#9 lore raw

PATCH v4 5/5 syscalls/clock_adjtime: Add support for time64 tests

In reply to Viresh Kumar

This adds support for time64 tests to the existing clock_adjtime() syscall tests.

---
 .../syscalls/clock_adjtime/clock_adjtime.h    | 220 +++++++++++++++---
 .../syscalls/clock_adjtime/clock_adjtime01.c  | 124 ++++++----
 .../syscalls/clock_adjtime/clock_adjtime02.c  |  90 +++++--
 3 files changed, 334 insertions(+), 100 deletions(-)
testcases/kernel/syscalls/clock_adjtime/clock_adjtime.h +186 -34
index d7f553a3a04b..4f65307be0ab 100644
@@ -16,43 +16,195 @@
 #include <sys/types.h>
 #include "lapi/timex.h"
 
-static int sys_clock_adjtime(clockid_t, struct timex *);
-static void timex_show(char *, struct timex);
+#ifndef __kernel_timex
+struct __kernel_timex_timeval {
+	__kernel_time64_t       tv_sec;
+	long long		tv_usec;
+};
 
-/*
- * bad pointer w/ libc causes SIGSEGV signal, call syscall directly
- */
-static int sys_clock_adjtime(clockid_t clk_id, struct timex *txc)
+struct __kernel_timex {
+	unsigned int modes;	/* mode selector */
+	int :32;            /* pad */
+	long long offset;	/* time offset (usec) */
+	long long freq;	/* frequency offset (scaled ppm) */
+	long long maxerror;/* maximum error (usec) */
+	long long esterror;/* estimated error (usec) */
+	int status;		/* clock command/status */
+	int :32;            /* pad */
+	long long constant;/* pll time constant */
+	long long precision;/* clock precision (usec) (read only) */
+	long long tolerance;/* clock frequency tolerance (ppm)
+				   * (read only)
+				   */
+	struct __kernel_timex_timeval time;	/* (read only, except for ADJ_SETOFFSET) */
+	long long tick;	/* (modified) usecs between clock ticks */
+
+	long long ppsfreq;/* pps frequency (scaled ppm) (ro) */
+	long long jitter; /* pps jitter (us) (ro) */
+	int shift;              /* interval duration (s) (shift) (ro) */
+	int :32;            /* pad */
+	long long stabil;            /* pps stability (scaled ppm) (ro) */
+	long long jitcnt; /* jitter limit exceeded (ro) */
+	long long calcnt; /* calibration intervals (ro) */
+	long long errcnt; /* calibration errors (ro) */
+	long long stbcnt; /* stability limit exceeded (ro) */
+
+	int tai;		/* TAI offset (ro) */
+
+	int  :32; int  :32; int  :32; int  :32;
+	int  :32; int  :32; int  :32; int  :32;
+	int  :32; int  :32; int  :32;
+};
+#endif
+
+enum tst_timex_type {
+	TST_LIBC_TIMEX,
+	TST_KERN_TIMEX,
+	/* Used for indicating failure test with bad address */
+	TST_KERN_TIMEX_BAD_ADDR
+};
+
+struct tst_timex {
+	enum tst_timex_type type;
+	union {
+		struct timex libc_timex;
+		struct __kernel_timex kern_timex;
+	};
+};
+
+static inline void *tst_get_timex(struct tst_timex *t)
+{
+	switch (t->type) {
+	case TST_LIBC_TIMEX:
+		return &t->libc_timex;
+	case TST_KERN_TIMEX:
+		return &t->kern_timex;
+	case TST_KERN_TIMEX_BAD_ADDR:
+		return tst_get_bad_addr(NULL);
+	default:
+		tst_brk(TBROK, "Invalid type: %d", t->type);
+		return NULL;
+	}
+}
+
+static inline int sys_clock_adjtime(clockid_t clk_id, struct tst_timex *t)
 {
-	return tst_syscall(__NR_clock_adjtime, clk_id, txc);
+	return tst_syscall(__NR_clock_adjtime, clk_id, tst_get_timex(t));
 }
 
-static void timex_show(char *given, struct timex txc)
+static inline int sys_clock_adjtime64(clockid_t clk_id, struct tst_timex *t)
 {
-	tst_res(TINFO,  "%s\n"
-			"             mode: %d\n"
-			"           offset: %ld\n"
-			"        frequency: %ld\n"
-			"         maxerror: %ld\n"
-			"         esterror: %ld\n"
-			"           status: %d (0x%x)\n"
-			"    time_constant: %ld\n"
-			"        precision: %ld\n"
-			"        tolerance: %ld\n"
-			"             tick: %ld\n"
-			"         raw time: %d(s) %d(us)",
-			given,
-			txc.modes,
-			txc.offset,
-			txc.freq,
-			txc.maxerror,
-			txc.esterror,
-			txc.status,
-			txc.status,
-			txc.constant,
-			txc.precision,
-			txc.tolerance,
-			txc.tick,
-			(int)txc.time.tv_sec,
-			(int)txc.time.tv_usec);
+	return tst_syscall(__NR_clock_adjtime64, clk_id, tst_get_timex(t));
+}
+
+#define _timex_show(_timex, _desc)					\
+	tst_res(TINFO,  "%s\n"						\
+			"             mode: %u\n"			\
+			"           offset: "#_desc"\n"			\
+			"        frequency: "#_desc"\n"			\
+			"         maxerror: "#_desc"\n"			\
+			"         esterror: "#_desc"\n"			\
+			"           status: %d (0x%x)\n"		\
+			"    time_constant: "#_desc"\n"			\
+			"        precision: "#_desc"\n"			\
+			"        tolerance: "#_desc"\n"			\
+			"             tick: "#_desc"\n"			\
+			"         raw time: "#_desc"(s) "#_desc"(us)",	\
+			given,						\
+			_timex.modes,					\
+			_timex.offset,					\
+			_timex.freq,					\
+			_timex.maxerror,				\
+			_timex.esterror,				\
+			_timex.status,					\
+			_timex.status,					\
+			_timex.constant,				\
+			_timex.precision,				\
+			_timex.tolerance,				\
+			_timex.tick,					\
+			_timex.time.tv_sec,				\
+			_timex.time.tv_usec)
+
+static inline void timex_show(char *given, struct tst_timex *timex)
+{
+	switch (timex->type) {
+	case TST_LIBC_TIMEX:
+		_timex_show(timex->libc_timex, %ld);
+		return;
+	case TST_KERN_TIMEX:
+		_timex_show(timex->kern_timex, %lld);
+		return;
+	default:
+		tst_res(TFAIL, "Invalid type: %d", timex->type);
+	}
+}
+
+#define ADJ_MODES	0
+
+#define _select_field(_timex, _field)					\
+{									\
+	if (_field == ADJ_MODES)					\
+		return &_timex.modes;					\
+	if (_field == ADJ_OFFSET)					\
+		return &_timex.offset;					\
+	if (_field == ADJ_FREQUENCY)					\
+		return &_timex.freq;					\
+	if (_field == ADJ_MAXERROR)					\
+		return &_timex.maxerror;				\
+	if (_field == ADJ_ESTERROR)					\
+		return &_timex.esterror;				\
+	if (_field == ADJ_TIMECONST)					\
+		return &_timex.constant;				\
+	if (_field == ADJ_TICK)						\
+		return &_timex.tick;					\
+	if (_field == ADJ_STATUS)					\
+		return &_timex.status;					\
+	tst_res(TFAIL, "Invalid type: %d", timex->type);		\
+	return NULL;							\
+}
+
+static inline void *_get_field(struct tst_timex *timex, unsigned int field)
+{
+	switch (timex->type) {
+	case TST_LIBC_TIMEX:
+		_select_field(timex->libc_timex, field);
+	case TST_KERN_TIMEX:
+		_select_field(timex->kern_timex, field);
+	default:
+		tst_res(TFAIL, "Invalid type: %d", timex->type);
+		return NULL;
+	}
+}
+
+#define timex_get_set_field_type(_type_libc, _type_kern)		\
+static inline _type_kern						\
+timex_get_field_##_type_libc(struct tst_timex *timex, unsigned int field) \
+{									\
+	switch (timex->type) {						\
+	case TST_LIBC_TIMEX:						\
+		return *((_type_libc*)_get_field(timex, field));	\
+	case TST_KERN_TIMEX:						\
+		return *((_type_kern*)_get_field(timex, field));	\
+	default:							\
+		tst_res(TFAIL, "Invalid type: %d", timex->type);	\
+		return 0;						\
+	}								\
+}									\
+									\
+static inline void							\
+timex_set_field_##_type_libc(struct tst_timex *timex, unsigned int field, \
+			    _type_kern value)				\
+{									\
+	switch (timex->type) {						\
+	case TST_LIBC_TIMEX:						\
+		*((_type_libc*)_get_field(timex, field)) = value;	\
+		return;							\
+	case TST_KERN_TIMEX:						\
+		*((_type_kern*)_get_field(timex, field)) = value;	\
+		return;							\
+	default:							\
+		tst_res(TFAIL, "Invalid type: %d", timex->type);	\
+	}								\
 }
+timex_get_set_field_type(uint, uint);
+timex_get_set_field_type(long, long long);
testcases/kernel/syscalls/clock_adjtime/clock_adjtime01.c +83 -41

225 lines not on this page · raw message

testcases/kernel/syscalls/clock_adjtime/clock_adjtime02.c +65 -25

179 lines not on this page · raw message

Signature · 1 line
2.25.0.rc1.19.g042ed3e048af
#2 lore raw

PATCH v4 1/5 syscalls/clock_gettime: Add support for time64 tests

In reply to Viresh Kumar

Hi!
Pushed with a few changes, thanks.

* Changed the nonzero check to check if nanoseconds are valid, which covers the 64bit check as well.

* Pushed the bad address handling down to the test, which means that we have to convert the struct tst_ts for each syscall, but I think that it's cleaner that way and we also map only single bad address per test.

Signature · 2 lines
Cyril Hrubis
[email protected]
#10 lore raw

PATCH v5 3/5 syscalls/clock_getres: Add support for time64 tests

In reply to Viresh Kumar

This adds support for time64 tests to the existing clock_getres() syscall tests.

---
 include/tst_timer.h                           | 18 ++++++
 .../syscalls/clock_getres/clock_getres01.c    | 58 ++++++++++++-------
 2 files changed, 54 insertions(+), 22 deletions(-)
include/tst_timer.h +18 -0
index 0c6b934157f9..4823d350fdc6 100644
@@ -131,6 +131,9 @@ struct tst_ts {
 
 static inline void *tst_ts_get(struct tst_ts *t)
 {
+	if (!t)
+		return NULL;
+
 	switch (t->type) {
 	case TST_LIBC_TIMESPEC:
 		return &t->ts.libc_ts;
@@ -144,6 +147,21 @@ static inline void *tst_ts_get(struct tst_ts *t)
 	}
 }
 
+static inline int libc_clock_getres(clockid_t clk_id, void *ts)
+{
+	return clock_getres(clk_id, ts);
+}
+
+static inline int sys_clock_getres(clockid_t clk_id, void *ts)
+{
+	return tst_syscall(__NR_clock_getres, clk_id, ts);
+}
+
+static inline int sys_clock_getres64(clockid_t clk_id, void *ts)
+{
+	return tst_syscall(__NR_clock_getres_time64, clk_id, ts);
+}
+
 static inline int libc_clock_gettime(clockid_t clk_id, void *ts)
 {
 	return clock_gettime(clk_id, ts);
testcases/kernel/syscalls/clock_getres/clock_getres01.c +36 -22

86 lines not on this page · raw message

Signature · 1 line
2.25.0.rc1.19.g042ed3e048af
#11 lore raw

PATCH v5 4/5 syscalls/clock_nanosleep: Add support for time64 tests

This adds support for time64 tests to the existing clock_nanosleep() syscall tests.

This also moves the tests from clock_nanosleep2/ directory to clock_nanosleep/ directory as it was added mistakenly there, as there is no clock_nanosleep2() syscall.

Also note that this patch doesn't update clock_nanosleep02.c test as that uses the sample test pattern and will result in many other changes to core libraries of LTP test suite.

---
 include/tst_timer.h                           |  20 ++++
 runtest/syscalls                              |   2 +-
 .../syscalls/clock_nanosleep/.gitignore       |   1 +
 .../clock_nanosleep/clock_nanosleep01.c       | 100 +++++++++++++-----
 .../clock_nanosleep/clock_nanosleep03.c       |  66 ++++++++++--
 .../clock_nanosleep/clock_nanosleep04.c       |  88 +++++++++++++++
 .../syscalls/clock_nanosleep2/.gitignore      |   1 -
 .../kernel/syscalls/clock_nanosleep2/Makefile |  10 --
 .../clock_nanosleep2/clock_nanosleep2_01.c    |  45 --------
 9 files changed, 243 insertions(+), 90 deletions(-)
 create mode 100644 testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep04.c
 delete mode 100644 testcases/kernel/syscalls/clock_nanosleep2/.gitignore
 delete mode 100644 testcases/kernel/syscalls/clock_nanosleep2/Makefile
 delete mode 100644 testcases/kernel/syscalls/clock_nanosleep2/clock_nanosleep2_01.c
include/tst_timer.h +20 -0
index 4823d350fdc6..256e1d71e1bc 100644
@@ -192,6 +192,26 @@ static inline int sys_clock_settime64(clockid_t clk_id, void *ts)
 	return tst_syscall(__NR_clock_settime64, clk_id, ts);
 }
 
+static inline int libc_clock_nanosleep(clockid_t clk_id, int flags,
+				       void *request, void *remain)
+{
+	return clock_nanosleep(clk_id, flags, request, remain);
+}
+
+static inline int sys_clock_nanosleep(clockid_t clk_id, int flags,
+				      void *request, void *remain)
+{
+	return tst_syscall(__NR_clock_nanosleep, clk_id, flags,
+			   request, remain);
+}
+
+static inline int sys_clock_nanosleep64(clockid_t clk_id, int flags,
+				        void *request, void *remain)
+{
+	return tst_syscall(__NR_clock_nanosleep_time64, clk_id, flags,
+			   request, remain);
+}
+
 /*
  * Returns tst_ts seconds.
  */
runtest/syscalls +1 -1
index f6df32859df6..6c23f75d3389 100644
@@ -90,8 +90,8 @@ clock_adjtime02 clock_adjtime02
 clock_getres01 clock_getres01
 clock_nanosleep01 clock_nanosleep01
 clock_nanosleep02 clock_nanosleep02
-clock_nanosleep2_01 clock_nanosleep2_01
 clock_nanosleep03 clock_nanosleep03
+clock_nanosleep04 clock_nanosleep04
 
 clock_gettime01 clock_gettime01
 clock_gettime02 clock_gettime02
testcases/kernel/syscalls/clock_nanosleep/.gitignore +1 -0
index 406897cded6d..1ab03a335f37 100644
@@ -1,3 +1,4 @@
 /clock_nanosleep01
 /clock_nanosleep02
 /clock_nanosleep03
+/clock_nanosleep04
testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep01.c +75 -25

176 lines not on this page · raw message

testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep03.c +58 -8

102 lines not on this page · raw message

testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep04.c new file +88 -0

88 lines not on this page · raw message

testcases/kernel/syscalls/clock_nanosleep2/.gitignore deleted +0 -1
deleted file mode 100644
index 5be9cd0e8a8d..000000000000
@@ -1 +0,0 @@
-/clock_nanosleep2_01
testcases/kernel/syscalls/clock_nanosleep2/Makefile deleted +0 -10
deleted file mode 100644
index 262eef71b02b..000000000000
@@ -1,10 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0-or-later
-# Copyright (c) International Business Machines  Corp., 2009
-
-top_srcdir		?= ../../../..
-
-include $(top_srcdir)/include/mk/testcases.mk
-
-LDLIBS			+= -lpthread -lrt
-
-include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/clock_nanosleep2/clock_nanosleep2_01.c deleted +0 -45

45 lines not on this page · raw message

Signature · 1 line
2.25.0.rc1.19.g042ed3e048af
#12 lore raw

PATCH v5 5/5 syscalls/clock_adjtime: Add support for time64 tests

In reply to Viresh Kumar

This adds support for time64 tests to the existing clock_adjtime() syscall tests.

---
 .../syscalls/clock_adjtime/clock_adjtime.h    | 216 +++++++++++++++---
 .../syscalls/clock_adjtime/clock_adjtime01.c  | 124 ++++++----
 .../syscalls/clock_adjtime/clock_adjtime02.c  |  95 +++++---
 3 files changed, 332 insertions(+), 103 deletions(-)
testcases/kernel/syscalls/clock_adjtime/clock_adjtime.h +182 -34
index d7f553a3a04b..138e6ca7f3d0 100644
@@ -16,43 +16,191 @@
 #include <sys/types.h>
 #include "lapi/timex.h"
 
-static int sys_clock_adjtime(clockid_t, struct timex *);
-static void timex_show(char *, struct timex);
+#ifndef __kernel_timex
+struct __kernel_timex_timeval {
+	__kernel_time64_t       tv_sec;
+	long long		tv_usec;
+};
 
-/*
- * bad pointer w/ libc causes SIGSEGV signal, call syscall directly
- */
-static int sys_clock_adjtime(clockid_t clk_id, struct timex *txc)
+struct __kernel_timex {
+	unsigned int modes;	/* mode selector */
+	int :32;            /* pad */
+	long long offset;	/* time offset (usec) */
+	long long freq;	/* frequency offset (scaled ppm) */
+	long long maxerror;/* maximum error (usec) */
+	long long esterror;/* estimated error (usec) */
+	int status;		/* clock command/status */
+	int :32;            /* pad */
+	long long constant;/* pll time constant */
+	long long precision;/* clock precision (usec) (read only) */
+	long long tolerance;/* clock frequency tolerance (ppm)
+				   * (read only)
+				   */
+	struct __kernel_timex_timeval time;	/* (read only, except for ADJ_SETOFFSET) */
+	long long tick;	/* (modified) usecs between clock ticks */
+
+	long long ppsfreq;/* pps frequency (scaled ppm) (ro) */
+	long long jitter; /* pps jitter (us) (ro) */
+	int shift;              /* interval duration (s) (shift) (ro) */
+	int :32;            /* pad */
+	long long stabil;            /* pps stability (scaled ppm) (ro) */
+	long long jitcnt; /* jitter limit exceeded (ro) */
+	long long calcnt; /* calibration intervals (ro) */
+	long long errcnt; /* calibration errors (ro) */
+	long long stbcnt; /* stability limit exceeded (ro) */
+
+	int tai;		/* TAI offset (ro) */
+
+	int  :32; int  :32; int  :32; int  :32;
+	int  :32; int  :32; int  :32; int  :32;
+	int  :32; int  :32; int  :32;
+};
+#endif
+
+enum tst_timex_type {
+	TST_LIBC_TIMEX,
+	TST_KERN_TIMEX
+};
+
+struct tst_timex {
+	enum tst_timex_type type;
+	union {
+		struct timex libc_timex;
+		struct __kernel_timex kern_timex;
+	} ts;
+};
+
+static inline void *tst_timex_get(struct tst_timex *t)
+{
+	switch (t->type) {
+	case TST_LIBC_TIMEX:
+		return &t->ts.libc_timex;
+	case TST_KERN_TIMEX:
+		return &t->ts.kern_timex;
+	default:
+		tst_brk(TBROK, "Invalid type: %d", t->type);
+		return NULL;
+	}
+}
+
+static inline int sys_clock_adjtime(clockid_t clk_id, void *timex)
 {
-	return tst_syscall(__NR_clock_adjtime, clk_id, txc);
+	return tst_syscall(__NR_clock_adjtime, clk_id, timex);
 }
 
-static void timex_show(char *given, struct timex txc)
+static inline int sys_clock_adjtime64(clockid_t clk_id, void *timex)
 {
-	tst_res(TINFO,  "%s\n"
-			"             mode: %d\n"
-			"           offset: %ld\n"
-			"        frequency: %ld\n"
-			"         maxerror: %ld\n"
-			"         esterror: %ld\n"
-			"           status: %d (0x%x)\n"
-			"    time_constant: %ld\n"
-			"        precision: %ld\n"
-			"        tolerance: %ld\n"
-			"             tick: %ld\n"
-			"         raw time: %d(s) %d(us)",
-			given,
-			txc.modes,
-			txc.offset,
-			txc.freq,
-			txc.maxerror,
-			txc.esterror,
-			txc.status,
-			txc.status,
-			txc.constant,
-			txc.precision,
-			txc.tolerance,
-			txc.tick,
-			(int)txc.time.tv_sec,
-			(int)txc.time.tv_usec);
+	return tst_syscall(__NR_clock_adjtime64, clk_id, timex);
+}
+
+#define _timex_show(_timex, _desc)					\
+	tst_res(TINFO,  "%s\n"						\
+			"             mode: %u\n"			\
+			"           offset: "#_desc"\n"			\
+			"        frequency: "#_desc"\n"			\
+			"         maxerror: "#_desc"\n"			\
+			"         esterror: "#_desc"\n"			\
+			"           status: %d (0x%x)\n"		\
+			"    time_constant: "#_desc"\n"			\
+			"        precision: "#_desc"\n"			\
+			"        tolerance: "#_desc"\n"			\
+			"             tick: "#_desc"\n"			\
+			"         raw time: "#_desc"(s) "#_desc"(us)",	\
+			given,						\
+			_timex.modes,					\
+			_timex.offset,					\
+			_timex.freq,					\
+			_timex.maxerror,				\
+			_timex.esterror,				\
+			_timex.status,					\
+			_timex.status,					\
+			_timex.constant,				\
+			_timex.precision,				\
+			_timex.tolerance,				\
+			_timex.tick,					\
+			_timex.time.tv_sec,				\
+			_timex.time.tv_usec)
+
+static inline void timex_show(char *given, struct tst_timex *timex)
+{
+	switch (timex->type) {
+	case TST_LIBC_TIMEX:
+		_timex_show(timex->ts.libc_timex, %ld);
+		return;
+	case TST_KERN_TIMEX:
+		_timex_show(timex->ts.kern_timex, %lld);
+		return;
+	default:
+		tst_res(TFAIL, "Invalid type: %d", timex->type);
+	}
+}
+
+#define ADJ_MODES	0
+
+#define _select_field(_timex, _field)					\
+{									\
+	if (_field == ADJ_MODES)					\
+		return &_timex.modes;					\
+	if (_field == ADJ_OFFSET)					\
+		return &_timex.offset;					\
+	if (_field == ADJ_FREQUENCY)					\
+		return &_timex.freq;					\
+	if (_field == ADJ_MAXERROR)					\
+		return &_timex.maxerror;				\
+	if (_field == ADJ_ESTERROR)					\
+		return &_timex.esterror;				\
+	if (_field == ADJ_TIMECONST)					\
+		return &_timex.constant;				\
+	if (_field == ADJ_TICK)						\
+		return &_timex.tick;					\
+	if (_field == ADJ_STATUS)					\
+		return &_timex.status;					\
+	tst_res(TFAIL, "Invalid type: %d", timex->type);		\
+	return NULL;							\
+}
+
+static inline void *_get_field(struct tst_timex *timex, unsigned int field)
+{
+	switch (timex->type) {
+	case TST_LIBC_TIMEX:
+		_select_field(timex->ts.libc_timex, field);
+	case TST_KERN_TIMEX:
+		_select_field(timex->ts.kern_timex, field);
+	default:
+		tst_res(TFAIL, "Invalid type: %d", timex->type);
+		return NULL;
+	}
+}
+
+#define timex_get_set_field_type(_type_libc, _type_kern)		\
+static inline _type_kern						\
+timex_get_field_##_type_libc(struct tst_timex *timex, unsigned int field) \
+{									\
+	switch (timex->type) {						\
+	case TST_LIBC_TIMEX:						\
+		return *((_type_libc*)_get_field(timex, field));	\
+	case TST_KERN_TIMEX:						\
+		return *((_type_kern*)_get_field(timex, field));	\
+	default:							\
+		tst_res(TFAIL, "Invalid type: %d", timex->type);	\
+		return 0;						\
+	}								\
+}									\
+									\
+static inline void							\
+timex_set_field_##_type_libc(struct tst_timex *timex, unsigned int field, \
+			    _type_kern value)				\
+{									\
+	switch (timex->type) {						\
+	case TST_LIBC_TIMEX:						\
+		*((_type_libc*)_get_field(timex, field)) = value;	\
+		return;							\
+	case TST_KERN_TIMEX:						\
+		*((_type_kern*)_get_field(timex, field)) = value;	\
+		return;							\
+	default:							\
+		tst_res(TFAIL, "Invalid type: %d", timex->type);	\
+	}								\
 }
+timex_get_set_field_type(uint, uint);
+timex_get_set_field_type(long, long long);
testcases/kernel/syscalls/clock_adjtime/clock_adjtime01.c +83 -41

225 lines not on this page · raw message

testcases/kernel/syscalls/clock_adjtime/clock_adjtime02.c +67 -28

181 lines not on this page · raw message

Signature · 1 line
2.25.0.rc1.19.g042ed3e048af
#3 lore raw

PATCH v4 1/5 syscalls/clock_gettime: Add support for time64 tests

In reply to Cyril Hrubis
Quoted 10 lines · Cyril Hrubis

Hi!
Pushed with a few changes, thanks.

* Changed the nonzero check to check if nanoseconds are valid, which covers the 64bit check as well.

* Pushed the bad address handling down to the test, which means that we have to convert the struct tst_ts for each syscall, but I think that it's cleaner that way and we also map only single bad address per test.

Thanks. I have resent the pending patches from this series with modification based on your changes to this patch, so you won't be required waste that much time on this :)

Signature · 1 line
viresh
#4 lore raw

PATCH v4 1/5 syscalls/clock_gettime: Add support for time64 tests

Hi!

Quoted 3 lines

Thanks. I have resent the pending patches from this series with modification based on your changes to this patch, so you won't be required waste that much time on this :)

I have pushed next two with a minor changes, thanks. I will finish the last one next week.

Signature · 2 lines
Cyril Hrubis
[email protected]
#13 lore raw

PATCH v5 5/5 syscalls/clock_adjtime: Add support for time64 tests

In reply to Viresh Kumar

Hi!
I've cleaned up the code and pushed, thanks.

Fixed things such as:

* Macros should be uppercase, otherwise it's confusing

* All local variables has to be passed to macros as parameters this one is confusing as hell

* No variables and parameters stating with underscore, unless we defined fallback for kernel types these are reserved for kernel/libc

* The tst_get_bad_addr() allocates a page for each call, so I have moved it to setup

* etc...

Signature · 1 line
[email protected]
#14 lore raw

PATCH v5 5/5 syscalls/clock_adjtime: Add support for time64 tests

Quoted 10 lines · Cyril Hrubis

Hi!
I've cleaned up the code and pushed, thanks.

Fixed things such as:

* Macros should be uppercase, otherwise it's confusing

* All local variables has to be passed to macros as parameters this one is confusing as hell

Quoted 8 lines

* No variables and parameters stating with underscore, unless we defined fallback for kernel types these are reserved for kernel/libc

* The tst_get_bad_addr() allocates a page for each call, so I have moved it to setup

* etc...

Thanks again.

Signature · 1 line
viresh