From: Richard Palethorpe <rpalethorpe@suse.de>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 6/8] syscalls/clock_gettime03: Add basic time namespace test
Date: Mon, 09 Mar 2020 14:23:29 +0100 [thread overview]
Message-ID: <87imjdfyr2.fsf@our.domain.is.not.set> (raw)
In-Reply-To: <20200305134834.16736-7-chrubis@suse.cz>
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.
next prev parent reply other threads:[~2020-03-09 13:23 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87imjdfyr2.fsf@our.domain.is.not.set \
--to=rpalethorpe@suse.de \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.