public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v4 4/8] lib: new restore_wallclock field to restore realtime clock
Date: Wed, 30 Jan 2019 14:53:24 +0100	[thread overview]
Message-ID: <20190130135323.GB4709@rei> (raw)
In-Reply-To: <20190129173659.27901-4-rafael.tinoco@linaro.org>

Hi!
I've changed the tst_wallclock.c so that it restores the time only if it
was saved previously, otherwise we will either set completely wrong time
if something has failed prior call to tst_wallclock_save() or generage
bogus error messages when the test exits because of unsufficient
priviledges.

full diff:

diff --git a/lib/tst_wallclock.c b/lib/tst_wallclock.c
index 1513882f4..f1c96c0cf 100644
--- a/lib/tst_wallclock.c
+++ b/lib/tst_wallclock.c
@@ -16,6 +16,8 @@
 
 static struct timespec real_begin, mono_begin;
 
+static int clock_saved;
+
 void tst_wallclock_save(void)
 {
 	/* save initial monotonic time to restore it when needed */
@@ -25,12 +27,19 @@ void tst_wallclock_save(void)
 
 	if (tst_clock_gettime(CLOCK_MONOTONIC_RAW, &mono_begin))
 		tst_brk(TBROK | TERRNO, "tst_clock_gettime() monotonic failed");
+
+	clock_saved = 1;
 }
 
 void tst_wallclock_restore(void)
 {
 	static struct timespec mono_end, elapsed, adjust;
 
+	if (!clock_saved)
+		return;
+
+	clock_saved = 0;
+
 	if (tst_clock_gettime(CLOCK_MONOTONIC_RAW, &mono_end))
 		tst_brk(TBROK | TERRNO, "tst_clock_gettime() monotonic failed");
 

-- 
Cyril Hrubis
chrubis@suse.cz

  reply	other threads:[~2019-01-30 13:53 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-05 19:30 [LTP] [PATCH 1/2] syscalls/clock_settime01.c: create syscall clock_settime test Rafael David Tinoco
2018-12-05 19:30 ` [LTP] [PATCH 2/2] timers/clock_settime: remove clock_settime tests Rafael David Tinoco
2018-12-06 13:03 ` [LTP] [PATCH 1/2] syscalls/clock_settime01.c: create syscall clock_settime test Cyril Hrubis
2018-12-06 14:49   ` Rafael David Tinoco
2018-12-06 19:07   ` [LTP] [PATCH v2 1/2] syscalls/clock_settime01.c: create syscall clock_settime Rafael David Tinoco
2018-12-06 19:07     ` [LTP] [PATCH v2 2/2] timers/clock_settime: remove clock_settime tests Rafael David Tinoco
2018-12-06 19:11     ` [LTP] [PATCH v2 1/2] syscalls/clock_settime01.c: create syscall clock_settime Rafael David Tinoco
2018-12-11 14:27     ` Cyril Hrubis
2018-12-11 16:05       ` Rafael David Tinoco
2018-12-12 20:37       ` [LTP] [PATCH v3 1/6] tst_timer.h: add tst_timespect_rem_us() function Rafael David Tinoco
2018-12-12 20:37         ` [LTP] [PATCH v3 2/6] lib: add tst_clock_settime() to tst_clocks.h Rafael David Tinoco
2018-12-12 20:37         ` [LTP] [PATCH v3 3/6] lib: include SAFE_CLOCK_SETTIME() macro Rafael David Tinoco
2018-12-12 20:37         ` [LTP] [PATCH v3 4/6] lib: new restore_wallclock field to restore realtime clock Rafael David Tinoco
2019-01-24 15:12           ` Cyril Hrubis
2018-12-12 20:37         ` [LTP] [PATCH v3 5/6] syscalls/clock_settime: create syscall clock_settime tests Rafael David Tinoco
2018-12-12 20:46           ` Rafael David Tinoco
2019-01-24 16:11           ` Cyril Hrubis
2019-01-29 17:36             ` [LTP] [PATCH v4 1/8] lib: add tst_clock_settime() to tst_clocks.h Rafael David Tinoco
2019-01-29 17:36               ` [LTP] [PATCH v4 2/8] lib: include SAFE_CLOCK_SETTIME() macro Rafael David Tinoco
2019-01-29 17:36               ` [LTP] [PATCH v4 3/8] tst_timer: Add tst_timespec_add() Rafael David Tinoco
2019-01-29 17:36               ` [LTP] [PATCH v4 4/8] lib: new restore_wallclock field to restore realtime clock Rafael David Tinoco
2019-01-30 13:53                 ` Cyril Hrubis [this message]
2019-01-29 17:36               ` [LTP] [PATCH v4 5/8] tst_timer: Add tst_timespec_sub_us() Rafael David Tinoco
2019-01-29 17:36               ` [LTP] [PATCH v4 6/8] tst_timer: Turn clock_name() function public Rafael David Tinoco
2019-01-30 13:54                 ` Cyril Hrubis
2019-01-29 17:36               ` [LTP] [PATCH v4 7/8] syscalls/clock_settime: create syscall clock_settime tests Rafael David Tinoco
2019-01-30 13:56                 ` Cyril Hrubis
2019-01-29 17:36               ` [LTP] [PATCH v4 8/8] timers/clock_settime: remove " Rafael David Tinoco
2019-01-30 13:50               ` [LTP] [PATCH v4 1/8] lib: add tst_clock_settime() to tst_clocks.h Cyril Hrubis
2019-01-30 14:50                 ` Rafael David Tinoco
2018-12-12 20:37         ` [LTP] [PATCH v3 6/6] timers/clock_settime: remove clock_settime tests Rafael David Tinoco
2019-01-08 12:04           ` Rafael David Tinoco
2019-01-08 12:42             ` Cyril Hrubis
2019-01-08 12:46               ` Rafael David Tinoco
2019-01-24 12:58             ` Rafael David Tinoco
2019-01-24 13:18               ` Cyril Hrubis
2019-01-24 15:06         ` [LTP] [PATCH v3 1/6] tst_timer.h: add tst_timespect_rem_us() function 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=20190130135323.GB4709@rei \
    --to=chrubis@suse.cz \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox