* [LTP] [PATCH 0/8] Add basic time namespace testcases
@ 2020-03-05 13:48 Cyril Hrubis
2020-03-05 13:48 ` [LTP] [PATCH 1/8] lapi/namespace_constants.h: Add CLONE_NEWTIME Cyril Hrubis
` (7 more replies)
0 siblings, 8 replies; 18+ messages in thread
From: Cyril Hrubis @ 2020-03-05 13:48 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.
Cyril Hrubis (8):
lapi/namespace_constants.h: Add CLONE_NEWTIME
lapi: Add a configure check and fallback for 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_timer.h | 35 +++---
runtest/containers | 7 ++
runtest/syscalls | 4 +
testcases/kernel/containers/timens/.gitignore | 1 +
testcases/kernel/containers/timens/Makefile | 6 +
testcases/kernel/containers/timens/timens01.c | 75 ++++++++++++
.../kernel/syscalls/clock_gettime/.gitignore | 1 +
.../syscalls/clock_gettime/clock_gettime03.c | 113 ++++++++++++++++++
.../syscalls/clock_nanosleep/.gitignore | 1 +
.../clock_nanosleep/clock_nanosleep03.c | 71 +++++++++++
testcases/kernel/syscalls/sysinfo/.gitignore | 1 +
testcases/kernel/syscalls/sysinfo/sysinfo03.c | 78 ++++++++++++
testcases/kernel/syscalls/timerfd/.gitignore | 1 +
testcases/kernel/syscalls/timerfd/timerfd04.c | 95 +++++++++++++++
17 files changed, 496 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.23.0
^ permalink raw reply [flat|nested] 18+ messages in thread
* [LTP] [PATCH 1/8] lapi/namespace_constants.h: Add CLONE_NEWTIME
2020-03-05 13:48 [LTP] [PATCH 0/8] Add basic time namespace testcases Cyril Hrubis
@ 2020-03-05 13:48 ` Cyril Hrubis
2020-03-05 13:48 ` [LTP] [PATCH 2/8] lapi: Add a configure check and fallback for setns Cyril Hrubis
` (6 subsequent siblings)
7 siblings, 0 replies; 18+ messages in thread
From: Cyril Hrubis @ 2020-03-05 13:48 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.23.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [LTP] [PATCH 2/8] lapi: Add a configure check and fallback for setns
2020-03-05 13:48 [LTP] [PATCH 0/8] Add basic time namespace testcases Cyril Hrubis
2020-03-05 13:48 ` [LTP] [PATCH 1/8] lapi/namespace_constants.h: Add CLONE_NEWTIME Cyril Hrubis
@ 2020-03-05 13:48 ` Cyril Hrubis
2020-03-09 10:15 ` Petr Vorel
2020-03-05 13:48 ` [LTP] [PATCH 3/8] include/tst_timer: Fix normalization Cyril Hrubis
` (5 subsequent siblings)
7 siblings, 1 reply; 18+ messages in thread
From: Cyril Hrubis @ 2020-03-05 13:48 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 c9ec39fce..cd52806de 100644
--- a/configure.ac
+++ b/configure.ac
@@ -110,6 +110,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.23.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [LTP] [PATCH 3/8] include/tst_timer: Fix normalization
2020-03-05 13:48 [LTP] [PATCH 0/8] Add basic time namespace testcases Cyril Hrubis
2020-03-05 13:48 ` [LTP] [PATCH 1/8] lapi/namespace_constants.h: Add CLONE_NEWTIME Cyril Hrubis
2020-03-05 13:48 ` [LTP] [PATCH 2/8] lapi: Add a configure check and fallback for setns Cyril Hrubis
@ 2020-03-05 13:48 ` Cyril Hrubis
2020-03-05 13:48 ` [LTP] [PATCH 4/8] syscalls/sysinfo03: Add time namespace test Cyril Hrubis
` (4 subsequent siblings)
7 siblings, 0 replies; 18+ messages in thread
From: Cyril Hrubis @ 2020-03-05 13:48 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.23.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [LTP] [PATCH 4/8] syscalls/sysinfo03: Add time namespace test
2020-03-05 13:48 [LTP] [PATCH 0/8] Add basic time namespace testcases Cyril Hrubis
` (2 preceding siblings ...)
2020-03-05 13:48 ` [LTP] [PATCH 3/8] include/tst_timer: Fix normalization Cyril Hrubis
@ 2020-03-05 13:48 ` Cyril Hrubis
2020-03-09 12:32 ` Richard Palethorpe
2020-03-05 13:48 ` [LTP] [PATCH 5/8] syscalls/clock_nanosleep03: Add test for time namespace Cyril Hrubis
` (3 subsequent siblings)
7 siblings, 1 reply; 18+ messages in thread
From: Cyril Hrubis @ 2020-03-05 13:48 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 | 78 +++++++++++++++++++
4 files changed, 83 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 06d96470c..34bd5c3da 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1441,6 +1441,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..979e6e0a7
--- /dev/null
+++ b/testcases/kernel/syscalls/sysinfo/sysinfo03.c
@@ -0,0 +1,78 @@
+// 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"
+ }
+};
--
2.23.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [LTP] [PATCH 5/8] syscalls/clock_nanosleep03: Add test for time namespace
2020-03-05 13:48 [LTP] [PATCH 0/8] Add basic time namespace testcases Cyril Hrubis
` (3 preceding siblings ...)
2020-03-05 13:48 ` [LTP] [PATCH 4/8] syscalls/sysinfo03: Add time namespace test Cyril Hrubis
@ 2020-03-05 13:48 ` Cyril Hrubis
2020-03-05 13:48 ` [LTP] [PATCH 6/8] syscalls/clock_gettime03: Add basic time namespace test Cyril Hrubis
` (2 subsequent siblings)
7 siblings, 0 replies; 18+ messages in thread
From: Cyril Hrubis @ 2020-03-05 13:48 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 34bd5c3da..d19ae0041 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.23.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [LTP] [PATCH 6/8] syscalls/clock_gettime03: Add basic time namespace test
2020-03-05 13:48 [LTP] [PATCH 0/8] Add basic time namespace testcases Cyril Hrubis
` (4 preceding siblings ...)
2020-03-05 13:48 ` [LTP] [PATCH 5/8] syscalls/clock_nanosleep03: Add test for time namespace Cyril Hrubis
@ 2020-03-05 13:48 ` Cyril Hrubis
2020-03-09 13:23 ` Richard Palethorpe
2020-03-05 13:48 ` [LTP] [PATCH 7/8] containers/timens: Add basic error test Cyril Hrubis
2020-03-05 13:48 ` [LTP] [PATCH 8/8] syscalls/timerfd04: Add time namespace test Cyril Hrubis
7 siblings, 1 reply; 18+ messages in thread
From: Cyril Hrubis @ 2020-03-05 13:48 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 | 113 ++++++++++++++++++
4 files changed, 116 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 d19ae0041..778f722a3 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..533b3898e
--- /dev/null
+++ b/testcases/kernel/syscalls/clock_gettime/clock_gettime03.c
@@ -0,0 +1,113 @@
+// 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 "lapi/setns.h"
+#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);
+
+ 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.23.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [LTP] [PATCH 7/8] containers/timens: Add basic error test
2020-03-05 13:48 [LTP] [PATCH 0/8] Add basic time namespace testcases Cyril Hrubis
` (5 preceding siblings ...)
2020-03-05 13:48 ` [LTP] [PATCH 6/8] syscalls/clock_gettime03: Add basic time namespace test Cyril Hrubis
@ 2020-03-05 13:48 ` Cyril Hrubis
2020-03-10 12:06 ` Richard Palethorpe
2020-03-05 13:48 ` [LTP] [PATCH 8/8] syscalls/timerfd04: Add time namespace test Cyril Hrubis
7 siblings, 1 reply; 18+ messages in thread
From: Cyril Hrubis @ 2020-03-05 13:48 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 | 75 +++++++++++++++++++
4 files changed, 83 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..08bc449f9
--- /dev/null
+++ b/testcases/kernel/containers/timens/timens01.c
@@ -0,0 +1,75 @@
+// 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/setns.h"
+#include "lapi/namespaces_constants.h"
+#include "lapi/posix_clocks.h"
+#include "tst_test.h"
+
+static struct tcase {
+ 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 nanosecond timer */
+ {"1 9223372036 0", ERANGE},
+ {"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, "Write returned %i", ret);
+ return;
+ }
+
+ if (errno != tc->exp_err) {
+ tst_res(TFAIL | TERRNO, "Write should fail with %s, got:",
+ tst_strerrno(tc->exp_err));
+ return;
+ }
+
+ tst_res(TPASS | TERRNO, "Write offsets='%s'", tc->offsets);
+}
+
+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.23.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [LTP] [PATCH 8/8] syscalls/timerfd04: Add time namespace test
2020-03-05 13:48 [LTP] [PATCH 0/8] Add basic time namespace testcases Cyril Hrubis
` (6 preceding siblings ...)
2020-03-05 13:48 ` [LTP] [PATCH 7/8] containers/timens: Add basic error test Cyril Hrubis
@ 2020-03-05 13:48 ` Cyril Hrubis
7 siblings, 0 replies; 18+ messages in thread
From: Cyril Hrubis @ 2020-03-05 13:48 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 | 95 +++++++++++++++++++
4 files changed, 98 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 778f722a3..8494a8b04 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1473,6 +1473,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..3b8bf761d
--- /dev/null
+++ b/testcases/kernel/syscalls/timerfd/timerfd04.c
@@ -0,0 +1,95 @@
+// 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,
+};
--
2.23.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [LTP] [PATCH 2/8] lapi: Add a configure check and fallback for setns
2020-03-05 13:48 ` [LTP] [PATCH 2/8] lapi: Add a configure check and fallback for setns Cyril Hrubis
@ 2020-03-09 10:15 ` Petr Vorel
2020-03-09 10:34 ` Cyril Hrubis
0 siblings, 1 reply; 18+ messages in thread
From: Petr Vorel @ 2020-03-09 10:15 UTC (permalink / raw)
To: ltp
Hi Cyril,
your patchset looks good to me.
There is an error for old glibc on centos 06:
https://api.travis-ci.org/v3/job/659994070/log.txt
In file included from /usr/src/ltp/testcases/kernel/syscalls/clock_gettime/clock_gettime03.c:21:
/usr/src/ltp/include/lapi/setns.h: In function 'setns':
/usr/src/ltp/include/lapi/setns.h:16: error: implicit declaration of function 'syscall'
/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
/usr/src/ltp/include/lapi/setns.h:16: error: for each function it appears in.)
In file included from /usr/src/ltp/include/tst_test.h:14,
from /usr/src/ltp/include/tst_safe_clocks.h:13,
from /usr/src/ltp/testcases/kernel/syscalls/clock_gettime/clock_gettime03.c:22:
/usr/include/unistd.h: At top level:
/usr/include/unistd.h:1068: error: conflicting types for 'syscall'
/usr/src/ltp/include/lapi/setns.h:16: note: previous implicit declaration of 'syscall' was here
Kind regards,
Petr
^ permalink raw reply [flat|nested] 18+ messages in thread
* [LTP] [PATCH 2/8] lapi: Add a configure check and fallback for setns
2020-03-09 10:15 ` Petr Vorel
@ 2020-03-09 10:34 ` Cyril Hrubis
0 siblings, 0 replies; 18+ messages in thread
From: Cyril Hrubis @ 2020-03-09 10:34 UTC (permalink / raw)
To: ltp
Hi!
> There is an error for old glibc on centos 06:
>
> https://api.travis-ci.org/v3/job/659994070/log.txt
>
> In file included from /usr/src/ltp/testcases/kernel/syscalls/clock_gettime/clock_gettime03.c:21:
>
> /usr/src/ltp/include/lapi/setns.h: In function 'setns':
>
> /usr/src/ltp/include/lapi/setns.h:16: error: implicit declaration of function 'syscall'
Hmm, I guess that we can include unistd.h in the lapi/syscalls.h so that
the syscall() function has a prototype.
> /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
>
> /usr/src/ltp/include/lapi/setns.h:16: error: for each function it appears in.)
>
> In file included from /usr/src/ltp/include/tst_test.h:14,
>
> from /usr/src/ltp/include/tst_safe_clocks.h:13,
>
> from /usr/src/ltp/testcases/kernel/syscalls/clock_gettime/clock_gettime03.c:22:
Okay, I guess that both errors could be fixed by moving the lapi/setns.h
include after the tst_test.h in the test, because tst_test.h both
includes unistd.h as well as defines the tst_brk() and TCONF.
Thanks for spotting this.
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 18+ messages in thread
* [LTP] [PATCH 4/8] syscalls/sysinfo03: Add time namespace test
2020-03-05 13:48 ` [LTP] [PATCH 4/8] syscalls/sysinfo03: Add time namespace test Cyril Hrubis
@ 2020-03-09 12:32 ` Richard Palethorpe
2020-03-09 12:48 ` Cyril Hrubis
0 siblings, 1 reply; 18+ messages in thread
From: Richard Palethorpe @ 2020-03-09 12:32 UTC (permalink / raw)
To: ltp
Hello,
Cyril Hrubis <chrubis@suse.cz> writes:
> 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 | 78 +++++++++++++++++++
> 4 files changed, 83 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 06d96470c..34bd5c3da 100644
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -1441,6 +1441,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..979e6e0a7
> --- /dev/null
> +++ b/testcases/kernel/syscalls/sysinfo/sysinfo03.c
> @@ -0,0 +1,78 @@
> +// 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"
> + }
> +};
Will you add a git ref when the fix is in mainline/for-next?
Should be safe to add it as soon as it is in the for-next tree.
> --
> 2.23.0
--
Thank you,
Richard.
^ permalink raw reply [flat|nested] 18+ messages in thread
* [LTP] [PATCH 4/8] syscalls/sysinfo03: Add time namespace test
2020-03-09 12:32 ` Richard Palethorpe
@ 2020-03-09 12:48 ` Cyril Hrubis
2020-03-09 13:26 ` Richard Palethorpe
0 siblings, 1 reply; 18+ messages in thread
From: Cyril Hrubis @ 2020-03-09 12:48 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"
> > + }
> > +};
>
> Will you add a git ref when the fix is in mainline/for-next?
>
> Should be safe to add it as soon as it is in the for-next tree.
I'm not sure how usefull that will be because the fix should get in
during the RC phase the functionality was introduced, so technically the
missing support of sysinfo() in time namespaces should not reach any
officially released kernel.
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 18+ messages in thread
* [LTP] [PATCH 6/8] syscalls/clock_gettime03: Add basic time namespace test
2020-03-05 13:48 ` [LTP] [PATCH 6/8] syscalls/clock_gettime03: Add basic time namespace test Cyril Hrubis
@ 2020-03-09 13:23 ` Richard Palethorpe
2020-03-09 13:49 ` Cyril Hrubis
0 siblings, 1 reply; 18+ messages in thread
From: Richard Palethorpe @ 2020-03-09 13:23 UTC (permalink / raw)
To: ltp
Hi,
Cyril Hrubis <chrubis@suse.cz> writes:
> 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 | 113 ++++++++++++++++++
> 4 files changed, 116 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 d19ae0041..778f722a3 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..533b3898e
> --- /dev/null
> +++ b/testcases/kernel/syscalls/clock_gettime/clock_gettime03.c
> @@ -0,0 +1,113 @@
> +// 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 "lapi/setns.h"
> +#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);
> +
> + setns(parent_ns, CLONE_NEWTIME);
Maybe check the error code?
--
Thank you,
Richard.
^ permalink raw reply [flat|nested] 18+ messages in thread
* [LTP] [PATCH 4/8] syscalls/sysinfo03: Add time namespace test
2020-03-09 12:48 ` Cyril Hrubis
@ 2020-03-09 13:26 ` Richard Palethorpe
2020-03-09 13:33 ` Cyril Hrubis
0 siblings, 1 reply; 18+ messages in thread
From: Richard Palethorpe @ 2020-03-09 13:26 UTC (permalink / raw)
To: ltp
Hello,
Cyril Hrubis <chrubis@suse.cz> writes:
> 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"
>> > + }
>> > +};
>>
>> Will you add a git ref when the fix is in mainline/for-next?
>>
>> Should be safe to add it as soon as it is in the for-next tree.
>
> I'm not sure how usefull that will be because the fix should get in
> during the RC phase the functionality was introduced, so technically the
> missing support of sysinfo() in time namespaces should not reach any
> officially released kernel.
What is the downside to including it?
Also, I can imagine some people will try backporting this and may miss
something not in the original patch set.
--
Thank you,
Richard.
^ permalink raw reply [flat|nested] 18+ messages in thread
* [LTP] [PATCH 4/8] syscalls/sysinfo03: Add time namespace test
2020-03-09 13:26 ` Richard Palethorpe
@ 2020-03-09 13:33 ` Cyril Hrubis
0 siblings, 0 replies; 18+ messages in thread
From: Cyril Hrubis @ 2020-03-09 13:33 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"
> >> > + }
> >> > +};
> >>
> >> Will you add a git ref when the fix is in mainline/for-next?
> >>
> >> Should be safe to add it as soon as it is in the for-next tree.
> >
> > I'm not sure how usefull that will be because the fix should get in
> > during the RC phase the functionality was introduced, so technically the
> > missing support of sysinfo() in time namespaces should not reach any
> > officially released kernel.
>
> What is the downside to including it?
>
> Also, I can imagine some people will try backporting this and may miss
> something not in the original patch set.
Okay, that's a valid reason to include the hash.
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 18+ messages in thread
* [LTP] [PATCH 6/8] syscalls/clock_gettime03: Add basic time namespace test
2020-03-09 13:23 ` Richard Palethorpe
@ 2020-03-09 13:49 ` Cyril Hrubis
0 siblings, 0 replies; 18+ messages in thread
From: Cyril Hrubis @ 2020-03-09 13:49 UTC (permalink / raw)
To: ltp
Hi!
> > +static void child(struct tcase *tc)
> > +{
> > + struct timespec then;
> > + struct timespec parent_then;
> > + long long diff;
> > +
> > + SAFE_CLOCK_GETTIME(tc->clk_id, &then);
> > +
> > + setns(parent_ns, CLONE_NEWTIME);
>
> Maybe check the error code?
Indeed, I guess that I should add SAFE_SETNS() and then make use of that
in the tests.
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 18+ messages in thread
* [LTP] [PATCH 7/8] containers/timens: Add basic error test
2020-03-05 13:48 ` [LTP] [PATCH 7/8] containers/timens: Add basic error test Cyril Hrubis
@ 2020-03-10 12:06 ` Richard Palethorpe
0 siblings, 0 replies; 18+ messages in thread
From: Richard Palethorpe @ 2020-03-10 12:06 UTC (permalink / raw)
To: ltp
Hi,
Cyril Hrubis <chrubis@suse.cz> writes:
> 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 | 75 +++++++++++++++++++
> 4 files changed, 83 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..08bc449f9
> --- /dev/null
> +++ b/testcases/kernel/containers/timens/timens01.c
> @@ -0,0 +1,75 @@
> +// 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/setns.h"
> +#include "lapi/namespaces_constants.h"
> +#include "lapi/posix_clocks.h"
> +#include "tst_test.h"
> +
> +static struct tcase {
> + const char *offsets;
> + int exp_err;
> +} tcases[] = {
> + /* obvious garbage */
You could include these comments in the struct and print them.
--
Thank you,
Richard.
^ permalink raw reply [flat|nested] 18+ messages in thread
end of thread, other threads:[~2020-03-10 12:06 UTC | newest]
Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-03-05 13:48 [LTP] [PATCH 0/8] Add basic time namespace testcases Cyril Hrubis
2020-03-05 13:48 ` [LTP] [PATCH 1/8] lapi/namespace_constants.h: Add CLONE_NEWTIME Cyril Hrubis
2020-03-05 13:48 ` [LTP] [PATCH 2/8] lapi: Add a configure check and fallback for setns Cyril Hrubis
2020-03-09 10:15 ` Petr Vorel
2020-03-09 10:34 ` Cyril Hrubis
2020-03-05 13:48 ` [LTP] [PATCH 3/8] include/tst_timer: Fix normalization Cyril Hrubis
2020-03-05 13:48 ` [LTP] [PATCH 4/8] syscalls/sysinfo03: Add time namespace test Cyril Hrubis
2020-03-09 12:32 ` Richard Palethorpe
2020-03-09 12:48 ` Cyril Hrubis
2020-03-09 13:26 ` Richard Palethorpe
2020-03-09 13:33 ` Cyril Hrubis
2020-03-05 13:48 ` [LTP] [PATCH 5/8] syscalls/clock_nanosleep03: Add test for time namespace Cyril Hrubis
2020-03-05 13:48 ` [LTP] [PATCH 6/8] syscalls/clock_gettime03: Add basic time namespace test Cyril Hrubis
2020-03-09 13:23 ` Richard Palethorpe
2020-03-09 13:49 ` Cyril Hrubis
2020-03-05 13:48 ` [LTP] [PATCH 7/8] containers/timens: Add basic error test Cyril Hrubis
2020-03-10 12:06 ` Richard Palethorpe
2020-03-05 13:48 ` [LTP] [PATCH 8/8] 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