public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH v2 0/9] Add basic time namespace testcases
@ 2020-03-18 15:37 Cyril Hrubis
  2020-03-18 15:37 ` [LTP] [PATCH v2 1/9] lapi/namespace_constants.h: Add CLONE_NEWTIME Cyril Hrubis
                   ` (8 more replies)
  0 siblings, 9 replies; 16+ messages in thread
From: Cyril Hrubis @ 2020-03-18 15:37 UTC (permalink / raw)
  To: ltp

This is a set of test for the time namespaces that are going to be part
of 5.6 kernel.

v2:

* Added git has into sysinfo03, as requested by ritchie

* Included description for the timens01 test as requsted by ritchie

* Added SAFE_NETNS() which fixed compilation problems reported by pvorel
  as well

Cyril Hrubis (9):
  lapi/namespace_constants.h: Add CLONE_NEWTIME
  lapi: Add a configure check and fallback for setns
  safe_macros: Add SAFE_SETNS()
  include/tst_timer: Fix normalization
  syscalls/sysinfo03: Add time namespace test
  syscalls/clock_nanosleep03: Add test for time namespace
  syscalls/clock_gettime03: Add basic time namespace test
  containers/timens: Add basic error test
  syscalls/timerfd04: Add time namespace test

 configure.ac                                  |   1 +
 include/lapi/namespaces_constants.h           |   3 +
 include/lapi/setns.h                          |  20 ++++
 include/tst_safe_macros.h                     |   4 +
 include/tst_timer.h                           |  35 +++---
 lib/tst_safe_macros.c                         |  12 ++
 runtest/containers                            |   7 ++
 runtest/syscalls                              |   4 +
 testcases/kernel/containers/timens/.gitignore |   1 +
 testcases/kernel/containers/timens/Makefile   |   6 +
 testcases/kernel/containers/timens/timens01.c |  68 +++++++++++
 .../kernel/syscalls/clock_gettime/.gitignore  |   1 +
 .../syscalls/clock_gettime/clock_gettime03.c  | 112 ++++++++++++++++++
 .../syscalls/clock_nanosleep/.gitignore       |   1 +
 .../clock_nanosleep/clock_nanosleep03.c       |  71 +++++++++++
 testcases/kernel/syscalls/sysinfo/.gitignore  |   1 +
 testcases/kernel/syscalls/sysinfo/sysinfo03.c |  81 +++++++++++++
 testcases/kernel/syscalls/timerfd/.gitignore  |   1 +
 testcases/kernel/syscalls/timerfd/timerfd04.c |  98 +++++++++++++++
 19 files changed, 510 insertions(+), 17 deletions(-)
 create mode 100644 include/lapi/setns.h
 create mode 100644 testcases/kernel/containers/timens/.gitignore
 create mode 100644 testcases/kernel/containers/timens/Makefile
 create mode 100644 testcases/kernel/containers/timens/timens01.c
 create mode 100644 testcases/kernel/syscalls/clock_gettime/clock_gettime03.c
 create mode 100644 testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep03.c
 create mode 100644 testcases/kernel/syscalls/sysinfo/sysinfo03.c
 create mode 100644 testcases/kernel/syscalls/timerfd/timerfd04.c

-- 
2.24.1


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

* [LTP] [PATCH v2 1/9] lapi/namespace_constants.h: Add CLONE_NEWTIME
  2020-03-18 15:37 [LTP] [PATCH v2 0/9] Add basic time namespace testcases Cyril Hrubis
@ 2020-03-18 15:37 ` Cyril Hrubis
  2020-03-18 15:37 ` [LTP] [PATCH v2 2/9] lapi: Add a configure check and fallback for setns Cyril Hrubis
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 16+ messages in thread
From: Cyril Hrubis @ 2020-03-18 15:37 UTC (permalink / raw)
  To: ltp

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 include/lapi/namespaces_constants.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/lapi/namespaces_constants.h b/include/lapi/namespaces_constants.h
index da4a7a4a1..8f73c4302 100644
--- a/include/lapi/namespaces_constants.h
+++ b/include/lapi/namespaces_constants.h
@@ -24,5 +24,8 @@
 #ifndef CLONE_NEWUTS
 #  define CLONE_NEWUTS	0x04000000
 #endif
+#ifndef CLONE_NEWTIME
+#  define CLONE_NEWTIME 0x00000080
+#endif
 
 #endif /* __NAMESPACES_CONSTANTS_H__ */
-- 
2.24.1


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

* [LTP] [PATCH v2 2/9] lapi: Add a configure check and fallback for setns
  2020-03-18 15:37 [LTP] [PATCH v2 0/9] Add basic time namespace testcases Cyril Hrubis
  2020-03-18 15:37 ` [LTP] [PATCH v2 1/9] lapi/namespace_constants.h: Add CLONE_NEWTIME Cyril Hrubis
@ 2020-03-18 15:37 ` Cyril Hrubis
  2020-03-18 15:37 ` [LTP] [PATCH v2 3/9] safe_macros: Add SAFE_SETNS() Cyril Hrubis
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 16+ messages in thread
From: Cyril Hrubis @ 2020-03-18 15:37 UTC (permalink / raw)
  To: ltp

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 configure.ac         |  1 +
 include/lapi/setns.h | 20 ++++++++++++++++++++
 2 files changed, 21 insertions(+)
 create mode 100644 include/lapi/setns.h

diff --git a/configure.ac b/configure.ac
index 238d1cde8..ce03b3a55 100644
--- a/configure.ac
+++ b/configure.ac
@@ -111,6 +111,7 @@ AC_CHECK_FUNCS([ \
     renameat2 \
     sched_getcpu \
     sendmmsg \
+    setns \
     sigpending \
     splice \
     statx \
diff --git a/include/lapi/setns.h b/include/lapi/setns.h
new file mode 100644
index 000000000..7b0a7afc4
--- /dev/null
+++ b/include/lapi/setns.h
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+  Copyright (c) 2020 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+#ifndef LAPI_SETNS_H__
+#define LAPI_SETNS_H__
+
+#include "config.h"
+#include "lapi/syscalls.h"
+#include <sched.h>
+
+#ifndef HAVE_SETNS
+int setns(int fd, int nstype)
+{
+	return tst_syscall(__NR_setns, fd, nstype);
+}
+#endif
+
+#endif /* LAPI_SETNS_H__ */
-- 
2.24.1


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

* [LTP] [PATCH v2 3/9] safe_macros: Add SAFE_SETNS()
  2020-03-18 15:37 [LTP] [PATCH v2 0/9] Add basic time namespace testcases Cyril Hrubis
  2020-03-18 15:37 ` [LTP] [PATCH v2 1/9] lapi/namespace_constants.h: Add CLONE_NEWTIME Cyril Hrubis
  2020-03-18 15:37 ` [LTP] [PATCH v2 2/9] lapi: Add a configure check and fallback for setns Cyril Hrubis
@ 2020-03-18 15:37 ` Cyril Hrubis
  2020-03-23 16:11   ` Petr Vorel
  2020-03-18 15:37 ` [LTP] [PATCH v2 4/9] include/tst_timer: Fix normalization Cyril Hrubis
                   ` (5 subsequent siblings)
  8 siblings, 1 reply; 16+ messages in thread
From: Cyril Hrubis @ 2020-03-18 15:37 UTC (permalink / raw)
  To: ltp

From: Cyril Hrubis <metan@ucw.cz>

Signed-off-by: Cyril Hrubis <metan@ucw.cz>
---
 include/tst_safe_macros.h |  4 ++++
 lib/tst_safe_macros.c     | 12 ++++++++++++
 2 files changed, 16 insertions(+)

diff --git a/include/tst_safe_macros.h b/include/tst_safe_macros.h
index 80c4d9cb9..291f2a722 100644
--- a/include/tst_safe_macros.h
+++ b/include/tst_safe_macros.h
@@ -547,4 +547,8 @@ int safe_personality(const char *filename, unsigned int lineno,
 void safe_unshare(const char *file, const int lineno, int flags);
 #define SAFE_UNSHARE(flags) safe_unshare(__FILE__, __LINE__, (flags))
 
+
+void safe_setns(const char *file, const int lineno, int fd, int nstype);
+#define SAFE_SETNS(fd, nstype) safe_setns(__FILE__, __LINE__, (fd), (nstype));
+
 #endif /* SAFE_MACROS_H__ */
diff --git a/lib/tst_safe_macros.c b/lib/tst_safe_macros.c
index f5413a18e..353ef5b1d 100644
--- a/lib/tst_safe_macros.c
+++ b/lib/tst_safe_macros.c
@@ -6,6 +6,7 @@
 #define _GNU_SOURCE
 #include <unistd.h>
 #include <errno.h>
+#include "lapi/setns.h"
 #include <sched.h>
 #include "config.h"
 #ifdef HAVE_SYS_FANOTIFY_H
@@ -202,3 +203,14 @@ void safe_unshare(const char *file, const int lineno, int flags)
 		}
 	}
 }
+
+void safe_setns(const char *file, const int lineno, int fd, int nstype)
+{
+	int ret;
+
+	ret = setns(fd, nstype);
+	if (ret == -1) {
+		tst_brk_(file, lineno, TBROK | TERRNO, "setns(%i, %i) failed",
+		         fd, nstype);
+	}
+}
-- 
2.24.1


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

* [LTP] [PATCH v2 4/9] include/tst_timer: Fix normalization
  2020-03-18 15:37 [LTP] [PATCH v2 0/9] Add basic time namespace testcases Cyril Hrubis
                   ` (2 preceding siblings ...)
  2020-03-18 15:37 ` [LTP] [PATCH v2 3/9] safe_macros: Add SAFE_SETNS() Cyril Hrubis
@ 2020-03-18 15:37 ` Cyril Hrubis
  2020-03-18 15:37 ` [LTP] [PATCH v2 5/9] syscalls/sysinfo03: Add time namespace test Cyril Hrubis
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 16+ messages in thread
From: Cyril Hrubis @ 2020-03-18 15:37 UTC (permalink / raw)
  To: ltp

The timespec_add and timespec_sub functions were producing incorrect
results when passed negative input. We have to normalize the result in
both cases for nseconds < 0 && nseconds > 1s.

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 include/tst_timer.h | 35 ++++++++++++++++++-----------------
 1 file changed, 18 insertions(+), 17 deletions(-)

diff --git a/include/tst_timer.h b/include/tst_timer.h
index de60bc62a..b091137dc 100644
--- a/include/tst_timer.h
+++ b/include/tst_timer.h
@@ -134,6 +134,21 @@ static inline int tst_timespec_lt(struct timespec t1, struct timespec t2)
 	return t1.tv_sec < t2.tv_sec;
 }
 
+static inline struct timespec tst_timespec_normalize(struct timespec t)
+{
+	if (t.tv_nsec >= 1000000000) {
+		t.tv_sec++;
+		t.tv_nsec -= 1000000000;
+	}
+
+	if (t.tv_nsec < 0) {
+		t.tv_sec--;
+		t.tv_nsec += 1000000000;
+	}
+
+	return t;
+}
+
 /*
  * Adds us microseconds to t.
  */
@@ -143,12 +158,8 @@ static inline struct timespec tst_timespec_add_us(struct timespec t,
 	t.tv_sec += us / 1000000;
 	t.tv_nsec += (us % 1000000) * 1000;
 
-	if (t.tv_nsec >= 1000000000) {
-		t.tv_sec++;
-		t.tv_nsec -= 1000000000;
-	}
 
-	return t;
+	return tst_timespec_normalize(t);
 }
 
 /*
@@ -162,12 +173,7 @@ static inline struct timespec tst_timespec_add(struct timespec t1,
 	res.tv_sec = t1.tv_sec + t2.tv_sec;
 	res.tv_nsec = t1.tv_nsec + t2.tv_nsec;
 
-	if (res.tv_nsec >= 1000000000) {
-		res.tv_sec++;
-		res.tv_nsec -= 1000000000;
-	}
-
-	return res;
+	return tst_timespec_normalize(res);
 }
 
 /*
@@ -179,12 +185,7 @@ static inline struct timespec tst_timespec_sub_us(struct timespec t,
 	t.tv_sec -= us / 1000000;
 	t.tv_nsec -= (us % 1000000) * 1000;
 
-	if (t.tv_nsec < 0) {
-		t.tv_sec--;
-		t.tv_nsec += 1000000000;
-	}
-
-	return t;
+	return tst_timespec_normalize(t);
 }
 
 /*
-- 
2.24.1


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

* [LTP] [PATCH v2 5/9] syscalls/sysinfo03: Add time namespace test
  2020-03-18 15:37 [LTP] [PATCH v2 0/9] Add basic time namespace testcases Cyril Hrubis
                   ` (3 preceding siblings ...)
  2020-03-18 15:37 ` [LTP] [PATCH v2 4/9] include/tst_timer: Fix normalization Cyril Hrubis
@ 2020-03-18 15:37 ` Cyril Hrubis
  2020-03-19  7:55   ` Li Wang
  2020-03-23 18:47   ` Petr Vorel
  2020-03-18 15:37 ` [LTP] [PATCH v2 6/9] syscalls/clock_nanosleep03: Add test for time namespace Cyril Hrubis
                   ` (3 subsequent siblings)
  8 siblings, 2 replies; 16+ messages in thread
From: Cyril Hrubis @ 2020-03-18 15:37 UTC (permalink / raw)
  To: ltp

This tests that the uptime in sysinfo() is adjusted correctly by the
namespace offset.

Also check that /proc/uptime is consistent with the uptime from the
sysinfo() syscall.

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 runtest/containers                            |  3 +
 runtest/syscalls                              |  1 +
 testcases/kernel/syscalls/sysinfo/.gitignore  |  1 +
 testcases/kernel/syscalls/sysinfo/sysinfo03.c | 81 +++++++++++++++++++
 4 files changed, 86 insertions(+)
 create mode 100644 testcases/kernel/syscalls/sysinfo/sysinfo03.c

diff --git a/runtest/containers b/runtest/containers
index 871cd2a42..4dc05af93 100644
--- a/runtest/containers
+++ b/runtest/containers
@@ -85,3 +85,6 @@ userns04 userns04
 userns05 userns05
 userns06 userns06
 userns07 userns07
+
+# time namespaces
+sysinfo03 sysinfo03
diff --git a/runtest/syscalls b/runtest/syscalls
index 6f2dcd82a..fb0b9e539 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1465,6 +1465,7 @@ sysfs06 sysfs06
 
 sysinfo01 sysinfo01
 sysinfo02 sysinfo02
+sysinfo03 sysinfo03
 
 syslog01 syslog01
 syslog02 syslog02
diff --git a/testcases/kernel/syscalls/sysinfo/.gitignore b/testcases/kernel/syscalls/sysinfo/.gitignore
index aa7c26946..8ad2279a4 100644
--- a/testcases/kernel/syscalls/sysinfo/.gitignore
+++ b/testcases/kernel/syscalls/sysinfo/.gitignore
@@ -1,2 +1,3 @@
 /sysinfo01
 /sysinfo02
+/sysinfo03
diff --git a/testcases/kernel/syscalls/sysinfo/sysinfo03.c b/testcases/kernel/syscalls/sysinfo/sysinfo03.c
new file mode 100644
index 000000000..af1024915
--- /dev/null
+++ b/testcases/kernel/syscalls/sysinfo/sysinfo03.c
@@ -0,0 +1,81 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+  Copyright (c) 2020 Cyril Hrubis <chrubis@suse.cz>
+ */
+/*
+
+  Test if CLOCK_BOOTTIME namespace offset is applied to sysinfo uptime and that
+  it's consistent with /proc/uptime as well.
+
+  After a call to unshare(CLONE_NEWTIME) a new timer namespace is created, the
+  process that has called the unshare() can adjust offsets for CLOCK_MONOTONIC
+  and CLOCK_BOOTTIME for its children by writing to the '/proc/self/timens_offsets'.
+
+ */
+
+#include <sys/sysinfo.h>
+#include "lapi/namespaces_constants.h"
+#include "tst_test.h"
+
+static int offsets[] = {
+	10,
+	-10,
+	3600,
+};
+
+static long read_proc_uptime(void)
+{
+	long sec, sec_rem;
+
+	SAFE_FILE_SCANF("/proc/uptime", "%li.%li", &sec, &sec_rem);
+
+	return sec + (sec_rem ? 1 : 0);
+}
+
+static void verify_sysinfo(unsigned int n)
+{
+	struct sysinfo si;
+	long uptime;
+	int off = offsets[n];
+
+	SAFE_UNSHARE(CLONE_NEWTIME);
+
+        SAFE_FILE_PRINTF("/proc/self/timens_offsets", "%d %d 0",
+	                 CLOCK_BOOTTIME, off);
+
+	sysinfo(&si);
+
+	uptime = si.uptime;
+
+	if (!SAFE_FORK()) {
+		sysinfo(&si);
+		long proc_uptime = read_proc_uptime();
+
+		long diff = si.uptime - uptime;
+
+		if (diff < off || diff > off + 1)
+			tst_res(TFAIL, "Wrong sysinfo uptime offset %li", diff);
+		else
+			tst_res(TPASS, "Correct sysinfo uptime offset %i", off);
+
+		if (si.uptime < proc_uptime || si.uptime > proc_uptime + 1) {
+			tst_res(TFAIL, "/proc/uptime %li differs from sysinfo %li",
+			        proc_uptime, si.uptime);
+		} else {
+			tst_res(TPASS, "/proc/uptime is consistent with sysinfo");
+		}
+	}
+}
+
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(offsets),
+	.test = verify_sysinfo,
+	.needs_root = 1,
+	.forks_child = 1,
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_TIME_NS=y"
+	}
+	.tags = (const struct tst_tag[]) {
+		{"linux-git", "ecc421e05bab"},
+	}
+};
-- 
2.24.1


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

* [LTP] [PATCH v2 6/9] syscalls/clock_nanosleep03: Add test for time namespace
  2020-03-18 15:37 [LTP] [PATCH v2 0/9] Add basic time namespace testcases Cyril Hrubis
                   ` (4 preceding siblings ...)
  2020-03-18 15:37 ` [LTP] [PATCH v2 5/9] syscalls/sysinfo03: Add time namespace test Cyril Hrubis
@ 2020-03-18 15:37 ` Cyril Hrubis
  2020-03-18 15:37 ` [LTP] [PATCH v2 7/9] syscalls/clock_gettime03: Add basic time namespace test Cyril Hrubis
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 16+ messages in thread
From: Cyril Hrubis @ 2020-03-18 15:37 UTC (permalink / raw)
  To: ltp

Test that absolute timeout for clock nanosleep is adjusted by the offset
correctly inside of a time namespace.

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 runtest/containers                            |  1 +
 runtest/syscalls                              |  1 +
 .../syscalls/clock_nanosleep/.gitignore       |  1 +
 .../clock_nanosleep/clock_nanosleep03.c       | 71 +++++++++++++++++++
 4 files changed, 74 insertions(+)
 create mode 100644 testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep03.c

diff --git a/runtest/containers b/runtest/containers
index 4dc05af93..8100cd2bc 100644
--- a/runtest/containers
+++ b/runtest/containers
@@ -88,3 +88,4 @@ userns07 userns07
 
 # time namespaces
 sysinfo03 sysinfo03
+clock_nanosleep03 clock_nanosleep03
diff --git a/runtest/syscalls b/runtest/syscalls
index fb0b9e539..eac4eeffc 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -87,6 +87,7 @@ clock_getres01 clock_getres01
 clock_nanosleep01 clock_nanosleep01
 clock_nanosleep02 clock_nanosleep02
 clock_nanosleep2_01 clock_nanosleep2_01
+clock_nanosleep03 clock_nanosleep03
 
 clock_gettime01 clock_gettime01
 clock_gettime02 clock_gettime02
diff --git a/testcases/kernel/syscalls/clock_nanosleep/.gitignore b/testcases/kernel/syscalls/clock_nanosleep/.gitignore
index 6714ff468..406897cde 100644
--- a/testcases/kernel/syscalls/clock_nanosleep/.gitignore
+++ b/testcases/kernel/syscalls/clock_nanosleep/.gitignore
@@ -1,2 +1,3 @@
 /clock_nanosleep01
 /clock_nanosleep02
+/clock_nanosleep03
diff --git a/testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep03.c b/testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep03.c
new file mode 100644
index 000000000..99ff99736
--- /dev/null
+++ b/testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep03.c
@@ -0,0 +1,71 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+
+  Copyright (c) 2020 Cyril Hrubis <chrubis@suse.cz>
+
+ */
+/*
+
+   Test that clock_nanosleep() adds correctly an offset with absolute timeout
+   and CLOCK_MONOTONIC inside of a timer namespace.
+
+   After a call to unshare(CLONE_NEWTIME) a new timer namespace is created, the
+   process that has called the unshare() can adjust offsets for CLOCK_MONOTONIC
+   and CLOCK_BOOTTIME for its children by writing to the '/proc/self/timens_offsets'.
+
+ */
+
+#include <stdlib.h>
+#include "tst_safe_clocks.h"
+#include "tst_timer.h"
+#include "lapi/namespaces_constants.h"
+#include "tst_test.h"
+
+#define OFFSET_S 10
+#define SLEEP_US 100000
+
+static void verify_clock_nanosleep(void)
+{
+	struct timespec start, end, sleep_abs;
+
+	SAFE_UNSHARE(CLONE_NEWTIME);
+
+	SAFE_FILE_PRINTF("/proc/self/timens_offsets", "%d %d 0", CLOCK_MONOTONIC, OFFSET_S);
+
+	SAFE_CLOCK_GETTIME(CLOCK_MONOTONIC, &start);
+
+	sleep_abs = tst_timespec_add_us(start, 1000000 * OFFSET_S + SLEEP_US);
+
+	if (!SAFE_FORK()) {
+		clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &sleep_abs, NULL);
+		exit(0);
+	}
+
+	SAFE_WAIT(NULL);
+
+	SAFE_CLOCK_GETTIME(CLOCK_MONOTONIC, &end);
+
+	long long diff = tst_timespec_diff_us(end, start);
+
+	if (diff > 5 * SLEEP_US) {
+		tst_res(TFAIL, "clock_nanosleep() slept too long %lli", diff);
+		return;
+	}
+
+	if (diff < SLEEP_US) {
+		tst_res(TFAIL, "clock_nanosleep() slept too short %lli", diff);
+		return;
+	}
+
+	tst_res(TPASS, "clock_nanosleep() slept correctly %lli", diff);
+}
+
+static struct tst_test test = {
+	.test_all = verify_clock_nanosleep,
+	.needs_root = 1,
+	.forks_child = 1,
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_TIME_NS=y"
+	}
+
+};
-- 
2.24.1


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

* [LTP] [PATCH v2 7/9] syscalls/clock_gettime03: Add basic time namespace test
  2020-03-18 15:37 [LTP] [PATCH v2 0/9] Add basic time namespace testcases Cyril Hrubis
                   ` (5 preceding siblings ...)
  2020-03-18 15:37 ` [LTP] [PATCH v2 6/9] syscalls/clock_nanosleep03: Add test for time namespace Cyril Hrubis
