mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: John Stultz <john.stultz@linaro.org>
To: lkml <linux-kernel@vger.kernel.org>
Cc: Greg Hackmann <ghackmann@google.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@kernel.org>,
	Miroslav Lichvar <mlichvar@redhat.com>,
	Richard Cochran <richardcochran@gmail.com>,
	Prarit Bhargava <prarit@redhat.com>,
	Stephen Boyd <stephen.boyd@linaro.org>,
	Shuah Khan <shuah@kernel.org>,
	linux-kselftest@vger.kernel.org,
	John Stultz <john.stultz@linaro.org>
Subject: [PATCH 4/6] kselftests: timers: set-timer-lat: Add one-shot timer test cases
Date: Fri, 18 Aug 2017 11:51:00 -0700	[thread overview]
Message-ID: <1503082262-29450-5-git-send-email-john.stultz@linaro.org> (raw)
In-Reply-To: <1503082262-29450-1-git-send-email-john.stultz@linaro.org>

From: Greg Hackmann <ghackmann@google.com>

These testcases are motivated by a recent alarmtimer regression, which
caused one-shot CLOCK_{BOOTTIME,REALTIME}_ALARM timers to become
periodic timers.

The new testcases are very similar to the existing testcases for
repeating timers.  But rather than waiting for 5 alarms, they wait for 5
seconds and verify that the alarm fired exactly once.

Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Miroslav Lichvar <mlichvar@redhat.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Stephen Boyd <stephen.boyd@linaro.org>
Cc: Shuah Khan <shuah@kernel.org>
Cc: linux-kselftest@vger.kernel.org
Signed-off-by: Greg Hackmann <ghackmann@google.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 tools/testing/selftests/timers/set-timer-lat.c | 86 ++++++++++++++++++++++----
 1 file changed, 73 insertions(+), 13 deletions(-)

diff --git a/tools/testing/selftests/timers/set-timer-lat.c b/tools/testing/selftests/timers/set-timer-lat.c
index 10c2e18..15434da 100644
--- a/tools/testing/selftests/timers/set-timer-lat.c
+++ b/tools/testing/selftests/timers/set-timer-lat.c
@@ -20,6 +20,7 @@
  */
 
 
+#include <errno.h>
 #include <stdio.h>
 #include <unistd.h>
 #include <time.h>
@@ -122,17 +123,17 @@ void sigalarm(int signo)
 		max_latency_ns = delta_ns;
 }
 
-void describe_timer(int flags)
+void describe_timer(int flags, int interval)
 {
-	printf("%-22s %s ",
+	printf("%-22s %s %s ",
 			clockstring(clock_id),
-			flags ? "ABSTIME":"RELTIME");
+			flags ? "ABSTIME":"RELTIME",
+			interval ? "PERIODIC":"ONE-SHOT");
 }
 
