Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1696576
| Path | csiph.com!aioe.org!bofh.it!news.nic.it!robomod |
|---|---|
| From | Greg Hackmann <ghackmann@google.com> |
| Newsgroups | linux.kernel |
| Subject | [PATCH 2/2] kselftests: set-timer-lat: add one-shot timer test cases |
| Date | Tue, 25 Jul 2017 23:40:02 +0200 |
| Message-ID | <u7fIC-8eE-23@gated-at.bofh.it> (permalink) |
| References | <u7fIC-8eE-25@gated-at.bofh.it> |
| Dkim-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Nr/owzP8AcvUTPg7BowpD+srRjXeDUHGZI97ubfDDyM=; b=j+2kmMrb70aOMedv/uoct2CC13kq+xdzAOiRpGmPdMkH0myCck4jiBi5LJl3540pBJ QVfCxzlCGwmK5ffd94Mwp3XOLz9UOb7P0a9jYEuO5uR3AW4arFwgjU1l5L85sjzeYIxO hbSK/2tQuh/atUzAk99vHrb9lyhZTqpxhqewmhaa/7P1gB3Ybs8B8nfUZpEbH5OBeF15 14qNNSMuT2ZXoyZSzsaprHru8nRB3f11LYwjMxqWsTeES5hkPHlRF2kxVmbi8ylJt87a bKaX4CBPDqlcskKnbrD4ZAYXMKShjgX+AdOytJLCqZa/A3I4H3/PPpRGFYIygKDedGl+ ME/Q== |
| X-Google-Dkim-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Nr/owzP8AcvUTPg7BowpD+srRjXeDUHGZI97ubfDDyM=; b=OdWjLyL4O9P02W9y8WE+6AvSycRm0DgpLP80g6F3UTYyS+m2w+Cp/V+D4Tv9Q00PWW eg9Vll3IaKWrFcnk5F1uYGwfaDqyr9nrDTVfWyMRNU1jVT9T5AtsQzhAQx5TUukGFGzj 2SmOhqHHn2hDQNR5/cGkHJBUHW5C0znk2+8ucVHBEdzqFglEB/SJ+Y9Lnb3ai2s9h6nR sgcRFqQwxPDC8xZrU3NYe9c9QsmAS/HitQuF7Bw39RrhKBODSxgQ7UUq5QmkoyuoneAN 4ZWlcFnY4u7zOCbjGJzKBt5gGuCiGYKajpsjhkR1afWT/0FrP6Bol2H9tpcY54c5kDg2 bnbA== |
| X-Gm-Message-State | AIVw110TsoqWCm564VFyUVRG3128Uulev0Gv750bi5ncmlSHW313kIq2 2usNTm5+K5wH+UjA |
| X-Received | by 10.101.89.3 with SMTP id f3mr2892212pgu.177.1501018622622; Tue, 25 Jul 2017 14:37:02 -0700 (PDT) |
| X-Mailer | git-send-email 2.14.0.rc0.400.g1c36432dff-goog |
| Sender | robomod@news.nic.it |
| List-ID | <linux-kernel.vger.kernel.org> |
| X-Mailing-List | linux-kernel@vger.kernel.org |
| Approved | robomod@news.nic.it |
| Lines | 170 |
| Organization | linux.* mail to news gateway |
| X-Original-Cc | linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Greg Hackmann <ghackmann@google.com> |
| X-Original-Date | Tue, 25 Jul 2017 14:36:26 -0700 |
| X-Original-Message-ID | <20170725213626.115123-3-ghackmann@google.com> |
| X-Original-References | <20170725213626.115123-1-ghackmann@google.com> |
| X-Original-Sender | linux-kernel-owner@vger.kernel.org |
| Xref | csiph.com linux.kernel:1696576 |
Show key headers only | View raw
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.
Signed-off-by: Greg Hackmann <ghackmann@google.com>
---
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 10c2e18737c0..15434da23b04 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.14.0.rc0.400.g1c36432dff-goog
Back to linux.kernel | Previous | Next | Find similar | Unroll thread
[PATCH 2/2] kselftests: set-timer-lat: add one-shot timer test cases Greg Hackmann <ghackmann@google.com> - 2017-07-25 23:40 +0200
csiph-web