@ 2020-03-18 15:37 ` Cyril Hrubis
  2020-03-18 15:38 ` [LTP] [PATCH v2 8/9] containers/timens: Add basic error test Cyril Hrubis
  2020-03-18 15:38 ` [LTP] [PATCH v2 9/9] syscalls/timerfd04: Add time namespace test Cyril Hrubis
  8 siblings, 0 replies; 16+ messages in thread
From: Cyril Hrubis @ 2020-03-18 15:37 UTC (permalink / raw)
  To: ltp

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 runtest/containers                            |   1 +
 runtest/syscalls                              |   1 +
 .../kernel/syscalls/clock_gettime/.gitignore  |   1 +
 .../syscalls/clock_gettime/clock_gettime03.c  | 112 ++++++++++++++++++
 4 files changed, 115 insertions(+)
 create mode 100644 testcases/kernel/syscalls/clock_gettime/clock_gettime03.c

diff --git a/runtest/containers b/runtest/containers
index 8100cd2bc..1006d8d35 100644
--- a/runtest/containers
+++ b/runtest/containers
@@ -89,3 +89,4 @@ userns07 userns07
 # time namespaces
 sysinfo03 sysinfo03
 clock_nanosleep03 clock_nanosleep03
+clock_gettime03 clock_gettime03
diff --git a/runtest/syscalls b/runtest/syscalls
index eac4eeffc..4949b5d36 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -91,6 +91,7 @@ clock_nanosleep03 clock_nanosleep03
 
 clock_gettime01 clock_gettime01
 clock_gettime02 clock_gettime02
+clock_gettime03 clock_gettime03
 leapsec01 leapsec01
 
 clock_settime01 clock_settime01
diff --git a/testcases/kernel/syscalls/clock_gettime/.gitignore b/testcases/kernel/syscalls/clock_gettime/.gitignore
index ba471c859..9d06613b6 100644
--- a/testcases/kernel/syscalls/clock_gettime/.gitignore
+++ b/testcases/kernel/syscalls/clock_gettime/.gitignore
@@ -1,3 +1,4 @@
 clock_gettime01
 clock_gettime02
+clock_gettime03
 leapsec01
diff --git a/testcases/kernel/syscalls/clock_gettime/clock_gettime03.c b/testcases/kernel/syscalls/clock_gettime/clock_gettime03.c
new file mode 100644
index 000000000..8b8613ed1
--- /dev/null
+++ b/testcases/kernel/syscalls/clock_gettime/clock_gettime03.c
@@ -0,0 +1,112 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+
+  Copyright (c) 2020 Cyril Hrubis <chrubis@suse.cz>
+
+ */
+/*
+
+  Basic test for timer namespaces.
+
+  After a call to unshare(CLONE_NEWTIME) a new timer namespace is created, the
+  process that has called the unshare() can adjust offsets for CLOCK_MONOTONIC
+  and CLOCK_BOOTTIME for its children by writing to the '/proc/self/timens_offsets'.
+
+  The child processes also switch to the initial parent namespace and checks
+  that the offset is set to 0.
+
+ */
+
+#define _GNU_SOURCE
+#include "tst_safe_clocks.h"
+#include "tst_timer.h"
+#include "lapi/namespaces_constants.h"
+#include "tst_test.h"
+
+static struct tcase {
+	int clk_id;
+	int clk_off;
+	int off;
+} tcases[] = {
+	{CLOCK_MONOTONIC, CLOCK_MONOTONIC, 10},
+	{CLOCK_BOOTTIME, CLOCK_BOOTTIME, 10},
+
+	{CLOCK_MONOTONIC, CLOCK_MONOTONIC, -10},
+	{CLOCK_BOOTTIME, CLOCK_BOOTTIME, -10},
+
+	{CLOCK_MONOTONIC_RAW, CLOCK_MONOTONIC, 100},
+	{CLOCK_MONOTONIC_COARSE, CLOCK_MONOTONIC, 100},
+};
+
+static struct timespec now;
+static int parent_ns;
+
+static void child(struct tcase *tc)
+{
+	struct timespec then;
+	struct timespec parent_then;
+	long long diff;
+
+	SAFE_CLOCK_GETTIME(tc->clk_id, &then);
+
+	SAFE_SETNS(parent_ns, CLONE_NEWTIME);
+
+	SAFE_CLOCK_GETTIME(tc->clk_id, &parent_then);
+
+	diff = tst_timespec_diff_ms(then, now);
+
+	if (diff/1000 != tc->off) {
+		tst_res(TFAIL, "Wrong offset (%s) read %llims",
+		        tst_clock_name(tc->clk_id), diff);
+	} else {
+		tst_res(TPASS, "Offset (%s) is correct %llims",
+		        tst_clock_name(tc->clk_id), diff);
+	}
+
+	diff = tst_timespec_diff_ms(parent_then, now);
+
+	if (diff/1000) {
+		tst_res(TFAIL, "Wrong offset (%s) read %llims",
+		        tst_clock_name(tc->clk_id), diff);
+	} else {
+		tst_res(TPASS, "Offset (%s) is correct %llims",
+		        tst_clock_name(tc->clk_id), diff);
+	}
+}
+
+static void verify_ns_clock(unsigned int n)
+{
+	struct tcase *tc = &tcases[n];
+
+	SAFE_UNSHARE(CLONE_NEWTIME);
+
+	SAFE_FILE_PRINTF("/proc/self/timens_offsets", "%d %d 0",
+	                 tc->clk_off, tc->off);
+
+	SAFE_CLOCK_GETTIME(tc->clk_id, &now);
+
+	if (!SAFE_FORK())
+		child(tc);
+}
+
+static void setup(void)
+{
+	parent_ns = SAFE_OPEN("/proc/self/ns/time_for_children", O_RDONLY);
+}
+
+static void cleanup(void)
+{
+	SAFE_CLOSE(parent_ns);
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.cleanup = cleanup,
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = verify_ns_clock,
+	.needs_root = 1,
+	.forks_child = 1,
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_TIME_NS=y"
+	}
+};
-- 
2.24.1


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

* [LTP] [PATCH v2 8/9] containers/timens: Add basic error test
  2020-03-18 15:37 [LTP] [PATCH v2 0/9] Add basic time namespace testcases Cyril Hrubis
                   ` (6 preceding siblings ...)
  2020-03-18 15:37 ` [LTP] [PATCH v2 7/9] syscalls/clock_gettime03: Add basic time namespace test Cyril Hrubis
@ 2020-03-18 15:38 ` Cyril Hrubis
  2020-03-18 15:38 ` [LTP] [PATCH v2 9/9] syscalls/timerfd04: Add time namespace test Cyril Hrubis
  8 siblings, 0 replies; 16+ messages in thread
From: Cyril Hrubis @ 2020-03-18 15:38 UTC (permalink / raw)
  To: ltp

Add basic error handling test for the /proc/$PID/timens_offsets file.

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 runtest/containers                            |  1 +
 testcases/kernel/containers/timens/.gitignore |  1 +
 testcases/kernel/containers/timens/Makefile   |  6 ++
 testcases/kernel/containers/timens/timens01.c | 68 +++++++++++++++++++
 4 files changed, 76 insertions(+)
 create mode 100644 testcases/kernel/containers/timens/.gitignore
 create mode 100644 testcases/kernel/containers/timens/Makefile
 create mode 100644 testcases/kernel/containers/timens/timens01.c

diff --git a/runtest/containers b/runtest/containers
index 1006d8d35..23e4a533d 100644
--- a/runtest/containers
+++ b/runtest/containers
@@ -90,3 +90,4 @@ userns07 userns07
 sysinfo03 sysinfo03
 clock_nanosleep03 clock_nanosleep03
 clock_gettime03 clock_gettime03
+timens01 timens01
diff --git a/testcases/kernel/containers/timens/.gitignore b/testcases/kernel/containers/timens/.gitignore
new file mode 100644
index 000000000..bcd2dd9dd
--- /dev/null
+++ b/testcases/kernel/containers/timens/.gitignore
@@ -0,0 +1 @@
+timens01
diff --git a/testcases/kernel/containers/timens/Makefile b/testcases/kernel/containers/timens/Makefile
new file mode 100644
index 000000000..5ea7d67db
--- /dev/null
+++ b/testcases/kernel/containers/timens/Makefile
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/containers/timens/timens01.c b/testcases/kernel/containers/timens/timens01.c
new file mode 100644
index 000000000..2dbfebfa8
--- /dev/null
+++ b/testcases/kernel/containers/timens/timens01.c
@@ -0,0 +1,68 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+
+  Copyright (c) 2020 Cyril Hrubis <chrubis@suse.cz>
+
+ */
+/*
+
+  Basic test for timens_offsets error handling.
+
+  After a call to unshare(CLONE_NEWTIME) a new timer namespace is created, the
+  process that has called the unshare() can adjust offsets for CLOCK_MONOTONIC
+  and CLOCK_BOOTTIME for its children by writing to the '/proc/self/timens_offsets'.
+
+ */
+
+#define _GNU_SOURCE
+#include "lapi/namespaces_constants.h"
+#include "lapi/posix_clocks.h"
+#include "tst_test.h"
+
+static struct tcase {
+	const char *desc;
+	const char *offsets;
+	int exp_err;
+} tcases[] = {
+	{"Obvious garbage", "not an offset", EINVAL},
+	{"Missing nanoseconds", "1 10", EINVAL},
+	{"Negative nanoseconds", "1 10 -10", EINVAL},
+	{"Nanoseconds > 1s", "1 10 1000000001", EINVAL},
+	{"Unsupported CLOCK_REALTIME", "0 10 0", EINVAL},
+	{"Mess on the second line", "1 10 0\na", EINVAL},
+	{"Overflow kernel 64bit ns timer", "1 9223372036 0", ERANGE},
+	{"Overflow kernel 64bit ns timer", "1 -9223372036 0", ERANGE},
+};
+
+static void verify_ns_clock(unsigned int n)
+{
+	struct tcase *tc = &tcases[n];
+	int fd, ret;
+
+	SAFE_UNSHARE(CLONE_NEWTIME);
+
+	fd = SAFE_OPEN("/proc/self/timens_offsets", O_WRONLY);
+	ret = write(fd, tc->offsets, strlen(tc->offsets));
+
+	if (ret != -1) {
+		tst_res(TFAIL, "%s returned %i", tc->desc, ret);
+		return;
+	}
+
+	if (errno != tc->exp_err) {
+		tst_res(TFAIL | TERRNO, "%s should fail with %s, got:",
+			tc->desc, tst_strerrno(tc->exp_err));
+		return;
+	}
+
+	tst_res(TPASS | TERRNO, "%s", tc->desc);
+}
+
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = verify_ns_clock,
+	.needs_root = 1,
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_TIME_NS=y"
+	}
+};
-- 
2.24.1


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

* [LTP] [PATCH v2 9/9] syscalls/timerfd04: Add time namespace test
  2020-03-18 15:37 [LTP] [PATCH v2 0/9] Add basic time namespace testcases Cyril Hrubis
                   ` (7 preceding siblings ...)
  2020-03-18 15:38 ` [LTP] [PATCH v2 8/9] containers/timens: Add basic error test Cyril Hrubis
@ 2020-03-18 15:38 ` Cyril Hrubis
  8 siblings, 0 replies; 16+ messages in thread
From: Cyril Hrubis @ 2020-03-18 15:38 UTC (permalink / raw)
  To: ltp

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 runtest/containers                            |  1 +
 runtest/syscalls                              |  1 +
 testcases/kernel/syscalls/timerfd/.gitignore  |  1 +
 testcases/kernel/syscalls/timerfd/timerfd04.c | 98 +++++++++++++++++++
 4 files changed, 101 insertions(+)
 create mode 100644 testcases/kernel/syscalls/timerfd/timerfd04.c

diff --git a/runtest/containers b/runtest/containers
index 23e4a533d..276096709 100644
--- a/runtest/containers
+++ b/runtest/containers
@@ -91,3 +91,4 @@ sysinfo03 sysinfo03
 clock_nanosleep03 clock_nanosleep03
 clock_gettime03 clock_gettime03
 timens01 timens01
+timerfd04 timerfd04
diff --git a/runtest/syscalls b/runtest/syscalls
index 4949b5d36..16ed8d8ec 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1497,6 +1497,7 @@ times03 times03
 timerfd01 timerfd01
 timerfd02 timerfd02
 timerfd03 timerfd03
+timerfd04 timerfd04
 timerfd_create01 timerfd_create01
 timerfd_gettime01 timerfd_gettime01
 timerfd_settime01 timerfd_settime01
diff --git a/testcases/kernel/syscalls/timerfd/.gitignore b/testcases/kernel/syscalls/timerfd/.gitignore
index 1c5329966..ef388685d 100644
--- a/testcases/kernel/syscalls/timerfd/.gitignore
+++ b/testcases/kernel/syscalls/timerfd/.gitignore
@@ -1,6 +1,7 @@
 /timerfd01
 /timerfd02
 /timerfd03
+/timerfd04
 /timerfd_create01
 /timerfd_gettime01
 /timerfd_settime01
diff --git a/testcases/kernel/syscalls/timerfd/timerfd04.c b/testcases/kernel/syscalls/timerfd/timerfd04.c
new file mode 100644
index 000000000..28f9e4e02
--- /dev/null
+++ b/testcases/kernel/syscalls/timerfd/timerfd04.c
@@ -0,0 +1,98 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+
+  Copyright (c) 2020 Cyril Hrubis <chrubis@suse.cz>
+
+ */
+/*
+
+   Test that timerfd adds correctly an offset with absolute expiration time.
+
+   After a call to unshare(CLONE_NEWTIME) a new timer namespace is created, the
+   process that has called the unshare() can adjust offsets for CLOCK_MONOTONIC
+   and CLOCK_BOOTTIME for its children by writing to the '/proc/self/timens_offsets'.
+
+ */
+
+#include <stdlib.h>
+#include "tst_safe_clocks.h"
+#include "tst_safe_timerfd.h"
+#include "tst_timer.h"
+#include "lapi/namespaces_constants.h"
+#include "tst_test.h"
+
+#define SLEEP_US 40000
+
+static struct tcase {
+	int clk_id;
+	int clk_off;
+	int off;
+} tcases[] = {
+	{CLOCK_MONOTONIC, CLOCK_MONOTONIC, 10},
+	{CLOCK_BOOTTIME, CLOCK_BOOTTIME, 10},
+
+	{CLOCK_MONOTONIC, CLOCK_MONOTONIC, -10},
+	{CLOCK_BOOTTIME, CLOCK_BOOTTIME, -10},
+};
+
+static void verify_timerfd(unsigned int n)
+{
+	struct timespec start, end;
+	struct itimerspec it = {};
+	struct tcase *tc = &tcases[n];
+
+	SAFE_UNSHARE(CLONE_NEWTIME);
+
+	SAFE_FILE_PRINTF("/proc/self/timens_offsets", "%d %d 0",
+	                 tc->clk_off, tc->off);
+
+	SAFE_CLOCK_GETTIME(tc->clk_id, &start);
+
+	it.it_value = tst_timespec_add_us(start, 1000000 * tc->off + SLEEP_US);
+
+	if (!SAFE_FORK()) {
+		uint64_t exp;
+		int fd = SAFE_TIMERFD_CREATE(tc->clk_id, 0);
+
+		SAFE_TIMERFD_SETTIME(fd, TFD_TIMER_ABSTIME, &it, NULL);
+
+		SAFE_READ(1, fd, &exp, sizeof(exp));
+
+		if (exp != 1)
+			tst_res(TFAIL, "Got %llu expirations", (long long unsigned)exp);
+
+		SAFE_CLOSE(fd);
+		exit(0);
+	}
+
+	SAFE_WAIT(NULL);
+
+	SAFE_CLOCK_GETTIME(CLOCK_MONOTONIC, &end);
+
+	long long diff = tst_timespec_diff_us(end, start);
+
+	if (diff > 5 * SLEEP_US) {
+		tst_res(TFAIL, "timerfd %s slept too long %lli",
+		        tst_clock_name(tc->clk_id), diff);
+		return;
+	}
+
+	if (diff < SLEEP_US) {
+		tst_res(TFAIL, "timerfd %s slept too short %lli",
+		        tst_clock_name(tc->clk_id), diff);
+		return;
+	}
+
+	tst_res(TPASS, "timerfd %s slept correctly %lli",
+		tst_clock_name(tc->clk_id), diff);
+}
+
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = verify_timerfd,
+	.needs_root = 1,
+	.forks_child = 1,
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_TIME_NS=y"
+	}
+};
-- 
2.24.1


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

* [LTP] [PATCH v2 5/9] syscalls/sysinfo03: Add time namespace test
  2020-03-18 15:37 ` [LTP] [PATCH v2 5/9] syscalls/sysinfo03: Add time namespace test Cyril Hrubis
@ 2020-03-19  7:55   ` Li Wang
  2020-03-19 22:00     ` Cyril Hrubis
  2020-03-23 18:47   ` Petr Vorel
  1 sibling, 1 reply; 16+ messages in thread
From: Li Wang @ 2020-03-19  7:55 UTC (permalink / raw)
  To: ltp

On Wed, Mar 18, 2020 at 11:35 PM Cyril Hrubis <chrubis@suse.cz> wrote:

> This tests that the uptime in sysinfo() is adjusted correctly by the
> namespace offset.
>
> Also check that /proc/uptime is consistent with the uptime from the
> sysinfo() syscall.
>
> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
> ---
>  runtest/containers                            |  3 +
>  runtest/syscalls                              |  1 +
>  testcases/kernel/syscalls/sysinfo/.gitignore  |  1 +
>  testcases/kernel/syscalls/sysinfo/sysinfo03.c | 81 +++++++++++++++++++
>  4 files changed, 86 insertions(+)
>  create mode 100644 testcases/kernel/syscalls/sysinfo/sysinfo03.c
>
> diff --git a/runtest/containers b/runtest/containers
> index 871cd2a42..4dc05af93 100644
> --- a/runtest/containers
> +++ b/runtest/containers
> @@ -85,3 +85,6 @@ userns04 userns04
>  userns05 userns05
>  userns06 userns06
>  userns07 userns07
> +
> +# time namespaces
> +sysinfo03 sysinfo03
> diff --git a/runtest/syscalls b/runtest/syscalls
> index 6f2dcd82a..fb0b9e539 100644
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -1465,6 +1465,7 @@ sysfs06 sysfs06
>
>  sysinfo01 sysinfo01
>  sysinfo02 sysinfo02
> +sysinfo03 sysinfo03
>
>  syslog01 syslog01
>  syslog02 syslog02
> diff --git a/testcases/kernel/syscalls/sysinfo/.gitignore
> b/testcases/kernel/syscalls/sysinfo/.gitignore
> index aa7c26946..8ad2279a4 100644
> --- a/testcases/kernel/syscalls/sysinfo/.gitignore
> +++ b/testcases/kernel/syscalls/sysinfo/.gitignore
> @@ -1,2 +1,3 @@
>  /sysinfo01
>  /sysinfo02
> +/sysinfo03
> diff --git a/testcases/kernel/syscalls/sysinfo/sysinfo03.c
> b/testcases/kernel/syscalls/sysinfo/sysinfo03.c
> new file mode 100644
> index 000000000..af1024915
> --- /dev/null
> +++ b/testcases/kernel/syscalls/sysinfo/sysinfo03.c
> @@ -0,0 +1,81 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> +  Copyright (c) 2020 Cyril Hrubis <chrubis@suse.cz>
> + */
> +/*
> +
> +  Test if CLOCK_BOOTTIME namespace offset is applied to sysinfo uptime
> and that
> +  it's consistent with /proc/uptime as well.
> +
> +  After a call to unshare(CLONE_NEWTIME) a new timer namespace is
> created, the
> +  process that has called the unshare() can adjust offsets for
> CLOCK_MONOTONIC
> +  and CLOCK_BOOTTIME for its children by writing to the
> '/proc/self/timens_offsets'.
> +
> + */
> +
> +#include <sys/sysinfo.h>
> +#include "lapi/namespaces_constants.h"
> +#include "tst_test.h"
> +
> +static int offsets[] = {
> +       10,
> +       -10,
> +       3600,
> +};
> +
> +static long read_proc_uptime(void)
> +{
> +       long sec, sec_rem;
> +
> +       SAFE_FILE_SCANF("/proc/uptime", "%li.%li", &sec, &sec_rem);
> +
> +       return sec + (sec_rem ? 1 : 0);
> +}
> +
> +static void verify_sysinfo(unsigned int n)
> +{
> +       struct sysinfo si;
> +       long uptime;
> +       int off = offsets[n];
> +
> +       SAFE_UNSHARE(CLONE_NEWTIME);
> +
> +        SAFE_FILE_PRINTF("/proc/self/timens_offsets", "%d %d 0",
> +                        CLOCK_BOOTTIME, off);
> +
> +       sysinfo(&si);
> +
> +       uptime = si.uptime;
> +
> +       if (!SAFE_FORK()) {
> +               sysinfo(&si);
> +               long proc_uptime = read_proc_uptime();
> +
> +               long diff = si.uptime - uptime;
> +
> +               if (diff < off || diff > off + 1)
> +                       tst_res(TFAIL, "Wrong sysinfo uptime offset %li",
> diff);
> +               else
> +                       tst_res(TPASS, "Correct sysinfo uptime offset %i",
> off);
> +
> +               if (si.uptime < proc_uptime || si.uptime > proc_uptime +
> 1) {
> +                       tst_res(TFAIL, "/proc/uptime %li differs from
> sysinfo %li",
> +                               proc_uptime, si.uptime);
> +               } else {
> +                       tst_res(TPASS, "/proc/uptime is consistent with
> sysinfo");
> +               }
> +       }
> +}
> +
> +static struct tst_test test = {
> +       .tcnt = ARRAY_SIZE(offsets),
> +       .test = verify_sysinfo,
> +       .needs_root = 1,
> +       .forks_child = 1,
> +       .needs_kconfigs = (const char *[]) {
> +               "CONFIG_TIME_NS=y"
>

Shouldn't end with 'NULL' in kconfig struct?
If not that will mislead arrary_len to recognise wrong number of arrry(cnt)
and caused segmentation fault in test.



> +       }
>

A comma is required here ^, otherwise it'd be failing in the build phase.

+       .tags = (const struct tst_tag[]) {
> +               {"linux-git", "ecc421e05bab"},
>

Ending with '{}' in tags struct?


> +       }
> +};
> --
> 2.24.1
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
>
>

-- 
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20200319/f8c9a0de/attachment.htm>

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

* [LTP] [PATCH v2 5/9] syscalls/sysinfo03: Add time namespace test
  2020-03-19  7:55   ` Li Wang
@ 2020-03-19 22:00     ` Cyril Hrubis
  2020-03-20  7:32       ` Li Wang
  0 siblings, 1 reply; 16+ messages in thread
From: Cyril Hrubis @ 2020-03-19 22:00 UTC (permalink / raw)
  To: ltp

Hi!
> > +static struct tst_test test = {
> > +       .tcnt = ARRAY_SIZE(offsets),
> > +       .test = verify_sysinfo,
> > +       .needs_root = 1,
> > +       .forks_child = 1,
> > +       .needs_kconfigs = (const char *[]) {
> > +               "CONFIG_TIME_NS=y"
> >
> 
> Shouldn't end with 'NULL' in kconfig struct?
> If not that will mislead arrary_len to recognise wrong number of arrry(cnt)
> and caused segmentation fault in test.
> 
> 
> 
> > +       }
> >
> 
> A comma is required here ^, otherwise it'd be failing in the build phase.
> 
> +       .tags = (const struct tst_tag[]) {
> > +               {"linux-git", "ecc421e05bab"},
> >
> 
> Ending with '{}' in tags struct?

Of course, thanks for catching that!

I will fix these before applying, if the patchset is acked otherwise.

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH v2 5/9] syscalls/sysinfo03: Add time namespace test
  2020-03-19 22:00     ` Cyril Hrubis
@ 2020-03-20  7:32       ` Li Wang
  0 siblings, 0 replies; 16+ messages in thread
From: Li Wang @ 2020-03-20  7:32 UTC (permalink / raw)
  To: ltp

Hi Cyril,

On Thu, Mar 19, 2020 at 10:04 PM Cyril Hrubis <chrubis@suse.cz> wrote:

> ...
> > Ending with '{}' in tags struct?
>
> Of course, thanks for catching that!
>

Thanks, and don't forget to fix in rest patches too.


>
> I will fix these before applying, if the patchset is acked otherwise.
>

I have finished all the patches' reviews. Nice patchset!
LGTM.

-- 
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20200320/b9c6088f/attachment.htm>

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

* [LTP] [PATCH v2 3/9] safe_macros: Add SAFE_SETNS()
  2020-03-18 15:37 ` [LTP] [PATCH v2 3/9] safe_macros: Add SAFE_SETNS() Cyril Hrubis
@ 2020-03-23 16:11   ` Petr Vorel
  2020-03-30 14:09     ` Cyril Hrubis
  0 siblings, 1 reply; 16+ messages in thread
From: Petr Vorel @ 2020-03-23 16:11 UTC (permalink / raw)
  To: ltp

Hi Cyril,

...
> diff --git a/lib/tst_safe_macros.c b/lib/tst_safe_macros.c
> index f5413a18e..353ef5b1d 100644
> --- a/lib/tst_safe_macros.c
> +++ b/lib/tst_safe_macros.c
> @@ -6,6 +6,7 @@
>  #define _GNU_SOURCE
>  #include <unistd.h>
>  #include <errno.h>
> +#include "lapi/setns.h"
One more fix needed: lapi file needs to be loaded later:

diff --git lib/tst_safe_macros.c lib/tst_safe_macros.c
index 353ef5b1d..7d33f2b79 100644
--- lib/tst_safe_macros.c
+++ lib/tst_safe_macros.c
@@ -6,7 +6,6 @@
 #define _GNU_SOURCE
 #include <unistd.h>
 #include <errno.h>
-#include "lapi/setns.h"
 #include <sched.h>
 #include "config.h"
 #ifdef HAVE_SYS_FANOTIFY_H
@@ -14,6 +13,7 @@
 #endif
 #define TST_NO_DEFAULT_MAIN
 #include "tst_test.h"
+#include "lapi/setns.h"
 #include "tst_safe_macros.h"
 #include "lapi/personality.h"
 
to prevent failure:
In file included from /usr/src/ltp/lib/tst_safe_macros.c:9:
/usr/src/ltp/include/lapi/setns.h: In function 'setns':
/usr/src/ltp/include/lapi/setns.h:16: error: implicit declaration of function 'tst_brk'
/usr/src/ltp/include/lapi/setns.h:16: error: 'TCONF' undeclared (first use in this function)
/usr/src/ltp/include/lapi/setns.h:16: error: (Each undeclared identifier is reported only once

The rest of the patchset looks ok to me:

Reviewed-by: Petr Vorel <pvorel@suse.cz>

Kind regards,
Petr

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

* [LTP] [PATCH v2 5/9] syscalls/sysinfo03: Add time namespace test
  2020-03-18 15:37 ` [LTP] [PATCH v2 5/9] syscalls/sysinfo03: Add time namespace test Cyril Hrubis
  2020-03-19  7:55   ` Li Wang
@ 2020-03-23 18:47   ` Petr Vorel
  1 sibling, 0 replies; 16+ messages in thread
From: Petr Vorel @ 2020-03-23 18:47 UTC (permalink / raw)
  To: ltp

Hi Cyril,

> +++ b/testcases/kernel/syscalls/sysinfo/sysinfo03.c
...
> +#include <sys/sysinfo.h>
> +#include "lapi/namespaces_constants.h"
> +#include "tst_test.h"
...
> +static void verify_sysinfo(unsigned int n)
> +{
> +	struct sysinfo si;
> +	long uptime;
> +	int off = offsets[n];
> +
> +	SAFE_UNSHARE(CLONE_NEWTIME);
> +
> +        SAFE_FILE_PRINTF("/proc/self/timens_offsets", "%d %d 0",
> +	                 CLOCK_BOOTTIME, off);
One more fix needed for CentOS 6 to get missing definition: CLOCK_BOOTTIME

#include "lapi/posix_clocks.h"

Or do we want to finally drop CentOS 6 ? (see [1]).

Kind regards,
Petr

[1] https://lists.linux.it/pipermail/ltp/2020-March/016164.html

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

* [LTP] [PATCH v2 3/9] safe_macros: Add SAFE_SETNS()
  2020-03-23 16:11   ` Petr Vorel
@ 2020-03-30 14:09     ` Cyril Hrubis
  0 siblings, 0 replies; 16+ messages in thread
From: Cyril Hrubis @ 2020-03-30 14:09 UTC (permalink / raw)
  To: ltp

Hi!
I've fixed up problems pointed out by you and Li and pushed.

Peter, Li thanks a lot for the review.

-- 
Cyril Hrubis
chrubis@suse.cz

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

end of thread, other threads:[~2020-03-30 14:09 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-03-18 15:37 [LTP] [PATCH v2 0/9] Add basic time namespace testcases Cyril Hrubis
2020-03-18 15:37 ` [LTP] [PATCH v2 1/9] lapi/namespace_constants.h: Add CLONE_NEWTIME Cyril Hrubis
2020-03-18 15:37 ` [LTP] [PATCH v2 2/9] lapi: Add a configure check and fallback for setns Cyril Hrubis
2020-03-18 15:37 ` [LTP] [PATCH v2 3/9] safe_macros: Add SAFE_SETNS() Cyril Hrubis
2020-03-23 16:11   ` Petr Vorel
2020-03-30 14:09     ` Cyril Hrubis
2020-03-18 15:37 ` [LTP] [PATCH v2 4/9] include/tst_timer: Fix normalization Cyril Hrubis
2020-03-18 15:37 ` [LTP] [PATCH v2 5/9] syscalls/sysinfo03: Add time namespace test Cyril Hrubis
2020-03-19  7:55   ` Li Wang
2020-03-19 22:00     ` Cyril Hrubis
2020-03-20  7:32       ` Li Wang
2020-03-23 18:47   ` Petr Vorel
2020-03-18 15:37 ` [LTP] [PATCH v2 6/9] syscalls/clock_nanosleep03: Add test for time namespace Cyril Hrubis
2020-03-18 15:37 ` [LTP] [PATCH v2 7/9] syscalls/clock_gettime03: Add basic time namespace test Cyril Hrubis
2020-03-18 15:38 ` [LTP] [PATCH v2 8/9] containers/timens: Add basic error test Cyril Hrubis
2020-03-18 15:38 ` [LTP] [PATCH v2 9/9] syscalls/timerfd04: Add time namespace test Cyril Hrubis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox