From ef0cabcc4558295b980441b8a4dc0d24c31358c3 Mon Sep 17 00:00:00 2001 From: Philippe Gerum Date: Mon, 4 Mar 2019 14:42:55 +0100 Subject: [PATCH] tests: periodic clock timer --- tests/clock-timer-periodic.c | 45 ++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 tests/clock-timer-periodic.c diff --git a/tests/clock-timer-periodic.c b/tests/clock-timer-periodic.c new file mode 100644 index 0000000..195c775 --- /dev/null +++ b/tests/clock-timer-periodic.c @@ -0,0 +1,45 @@ +/* + * SPDX-License-Identifier: MIT + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "helpers.h" + +int main(int argc, char *argv[]) +{ + struct itimerspec value, ovalue; + struct timespec now; + int tmfd, ret, n; + __u32 ticks; + + ret = evl_attach_self("periodic-timer:%d", getpid()); + /* + * evl_init() was indirectly called when attaching, so we may + * create a timer from that point. + */ + __Tcall_assert(tmfd, evl_new_timer(EVL_CLOCK_MONOTONIC)); + __Tcall_assert(ret, evl_read_clock(EVL_CLOCK_MONOTONIC, &now)); + timespec_add_ns(&value.it_value, &now, 1000000000ULL); + value.it_interval.tv_sec = 0; + value.it_interval.tv_nsec = 5000000; + __Tcall_assert(ret, evl_set_timer(tmfd, &value, &ovalue)); + + for (n = 0; n < 200; n++) { + __Tcall_assert(ret, oob_read(tmfd, &ticks, sizeof(ticks))); + __Texpr_assert(ticks == 1); + } + + value.it_interval.tv_sec = 0; + value.it_interval.tv_nsec = 0; + __Tcall_assert(ret, evl_set_timer(tmfd, &value, &ovalue)); + + return 0; +}