All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH V3 0/2] syscalls/clock_gettime: Add support for time64 tests
@ 2020-04-16 10:42 Viresh Kumar
  2020-04-16 10:42 ` [LTP] [PATCH V3 1/2] tst_timer: Add support for kernel's 64 bit timespec Viresh Kumar
  2020-04-16 10:42 ` [LTP] [PATCH V3 2/2] syscalls/clock_gettime: Add support for time64 tests Viresh Kumar
  0 siblings, 2 replies; 8+ messages in thread
From: Viresh Kumar @ 2020-04-16 10:42 UTC (permalink / raw)
  To: ltp

Hello,

Here is the third version which looks very different from the previous
one again :)

V2->V3:
- Define an enum for timespec type create struct tst_timespec and update
  all generic helpers to handle them.
- Update clock_gettime tests to use them.

Viresh Kumar (2):
  tst_timer: Add support for kernel's 64 bit timespec
  syscalls/clock_gettime: Add support for time64 tests

 include/tst_timer.h                                | 549 +++++++++++++++++----
 .../syscalls/clock_gettime/clock_gettime01.c       | 116 ++---
 .../syscalls/clock_gettime/clock_gettime02.c       |  72 +--
 .../syscalls/clock_gettime/clock_gettime03.c       |  55 ++-
 4 files changed, 602 insertions(+), 190 deletions(-)

-- 
2.7.4


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [LTP] [PATCH V3 1/2] tst_timer: Add support for kernel's 64 bit timespec
  2020-04-16 10:42 [LTP] [PATCH V3 0/2] syscalls/clock_gettime: Add support for time64 tests Viresh Kumar