-int do_timer(int clock_id, int flags)
+int setup_timer(int clock_id, int flags, int interval, timer_t *tm1)
 {
 	struct sigevent se;
-	timer_t tm1;
 	struct itimerspec its1, its2;
 	int err;
 
@@ -146,7 +147,7 @@ int do_timer(int clock_id, int flags)
 	alarmcount = 0;
 	timer_fired_early = 0;
 
-	err = timer_create(clock_id, &se, &tm1);
+	err = timer_create(clock_id, &se, tm1);
 	if (err) {
 		if ((clock_id == CLOCK_REALTIME_ALARM) ||
 		    (clock_id == CLOCK_BOOTTIME_ALARM)) {
@@ -167,19 +168,23 @@ int do_timer(int clock_id, int flags)
 		its1.it_value.tv_sec = TIMER_SECS;
 		its1.it_value.tv_nsec = 0;
 	}
-	its1.it_interval.tv_sec = TIMER_SECS;
+	its1.it_interval.tv_sec = interval;
 	its1.it_interval.tv_nsec = 0;
 
-	err = timer_settime(tm1, flags, &its1, &its2);
+	err = timer_settime(*tm1, flags, &its1, &its2);
 	if (err) {
 		printf("%s - timer_settime() failed\n", clockstring(clock_id));
 		return -1;
 	}
 
-	while (alarmcount < 5)
-		sleep(1);
+	return 0;
+}
 
-	describe_timer(flags);
+int check_timer_latency(int flags, int interval)
+{
+	int err = 0;
+
+	describe_timer(flags, interval);
 	printf("timer fired early: %7d : ", timer_fired_early);
 	if (!timer_fired_early) {
 		printf("[OK]\n");
@@ -188,10 +193,9 @@ int do_timer(int clock_id, int flags)
 		err = -1;
 	}
 
-	describe_timer(flags);
+	describe_timer(flags, interval);
 	printf("max latency: %10lld ns : ", max_latency_ns);
 
-	timer_delete(tm1);
 	if (max_latency_ns < UNRESONABLE_LATENCY) {
 		printf("[OK]\n");
 	} else {
@@ -201,6 +205,60 @@ int do_timer(int clock_id, int flags)
 	return err;
 }
 
+int check_alarmcount(int flags, int interval)
+{
+	describe_timer(flags, interval);
+	printf("count: %19d : ", alarmcount);
+	if (alarmcount == 1) {
+		printf("[OK]\n");
+		return 0;
+	}
+	printf("[FAILED]\n");
+	return -1;
+}
+
+int do_timer(int clock_id, int flags)
+{
+	timer_t tm1;
+	const int interval = TIMER_SECS;
+	int err;
+
+	err = setup_timer(clock_id, flags, interval, &tm1);
+	if (err)
+		return err;
+
+	while (alarmcount < 5)
+		sleep(1);
+
+	timer_delete(tm1);
+	return check_timer_latency(flags, interval);
+}
+
+int do_timer_oneshot(int clock_id, int flags)
+{
+	timer_t tm1;
+	const int interval = 0;
+	struct timeval timeout;
+	fd_set fds;
+	int err;
+
+	err = setup_timer(clock_id, flags, interval, &tm1);
+	if (err)
+		return err;
+
+	memset(&timeout, 0, sizeof(timeout));
+	timeout.tv_sec = 5;
+	FD_ZERO(&fds);
+	do {
+		err = select(FD_SETSIZE, &fds, NULL, NULL, &timeout);
+	} while (err == -1 && errno == EINTR);
+
+	timer_delete(tm1);
+	err = check_timer_latency(flags, interval);
+	err |= check_alarmcount(flags, interval);
+	return err;
+}
+
 int main(void)
 {
 	struct sigaction act;
@@ -226,6 +284,8 @@ int main(void)
 
 		ret |= do_timer(clock_id, TIMER_ABSTIME);
 		ret |= do_timer(clock_id, 0);
+		ret |= do_timer_oneshot(clock_id, TIMER_ABSTIME);
+		ret |= do_timer_oneshot(clock_id, 0);
 	}
 	if (ret)
 		return ksft_exit_fail();
-- 
2.7.4

  parent reply	other threads:[~2017-08-18 18:51 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-18 18:50 [GIT PULL][PATCH 0/6] Timekeeping queue for 4.14 John Stultz
2017-08-18 18:50 ` [PATCH 1/6] kselftests: timers: freq-step: Define ADJ_SETOFFSET if device has older kernel headers John Stultz
2017-08-18 18:50 ` [PATCH 2/6] kselftests: timers: freq-step: Fix build warning John Stultz
2017-08-18 18:50 ` [PATCH 3/6] kselftests: timers: set-timer-lat: Tweak reporting when timer fires early John Stultz
2017-08-18 18:51 ` John Stultz [this message]
2017-08-18 18:51 ` [PATCH 5/6] timekeeping: Use proper timekeeper for debug code John Stultz
2017-08-18 18:51 ` [PATCH 6/6] alarmtimer: Fix unavailable wake-up source in sysfs John Stultz

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=1503082262-29450-5-git-send-email-john.stultz@linaro.org \
    --to=john.stultz@linaro.org \
    --cc=ghackmann@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=mlichvar@redhat.com \
    --cc=prarit@redhat.com \
    --cc=richardcochran@gmail.com \
    --cc=shuah@kernel.org \
    --cc=stephen.boyd@linaro.org \
    --cc=tglx@linutronix.de \
    /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

Powered by JetHome