@ 2020-04-16 10:42 ` Viresh Kumar
  2020-04-21 15:40   ` Cyril Hrubis
  2020-04-16 10:42 ` [LTP] [PATCH V3 2/2] syscalls/clock_gettime: Add support for time64 tests Viresh Kumar
  1 sibling, 1 reply; 8+ messages in thread
From: Viresh Kumar @ 2020-04-16 10:42 UTC (permalink / raw)
  To: ltp

The Linux kernel defined a new 64bit timespec some time back and this
patch makes necessary changes to tst_timer.h in order to prepare for
supporting changes in syscalls testcases.

A new enum is introduced to keep a list of all timespec variants we need
to support and all the timespec routines are updated to support the
listed variants.

In order to not do unnecessary changes to other syscall tests, the name
of the earlier routines are kept as is (with help of some macros that
eventually call the new helpers).

The LTP testsuite is build tested with this patch and nothing fails to
compile.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 include/tst_timer.h | 508 ++++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 411 insertions(+), 97 deletions(-)

diff --git a/include/tst_timer.h b/include/tst_timer.h
index cdb8de7987d9..0865fce88a2b 100644
--- a/include/tst_timer.h
+++ b/include/tst_timer.h
@@ -14,27 +14,45 @@
 
 #include <sys/time.h>
 #include <time.h>
-
-static inline long long tst_timespec_to_ns(struct timespec t)
-{
-	return t.tv_sec * 1000000000 + t.tv_nsec;
-}
-
-/*
- * Converts timespec to microseconds.
- */
-static inline long long tst_timespec_to_us(struct timespec t)
-{
-	return t.tv_sec * 1000000 + (t.tv_nsec + 500) / 1000;
-}
-
-/*
- * Converts timespec to milliseconds.
- */
-static inline long long tst_timespec_to_ms(struct timespec t)
-{
-	return t.tv_sec * 1000 + (t.tv_nsec + 500000) / 1000000;
-}
+#include "tst_test.h"
+
+#ifndef __kernel_timespec
+
+#if defined(__x86_64__) && defined(__ILP32__)
+typedef long long __kernel_long_t;
+#else
+typedef long __kernel_long_t;
+#endif
+
+typedef __kernel_long_t	__kernel_old_time_t;
+
+struct __kernel_old_timespec {
+	__kernel_old_time_t	tv_sec;		/* seconds */
+	__kernel_old_time_t	tv_nsec;	/* nanoseconds */
+};
+
+typedef long long __kernel_time64_t;
+
+struct __kernel_timespec {
+	__kernel_time64_t       tv_sec;                 /* seconds */
+	long long               tv_nsec;                /* nanoseconds */
+};
+#endif
+
+enum tst_timespec_type {
+	TST_LIBC_TIMESPEC,
+	TST_KERN_OLD_TIMESPEC,
+	TST_KERN_TIMESPEC
+};
+
+struct tst_timespec {
+	enum tst_timespec_type type;
+	union {
+		struct timespec libc_ts;
+		struct __kernel_old_timespec kern_old_ts;
+		struct __kernel_timespec kern_ts;
+	};
+};
 
 /*
  * Converts timeval to microseconds.
@@ -78,134 +96,427 @@ static inline struct timeval tst_us_to_timeval(long long us)
 	return ret;
 }
 
+#define TST_TIMESPEC_SINGLE_TS_TO(_name)				\
+static inline long long _name(struct timespec t)			\
+{									\
+	struct tst_timespec tst_t = {					\
+		.type = TST_LIBC_TIMESPEC,				\
+		.libc_ts = t,						\
+	};								\
+									\
+	return tst_##_name(tst_t);					\
+}
+
+static inline long long tst_tst_timespec_to_ns(struct tst_timespec t)
+{
+	switch (t.type) {
+	case TST_LIBC_TIMESPEC:
+		return t.libc_ts.tv_sec * 1000000000 + t.libc_ts.tv_nsec;
+	case TST_KERN_OLD_TIMESPEC:
+		return t.kern_old_ts.tv_sec * 1000000000 + t.kern_old_ts.tv_nsec;
+	case TST_KERN_TIMESPEC:
+		return t.kern_ts.tv_sec * 1000000000 + t.kern_ts.tv_nsec;
+	default:
+		tst_brk(TBROK, "Invalid type: %d", t.type);
+		return -1;
+	}
+}
+TST_TIMESPEC_SINGLE_TS_TO(tst_timespec_to_ns);
+
 /*
- * Converts ms to struct timespec
+ * Converts timespec to microseconds.
  */
-static inline struct timespec tst_ms_to_timespec(long long ms)
+static inline long long tst_tst_timespec_to_us(struct tst_timespec t)
 {
-	struct timespec ret;
-
-	ret.tv_sec = ms / 1000;
-	ret.tv_nsec = (ms % 1000) * 1000000;
-
-	return ret;
+	switch (t.type) {
+	case TST_LIBC_TIMESPEC:
+		return t.libc_ts.tv_sec * 1000000 + (t.libc_ts.tv_nsec + 500) / 1000;
+	case TST_KERN_OLD_TIMESPEC:
+		return t.kern_old_ts.tv_sec * 1000000 + (t.kern_old_ts.tv_nsec + 500) / 1000;
+	case TST_KERN_TIMESPEC:
+		return t.kern_ts.tv_sec * 1000000 + (t.kern_ts.tv_nsec + 500) / 1000;
+	default:
+		tst_brk(TBROK, "Invalid type: %d", t.type);
+		return -1;
+	}
 }
+TST_TIMESPEC_SINGLE_TS_TO(tst_timespec_to_us);
 
 /*
- * Converts us to struct timespec
+ * Converts timespec to milliseconds.
  */
-static inline struct timespec tst_us_to_timespec(long long us)
+static inline long long tst_tst_timespec_to_ms(struct tst_timespec t)
 {
-	struct timespec ret;
+	switch (t.type) {
+	case TST_LIBC_TIMESPEC:
+		return t.libc_ts.tv_sec * 1000 + (t.libc_ts.tv_nsec + 500000) / 1000000;
+	case TST_KERN_OLD_TIMESPEC:
+		return t.kern_old_ts.tv_sec * 1000 + (t.kern_old_ts.tv_nsec + 500000) / 1000000;
+	case TST_KERN_TIMESPEC:
+		return t.kern_ts.tv_sec * 1000 + (t.kern_ts.tv_nsec + 500000) / 1000000;
+	default:
+		tst_brk(TBROK, "Invalid type: %d", t.type);
+		return -1;
+	}
+}
+TST_TIMESPEC_SINGLE_TS_TO(tst_timespec_to_ms);
+
+#define TST_TIMESPEC_SINGLE_TO_TS(_name)					\
+static inline struct timespec _name##_timespec(long long time)		\
+{									\
+	struct tst_timespec tst_t;					\
+									\
+	tst_t = _name##_tst_timespec(TST_LIBC_TIMESPEC, time);		\
+	return tst_t.libc_ts;						\
+}
 
-	ret.tv_sec = us / 1000000;
-	ret.tv_nsec = (us % 1000000) * 1000;
+/*
+ * Converts ms to struct tst_timespec
+ */
+static inline struct tst_timespec tst_ms_to_tst_timespec(enum tst_timespec_type type, long long ms)
+{
+	struct tst_timespec ret = {.type = type};
+
+	switch (type) {
+	case TST_LIBC_TIMESPEC:
+		ret.libc_ts.tv_sec = ms / 1000;
+		ret.libc_ts.tv_nsec = (ms % 1000) * 1000000;
+		break;
+	case TST_KERN_OLD_TIMESPEC:
+		ret.kern_old_ts.tv_sec = ms / 1000;
+		ret.kern_old_ts.tv_nsec = (ms % 1000) * 1000000;
+		break;
+	case TST_KERN_TIMESPEC:
+		ret.kern_ts.tv_sec = ms / 1000;
+		ret.kern_ts.tv_nsec = (ms % 1000) * 1000000;
+		break;
+	default:
+		tst_brk(TBROK, "Invalid type: %d", type);
+	}
 
 	return ret;
 }
+TST_TIMESPEC_SINGLE_TO_TS(tst_ms_to);
 
 /*
- * Comparsions
+ * Converts us to struct tst_timespec
  */
-static inline int tst_timespec_lt(struct timespec t1, struct timespec t2)
+static inline struct tst_timespec
+tst_us_to_tst_timespec(enum tst_timespec_type type, long long us)
 {
-	if (t1.tv_sec == t2.tv_sec)
-		return t1.tv_nsec < t2.tv_nsec;
+	struct tst_timespec ret = {.type = type};
+
+	switch (type) {
+	case TST_LIBC_TIMESPEC:
+		ret.libc_ts.tv_sec = us / 1000000;
+		ret.libc_ts.tv_nsec = (us % 1000000) * 1000;
+		break;
+	case TST_KERN_OLD_TIMESPEC:
+		ret.kern_old_ts.tv_sec = us / 1000000;
+		ret.kern_old_ts.tv_nsec = (us % 1000000) * 1000;
+		break;
+	case TST_KERN_TIMESPEC:
+		ret.kern_ts.tv_sec = us / 1000000;
+		ret.kern_ts.tv_nsec = (us % 1000000) * 1000;
+		break;
+	default:
+		tst_brk(TBROK, "Invalid type: %d", type);
+	}
 
-	return t1.tv_sec < t2.tv_sec;
+	return ret;
+}
+TST_TIMESPEC_SINGLE_TO_TS(tst_us_to);
+
+#define TST_TIMESPEC_MULT_TS_TO(_name, _ret_type)			\
+static inline _ret_type _name(struct timespec t1, struct timespec t2)	\
+{									\
+	struct tst_timespec tst_t1 = {					\
+		.type = TST_LIBC_TIMESPEC,				\
+		.libc_ts = t1,						\
+	};								\
+									\
+	struct tst_timespec tst_t2 = {					\
+		.type = TST_LIBC_TIMESPEC,				\
+		.libc_ts = t2,						\
+	};								\
+									\
+	return tst_##_name(tst_t1, tst_t2);				\
 }
 
-static inline struct timespec tst_timespec_normalize(struct timespec t)
+/*
+ * Comparsions
+ */
+static inline int tst_tst_timespec_lt(struct tst_timespec t1, struct tst_timespec t2)
 {
-	if (t.tv_nsec >= 1000000000) {
-		t.tv_sec++;
-		t.tv_nsec -= 1000000000;
+	if (t1.type != t2.type)
+		tst_brk(TBROK, "Incompatible timespec type (%d:%d)", t1.type, t2.type);
+
+	switch (t1.type) {
+	case TST_LIBC_TIMESPEC:
+		if (t1.libc_ts.tv_sec == t2.libc_ts.tv_sec)
+			return t1.libc_ts.tv_nsec < t2.libc_ts.tv_nsec;
+
+		return t1.libc_ts.tv_sec < t2.libc_ts.tv_sec;
+	case TST_KERN_OLD_TIMESPEC:
+		if (t1.kern_old_ts.tv_sec == t2.kern_old_ts.tv_sec)
+			return t1.kern_old_ts.tv_nsec < t2.kern_old_ts.tv_nsec;
+
+		return t1.kern_old_ts.tv_sec < t2.kern_old_ts.tv_sec;
+		break;
+	case TST_KERN_TIMESPEC:
+		if (t1.kern_ts.tv_sec == t2.kern_ts.tv_sec)
+			return t1.kern_ts.tv_nsec < t2.kern_ts.tv_nsec;
+
+		return t1.kern_ts.tv_sec < t2.kern_ts.tv_sec;
+		break;
+	default:
+		tst_brk(TBROK, "Invalid type: %d", t1.type);
+		return -1;
 	}
+}
+TST_TIMESPEC_MULT_TS_TO(tst_timespec_lt, int);
 
-	if (t.tv_nsec < 0) {
-		t.tv_sec--;
-		t.tv_nsec += 1000000000;
+static inline struct tst_timespec tst_timespec_normalize(struct tst_timespec t)
+{
+	switch (t.type) {
+	case TST_LIBC_TIMESPEC:
+		if (t.libc_ts.tv_nsec >= 1000000000) {
+			t.libc_ts.tv_sec++;
+			t.libc_ts.tv_nsec -= 1000000000;
+		}
+
+		if (t.libc_ts.tv_nsec < 0) {
+			t.libc_ts.tv_sec--;
+			t.libc_ts.tv_nsec += 1000000000;
+		}
+		break;
+	case TST_KERN_OLD_TIMESPEC:
+		if (t.kern_old_ts.tv_nsec >= 1000000000) {
+			t.kern_old_ts.tv_sec++;
+			t.kern_old_ts.tv_nsec -= 1000000000;
+		}
+
+		if (t.kern_old_ts.tv_nsec < 0) {
+			t.kern_old_ts.tv_sec--;
+			t.kern_old_ts.tv_nsec += 1000000000;
+		}
+		break;
+	case TST_KERN_TIMESPEC:
+		if (t.kern_ts.tv_nsec >= 1000000000) {
+			t.kern_ts.tv_sec++;
+			t.kern_ts.tv_nsec -= 1000000000;
+		}
+
+		if (t.kern_ts.tv_nsec < 0) {
+			t.kern_ts.tv_sec--;
+			t.kern_ts.tv_nsec += 1000000000;
+		}
+		break;
+	default:
+		tst_brk(TBROK, "Invalid type: %d", t.type);
 	}
 
 	return t;
 }
 
+#define TST_TIMESPEC_SINGLE_TS_TO_TS(_name)				\
+static inline struct timespec _name(struct timespec t, long long time)	\
+{									\
+	struct tst_timespec ret, tst_t = {				\
+		.type = TST_LIBC_TIMESPEC,				\
+		.libc_ts = t,						\
+	};								\
+									\
+	ret = tst_##_name(tst_t, time);					\
+	return ret.libc_ts;						\
+}
+
 /*
  * Adds us microseconds to t.
  */
-static inline struct timespec tst_timespec_add_us(struct timespec t,
-                                                  long long us)
+static inline struct tst_timespec tst_tst_timespec_add_us(struct tst_timespec t,
+							  long long us)
 {
-	t.tv_sec += us / 1000000;
-	t.tv_nsec += (us % 1000000) * 1000;
-
+	switch (t.type) {
+	case TST_LIBC_TIMESPEC:
+		t.libc_ts.tv_sec += us / 1000000;
+		t.libc_ts.tv_nsec += (us % 1000000) * 1000;
+		break;
+	case TST_KERN_OLD_TIMESPEC:
+		t.kern_old_ts.tv_sec += us / 1000000;
+		t.kern_old_ts.tv_nsec += (us % 1000000) * 1000;
+		break;
+	case TST_KERN_TIMESPEC:
+		t.kern_ts.tv_sec += us / 1000000;
+		t.kern_ts.tv_nsec += (us % 1000000) * 1000;
+		break;
+	default:
+		tst_brk(TBROK, "Invalid type: %d", t.type);
+	}
 
 	return tst_timespec_normalize(t);
 }
+TST_TIMESPEC_SINGLE_TS_TO_TS(tst_timespec_add_us);
 
 /*
- * Adds two timespec structures.
+ * Subtracts us microseconds from t.
  */
-static inline struct timespec tst_timespec_add(struct timespec t1,
-                                               struct timespec t2)
+static inline struct tst_timespec tst_tst_timespec_sub_us(struct tst_timespec t,
+							  long long us)
 {
-	struct timespec res;
-
-	res.tv_sec = t1.tv_sec + t2.tv_sec;
-	res.tv_nsec = t1.tv_nsec + t2.tv_nsec;
+	switch (t.type) {
+	case TST_LIBC_TIMESPEC:
+		t.libc_ts.tv_sec -= us / 1000000;
+		t.libc_ts.tv_nsec -= (us % 1000000) * 1000;
+		break;
+	case TST_KERN_OLD_TIMESPEC:
+		t.kern_old_ts.tv_sec -= us / 1000000;
+		t.kern_old_ts.tv_nsec -= (us % 1000000) * 1000;
+		break;
+	case TST_KERN_TIMESPEC:
+		t.kern_ts.tv_sec -= us / 1000000;
+		t.kern_ts.tv_nsec -= (us % 1000000) * 1000;
+		break;
+	default:
+		tst_brk(TBROK, "Invalid type: %d", t.type);
+	}
 
-	return tst_timespec_normalize(res);
+	return tst_timespec_normalize(t);
+}
+TST_TIMESPEC_SINGLE_TS_TO_TS(tst_timespec_sub_us);
+
+#define TST_TIMESPEC_MULT_TS_TO_TS(_name)					\
+static inline struct timespec _name(struct timespec t1, struct timespec t2)	\
+{									\
+	struct tst_timespec ret, tst_t1 = {				\
+		.type = TST_LIBC_TIMESPEC,				\
+		.libc_ts = t1,						\
+	};								\
+									\
+	struct tst_timespec tst_t2 = {					\
+		.type = TST_LIBC_TIMESPEC,				\
+		.libc_ts = t2,						\
+	};								\
+									\
+	ret = tst_##_name(tst_t1, tst_t2);				\
+	return ret.libc_ts;						\
 }
 
 /*
- * Subtracts us microseconds from t.
+ * Adds two tst_timespec structures.
  */
-static inline struct timespec tst_timespec_sub_us(struct timespec t,
-                                                  long long us)
+static inline struct tst_timespec tst_tst_timespec_add(struct tst_timespec t1,
+						       struct tst_timespec t2)
 {
-	t.tv_sec -= us / 1000000;
-	t.tv_nsec -= (us % 1000000) * 1000;
+	struct tst_timespec res = {.type = t1.type};
+
+	if (t1.type != t2.type)
+		tst_brk(TBROK, "Incompatible timespec type (%d:%d)", t1.type, t2.type);
+
+	switch (t2.type) {
+	case TST_LIBC_TIMESPEC:
+		res.libc_ts.tv_sec = t1.libc_ts.tv_sec + t2.libc_ts.tv_sec;
+		res.libc_ts.tv_nsec = t1.libc_ts.tv_nsec + t2.libc_ts.tv_nsec;
+		break;
+	case TST_KERN_OLD_TIMESPEC:
+		res.kern_old_ts.tv_sec = t1.kern_old_ts.tv_sec + t2.kern_old_ts.tv_sec;
+		res.kern_old_ts.tv_nsec = t1.kern_old_ts.tv_nsec + t2.kern_old_ts.tv_nsec;
+		break;
+	case TST_KERN_TIMESPEC:
+		res.kern_ts.tv_sec = t1.kern_ts.tv_sec + t2.kern_ts.tv_sec;
+		res.kern_ts.tv_nsec = t1.kern_ts.tv_nsec + t2.kern_ts.tv_nsec;
+		break;
+	default:
+		tst_brk(TBROK, "Invalid type: %d", t1.type);
+	}
 
-	return tst_timespec_normalize(t);
+	return tst_timespec_normalize(res);
 }
+TST_TIMESPEC_MULT_TS_TO_TS(tst_timespec_add);
 
 /*
- * Returns difference between two timespec structures.
+ * Returns difference between two tst_timespec structures.
  */
-static inline struct timespec tst_timespec_diff(struct timespec t1,
-                                                struct timespec t2)
+static inline struct tst_timespec tst_tst_timespec_diff(struct tst_timespec t1,
+							struct tst_timespec t2)
 {
-	struct timespec res;
-
-	res.tv_sec = t1.tv_sec - t2.tv_sec;
-
-	if (t1.tv_nsec < t2.tv_nsec) {
-		res.tv_sec--;
-		res.tv_nsec = 1000000000 - (t2.tv_nsec - t1.tv_nsec);
-	} else {
-		res.tv_nsec = t1.tv_nsec - t2.tv_nsec;
+	struct tst_timespec res = {.type = t1.type};
+
+	if (t1.type != t2.type)
+		tst_brk(TBROK, "Incompatible timespec type (%d:%d)", t1.type, t2.type);
+
+	switch (t1.type) {
+	case TST_LIBC_TIMESPEC:
+		res.libc_ts.tv_sec = t1.libc_ts.tv_sec - t2.libc_ts.tv_sec;
+
+		if (t1.libc_ts.tv_nsec < t2.libc_ts.tv_nsec) {
+			res.libc_ts.tv_sec--;
+			res.libc_ts.tv_nsec = 1000000000 - (t2.libc_ts.tv_nsec - t1.libc_ts.tv_nsec);
+		} else {
+			res.libc_ts.tv_nsec = t1.libc_ts.tv_nsec - t2.libc_ts.tv_nsec;
+		}
+		break;
+	case TST_KERN_OLD_TIMESPEC:
+		res.kern_old_ts.tv_sec = t1.kern_old_ts.tv_sec - t2.kern_old_ts.tv_sec;
+
+		if (t1.kern_old_ts.tv_nsec < t2.kern_old_ts.tv_nsec) {
+			res.kern_old_ts.tv_sec--;
+			res.kern_old_ts.tv_nsec = 1000000000 - (t2.kern_old_ts.tv_nsec - t1.kern_old_ts.tv_nsec);
+		} else {
+			res.kern_old_ts.tv_nsec = t1.kern_old_ts.tv_nsec - t2.kern_old_ts.tv_nsec;
+		}
+		break;
+	case TST_KERN_TIMESPEC:
+		res.kern_ts.tv_sec = t1.kern_ts.tv_sec - t2.kern_ts.tv_sec;
+
+		if (t1.kern_ts.tv_nsec < t2.kern_ts.tv_nsec) {
+			res.kern_ts.tv_sec--;
+			res.kern_ts.tv_nsec = 1000000000 - (t2.kern_ts.tv_nsec - t1.kern_ts.tv_nsec);
+		} else {
+			res.kern_ts.tv_nsec = t1.kern_ts.tv_nsec - t2.kern_ts.tv_nsec;
+		}
+		break;
+	default:
+		tst_brk(TBROK, "Invalid type: %d", t1.type);
 	}
 
 	return res;
 }
+TST_TIMESPEC_MULT_TS_TO_TS(tst_timespec_diff);
 
-static inline long long tst_timespec_diff_ns(struct timespec t1,
-					     struct timespec t2)
+static inline long long tst_tst_timespec_diff_ns(struct tst_timespec t1,
+					     struct tst_timespec t2)
 {
-	return t1.tv_nsec - t2.tv_nsec + 1000000000LL * (t1.tv_sec - t2.tv_sec);
+	if (t1.type != t2.type)
+		tst_brk(TBROK, "Incompatible timespec type (%d:%d)", t1.type, t2.type);
+
+	switch (t1.type) {
+	case TST_LIBC_TIMESPEC:
+		return t1.libc_ts.tv_nsec - t2.libc_ts.tv_nsec + 1000000000LL * (t1.libc_ts.tv_sec - t2.libc_ts.tv_sec);
+	case TST_KERN_OLD_TIMESPEC:
+		return t1.kern_old_ts.tv_nsec - t2.kern_old_ts.tv_nsec + 1000000000LL * (t1.kern_old_ts.tv_sec - t2.kern_old_ts.tv_sec);
+	case TST_KERN_TIMESPEC:
+		return t1.kern_ts.tv_nsec - t2.kern_ts.tv_nsec + 1000000000LL * (t1.kern_ts.tv_sec - t2.kern_ts.tv_sec);
+	default:
+		tst_brk(TBROK, "Invalid type: %d", t1.type);
+		return -1;
+	}
 }
+TST_TIMESPEC_MULT_TS_TO(tst_timespec_diff_ns, long long);
 
-static inline long long tst_timespec_diff_us(struct timespec t1,
-                                             struct timespec t2)
+static inline long long tst_tst_timespec_diff_us(struct tst_timespec t1,
+                                             struct tst_timespec t2)
 {
-	return tst_timespec_to_us(tst_timespec_diff(t1, t2));
+	return tst_tst_timespec_to_us(tst_tst_timespec_diff(t1, t2));
 }
+TST_TIMESPEC_MULT_TS_TO(tst_timespec_diff_us, long long);
 
-static inline long long tst_timespec_diff_ms(struct timespec t1,
-                                             struct timespec t2)
+static inline long long tst_tst_timespec_diff_ms(struct tst_timespec t1,
+                                             struct tst_timespec t2)
 {
-	return tst_timespec_to_ms(tst_timespec_diff(t1, t2));
+	return tst_tst_timespec_to_ms(tst_tst_timespec_diff(t1, t2));
 }
+TST_TIMESPEC_MULT_TS_TO(tst_timespec_diff_ms, long long);
 
 /*
  * Returns difference between two timeval structures.
@@ -242,26 +553,29 @@ static inline long long tst_timeval_diff_ms(struct timeval t1,
 /*
  * Returns absolute value of difference between two timespec structures.
  */
-static inline struct timespec tst_timespec_abs_diff(struct timespec t1,
-                                                    struct timespec t2)
+static inline struct tst_timespec
+tst_tst_timespec_abs_diff(struct tst_timespec t1, struct tst_timespec t2)
 {
-	if (tst_timespec_lt(t1, t2))
-		return tst_timespec_diff(t2, t1);
+	if (tst_tst_timespec_lt(t1, t2))
+		return tst_tst_timespec_diff(t2, t1);
 	else
-		return tst_timespec_diff(t1, t2);
+		return tst_tst_timespec_diff(t1, t2);
 }
+TST_TIMESPEC_MULT_TS_TO_TS(tst_timespec_abs_diff);
 
-static inline long long tst_timespec_abs_diff_us(struct timespec t1,
-                                                 struct timespec t2)
+static inline long long tst_tst_timespec_abs_diff_us(struct tst_timespec t1,
+						     struct tst_timespec t2)
 {
-       return tst_timespec_to_us(tst_timespec_abs_diff(t1, t2));
+	return tst_tst_timespec_to_us(tst_tst_timespec_abs_diff(t1, t2));
 }
+TST_TIMESPEC_MULT_TS_TO(tst_timespec_abs_diff_us, long long);
 
-static inline long long tst_timespec_abs_diff_ms(struct timespec t1,
-                                                 struct timespec t2)
+static inline long long tst_tst_timespec_abs_diff_ms(struct tst_timespec t1,
+						     struct tst_timespec t2)
 {
-       return tst_timespec_to_ms(tst_timespec_abs_diff(t1, t2));
+	return tst_tst_timespec_to_ms(tst_tst_timespec_abs_diff(t1, t2));
 }
+TST_TIMESPEC_MULT_TS_TO(tst_timespec_abs_diff_ms, long long);
 
 /*
  * Exits the test with TCONF if particular timer is not supported. This is
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [LTP] [PATCH V3 2/2] syscalls/clock_gettime: Add support for time64 tests
  2020-04-16 10:42 [LTP] [PATCH V3 0/2] syscalls/clock_gettime: Add support for time64 tests Viresh Kumar
  2020-04-16 10:42 ` [LTP] [PATCH V3 1/2] tst_timer: Add support for kernel's 64 bit timespec Viresh Kumar
@ 2020-04-16 10:42 ` Viresh Kumar
  1 sibling, 0 replies; 8+ messages in thread
From: Viresh Kumar @ 2020-04-16 10:42 UTC (permalink / raw)
  To: ltp

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

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 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       |  55 ++++++++--
 4 files changed, 203 insertions(+), 105 deletions(-)

diff --git a/include/tst_timer.h b/include/tst_timer.h
index 0865fce88a2b..1f2893970397 100644
--- a/include/tst_timer.h
+++ b/include/tst_timer.h
@@ -15,6 +15,7 @@
 #include <sys/time.h>
 #include <time.h>
 #include "tst_test.h"
+#include "lapi/syscalls.h"
 
 #ifndef __kernel_timespec
 
@@ -42,7 +43,9 @@ struct __kernel_timespec {
 enum tst_timespec_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_timespec {
@@ -54,6 +57,66 @@ struct tst_timespec {
 	};
 };
 
+static inline void *tst_get_timespec(struct tst_timespec *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_timespec *t)
+{
+	return clock_gettime(clk_id, tst_get_timespec(t));
+}
+
+static inline int sys_clock_gettime(clockid_t clk_id, struct tst_timespec *t)
+{
+	return tst_syscall(__NR_clock_gettime, clk_id, tst_get_timespec(t));
+}
+
+static inline int sys_clock_gettime64(clockid_t clk_id, struct tst_timespec *t)
+{
+	return tst_syscall(__NR_clock_gettime64, clk_id, tst_get_timespec(t));
+}
+
+/*
+ * tst_timespec_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_timespec_nonzero(struct tst_timespec *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;
+	}
+}
+
 /*
  * Converts timeval to microseconds.
  */
diff --git a/testcases/kernel/syscalls/clock_gettime/clock_gettime01.c b/testcases/kernel/syscalls/clock_gettime/clock_gettime01.c
index d365823b2f0f..f37bb1a54f77 100644
--- a/testcases/kernel/syscalls/clock_gettime/clock_gettime01.c
+++ b/testcases/kernel/syscalls/clock_gettime/clock_gettime01.c
@@ -19,20 +19,14 @@
 #include "config.h"
 #include "tst_timer.h"
 #include "tst_safe_clocks.h"
-#include "tst_test.h"
-#include "lapi/syscalls.h"
+#include "lapi/abisize.h"
 
 struct test_case {
 	clockid_t clktype;
 	int allow_inval;
 };
 
-struct tmpfunc {
-	int (*func)(clockid_t clk_id, struct timespec *tp);
-	char *desc;
-};
-
-struct test_case tc[] = {
+static struct test_case tc[] = {
 	{
 	 .clktype = CLOCK_REALTIME,
 	 },
@@ -63,73 +57,65 @@ struct test_case tc[] = {
 	 },
 };
 
-static int sys_clock_gettime(clockid_t clk_id, struct timespec *tp)
-{
-	return tst_syscall(__NR_clock_gettime, clk_id, tp);
-}
+static struct tst_timespec spec;
 
-static int check_spec(struct timespec *spec)
+static struct test_variants {
+	int (*func)(clockid_t clk_id, struct tst_timespec *spec);
+	enum tst_timespec_type type;
+	char *desc;
+} variants[] = {
+#if defined(TST_ABI32)
+	{ .func = libc_clock_gettime, .type = TST_LIBC_TIMESPEC, .desc = "vDSO or syscall with libc spec"},
+	{ .func = sys_clock_gettime, .type = TST_LIBC_TIMESPEC, .desc = "syscall with libc spec"},
+	{ .func = sys_clock_gettime, .type = TST_KERN_OLD_TIMESPEC, .desc = "syscall with kernel spec32"},
+#endif
+
+#if defined(TST_ABI64)
+	{ .func = sys_clock_gettime, .type = TST_KERN_TIMESPEC, .desc = "syscall with kernel spec64"},
+#endif
+
+#if (__NR_clock_gettime64 != __LTP__NR_INVALID_SYSCALL)
+	{ .func = sys_clock_gettime64, .type = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec64"},
+#endif
+};
+
+static void setup(void)
 {
-	return (spec->tv_nsec != 0 || spec->tv_sec != 0) ? 1 : 0;
+	tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
 }
 
 static void verify_clock_gettime(unsigned int i)
 {
-	size_t sz;
-	struct timespec spec;
-
-	/*
-	 * check clock_gettime() syscall AND libc (or vDSO) functions
-	 */
-	struct tmpfunc tf[] = {
-		{ .func = sys_clock_gettime, .desc = "syscall"      },
-		{ .func = clock_gettime, .desc = "vDSO or syscall"  },
-	};
-
-	for (sz = 0; sz < ARRAY_SIZE(tf); sz++) {
+	struct test_variants *tv = &variants[tst_variant];
+	int ret;
 
-		memset(&spec, 0, sizeof(struct timespec));
+	memset(&spec, 0, sizeof(spec));
+	spec.type = tv->type;
 
-		TEST(tf[sz].func(tc[i].clktype, &spec));
-
-		if (TST_RET == -1) {
-
-			/* errors: allow unsupported clock types */
-
-			if (tc[i].allow_inval && TST_ERR == EINVAL) {
-
-				tst_res(TPASS, "clock_gettime(2): unsupported "
-						"clock %s (%s) failed as "
-						"expected",
-						tst_clock_name(tc[i].clktype),
-						tf[sz].desc);
-
-			} else {
-
-				tst_res(TFAIL | TTERRNO, "clock_gettime(2): "
-						"clock %s (%s) failed "
-						"unexpectedly",
-						tst_clock_name(tc[i].clktype),
-						tf[sz].desc);
-			}
+	TEST(tv->func(tc[i].clktype, &spec));
 
+	if (TST_RET == -1) {
+		/* errors: allow unsupported clock types */
+		if (tc[i].allow_inval && TST_ERR == EINVAL) {
+			tst_res(TPASS, "clock_gettime(2): unsupported clock %s failed as expected",
+				tst_clock_name(tc[i].clktype));
 		} else {
+			tst_res(TFAIL | TTERRNO, "clock_gettime(2): clock %s failed unexpectedly",
+				tst_clock_name(tc[i].clktype));
+		}
 
-			/* success: also check if timespec was changed */
-
-			if (check_spec(&spec)) {
-				tst_res(TPASS, "clock_gettime(2): clock %s "
-						"(%s) passed",
-						tst_clock_name(tc[i].clktype),
-						tf[sz].desc);
-			} else {
-
-				tst_res(TFAIL, "clock_gettime(2): clock %s "
-						"(%s) passed, unchanged "
-						"timespec",
-						tst_clock_name(tc[i].clktype),
-						tf[sz].desc);
-			}
+	} else {
+		/* success: also check if timespec was changed */
+		ret = tst_timespec_nonzero(&spec);
+		if (!ret) {
+			tst_res(TPASS, "clock_gettime(2): clock %s passed",
+				tst_clock_name(tc[i].clktype));
+		} else if (ret == -1) {
+			tst_res(TFAIL, "clock_gettime(2): clock %s passed, unchanged timespec",
+				tst_clock_name(tc[i].clktype));
+		} else if (ret == -2) {
+			tst_res(TFAIL, "clock_gettime(2): clock %s passed, Corrupted timespec",
+				tst_clock_name(tc[i].clktype));
 		}
 	}
 }
@@ -137,5 +123,7 @@ static void verify_clock_gettime(unsigned int i)
 static struct tst_test test = {
 	.test = verify_clock_gettime,
 	.tcnt = ARRAY_SIZE(tc),
+	.test_variants = ARRAY_SIZE(variants),
+	.setup = setup,
 	.needs_root = 1,
 };
diff --git a/testcases/kernel/syscalls/clock_gettime/clock_gettime02.c b/testcases/kernel/syscalls/clock_gettime/clock_gettime02.c
index b4bc6e2d55d4..ef322363b963 100644
--- a/testcases/kernel/syscalls/clock_gettime/clock_gettime02.c
+++ b/testcases/kernel/syscalls/clock_gettime/clock_gettime02.c
@@ -19,10 +19,9 @@
  */
 
 #include "config.h"
-#include "tst_test.h"
-#include "lapi/syscalls.h"
 #include "tst_timer.h"
 #include "tst_safe_clocks.h"
+#include "lapi/abisize.h"
 
 struct test_case {
 	clockid_t clktype;
@@ -30,7 +29,7 @@ struct test_case {
 	int allow_inval;
 };
 
-struct test_case tc[] = {
+static struct test_case tc[] = {
 	{
 	 .clktype = MAX_CLOCKS,
 	 .exp_err = EINVAL,
@@ -81,52 +80,67 @@ struct test_case tc[] = {
 	 },
 };
 
+static struct tst_timespec spec;
+
 /*
  * bad pointer w/ libc causes SIGSEGV signal, call syscall directly
  */
-static int sys_clock_gettime(clockid_t clk_id, struct timespec *tp)
+static struct test_variants {
+	int (*func)(clockid_t clk_id, struct tst_timespec *t);
+	enum tst_timespec_type type;
+	char *desc;
+} variants[] = {
+#if defined(TST_ABI32)
+	{ .func = sys_clock_gettime, .type = TST_LIBC_TIMESPEC, .desc = "vDSO or syscall with libc spec"},
+	{ .func = sys_clock_gettime, .type = TST_KERN_OLD_TIMESPEC, .desc = "syscall with kernel spec32"},
+#endif
+
+#if defined(TST_ABI64)
+	{ .func = sys_clock_gettime, .type = TST_KERN_TIMESPEC, .desc = "syscall with kernel spec64"},
+#endif
+
+#if (__NR_clock_gettime64 != __LTP__NR_INVALID_SYSCALL)
+	{ .func = sys_clock_gettime64, .type = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec64"},
+#endif
+};
+
+static void setup(void)
 {
-	return tst_syscall(__NR_clock_gettime, clk_id, tp);
+	tst_res(TINFO, "Testing variant: %d: %s", tst_variant, variants[tst_variant].desc);
 }
 
 static void verify_clock_gettime(unsigned int i)
 {
-	struct timespec spec, *specptr;
-
-	specptr = &spec;
+	struct test_variants *tv = &variants[tst_variant];
 
 	/* bad pointer cases */
 	if (tc[i].exp_err == EFAULT)
-		specptr = tst_get_bad_addr(NULL);
-
-	TEST(sys_clock_gettime(tc[i].clktype, specptr));
+		spec.type = TST_KERN_BAD_ADDR;
+	else
+		spec.type = tv->type;
 
-	if (TST_RET == -1) {
+	TEST(tv->func(tc[i].clktype, &spec));
 
-		if ((tc[i].exp_err == TST_ERR) ||
-			(tc[i].allow_inval && TST_ERR == EINVAL)) {
-
-			tst_res(TPASS | TTERRNO, "clock_gettime(2): "
-					"clock %s failed as expected",
-					tst_clock_name(tc[i].clktype));
-
-		} else {
-
-			tst_res(TFAIL | TTERRNO, "clock_gettime(2): "
-					"clock %s failed unexpectedly",
-					tst_clock_name(tc[i].clktype));
-		}
+	if (TST_RET != -1) {
+		tst_res(TFAIL, "clock_gettime(2): clock %s passed unexcpectedly",
+			tst_clock_name(tc[i].clktype));
+		return;
+	}
 
+	if ((tc[i].exp_err == TST_ERR) ||
+	    (tc[i].allow_inval && TST_ERR == EINVAL)) {
+		tst_res(TPASS | TTERRNO, "clock_gettime(2): clock %s failed as expected",
+			tst_clock_name(tc[i].clktype));
 	} else {
-
-		tst_res(TFAIL, "clock_gettime(2): clock %s passed"
-				" unexcpectedly",
-				tst_clock_name(tc[i].clktype));
+		tst_res(TFAIL | TTERRNO, "clock_gettime(2): clock %s failed unexpectedly",
+			tst_clock_name(tc[i].clktype));
 	}
 }
 
 static struct tst_test test = {
 	.test = verify_clock_gettime,
 	.tcnt = ARRAY_SIZE(tc),
+	.test_variants = ARRAY_SIZE(variants),
+	.setup = setup,
 	.needs_root = 1,
 };
diff --git a/testcases/kernel/syscalls/clock_gettime/clock_gettime03.c b/testcases/kernel/syscalls/clock_gettime/clock_gettime03.c
index cf4706fa0c30..ddc835c07669 100644
--- a/testcases/kernel/syscalls/clock_gettime/clock_gettime03.c
+++ b/testcases/kernel/syscalls/clock_gettime/clock_gettime03.c
@@ -21,7 +21,7 @@
 #include "tst_safe_clocks.h"
 #include "tst_timer.h"
 #include "lapi/namespaces_constants.h"
-#include "tst_test.h"
+#include "lapi/abisize.h"
 
 static struct tcase {
 	int clk_id;
@@ -38,22 +38,46 @@ static struct tcase {
 	{CLOCK_MONOTONIC_COARSE, CLOCK_MONOTONIC, 100},
 };
 
-static struct timespec now;
+static struct tst_timespec now, then, parent_then;
 static int parent_ns;
 
-static void child(struct tcase *tc)
+static struct test_variants {
+	int (*func)(clockid_t clk_id, struct tst_timespec *spec);
+	enum tst_timespec_type type;
+	char *desc;
+} variants[] = {
+#if defined(TST_ABI32)
+	{ .func = libc_clock_gettime, .type = TST_LIBC_TIMESPEC, .desc = "vDSO or syscall with libc spec"},
+	{ .func = sys_clock_gettime, .type = TST_LIBC_TIMESPEC, .desc = "syscall with libc spec"},
+	{ .func = sys_clock_gettime, .type = TST_KERN_OLD_TIMESPEC, .desc = "syscall with kernel spec32"},
+#endif
+
+#if defined(TST_ABI64)
+	{ .func = sys_clock_gettime, .type = TST_KERN_TIMESPEC, .desc = "syscall with kernel spec64"},
+#endif
+
+#if (__NR_clock_gettime64 != __LTP__NR_INVALID_SYSCALL)
+	{ .func = sys_clock_gettime64, .type = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec64"},
+#endif
+};
+
+static void child(struct test_variants *tv, struct tcase *tc)
 {
-	struct timespec then;
-	struct timespec parent_then;
 	long long diff;
 
-	SAFE_CLOCK_GETTIME(tc->clk_id, &then);
+	if (tv->func(tc->clk_id, &then)) {
+		tst_brk(TBROK | TERRNO, "clock_gettime(%s) failed",
+			tst_clock_name(tc->clk_id));
+	}
 
 	SAFE_SETNS(parent_ns, CLONE_NEWTIME);
 
-	SAFE_CLOCK_GETTIME(tc->clk_id, &parent_then);
+	if (tv->func(tc->clk_id, &parent_then)) {
+		tst_brk(TBROK | TERRNO, "clock_gettime(%s) failed",
+			tst_clock_name(tc->clk_id));
+	}
 
-	diff = tst_timespec_diff_ms(then, now);
+	diff = tst_tst_timespec_diff_ms(then, now);
 
 	if (diff/1000 != tc->off) {
 		tst_res(TFAIL, "Wrong offset (%s) read %llims",
@@ -63,7 +87,7 @@ static void child(struct tcase *tc)
 		        tst_clock_name(tc->clk_id), diff);
 	}
 
-	diff = tst_timespec_diff_ms(parent_then, now);
+	diff = tst_tst_timespec_diff_ms(parent_then, now);
 
 	if (diff/1000) {
 		tst_res(TFAIL, "Wrong offset (%s) read %llims",
@@ -76,6 +100,7 @@ static void child(struct tcase *tc)
 
 static void verify_ns_clock(unsigned int n)
 {
+	struct test_variants *tv = &variants[tst_variant];
 	struct tcase *tc = &tcases[n];
 
 	SAFE_UNSHARE(CLONE_NEWTIME);
@@ -83,14 +108,21 @@ static void verify_ns_clock(unsigned int n)
 	SAFE_FILE_PRINTF("/proc/self/timens_offsets", "%d %d 0",
 	                 tc->clk_off, tc->off);
 
-	SAFE_CLOCK_GETTIME(tc->clk_id, &now);
+	if (tv->func(tc->clk_id, &now)) {
+		tst_brk(TBROK | TERRNO, "%d clock_gettime(%s) failed",
+			__LINE__, tst_clock_name(tc->clk_id));
+	}
 
 	if (!SAFE_FORK())
-		child(tc);
+		child(tv, tc);
 }
 
 static void setup(void)
 {
+	struct test_variants *tv = &variants[tst_variant];
+
+	now.type = then.type = parent_then.type = tv->type;
+	tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
 	parent_ns = SAFE_OPEN("/proc/self/ns/time_for_children", O_RDONLY);
 }
 
@@ -104,6 +136,7 @@ static struct tst_test test = {
 	.cleanup = cleanup,
 	.tcnt = ARRAY_SIZE(tcases),
 	.test = verify_ns_clock,
+	.test_variants = ARRAY_SIZE(variants),
 	.needs_root = 1,
 	.forks_child = 1,
 	.needs_kconfigs = (const char *[]) {
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [LTP] [PATCH V3 1/2] tst_timer: Add support for kernel's 64 bit timespec
  2020-04-16 10:42 ` [LTP] [PATCH V3 1/2] tst_timer: Add support for kernel's 64 bit timespec Viresh Kumar
@ 2020-04-21 15:40   ` Cyril Hrubis
  2020-04-22  4:07     ` Viresh Kumar
  2020-04-22 13:18     ` Petr Vorel
  0 siblings, 2 replies; 8+ messages in thread
From: Cyril Hrubis @ 2020-04-21 15:40 UTC (permalink / raw)
  To: ltp

Hi!
I've cleaned up and simplified these changes + wrote a simple test and
pushed the result, thanks a lot for your effors.

Can you please rebase the test changes on the top of these changes? It
should be merely cosmetical, function names have changes etc.

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [LTP] [PATCH V3 1/2] tst_timer: Add support for kernel's 64 bit timespec
  2020-04-21 15:40   ` Cyril Hrubis
@ 2020-04-22  4:07     ` Viresh Kumar
  2020-04-22 13:18     ` Petr Vorel
  1 sibling, 0 replies; 8+ messages in thread
From: Viresh Kumar @ 2020-04-22  4:07 UTC (permalink / raw)
  To: ltp

On 21-04-20, 17:40, Cyril Hrubis wrote:
> Hi!
> I've cleaned up and simplified these changes + wrote a simple test and
> pushed the result, thanks a lot for your effors.
> 
> Can you please rebase the test changes on the top of these changes? It
> should be merely cosmetical, function names have changes etc.

Thanks for the changes, they look much better now :)

-- 
viresh

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [LTP] [PATCH V3 1/2] tst_timer: Add support for kernel's 64 bit timespec
  2020-04-21 15:40   ` Cyril Hrubis
  2020-04-22  4:07     ` Viresh Kumar
@ 2020-04-22 13:18     ` Petr Vorel
  2020-04-22 13:26       ` Cyril Hrubis
  1 sibling, 1 reply; 8+ messages in thread
From: Petr Vorel @ 2020-04-22 13:18 UTC (permalink / raw)
  To: ltp

Hi,

> I've cleaned up and simplified these changes + wrote a simple test and
> pushed the result, thanks a lot for your effors.

> Can you please rebase the test changes on the top of these changes? It
> should be merely cosmetical, function names have changes etc.

include/tst_timer.h is broken on gcc 4, which we have in Travis (CentOS 6).
I don't know how to fix this, but maybe fix is trivial.
Or is it time to finally drop this oldest distro? If it's easy to fix, I'd
postpone dropping CentOS 6 after release (some embedded distros/projects might
still use old compilers).

gcc -g -O2 -g -O2 -fno-strict-aliasing -pipe -Wall -W -Wold-style-definition -W -Wall -D_FORTIFY_SOURCE=2 -I../../include -I../../include -I../../include/old/   -L../../lib  test_timer.c   -lltp -o test_timer
In file included from test_timer.c:11:
../../include/tst_timer.h: In function ?tst_ts_from_timespec?:
../../include/tst_timer.h:214: error: unknown field ?libc_ts? specified in initializer
../../include/tst_timer.h:214: warning: missing braces around initializer
../../include/tst_timer.h:214: warning: (near initialization for ?t.<anonymous>?)
../../include/tst_timer.h:215: warning: missing initializer
../../include/tst_timer.h:215: warning: (near initialization for ?t.<anonymous>.libc_ts.tv_nsec?)
../../include/tst_timer.h:215: error: unknown field ?libc_ts? specified in initializer
../../include/tst_timer.h:215: warning: excess elements in struct initializer
../../include/tst_timer.h:215: warning: (near initialization for ?t?)
make: *** [test_timer] Error 1

$ gcc --version
gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-18)

Kind regards,
Petr

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [LTP] [PATCH V3 1/2] tst_timer: Add support for kernel's 64 bit timespec
  2020-04-22 13:18     ` Petr Vorel
@ 2020-04-22 13:26       ` Cyril Hrubis
  2020-04-22 14:29         ` Cyril Hrubis
  0 siblings, 1 reply; 8+ messages in thread
From: Cyril Hrubis @ 2020-04-22 13:26 UTC (permalink / raw)
  To: ltp

Hi!
> include/tst_timer.h is broken on gcc 4, which we have in Travis (CentOS 6).
> I don't know how to fix this, but maybe fix is trivial.
> Or is it time to finally drop this oldest distro? If it's easy to fix, I'd
> postpone dropping CentOS 6 after release (some embedded distros/projects might
> still use old compilers).
> 
> gcc -g -O2 -g -O2 -fno-strict-aliasing -pipe -Wall -W -Wold-style-definition -W -Wall -D_FORTIFY_SOURCE=2 -I../../include -I../../include -I../../include/old/   -L../../lib  test_timer.c   -lltp -o test_timer
> In file included from test_timer.c:11:
> ../../include/tst_timer.h: In function ???tst_ts_from_timespec???:
> ../../include/tst_timer.h:214: error: unknown field ???libc_ts??? specified in initializer
> ../../include/tst_timer.h:214: warning: missing braces around initializer
> ../../include/tst_timer.h:214: warning: (near initialization for ???t.<anonymous>???)
> ../../include/tst_timer.h:215: warning: missing initializer
> ../../include/tst_timer.h:215: warning: (near initialization for ???t.<anonymous>.libc_ts.tv_nsec???)
> ../../include/tst_timer.h:215: error: unknown field ???libc_ts??? specified in initializer
> ../../include/tst_timer.h:215: warning: excess elements in struct initializer
> ../../include/tst_timer.h:215: warning: (near initialization for ???t???)
> make: *** [test_timer] Error 1
> 
> $ gcc --version
> gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-18)

Looks like there are some problems with the anonymouns unions, probably
gcc 4.4 does not support these. I will have a look later on.

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [LTP] [PATCH V3 1/2] tst_timer: Add support for kernel's 64 bit timespec
  2020-04-22 13:26       ` Cyril Hrubis
@ 2020-04-22 14:29         ` Cyril Hrubis
  0 siblings, 0 replies; 8+ messages in thread
From: Cyril Hrubis @ 2020-04-22 14:29 UTC (permalink / raw)
  To: ltp

Hi!
> > $ gcc --version
> > gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-18)
> 
> Looks like there are some problems with the anonymouns unions, probably
> gcc 4.4 does not support these. I will have a look later on.

Looking into the issue, anonymous unions are part of c11 standard so it
looks like gcc 4.4 is too old to support that. I have tested 4.4.5 which
definitelly lacks the support.

So I guess I will have to change the code so that the union has a name,
its not a big deal since we aren't touching the fields directly but only
in a few get/set functions.

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-04-22 14:29 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-16 10:42 [LTP] [PATCH V3 0/2] syscalls/clock_gettime: Add support for time64 tests Viresh Kumar
2020-04-16 10:42 ` [LTP] [PATCH V3 1/2] tst_timer: Add support for kernel's 64 bit timespec Viresh Kumar
2020-04-21 15:40   ` Cyril Hrubis
2020-04-22  4:07     ` Viresh Kumar
2020-04-22 13:18     ` Petr Vorel
2020-04-22 13:26       ` Cyril Hrubis
2020-04-22 14:29         ` Cyril Hrubis
2020-04-16 10:42 ` [LTP] [PATCH V3 2/2] syscalls/clock_gettime: Add support for time64 tests Viresh Kumar

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.