linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/19 v3] Add timekeeping tests to kernel selftest
@ 2015-03-02 21:09 John Stultz
  2015-03-02 21:09 ` [PATCH 01/19] selftests/timers: Cleanup Makefile to make it easier to add future tests John Stultz
                   ` (20 more replies)
  0 siblings, 21 replies; 25+ messages in thread
From: John Stultz @ 2015-03-02 21:09 UTC (permalink / raw)
  To: Linux Kernel Mailing List
  Cc: John Stultz, Shuah Khan, Prarit Bhargava, Thomas Gleixner,
	Richard Cochran

I've hosted my timekeeping tests on github for the last few years:
	https://github.com/johnstultz-work/timetests

but I suspect not too many folks have actually used them.

I've been meaning to get them reworked and submitted into the
selftest infrastructure, but haven't had much time until
recently.

I've added both the non-desctructive and destructive tests
(which set the time, possibly to strange values, or tries
to trigger historical issues that could crash the machine).
The destructive tests are run (as root, or with proper
privledge) via:
	# make run_destructive_tests

Changes in v3:
* Lots of -Wall build warning fixups
* Handle the CROSS_COMPILER build variable properly
 (Thanks to LinusW for pointing that out)
* Integrate w/ ksft_exit_* infrastructure

Let me know if there is any further comments or feedback!

thanks
-john

Cc: Shuah Khan <shuahkh@osg.samsung.com>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Richard Cochran <richardcochran@gmail.com>

John Stultz (19):
  selftests/timers: Cleanup Makefile to make it easier to add future
    tests
  selftests/timers: Quiet warning due to lack of return check on brk
  selftests/timers: Add nanosleep test from timetest suite
  selftests/timers: Add inconsistency-check test from timetests
  selftests/timers: Add nsleep-lat test from timetest suite
  selftests/timers: Add clock skew estimation test from timetest suite
  selftests/timers: Add set-timer-lat test from timetest suite
  selftests/timers: Add threaded time inconsistency test from timetest
    suite
  selftests/timers: Add mqueue latency test from the timetest suite
  selftests/timers: Add adjtimex validation test from timetest suite
  selftests/timers: Add alarmtimer-suspend test from timetests suite
  selftests/timers: Add change_skew test from timetest suite
  selftests/timers: Add skew_consistency test from the timetests suite
  selftests/timers: Add clocksource-switch test from timetest suite
  selftests/timers: Add leap-a-day test from timetest suite
  selftests/timers: Add leapcrash test from the timetest suite
  selftests/timers: Add set-tai from the timetest suite
  selftests/timers: Add set-2038 test from timetest suite
  MAINTAINERS: Add selftests/timers to the timekeeping maintainance list

 MAINTAINERS                                        |   1 +
 tools/testing/selftests/timers/Makefile            |  37 ++-
 .../testing/selftests/timers/alarmtimer-suspend.c  | 186 ++++++++++++
 tools/testing/selftests/timers/change_skew.c       | 107 +++++++
 .../testing/selftests/timers/clocksource-switch.c  | 179 ++++++++++++
 .../testing/selftests/timers/inconsistency-check.c | 207 +++++++++++++
 tools/testing/selftests/timers/leap-a-day.c        | 323 +++++++++++++++++++++
 tools/testing/selftests/timers/leapcrash.c         | 120 ++++++++
 tools/testing/selftests/timers/mqueue-lat.c        | 124 ++++++++
 tools/testing/selftests/timers/nanosleep.c         | 174 +++++++++++
 tools/testing/selftests/timers/nsleep-lat.c        | 190 ++++++++++++
 tools/testing/selftests/timers/posix_timers.c      |   9 +-
 tools/testing/selftests/timers/raw_skew.c          | 154 ++++++++++
 tools/testing/selftests/timers/set-2038.c          | 147 ++++++++++
 tools/testing/selftests/timers/set-tai.c           |  79 +++++
 tools/testing/selftests/timers/set-timer-lat.c     | 210 ++++++++++++++
 tools/testing/selftests/timers/skew_consistency.c  |  89 ++++++
 tools/testing/selftests/timers/threadtest.c        | 202 +++++++++++++
 tools/testing/selftests/timers/valid-adjtimex.c    | 204 +++++++++++++
 19 files changed, 2734 insertions(+), 8 deletions(-)
 create mode 100644 tools/testing/selftests/timers/alarmtimer-suspend.c
 create mode 100644 tools/testing/selftests/timers/change_skew.c
 create mode 100644 tools/testing/selftests/timers/clocksource-switch.c
 create mode 100644 tools/testing/selftests/timers/inconsistency-check.c
 create mode 100644 tools/testing/selftests/timers/leap-a-day.c
 create mode 100644 tools/testing/selftests/timers/leapcrash.c
 create mode 100644 tools/testing/selftests/timers/mqueue-lat.c
 create mode 100644 tools/testing/selftests/timers/nanosleep.c
 create mode 100644 tools/testing/selftests/timers/nsleep-lat.c
 create mode 100644 tools/testing/selftests/timers/raw_skew.c
 create mode 100644 tools/testing/selftests/timers/set-2038.c
 create mode 100644 tools/testing/selftests/timers/set-tai.c
 create mode 100644 tools/testing/selftests/timers/set-timer-lat.c
 create mode 100644 tools/testing/selftests/timers/skew_consistency.c
 create mode 100644 tools/testing/selftests/timers/threadtest.c
 create mode 100644 tools/testing/selftests/timers/valid-adjtimex.c

-- 
1.9.1


^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 01/19] selftests/timers: Cleanup Makefile to make it easier to add future tests
  2015-03-02 21:09 [PATCH 00/19 v3] Add timekeeping tests to kernel selftest John Stultz
@ 2015-03-02 21:09 ` John Stultz
  2015-03-02 21:09 ` [PATCH 02/19] selftests/timers: Quiet warning due to lack of return check on brk John Stultz
                   ` (19 subsequent siblings)
  20 siblings, 0 replies; 25+ messages in thread
From: John Stultz @ 2015-03-02 21:09 UTC (permalink / raw)
  To: Linux Kernel Mailing List
  Cc: John Stultz, Shuah Khan, Prarit Bhargava, Thomas Gleixner,
	Richard Cochran

Try to streamline the makefile so its easier to add timer/timekeeping
tests.

Also adds support for the CROSS_COMPILE variable.

Cc: Shuah Khan <shuahkh@osg.samsung.com>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Richard Cochran <richardcochran@gmail.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 tools/testing/selftests/timers/Makefile | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/timers/Makefile b/tools/testing/selftests/timers/Makefile
index eb2859f..e65c543 100644
--- a/tools/testing/selftests/timers/Makefile
+++ b/tools/testing/selftests/timers/Makefile
@@ -1,8 +1,13 @@
-all:
-	gcc posix_timers.c -o posix_timers -lrt
+CC = $(CROSS_COMPILE)gcc
+BUILD_FLAGS = -DKTEST
+CFLAGS += -O3 -Wl,-no-as-needed -Wall $(BUILD_FLAGS)
+LDFLAGS += -lrt -lpthread
+bins = posix_timers
+
+all: ${bins}
 
 run_tests: all
 	./posix_timers
 
 clean:
-	rm -f ./posix_timers
+	rm -f ${bins}
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 02/19] selftests/timers: Quiet warning due to lack of return check on brk
  2015-03-02 21:09 [PATCH 00/19 v3] Add timekeeping tests to kernel selftest John Stultz
  2015-03-02 21:09 ` [PATCH 01/19] selftests/timers: Cleanup Makefile to make it easier to add future tests John Stultz
@ 2015-03-02 21:09 ` John Stultz
  2015-03-02 21:09 ` [PATCH 03/19] selftests/timers: Add nanosleep test from timetest suite John Stultz
                   ` (18 subsequent siblings)
  20 siblings, 0 replies; 25+ messages in thread
From: John Stultz @ 2015-03-02 21:09 UTC (permalink / raw)
  To: Linux Kernel Mailing List
  Cc: John Stultz, Shuah Khan, Prarit Bhargava, Thomas Gleixner,
	Richard Cochran

The posix_timers.c test has a loop that tries to keep it in
kernel space, repeatedly calling brk(). However, it doesn't
check the return value, which causes warnings.

This patch adds a err value which captures the return value
and modifies the test so it will quit if a failure occurs.

Cc: Shuah Khan <shuahkh@osg.samsung.com>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Richard Cochran <richardcochran@gmail.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 tools/testing/selftests/timers/posix_timers.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/tools/testing/selftests/timers/posix_timers.c b/tools/testing/selftests/timers/posix_timers.c
index f87d970..5a246a0 100644
--- a/tools/testing/selftests/timers/posix_timers.c
+++ b/tools/testing/selftests/timers/posix_timers.c
@@ -35,10 +35,11 @@ static void user_loop(void)
 static void kernel_loop(void)
 {
 	void *addr = sbrk(0);
+	int err = 0;
 
-	while (!done) {
-		brk(addr + 4096);
-		brk(addr);
+	while (!done && !err) {
+		err = brk(addr + 4096);
+		err |= brk(addr);
 	}
 }
 
@@ -190,8 +191,6 @@ static int check_timer_create(int which)
 
 int main(int argc, char **argv)
 {
-	int err;
-
 	printf("Testing posix timers. False negative may happen on CPU execution \n");
 	printf("based timers if other threads run on the CPU...\n");
 
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 03/19] selftests/timers: Add nanosleep test from timetest suite
  2015-03-02 21:09 [PATCH 00/19 v3] Add timekeeping tests to kernel selftest John Stultz
  2015-03-02 21:09 ` [PATCH 01/19] selftests/timers: Cleanup Makefile to make it easier to add future tests John Stultz
  2015-03-02 21:09 ` [PATCH 02/19] selftests/timers: Quiet warning due to lack of return check on brk John Stultz
@ 2015-03-02 21:09 ` John Stultz
  2015-03-02 21:09 ` [PATCH 04/19] selftests/timers: Add inconsistency-check test from timetests John Stultz
                   ` (17 subsequent siblings)
  20 siblings, 0 replies; 25+ messages in thread
From: John Stultz @ 2015-03-02 21:09 UTC (permalink / raw)
  To: Linux Kernel Mailing List
  Cc: John Stultz, Shuah Khan, Prarit Bhargava, Thomas Gleixner,
	Richard Cochran

Add my basic nanosleep test from my timetest suite.
This test validates that nanosleep doesn't return early
against a number of clockids.

Cc: Shuah Khan <shuahkh@osg.samsung.com>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Richard Cochran <richardcochran@gmail.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 tools/testing/selftests/timers/Makefile    |   3 +-
 tools/testing/selftests/timers/nanosleep.c | 174 +++++++++++++++++++++++++++++
 2 files changed, 176 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/timers/nanosleep.c

diff --git a/tools/testing/selftests/timers/Makefile b/tools/testing/selftests/timers/Makefile
index e65c543..9409423 100644
--- a/tools/testing/selftests/timers/Makefile
+++ b/tools/testing/selftests/timers/Makefile
@@ -2,12 +2,13 @@ CC = $(CROSS_COMPILE)gcc
 BUILD_FLAGS = -DKTEST
 CFLAGS += -O3 -Wl,-no-as-needed -Wall $(BUILD_FLAGS)
 LDFLAGS += -lrt -lpthread
-bins = posix_timers
+bins = posix_timers nanosleep
 
 all: ${bins}
 
 run_tests: all
 	./posix_timers
+	./nanosleep
 
 clean:
 	rm -f ${bins}
diff --git a/tools/testing/selftests/timers/nanosleep.c b/tools/testing/selftests/timers/nanosleep.c
new file mode 100644
index 0000000..8a3c29d
--- /dev/null
+++ b/tools/testing/selftests/timers/nanosleep.c
@@ -0,0 +1,174 @@
+/* Make sure timers don't return early
+ *              by: john stultz (johnstul@us.ibm.com)
+ *		    John Stultz (john.stultz@linaro.org)
+ *              (C) Copyright IBM 2012
+ *              (C) Copyright Linaro 2013 2015
+ *              Licensed under the GPLv2
+ *
+ *  To build:
+ *	$ gcc nanosleep.c -o nanosleep -lrt
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <sys/time.h>
+#include <sys/timex.h>
+#include <string.h>
+#include <signal.h>
+#ifdef KTEST
+#include "../kselftest.h"
+#else
+static inline int ksft_exit_pass(void)
+{
+	exit(0);
+}
+static inline int ksft_exit_fail(void)
+{
+	exit(1);
+}
+#endif
+
+#define NSEC_PER_SEC 1000000000ULL
+
+#define CLOCK_REALTIME			0
+#define CLOCK_MONOTONIC			1
+#define CLOCK_PROCESS_CPUTIME_ID	2
+#define CLOCK_THREAD_CPUTIME_ID		3
+#define CLOCK_MONOTONIC_RAW		4
+#define CLOCK_REALTIME_COARSE		5
+#define CLOCK_MONOTONIC_COARSE		6
+#define CLOCK_BOOTTIME			7
+#define CLOCK_REALTIME_ALARM		8
+#define CLOCK_BOOTTIME_ALARM		9
+#define CLOCK_HWSPECIFIC		10
+#define CLOCK_TAI			11
+#define NR_CLOCKIDS			12
+
+#define UNSUPPORTED 0xf00f
+
+char *clockstring(int clockid)
+{
+	switch (clockid) {
+	case CLOCK_REALTIME:
+		return "CLOCK_REALTIME";
+	case CLOCK_MONOTONIC:
+		return "CLOCK_MONOTONIC";
+	case CLOCK_PROCESS_CPUTIME_ID:
+		return "CLOCK_PROCESS_CPUTIME_ID";
+	case CLOCK_THREAD_CPUTIME_ID:
+		return "CLOCK_THREAD_CPUTIME_ID";
+	case CLOCK_MONOTONIC_RAW:
+		return "CLOCK_MONOTONIC_RAW";
+	case CLOCK_REALTIME_COARSE:
+		return "CLOCK_REALTIME_COARSE";
+	case CLOCK_MONOTONIC_COARSE:
+		return "CLOCK_MONOTONIC_COARSE";
+	case CLOCK_BOOTTIME:
+		return "CLOCK_BOOTTIME";
+	case CLOCK_REALTIME_ALARM:
+		return "CLOCK_REALTIME_ALARM";
+	case CLOCK_BOOTTIME_ALARM:
+		return "CLOCK_BOOTTIME_ALARM";
+	case CLOCK_TAI:
+		return "CLOCK_TAI";
+	};
+	return "UNKNOWN_CLOCKID";
+}
+
+/* returns 1 if a <= b, 0 otherwise */
+static inline int in_order(struct timespec a, struct timespec b)
+{
+	if (a.tv_sec < b.tv_sec)
+		return 1;
+	if (a.tv_sec > b.tv_sec)
+		return 0;
+	if (a.tv_nsec > b.tv_nsec)
+		return 0;
+	return 1;
+}
+
+struct timespec timespec_add(struct timespec ts, unsigned long long ns)
+{
+	ts.tv_nsec += ns;
+	while (ts.tv_nsec >= NSEC_PER_SEC) {
+		ts.tv_nsec -= NSEC_PER_SEC;
+		ts.tv_sec++;
+	}
+	return ts;
+}
+
+int nanosleep_test(int clockid, long long ns)
+{
+	struct timespec now, target, rel;
+
+	/* First check abs time */
+	if (clock_gettime(clockid, &now))
+		return UNSUPPORTED;
+	target = timespec_add(now, ns);
+
+	if (clock_nanosleep(clockid, TIMER_ABSTIME, &target, NULL))
+		return UNSUPPORTED;
+	clock_gettime(clockid, &now);
+
+	if (!in_order(target, now))
+		return -1;
+
+	/* Second check reltime */
+	clock_gettime(clockid, &now);
+	rel.tv_sec = 0;
+	rel.tv_nsec = 0;
+	rel = timespec_add(rel, ns);
+	target = timespec_add(now, ns);
+	clock_nanosleep(clockid, 0, &rel, NULL);
+	clock_gettime(clockid, &now);
+
+	if (!in_order(target, now))
+		return -1;
+	return 0;
+}
+
+int main(int argc, char **argv)
+{
+	long long length;
+	int clockid, ret;
+
+	for (clockid = CLOCK_REALTIME; clockid < NR_CLOCKIDS; clockid++) {
+
+		/* Skip cputime clockids since nanosleep won't increment cputime */
+		if (clockid == CLOCK_PROCESS_CPUTIME_ID ||
+				clockid == CLOCK_THREAD_CPUTIME_ID ||
+				clockid == CLOCK_HWSPECIFIC)
+			continue;
+
+		printf("Nanosleep %-31s ", clockstring(clockid));
+
+		length = 10;
+		while (length <= (NSEC_PER_SEC * 10)) {
+			ret = nanosleep_test(clockid, length);
+			if (ret == UNSUPPORTED) {
+				printf("[UNSUPPORTED]\n");
+				goto next;
+			}
+			if (ret < 0) {
+				printf("[FAILED]\n");
+				return ksft_exit_fail();
+			}
+			length *= 100;
+		}
+		printf("[OK]\n");
+next:
+		ret = 0;
+	}
+	return ksft_exit_pass();
+}
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 04/19] selftests/timers: Add inconsistency-check test from timetests
  2015-03-02 21:09 [PATCH 00/19 v3] Add timekeeping tests to kernel selftest John Stultz
                   ` (2 preceding siblings ...)
  2015-03-02 21:09 ` [PATCH 03/19] selftests/timers: Add nanosleep test from timetest suite John Stultz
@ 2015-03-02 21:09 ` John Stultz
  2015-03-02 21:09 ` [PATCH 05/19] selftests/timers: Add nsleep-lat test from timetest suite John Stultz
                   ` (16 subsequent siblings)
  20 siblings, 0 replies; 25+ messages in thread
From: John Stultz @ 2015-03-02 21:09 UTC (permalink / raw)
  To: Linux Kernel Mailing List
  Cc: John Stultz, Shuah Khan, Prarit Bhargava, Thomas Gleixner,
	Richard Cochran

This adds my inconsistency-test from my timetests suite,
which checks for (single threaded) time inconsistencies
across the various clockids.

Cc: Shuah Khan <shuahkh@osg.samsung.com>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Richard Cochran <richardcochran@gmail.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 tools/testing/selftests/timers/Makefile            |   4 +-
 .../testing/selftests/timers/inconsistency-check.c | 207 +++++++++++++++++++++
 2 files changed, 209 insertions(+), 2 deletions(-)
 create mode 100644 tools/testing/selftests/timers/inconsistency-check.c

diff --git a/tools/testing/selftests/timers/Makefile b/tools/testing/selftests/timers/Makefile
index 9409423..fcb7c2f 100644
--- a/tools/testing/selftests/timers/Makefile
+++ b/tools/testing/selftests/timers/Makefile
@@ -2,13 +2,13 @@ CC = $(CROSS_COMPILE)gcc
 BUILD_FLAGS = -DKTEST
 CFLAGS += -O3 -Wl,-no-as-needed -Wall $(BUILD_FLAGS)
 LDFLAGS += -lrt -lpthread
-bins = posix_timers nanosleep
+bins = posix_timers nanosleep inconsistency-check
 
 all: ${bins}
 
 run_tests: all
 	./posix_timers
 	./nanosleep
-
+	./inconsistency-check
 clean:
 	rm -f ${bins}
diff --git a/tools/testing/selftests/timers/inconsistency-check.c b/tools/testing/selftests/timers/inconsistency-check.c
new file mode 100644
index 0000000..04c63b9
--- /dev/null
+++ b/tools/testing/selftests/timers/inconsistency-check.c
@@ -0,0 +1,207 @@
+/* Time inconsistency check test
+ *		by: john stultz (johnstul@us.ibm.com)
+ *		(C) Copyright IBM 2003, 2004, 2005, 2012
+ *		(C) Copyright Linaro Limited 2015
+ *		Licensed under the GPLv2
+ *
+ *  To build:
+ *	$ gcc inconsistency-check.c -o inconsistency-check -lrt
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ */
+
+
+
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <time.h>
+#include <sys/time.h>
+#include <sys/timex.h>
+#include <string.h>
+#include <signal.h>
+#ifdef KTEST
+#include "../kselftest.h"
+#else
+static inline int ksft_exit_pass(void)
+{
+	exit(0);
+}
+static inline int ksft_exit_fail(void)
+{
+	exit(1);
+}
+#endif
+
+extern char *optarg;
+
+
+#define CALLS_PER_LOOP 64
+#define NSEC_PER_SEC 1000000000ULL
+
+#define CLOCK_REALTIME			0
+#define CLOCK_MONOTONIC			1
+#define CLOCK_PROCESS_CPUTIME_ID	2
+#define CLOCK_THREAD_CPUTIME_ID		3
+#define CLOCK_MONOTONIC_RAW		4
+#define CLOCK_REALTIME_COARSE		5
+#define CLOCK_MONOTONIC_COARSE		6
+#define CLOCK_BOOTTIME			7
+#define CLOCK_REALTIME_ALARM		8
+#define CLOCK_BOOTTIME_ALARM		9
+#define CLOCK_HWSPECIFIC		10
+#define CLOCK_TAI			11
+#define NR_CLOCKIDS			12
+
+char *clockstring(int clockid)
+{
+	switch (clockid) {
+	case CLOCK_REALTIME:
+		return "CLOCK_REALTIME";
+	case CLOCK_MONOTONIC:
+		return "CLOCK_MONOTONIC";
+	case CLOCK_PROCESS_CPUTIME_ID:
+		return "CLOCK_PROCESS_CPUTIME_ID";
+	case CLOCK_THREAD_CPUTIME_ID:
+		return "CLOCK_THREAD_CPUTIME_ID";
+	case CLOCK_MONOTONIC_RAW:
+		return "CLOCK_MONOTONIC_RAW";
+	case CLOCK_REALTIME_COARSE:
+		return "CLOCK_REALTIME_COARSE";
+	case CLOCK_MONOTONIC_COARSE:
+		return "CLOCK_MONOTONIC_COARSE";
+	case CLOCK_BOOTTIME:
+		return "CLOCK_BOOTTIME";
+	case CLOCK_REALTIME_ALARM:
+		return "CLOCK_REALTIME_ALARM";
+	case CLOCK_BOOTTIME_ALARM:
+		return "CLOCK_BOOTTIME_ALARM";
+	case CLOCK_TAI:
+		return "CLOCK_TAI";
+	};
+	return "UNKNOWN_CLOCKID";
+}
+
+/* returns 1 if a <= b, 0 otherwise */
+static inline int in_order(struct timespec a, struct timespec b)
+{
+	/* use unsigned to avoid false positives on 2038 rollover */
+	if ((unsigned long)a.tv_sec < (unsigned long)b.tv_sec)
+		return 1;
+	if ((unsigned long)a.tv_sec > (unsigned long)b.tv_sec)
+		return 0;
+	if (a.tv_nsec > b.tv_nsec)
+		return 0;
+	return 1;
+}
+
+
+
+int consistency_test(int clock_type, unsigned long seconds)
+{
+	struct timespec list[CALLS_PER_LOOP];
+	int i, inconsistent;
+	long now, then;
+	time_t t;
+	char *start_str;
+
+	clock_gettime(clock_type, &list[0]);
+	now = then = list[0].tv_sec;
+
+	/* timestamp start of test */
+	t = time(0);
+	start_str = ctime(&t);
+
+	while (seconds == -1 || now - then < seconds) {
+		inconsistent = 0;
+
+		/* Fill list */
+		for (i = 0; i < CALLS_PER_LOOP; i++)
+			clock_gettime(clock_type, &list[i]);
+
+		/* Check for inconsistencies */
+		for (i = 0; i < CALLS_PER_LOOP - 1; i++)
+			if (!in_order(list[i], list[i+1]))
+				inconsistent = i;
+
+		/* display inconsistency */
+		if (inconsistent) {
+			unsigned long long delta;
+
+			printf("\%s\n", start_str);
+			for (i = 0; i < CALLS_PER_LOOP; i++) {
+				if (i == inconsistent)
+					printf("--------------------\n");
+				printf("%lu:%lu\n", list[i].tv_sec,
+							list[i].tv_nsec);
+				if (i == inconsistent + 1)
+					printf("--------------------\n");
+			}
+			delta = list[inconsistent].tv_sec * NSEC_PER_SEC;
+			delta += list[inconsistent].tv_nsec;
+			delta -= list[inconsistent+1].tv_sec * NSEC_PER_SEC;
+			delta -= list[inconsistent+1].tv_nsec;
+			printf("Delta: %llu ns\n", delta);
+			fflush(0);
+			/* timestamp inconsistency*/
+			t = time(0);
+			printf("%s\n", ctime(&t));
+			printf("[FAILED]\n");
+			return -1;
+		}
+		now = list[0].tv_sec;
+	}
+	printf("[OK]\n");
+	return 0;
+}
+
+
+int main(int argc, char *argv[])
+{
+	int clockid, opt;
+	int userclock = CLOCK_REALTIME;
+	int maxclocks = NR_CLOCKIDS;
+	int runtime = 30;
+	struct timespec ts;
+
+	/* Process arguments */
+	while ((opt = getopt(argc, argv, "t:c:")) != -1) {
+		switch (opt) {
+		case 't':
+			runtime = atoi(optarg);
+			break;
+		case 'c':
+			userclock = atoi(optarg);
+			maxclocks = userclock + 1;
+			break;
+		default:
+			printf("Usage: %s [-t <secs>] [-c <clockid>]\n", argv[0]);
+			printf("	-t: Number of seconds to run\n");
+			printf("	-c: clockid to use (default, all clockids)\n");
+			exit(-1);
+		}
+	}
+
+	setbuf(stdout, NULL);
+
+	for (clockid = userclock; clockid < maxclocks; clockid++) {
+
+		if (clockid == CLOCK_HWSPECIFIC)
+			continue;
+
+		if (!clock_gettime(clockid, &ts)) {
+			printf("Consistent %-30s ", clockstring(clockid));
+			if (consistency_test(clockid, runtime))
+				return ksft_exit_fail();
+		}
+	}
+	return ksft_exit_pass();
+}
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 05/19] selftests/timers: Add nsleep-lat test from timetest suite
  2015-03-02 21:09 [PATCH 00/19 v3] Add timekeeping tests to kernel selftest John Stultz
                   ` (3 preceding siblings ...)
  2015-03-02 21:09 ` [PATCH 04/19] selftests/timers: Add inconsistency-check test from timetests John Stultz
@ 2015-03-02 21:09 ` John Stultz
  2015-03-02 21:09 ` [PATCH 06/19] selftests/timers: Add clock skew estimation " John Stultz
                   ` (15 subsequent siblings)
  20 siblings, 0 replies; 25+ messages in thread
From: John Stultz @ 2015-03-02 21:09 UTC (permalink / raw)
  To: Linux Kernel Mailing List
  Cc: John Stultz, Shuah Khan, Prarit Bhargava, Thomas Gleixner,
	Richard Cochran

Adds my nanosleep latency test from the timetest suite.
This checks to make sure we don't see "unreasonable"
latencies (> 40ms) when calling nanosleep.

Cc: Shuah Khan <shuahkh@osg.samsung.com>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Richard Cochran <richardcochran@gmail.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 tools/testing/selftests/timers/Makefile     |   3 +-
 tools/testing/selftests/timers/nsleep-lat.c | 190 ++++++++++++++++++++++++++++
 2 files changed, 192 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/timers/nsleep-lat.c

diff --git a/tools/testing/selftests/timers/Makefile b/tools/testing/selftests/timers/Makefile
index fcb7c2f..dae9ee7 100644
--- a/tools/testing/selftests/timers/Makefile
+++ b/tools/testing/selftests/timers/Makefile
@@ -2,13 +2,14 @@ CC = $(CROSS_COMPILE)gcc
 BUILD_FLAGS = -DKTEST
 CFLAGS += -O3 -Wl,-no-as-needed -Wall $(BUILD_FLAGS)
 LDFLAGS += -lrt -lpthread
-bins = posix_timers nanosleep inconsistency-check
+bins = posix_timers nanosleep inconsistency-check nsleep-lat
 
 all: ${bins}
 
 run_tests: all
 	./posix_timers
 	./nanosleep
+	./nsleep-lat
 	./inconsistency-check
 clean:
 	rm -f ${bins}
diff --git a/tools/testing/selftests/timers/nsleep-lat.c b/tools/testing/selftests/timers/nsleep-lat.c
new file mode 100644
index 0000000..2d7898f
--- /dev/null
+++ b/tools/testing/selftests/timers/nsleep-lat.c
@@ -0,0 +1,190 @@
+/* Measure nanosleep timer latency
+ *              by: john stultz (john.stultz@linaro.org)
+ *		(C) Copyright Linaro 2013
+ *              Licensed under the GPLv2
+ *
+ *  To build:
+ *	$ gcc nsleep-lat.c -o nsleep-lat -lrt
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <sys/time.h>
+#include <sys/timex.h>
+#include <string.h>
+#include <signal.h>
+#ifdef KTEST
+#include "../kselftest.h"
+#else
+static inline int ksft_exit_pass(void)
+{
+	exit(0);
+}
+static inline int ksft_exit_fail(void)
+{
+	exit(1);
+}
+#endif
+
+#define NSEC_PER_SEC 1000000000ULL
+
+#define UNRESONABLE_LATENCY 40000000 /* 40ms in nanosecs */
+
+
+#define CLOCK_REALTIME			0
+#define CLOCK_MONOTONIC			1
+#define CLOCK_PROCESS_CPUTIME_ID	2
+#define CLOCK_THREAD_CPUTIME_ID		3
+#define CLOCK_MONOTONIC_RAW		4
+#define CLOCK_REALTIME_COARSE		5
+#define CLOCK_MONOTONIC_COARSE		6
+#define CLOCK_BOOTTIME			7
+#define CLOCK_REALTIME_ALARM		8
+#define CLOCK_BOOTTIME_ALARM		9
+#define CLOCK_HWSPECIFIC		10
+#define CLOCK_TAI			11
+#define NR_CLOCKIDS			12
+
+#define UNSUPPORTED 0xf00f
+
+char *clockstring(int clockid)
+{
+	switch (clockid) {
+	case CLOCK_REALTIME:
+		return "CLOCK_REALTIME";
+	case CLOCK_MONOTONIC:
+		return "CLOCK_MONOTONIC";
+	case CLOCK_PROCESS_CPUTIME_ID:
+		return "CLOCK_PROCESS_CPUTIME_ID";
+	case CLOCK_THREAD_CPUTIME_ID:
+		return "CLOCK_THREAD_CPUTIME_ID";
+	case CLOCK_MONOTONIC_RAW:
+		return "CLOCK_MONOTONIC_RAW";
+	case CLOCK_REALTIME_COARSE:
+		return "CLOCK_REALTIME_COARSE";
+	case CLOCK_MONOTONIC_COARSE:
+		return "CLOCK_MONOTONIC_COARSE";
+	case CLOCK_BOOTTIME:
+		return "CLOCK_BOOTTIME";
+	case CLOCK_REALTIME_ALARM:
+		return "CLOCK_REALTIME_ALARM";
+	case CLOCK_BOOTTIME_ALARM:
+		return "CLOCK_BOOTTIME_ALARM";
+	case CLOCK_TAI:
+		return "CLOCK_TAI";
+	};
+	return "UNKNOWN_CLOCKID";
+}
+
+struct timespec timespec_add(struct timespec ts, unsigned long long ns)
+{
+	ts.tv_nsec += ns;
+	while (ts.tv_nsec >= NSEC_PER_SEC) {
+		ts.tv_nsec -= NSEC_PER_SEC;
+		ts.tv_sec++;
+	}
+	return ts;
+}
+
+
+long long timespec_sub(struct timespec a, struct timespec b)
+{
+	long long ret = NSEC_PER_SEC * b.tv_sec + b.tv_nsec;
+
+	ret -= NSEC_PER_SEC * a.tv_sec + a.tv_nsec;
+	return ret;
+}
+
+int nanosleep_lat_test(int clockid, long long ns)
+{
+	struct timespec start, end, target;
+	long long latency = 0;
+	int i, count;
+
+	target.tv_sec = ns/NSEC_PER_SEC;
+	target.tv_nsec = ns%NSEC_PER_SEC;
+
+	if (clock_gettime(clockid, &start))
+		return UNSUPPORTED;
+	if (clock_nanosleep(clockid, 0, &target, NULL))
+		return UNSUPPORTED;
+
+	count = 10;
+
+	/* First check relative latency */
+	clock_gettime(clockid, &start);
+	for (i = 0; i < count; i++)
+		clock_nanosleep(clockid, 0, &target, NULL);
+	clock_gettime(clockid, &end);
+
+	if (((timespec_sub(start, end)/count)-ns) > UNRESONABLE_LATENCY) {
+		printf("Large rel latency: %lld ns :", (timespec_sub(start, end)/count)-ns);
+		return -1;
+	}
+
+	/* Next check absolute latency */
+	for (i = 0; i < count; i++) {
+		clock_gettime(clockid, &start);
+		target = timespec_add(start, ns);
+		clock_nanosleep(clockid, TIMER_ABSTIME, &target, NULL);
+		clock_gettime(clockid, &end);
+		latency += timespec_sub(target, end);
+	}
+
+	if (latency/count > UNRESONABLE_LATENCY) {
+		printf("Large abs latency: %lld ns :", latency/count);
+		return -1;
+	}
+
+	return 0;
+}
+
+
+
+int main(int argc, char **argv)
+{
+	long long length;
+	int clockid, ret;
+
+	for (clockid = CLOCK_REALTIME; clockid < NR_CLOCKIDS; clockid++) {
+
+		/* Skip cputime clockids since nanosleep won't increment cputime */
+		if (clockid == CLOCK_PROCESS_CPUTIME_ID ||
+				clockid == CLOCK_THREAD_CPUTIME_ID ||
+				clockid == CLOCK_HWSPECIFIC)
+			continue;
+
+		printf("nsleep latency %-26s ", clockstring(clockid));
+
+		length = 10;
+		while (length <= (NSEC_PER_SEC * 10)) {
+			ret = nanosleep_lat_test(clockid, length);
+			if (ret)
+				break;
+			length *= 100;
+
+		}
+
+		if (ret == UNSUPPORTED) {
+			printf("[UNSUPPORTED]\n");
+			continue;
+		}
+		if (ret < 0) {
+			printf("[FAILED]\n");
+			return ksft_exit_fail();
+		}
+		printf("[OK]\n");
+	}
+	return ksft_exit_pass();
+}
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 06/19] selftests/timers: Add clock skew estimation test from timetest suite
  2015-03-02 21:09 [PATCH 00/19 v3] Add timekeeping tests to kernel selftest John Stultz
                   ` (4 preceding siblings ...)
  2015-03-02 21:09 ` [PATCH 05/19] selftests/timers: Add nsleep-lat test from timetest suite John Stultz
@ 2015-03-02 21:09 ` John Stultz
  2015-03-02 21:10 ` [PATCH 07/19] selftests/timers: Add set-timer-lat " John Stultz
                   ` (14 subsequent siblings)
  20 siblings, 0 replies; 25+ messages in thread
From: John Stultz @ 2015-03-02 21:09 UTC (permalink / raw)
  To: Linux Kernel Mailing List
  Cc: John Stultz, Shuah Khan, Prarit Bhargava, Thomas Gleixner,
	Richard Cochran

This adds my clock skew estimation test from the timetest suite.
It measures the drift between CLOCK_MONOTONIC and CLOCK_MONOTONIC_RAW
and compares it with the current frequency value from adjtimex.

It sometimes can trigger false failures when ntpd isn't in a
steady state, but its a useful too when doing adjtimex testing.

Cc: Shuah Khan <shuahkh@osg.samsung.com>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Richard Cochran <richardcochran@gmail.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 tools/testing/selftests/timers/Makefile   |   3 +-
 tools/testing/selftests/timers/raw_skew.c | 154 ++++++++++++++++++++++++++++++
 2 files changed, 156 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/timers/raw_skew.c

diff --git a/tools/testing/selftests/timers/Makefile b/tools/testing/selftests/timers/Makefile
index dae9ee7..088a791 100644
--- a/tools/testing/selftests/timers/Makefile
+++ b/tools/testing/selftests/timers/Makefile
@@ -2,7 +2,7 @@ CC = $(CROSS_COMPILE)gcc
 BUILD_FLAGS = -DKTEST
 CFLAGS += -O3 -Wl,-no-as-needed -Wall $(BUILD_FLAGS)
 LDFLAGS += -lrt -lpthread
-bins = posix_timers nanosleep inconsistency-check nsleep-lat
+bins = posix_timers nanosleep inconsistency-check nsleep-lat raw_skew
 
 all: ${bins}
 
@@ -11,5 +11,6 @@ run_tests: all
 	./nanosleep
 	./nsleep-lat
 	./inconsistency-check
+	./raw_skew
 clean:
 	rm -f ${bins}
diff --git a/tools/testing/selftests/timers/raw_skew.c b/tools/testing/selftests/timers/raw_skew.c
new file mode 100644
index 0000000..30906bf
--- /dev/null
+++ b/tools/testing/selftests/timers/raw_skew.c
@@ -0,0 +1,154 @@
+/* CLOCK_MONOTONIC vs CLOCK_MONOTONIC_RAW skew test
+ *		by: john stultz (johnstul@us.ibm.com)
+ *		    John Stultz <john.stultz@linaro.org>
+ *		(C) Copyright IBM 2012
+ *		(C) Copyright Linaro Limited 2015
+ *		Licensed under the GPLv2
+ *
+ *  To build:
+ *	$ gcc raw_skew.c -o raw_skew -lrt
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <sys/timex.h>
+#include <time.h>
+#ifdef KTEST
+#include "../kselftest.h"
+#else
+static inline int ksft_exit_pass(void)
+{
+	exit(0);
+}
+static inline int ksft_exit_fail(void)
+{
+	exit(1);
+}
+#endif
+
+
+#define CLOCK_MONOTONIC_RAW		4
+#define NSEC_PER_SEC 1000000000LL
+
+#define shift_right(x, s) ({		\
+	__typeof__(x) __x = (x);	\
+	__typeof__(s) __s = (s);	\
+	__x < 0 ? -(-__x >> __s) : __x >> __s; \
+})
+
+long long llabs(long long val)
+{
+	if (val < 0)
+		val = -val;
+	return val;
+}
+
+unsigned long long ts_to_nsec(struct timespec ts)
+{
+	return ts.tv_sec * NSEC_PER_SEC + ts.tv_nsec;
+}
+
+struct timespec nsec_to_ts(long long ns)
+{
+	struct timespec ts;
+
+	ts.tv_sec = ns/NSEC_PER_SEC;
+	ts.tv_nsec = ns%NSEC_PER_SEC;
+	return ts;
+}
+
+long long diff_timespec(struct timespec start, struct timespec end)
+{
+	long long start_ns, end_ns;
+
+	start_ns = ts_to_nsec(start);
+	end_ns = ts_to_nsec(end);
+	return end_ns - start_ns;
+}
+
+void get_monotonic_and_raw(struct timespec *mon, struct timespec *raw)
+{
+	struct timespec start, mid, end;
+	long long diff = 0, tmp;
+	int i;
+
+	for (i = 0; i < 3; i++) {
+		long long newdiff;
+
+		clock_gettime(CLOCK_MONOTONIC, &start);
+		clock_gettime(CLOCK_MONOTONIC_RAW, &mid);
+		clock_gettime(CLOCK_MONOTONIC, &end);
+
+		newdiff = diff_timespec(start, end);
+		if (diff == 0 || newdiff < diff) {
+			diff = newdiff;
+			*raw = mid;
+			tmp = (ts_to_nsec(start) + ts_to_nsec(end))/2;
+			*mon = nsec_to_ts(tmp);
+		}
+	}
+}
+
+int main(int argv, char **argc)
+{
+	struct timespec mon, raw, start, end;
+	long long delta1, delta2, interval, eppm, ppm;
+	struct timex tx1, tx2;
+
+	setbuf(stdout, NULL);
+
+	if (clock_gettime(CLOCK_MONOTONIC_RAW, &raw)) {
+		printf("ERR: NO CLOCK_MONOTONIC_RAW\n");
+		return -1;
+	}
+
+	tx1.modes = 0;
+	adjtimex(&tx1);
+	get_monotonic_and_raw(&mon, &raw);
+	start = mon;
+	delta1 = diff_timespec(mon, raw);
+
+	if (tx1.offset)
+		printf("WARNING: ADJ_OFFSET in progress, this will cause inaccurate results\n");
+
+	printf("Estimating clock drift: ");
+	sleep(120);
+
+	get_monotonic_and_raw(&mon, &raw);
+	end = mon;
+	tx2.modes = 0;
+	adjtimex(&tx2);
+	delta2 = diff_timespec(mon, raw);
+
+	interval = diff_timespec(start, end);
+
+	/* calculate measured ppm between MONOTONIC and MONOTONIC_RAW */
+	eppm = ((delta2-delta1)*NSEC_PER_SEC)/interval;
+	eppm = -eppm;
+	printf("%lld.%i(est)", eppm/1000, abs((int)(eppm%1000)));
+
+	/* Avg the two actual freq samples adjtimex gave us */
+	ppm = (tx1.freq + tx2.freq) * 1000 / 2;
+	ppm = (long long)tx1.freq * 1000;
+	ppm = shift_right(ppm, 16);
+	printf(" %lld.%i(act)", ppm/1000, abs((int)(ppm%1000)));
+
+	if (llabs(eppm - ppm) > 1000) {
+		printf("	[FAILED]\n");
+		return ksft_exit_fail();
+	}
+	printf("	[OK]\n");
+	return  ksft_exit_pass();
+}
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 07/19] selftests/timers: Add set-timer-lat test from timetest suite
  2015-03-02 21:09 [PATCH 00/19 v3] Add timekeeping tests to kernel selftest John Stultz
                   ` (5 preceding siblings ...)
  2015-03-02 21:09 ` [PATCH 06/19] selftests/timers: Add clock skew estimation " John Stultz
@ 2015-03-02 21:10 ` John Stultz
  2015-03-02 21:10 ` [PATCH 08/19] selftests/timers: Add threaded time inconsistency " John Stultz
                   ` (13 subsequent siblings)
  20 siblings, 0 replies; 25+ messages in thread
From: John Stultz @ 2015-03-02 21:10 UTC (permalink / raw)
  To: Linux Kernel Mailing List
  Cc: John Stultz, Shuah Khan, Prarit Bhargava, Thomas Gleixner,
	Richard Cochran

Add my set-timer-lat test from the timetest suite. This
test checks the latency from set_timer and reports if
any are unreasonable (>40ms).

Cc: Shuah Khan <shuahkh@osg.samsung.com>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Richard Cochran <richardcochran@gmail.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 tools/testing/selftests/timers/Makefile        |   5 +-
 tools/testing/selftests/timers/set-timer-lat.c | 210 +++++++++++++++++++++++++
 2 files changed, 214 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/timers/set-timer-lat.c

diff --git a/tools/testing/selftests/timers/Makefile b/tools/testing/selftests/timers/Makefile
index 088a791..f69bdce 100644
--- a/tools/testing/selftests/timers/Makefile
+++ b/tools/testing/selftests/timers/Makefile
@@ -2,7 +2,8 @@ CC = $(CROSS_COMPILE)gcc
 BUILD_FLAGS = -DKTEST
 CFLAGS += -O3 -Wl,-no-as-needed -Wall $(BUILD_FLAGS)
 LDFLAGS += -lrt -lpthread
-bins = posix_timers nanosleep inconsistency-check nsleep-lat raw_skew
+bins = posix_timers nanosleep inconsistency-check nsleep-lat raw_skew \
+	set-timer-lat
 
 all: ${bins}
 
@@ -10,7 +11,9 @@ run_tests: all
 	./posix_timers
 	./nanosleep
 	./nsleep-lat
+	./set-timer-lat
 	./inconsistency-check
 	./raw_skew
+
 clean:
 	rm -f ${bins}
diff --git a/tools/testing/selftests/timers/set-timer-lat.c b/tools/testing/selftests/timers/set-timer-lat.c
new file mode 100644
index 0000000..de4efef
--- /dev/null
+++ b/tools/testing/selftests/timers/set-timer-lat.c
@@ -0,0 +1,210 @@
+/* set_timer latency test
+ *		John Stultz (john.stultz@linaro.org)
+ *              (C) Copyright Linaro 2014
+ *              Licensed under the GPLv2
+ *
+ *   This test makes sure the set_timer api is correct
+ *
+ *  To build:
+ *	$ gcc set-timer-lat.c -o set-timer-lat -lrt
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ */
+
+
+#include <stdio.h>
+#include <unistd.h>
+#include <time.h>
+#include <string.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <pthread.h>
+#ifdef KTEST
+#include "../kselftest.h"
+#else
+static inline int ksft_exit_pass(void)
+{
+	exit(0);
+}
+static inline int ksft_exit_fail(void)
+{
+	exit(1);
+}
+#endif
+
+#define CLOCK_REALTIME			0
+#define CLOCK_MONOTONIC			1
+#define CLOCK_PROCESS_CPUTIME_ID	2
+#define CLOCK_THREAD_CPUTIME_ID		3
+#define CLOCK_MONOTONIC_RAW		4
+#define CLOCK_REALTIME_COARSE		5
+#define CLOCK_MONOTONIC_COARSE		6
+#define CLOCK_BOOTTIME			7
+#define CLOCK_REALTIME_ALARM		8
+#define CLOCK_BOOTTIME_ALARM		9
+#define CLOCK_HWSPECIFIC		10
+#define CLOCK_TAI			11
+#define NR_CLOCKIDS			12
+
+
+#define NSEC_PER_SEC 1000000000ULL
+#define UNRESONABLE_LATENCY 40000000 /* 40ms in nanosecs */
+
+#define TIMER_SECS 3
+int alarmcount;
+int clock_id;
+struct timespec start_time;
+long long max_latency_ns;
+
+char *clockstring(int clockid)
+{
+	switch (clockid) {
+	case CLOCK_REALTIME:
+		return "CLOCK_REALTIME";
+	case CLOCK_MONOTONIC:
+		return "CLOCK_MONOTONIC";
+	case CLOCK_PROCESS_CPUTIME_ID:
+		return "CLOCK_PROCESS_CPUTIME_ID";
+	case CLOCK_THREAD_CPUTIME_ID:
+		return "CLOCK_THREAD_CPUTIME_ID";
+	case CLOCK_MONOTONIC_RAW:
+		return "CLOCK_MONOTONIC_RAW";
+	case CLOCK_REALTIME_COARSE:
+		return "CLOCK_REALTIME_COARSE";
+	case CLOCK_MONOTONIC_COARSE:
+		return "CLOCK_MONOTONIC_COARSE";
+	case CLOCK_BOOTTIME:
+		return "CLOCK_BOOTTIME";
+	case CLOCK_REALTIME_ALARM:
+		return "CLOCK_REALTIME_ALARM";
+	case CLOCK_BOOTTIME_ALARM:
+		return "CLOCK_BOOTTIME_ALARM";
+	case CLOCK_TAI:
+		return "CLOCK_TAI";
+	};
+	return "UNKNOWN_CLOCKID";
+}
+
+
+long long timespec_sub(struct timespec a, struct timespec b)
+{
+	long long ret = NSEC_PER_SEC * b.tv_sec + b.tv_nsec;
+
+	ret -= NSEC_PER_SEC * a.tv_sec + a.tv_nsec;
+	return ret;
+}
+
+
+void sigalarm(int signo)
+{
+	long long delta_ns;
+	struct timespec ts;
+
+	clock_gettime(clock_id, &ts);
+	alarmcount++;
+
+	delta_ns = timespec_sub(start_time, ts);
+	delta_ns -= NSEC_PER_SEC * TIMER_SECS * alarmcount;
+
+	if (delta_ns < 0)
+		printf("%s timer fired early: FAIL\n", clockstring(clock_id));
+
+	if (delta_ns > max_latency_ns)
+		max_latency_ns = delta_ns;
+}
+
+int do_timer(int clock_id, int flags)
+{
+	struct sigevent se;
+	timer_t tm1;
+	struct itimerspec its1, its2;
+	int err;
+
+	/* Set up timer: */
+	memset(&se, 0, sizeof(se));
+	se.sigev_notify = SIGEV_SIGNAL;
+	se.sigev_signo = SIGRTMAX;
+	se.sigev_value.sival_int = 0;
+
+	max_latency_ns = 0;
+	alarmcount = 0;
+
+	err = timer_create(clock_id, &se, &tm1);
+	if (err) {
+		printf("%s - timer_create() failed\n", clockstring(clock_id));
+		return -1;
+	}
+
+	clock_gettime(clock_id, &start_time);
+	if (flags) {
+		its1.it_value = start_time;
+		its1.it_value.tv_sec += TIMER_SECS;
+	} else {
+		its1.it_value.tv_sec = TIMER_SECS;
+		its1.it_value.tv_nsec = 0;
+	}
+	its1.it_interval.tv_sec = TIMER_SECS;
+	its1.it_interval.tv_nsec = 0;
+
+	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);
+
+	printf("%-22s %s max latency: %10lld ns : ",
+			clockstring(clock_id),
+			flags ? "ABSTIME":"RELTIME",
+			max_latency_ns);
+
+	timer_delete(tm1);
+	if (max_latency_ns < UNRESONABLE_LATENCY) {
+		printf("[OK]\n");
+		return 0;
+	}
+	printf("[FAILED]\n");
+	return -1;
+}
+
+int main(void)
+{
+	struct sigaction act;
+	int signum = SIGRTMAX;
+	int ret = 0;
+
+	/* Set up signal handler: */
+	sigfillset(&act.sa_mask);
+	act.sa_flags = 0;
+	act.sa_handler = sigalarm;
+	sigaction(signum, &act, NULL);
+
+	printf("Setting timers for every %i seconds\n", TIMER_SECS);
+	for (clock_id = 0; clock_id < NR_CLOCKIDS; clock_id++) {
+
+		if ((clock_id == CLOCK_PROCESS_CPUTIME_ID) ||
+				(clock_id == CLOCK_THREAD_CPUTIME_ID) ||
+				(clock_id == CLOCK_MONOTONIC_RAW) ||
+				(clock_id == CLOCK_REALTIME_COARSE) ||
+				(clock_id == CLOCK_MONOTONIC_COARSE) ||
+				(clock_id == CLOCK_HWSPECIFIC))
+			continue;
+
+		ret |= do_timer(clock_id, TIMER_ABSTIME);
+		ret |= do_timer(clock_id, 0);
+	}
+	if (ret)
+		return ksft_exit_fail();
+	return ksft_exit_pass();
+}
+
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 08/19] selftests/timers: Add threaded time inconsistency test from timetest suite
  2015-03-02 21:09 [PATCH 00/19 v3] Add timekeeping tests to kernel selftest John Stultz
                   ` (6 preceding siblings ...)
  2015-03-02 21:10 ` [PATCH 07/19] selftests/timers: Add set-timer-lat " John Stultz
@ 2015-03-02 21:10 ` John Stultz
  2015-03-02 21:10 ` [PATCH 09/19] selftests/timers: Add mqueue latency test from the " John Stultz
                   ` (12 subsequent siblings)
  20 siblings, 0 replies; 25+ messages in thread
From: John Stultz @ 2015-03-02 21:10 UTC (permalink / raw)
  To: Linux Kernel Mailing List
  Cc: John Stultz, Shuah Khan, Prarit Bhargava, Thomas Gleixner,
	Richard Cochran

Add the threaded time inconsistency test from the timetest suite.
This checks for time inconsistencies between cpus, usually associated
with clock skew as sometimes found w/ TSCs.

Cc: Shuah Khan <shuahkh@osg.samsung.com>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Richard Cochran <richardcochran@gmail.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 tools/testing/selftests/timers/Makefile     |   4 +-
 tools/testing/selftests/timers/threadtest.c | 202 ++++++++++++++++++++++++++++
 2 files changed, 204 insertions(+), 2 deletions(-)
 create mode 100644 tools/testing/selftests/timers/threadtest.c

diff --git a/tools/testing/selftests/timers/Makefile b/tools/testing/selftests/timers/Makefile
index f69bdce..e53b675 100644
--- a/tools/testing/selftests/timers/Makefile
+++ b/tools/testing/selftests/timers/Makefile
@@ -3,7 +3,7 @@ BUILD_FLAGS = -DKTEST
 CFLAGS += -O3 -Wl,-no-as-needed -Wall $(BUILD_FLAGS)
 LDFLAGS += -lrt -lpthread
 bins = posix_timers nanosleep inconsistency-check nsleep-lat raw_skew \
-	set-timer-lat
+	set-timer-lat threadtest
 
 all: ${bins}
 
@@ -14,6 +14,6 @@ run_tests: all
 	./set-timer-lat
 	./inconsistency-check
 	./raw_skew
-
+	./threadtest -t 30 -n 8
 clean:
 	rm -f ${bins}
diff --git a/tools/testing/selftests/timers/threadtest.c b/tools/testing/selftests/timers/threadtest.c
new file mode 100644
index 0000000..6f5fc1c
--- /dev/null
+++ b/tools/testing/selftests/timers/threadtest.c
@@ -0,0 +1,202 @@
+/* threadtest.c
+ *		by: john stultz (johnstul@us.ibm.com)
+ *		(C) Copyright IBM 2004, 2005, 2006, 2012
+ *		Licensed under the GPLv2
+ *
+ *  To build:
+ *	$ gcc threadtest.c -o threadtest -lrt
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ */
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <pthread.h>
+#ifdef KTEST
+#include "../kselftest.h"
+#else
+static inline int ksft_exit_pass(void)
+{
+	exit(0);
+}
+static inline int ksft_exit_fail(void)
+{
+	exit(1);
+}
+#endif
+
+
+/* serializes shared list access */
+pthread_mutex_t list_lock = PTHREAD_MUTEX_INITIALIZER;
+/* serializes console output */
+pthread_mutex_t print_lock = PTHREAD_MUTEX_INITIALIZER;
+
+
+#define MAX_THREADS 128
+#define LISTSIZE 128
+
+extern char *optarg;
+
+int done = 0;
+
+struct timespec global_list[LISTSIZE];
+int listcount = 0;
+
+
+void checklist(struct timespec *list, int size)
+{
+	int i, j;
+	struct timespec *a, *b;
+
+	/* scan the list */
+	for (i = 0; i < size-1; i++) {
+		a = &list[i];
+		b = &list[i+1];
+
+		/* look for any time inconsistencies */
+		if ((b->tv_sec <= a->tv_sec) &&
+			(b->tv_nsec < a->tv_nsec)) {
+
+			/* flag other threads */
+			done = 1;
+
+			/*serialize printing to avoid junky output*/
+			pthread_mutex_lock(&print_lock);
+
+			/* dump the list */
+			printf("\n");
+			for (j = 0; j < size; j++) {
+				if (j == i)
+					printf("---------------\n");
+				printf("%lu:%lu\n", list[j].tv_sec, list[j].tv_nsec);
+				if (j == i+1)
+					printf("---------------\n");
+			}
+			printf("[FAILED]\n");
+
+			pthread_mutex_unlock(&print_lock);
+		}
+	}
+}
+
+/* The shared thread shares a global list
+ * that each thread fills while holding the lock.
+ * This stresses clock syncronization across cpus.
+ */
+void *shared_thread(void *arg)
+{
+	while (!done) {
+		/* protect the list */
+		pthread_mutex_lock(&list_lock);
+
+		/* see if we're ready to check the list */
+		if (listcount >= LISTSIZE) {
+			checklist(global_list, LISTSIZE);
+			listcount = 0;
+		}
+		clock_gettime(CLOCK_MONOTONIC, &global_list[listcount++]);
+
+		pthread_mutex_unlock(&list_lock);
+	}
+	return NULL;
+}
+
+
+/* Each independent thread fills in its own
+ * list. This stresses clock_gettime() lock contention.
+ */
+void *independent_thread(void *arg)
+{
+	struct timespec my_list[LISTSIZE];
+	int count;
+
+	while (!done) {
+		/* fill the list */
+		for (count = 0; count < LISTSIZE; count++)
+			clock_gettime(CLOCK_MONOTONIC, &my_list[count]);
+		checklist(my_list, LISTSIZE);
+	}
+	return NULL;
+}
+
+
+int main(int argc, char **argv)
+{
+	int thread_count = 1, i;
+	time_t start, now, runtime = 60;
+	char buf[255];
+	pthread_t pth[MAX_THREADS];
+	int opt;
+	void *tret;
+	int ret = 0;
+	void *(*thread)(void *) = shared_thread;
+
+
+	/* Process arguments */
+	while ((opt = getopt(argc, argv, "t:n:i")) != -1) {
+		switch (opt) {
+		case 't':
+			runtime = atoi(optarg);
+			break;
+		case 'n':
+			thread_count = atoi(optarg);
+			break;
+		case 'i':
+			thread = independent_thread;
+			printf("using independent threads\n");
+			break;
+		default:
+			printf("Usage: %s [-t <secs>] [-n <numthreads>] [-i]\n", argv[0]);
+			printf("	-t: time to run\n");
+			printf("	-n: number of threads\n");
+			printf("	-i: use independent threads\n");
+			return -1;
+		}
+	}
+
+	if (thread_count > MAX_THREADS)
+		thread_count = MAX_THREADS;
+
+
+	setbuf(stdout, NULL);
+
+	start = time(0);
+	strftime(buf, 255, "%a, %d %b %Y %T %z", localtime(&start));
+	printf("%s\n", buf);
+	printf("Testing consistency with %i threads for %ld seconds: ", thread_count, runtime);
+
+	/* spawn */
+	for (i = 0; i < thread_count; i++)
+		pthread_create(&pth[i], 0, thread, 0);
+
+	while (time(&now) < start + runtime) {
+		sleep(1);
+		if (done) {
+			ret = 1;
+			strftime(buf, 255, "%a, %d %b %Y %T %z", localtime(&now));
+			printf("%s\n", buf);
+			goto out;
+		}
+	}
+	printf("[OK]\n");
+	done = 1;
+
+out:
+	/* wait */
+	for (i = 0; i < thread_count; i++)
+		pthread_join(pth[i], &tret);
+
+	/* die */
+	if (ret)
+		ksft_exit_fail();
+	return ksft_exit_pass();
+}
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 09/19] selftests/timers: Add mqueue latency test from the timetest suite
  2015-03-02 21:09 [PATCH 00/19 v3] Add timekeeping tests to kernel selftest John Stultz
                   ` (7 preceding siblings ...)
  2015-03-02 21:10 ` [PATCH 08/19] selftests/timers: Add threaded time inconsistency " John Stultz
@ 2015-03-02 21:10 ` John Stultz
  2015-03-02 21:10 ` [PATCH 10/19] selftests/timers: Add adjtimex validation test from " John Stultz
                   ` (11 subsequent siblings)
  20 siblings, 0 replies; 25+ messages in thread
From: John Stultz @ 2015-03-02 21:10 UTC (permalink / raw)
  To: Linux Kernel Mailing List
  Cc: John Stultz, Shuah Khan, Prarit Bhargava, Thomas Gleixner,
	Richard Cochran

Add test to validate mqueue timeout latency from the timetest suite

Cc: Shuah Khan <shuahkh@osg.samsung.com>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Richard Cochran <richardcochran@gmail.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 tools/testing/selftests/timers/Makefile     |   3 +-
 tools/testing/selftests/timers/mqueue-lat.c | 124 ++++++++++++++++++++++++++++
 2 files changed, 126 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/timers/mqueue-lat.c

diff --git a/tools/testing/selftests/timers/Makefile b/tools/testing/selftests/timers/Makefile
index e53b675..d0bfb2d 100644
--- a/tools/testing/selftests/timers/Makefile
+++ b/tools/testing/selftests/timers/Makefile
@@ -3,7 +3,7 @@ BUILD_FLAGS = -DKTEST
 CFLAGS += -O3 -Wl,-no-as-needed -Wall $(BUILD_FLAGS)
 LDFLAGS += -lrt -lpthread
 bins = posix_timers nanosleep inconsistency-check nsleep-lat raw_skew \
-	set-timer-lat threadtest
+	set-timer-lat threadtest mqueue-lat
 
 all: ${bins}
 
@@ -12,6 +12,7 @@ run_tests: all
 	./nanosleep
 	./nsleep-lat
 	./set-timer-lat
+	./mqueue-lat
 	./inconsistency-check
 	./raw_skew
 	./threadtest -t 30 -n 8
diff --git a/tools/testing/selftests/timers/mqueue-lat.c b/tools/testing/selftests/timers/mqueue-lat.c
new file mode 100644
index 0000000..a2a3924
--- /dev/null
+++ b/tools/testing/selftests/timers/mqueue-lat.c
@@ -0,0 +1,124 @@
+/* Measure mqueue timeout latency
+ *              by: john stultz (john.stultz@linaro.org)
+ *		(C) Copyright Linaro 2013
+ *
+ *		Inspired with permission from example test by:
+ *			Romain Francoise <romain@orebokech.com>
+ *              Licensed under the GPLv2
+ *
+ *  To build:
+ *	$ gcc mqueue-lat.c -o mqueue-lat -lrt
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <sys/time.h>
+#include <sys/timex.h>
+#include <string.h>
+#include <signal.h>
+#include <errno.h>
+#include <mqueue.h>
+#ifdef KTEST
+#include "../kselftest.h"
+#else
+static inline int ksft_exit_pass(void)
+{
+	exit(0);
+}
+static inline int ksft_exit_fail(void)
+{
+	exit(1);
+}
+#endif
+
+#define NSEC_PER_SEC 1000000000ULL
+
+#define TARGET_TIMEOUT		100000000	/* 100ms in nanoseconds */
+#define UNRESONABLE_LATENCY	40000000	/* 40ms in nanosecs */
+
+
+long long timespec_sub(struct timespec a, struct timespec b)
+{
+	long long ret = NSEC_PER_SEC * b.tv_sec + b.tv_nsec;
+
+	ret -= NSEC_PER_SEC * a.tv_sec + a.tv_nsec;
+	return ret;
+}
+
+struct timespec timespec_add(struct timespec ts, unsigned long long ns)
+{
+	ts.tv_nsec += ns;
+	while (ts.tv_nsec >= NSEC_PER_SEC) {
+		ts.tv_nsec -= NSEC_PER_SEC;
+		ts.tv_sec++;
+	}
+	return ts;
+}
+
+int mqueue_lat_test(void)
+{
+
+	mqd_t q;
+	struct mq_attr attr;
+	struct timespec start, end, now, target;
+	int i, count, ret;
+
+	q = mq_open("/foo", O_CREAT | O_RDONLY, 0666, NULL);
+	if (q < 0) {
+		perror("mq_open");
+		return -1;
+	}
+	mq_getattr(q, &attr);
+
+
+	count = 100;
+	clock_gettime(CLOCK_MONOTONIC, &start);
+
+	for (i = 0; i < count; i++) {
+		char buf[attr.mq_msgsize];
+
+		clock_gettime(CLOCK_REALTIME, &now);
+		target = now;
+		target = timespec_add(now, TARGET_TIMEOUT); /* 100ms */
+
+		ret = mq_timedreceive(q, buf, sizeof(buf), NULL, &target);
+		if (ret < 0 && errno != ETIMEDOUT) {
+			perror("mq_timedreceive");
+			return -1;
+		}
+	}
+	clock_gettime(CLOCK_MONOTONIC, &end);
+
+	mq_close(q);
+
+	if ((timespec_sub(start, end)/count) > TARGET_TIMEOUT + UNRESONABLE_LATENCY)
+		return -1;
+
+	return 0;
+}
+
+int main(int argc, char **argv)
+{
+	int ret;
+
+	printf("Mqueue latency :                          ");
+
+	ret = mqueue_lat_test();
+	if (ret < 0) {
+		printf("[FAILED]\n");
+		return ksft_exit_fail();
+	}
+	printf("[OK]\n");
+	return ksft_exit_pass();
+}
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 10/19] selftests/timers: Add adjtimex validation test from timetest suite
  2015-03-02 21:09 [PATCH 00/19 v3] Add timekeeping tests to kernel selftest John Stultz
                   ` (8 preceding siblings ...)
  2015-03-02 21:10 ` [PATCH 09/19] selftests/timers: Add mqueue latency test from the " John Stultz
@ 2015-03-02 21:10 ` John Stultz
  2015-03-02 21:10 ` [PATCH 11/19] selftests/timers: Add alarmtimer-suspend test from timetests suite John Stultz
                   ` (10 subsequent siblings)
  20 siblings, 0 replies; 25+ messages in thread
From: John Stultz @ 2015-03-02 21:10 UTC (permalink / raw)
  To: Linux Kernel Mailing List
  Cc: John Stultz, Shuah Khan, Prarit Bhargava, Thomas Gleixner,
	Richard Cochran

This adds a adjtimex validation test which checks the behavior
for a set of valida and invalid inputs. So far this only tests
ADJ_FREQUENCY, but hopefully will grow.

Cc: Shuah Khan <shuahkh@osg.samsung.com>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Richard Cochran <richardcochran@gmail.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 tools/testing/selftests/timers/Makefile         |  11 +-
 tools/testing/selftests/timers/valid-adjtimex.c | 204 ++++++++++++++++++++++++
 2 files changed, 214 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/timers/valid-adjtimex.c

diff --git a/tools/testing/selftests/timers/Makefile b/tools/testing/selftests/timers/Makefile
index d0bfb2d..01b5a2e 100644
--- a/tools/testing/selftests/timers/Makefile
+++ b/tools/testing/selftests/timers/Makefile
@@ -3,10 +3,12 @@ BUILD_FLAGS = -DKTEST
 CFLAGS += -O3 -Wl,-no-as-needed -Wall $(BUILD_FLAGS)
 LDFLAGS += -lrt -lpthread
 bins = posix_timers nanosleep inconsistency-check nsleep-lat raw_skew \
-	set-timer-lat threadtest mqueue-lat
+	set-timer-lat threadtest mqueue-lat valid-adjtimex
 
 all: ${bins}
 
+# these are all "safe" tests that don't modify
+# system time or require escalated privledges
 run_tests: all
 	./posix_timers
 	./nanosleep
@@ -16,5 +18,12 @@ run_tests: all
 	./inconsistency-check
 	./raw_skew
 	./threadtest -t 30 -n 8
+
+# these tests require escalated privledges
+# and may modify the system time or trigger
+# other behavior like suspend
+run_destructive_tests: all
+	./valid-adjtimex
+
 clean:
 	rm -f ${bins}
diff --git a/tools/testing/selftests/timers/valid-adjtimex.c b/tools/testing/selftests/timers/valid-adjtimex.c
new file mode 100644
index 0000000..5006390
--- /dev/null
+++ b/tools/testing/selftests/timers/valid-adjtimex.c
@@ -0,0 +1,204 @@
+/* valid adjtimex test
+ *              by: John Stultz <john.stultz@linaro.org>
+ *              (C) Copyright Linaro 2015
+ *              Licensed under the GPLv2
+ *
+ *  This test validates adjtimex interface with valid
+ *  and invalid test data.
+ *
+ *  Usage: valid-adjtimex
+ *
+ *  To build:
+ *	$ gcc valid-adjtimex.c -o valid-adjtimex -lrt
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ */
+
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <sys/time.h>
+#include <sys/timex.h>
+#include <string.h>
+#include <signal.h>
+#include <unistd.h>
+#ifdef KTEST
+#include "../kselftest.h"
+#else
+static inline int ksft_exit_pass(void)
+{
+	exit(0);
+}
+static inline int ksft_exit_fail(void)
+{
+	exit(1);
+}
+#endif
+
+extern char *optarg;
+
+#define NSEC_PER_SEC 1000000000L
+
+/* clear NTP time_status & time_state */
+int clear_time_state(void)
+{
+	struct timex tx;
+	int ret;
+
+	tx.modes = ADJ_STATUS;
+	tx.status = 0;
+	ret = adjtimex(&tx);
+	return ret;
+}
+
+#define NUM_FREQ_VALID 32
+#define NUM_FREQ_OUTOFRANGE 4
+#define NUM_FREQ_INVALID 2
+
+long valid_freq[NUM_FREQ_VALID] = {
+	-499<<16,
+	-450<<16,
+	-400<<16,
+	-350<<16,
+	-300<<16,
+	-250<<16,
+	-200<<16,
+	-150<<16,
+	-100<<16,
+	-75<<16,
+	-50<<16,
+	-25<<16,
+	-10<<16,
+	-5<<16,
+	-1<<16,
+	-1000,
+	1<<16,
+	5<<16,
+	10<<16,
+	25<<16,
+	50<<16,
+	75<<16,
+	100<<16,
+	150<<16,
+	200<<16,
+	250<<16,
+	300<<16,
+	350<<16,
+	400<<16,
+	450<<16,
+	499<<16,
+};
+
+long outofrange_freq[NUM_FREQ_OUTOFRANGE] = {
+	-1000<<16,
+	-550<<16,
+	550<<16,
+	1000<<16,
+};
+
+#define LONG_MAX (~0UL>>1)
+#define LONG_MIN (-LONG_MAX - 1)
+
+long invalid_freq[NUM_FREQ_INVALID] = {
+	LONG_MAX,
+	LONG_MIN,
+};
+
+int validate_freq(void)
+{
+	struct timex tx;
+	int ret, pass = 0;
+	int i;
+
+	clear_time_state();
+
+	memset(&tx, 0, sizeof(struct timex));
+	/* Set the leap second insert flag */
+
+	printf("Testing ADJ_FREQ... ");
+	for (i = 0; i < NUM_FREQ_VALID; i++) {
+		tx.modes = ADJ_FREQUENCY;
+		tx.freq = valid_freq[i];
+
+		ret = adjtimex(&tx);
+		if (ret < 0) {
+			printf("[FAIL]\n");
+			printf("Error: adjtimex(ADJ_FREQ, %ld - %ld ppm\n",
+				valid_freq[i], valid_freq[i]>>16);
+			pass = -1;
+			goto out;
+		}
+		tx.modes = 0;
+		ret = adjtimex(&tx);
+		if (tx.freq != valid_freq[i]) {
+			printf("Warning: freq value %ld not what we set it (%ld)!\n",
+					tx.freq, valid_freq[i]);
+		}
+	}
+	for (i = 0; i < NUM_FREQ_OUTOFRANGE; i++) {
+		tx.modes = ADJ_FREQUENCY;
+		tx.freq = outofrange_freq[i];
+
+		ret = adjtimex(&tx);
+		if (ret < 0) {
+			printf("[FAIL]\n");
+			printf("Error: adjtimex(ADJ_FREQ, %ld - %ld ppm\n",
+				outofrange_freq[i], outofrange_freq[i]>>16);
+			pass = -1;
+			goto out;
+		}
+		tx.modes = 0;
+		ret = adjtimex(&tx);
+		if (tx.freq == outofrange_freq[i]) {
+			printf("[FAIL]\n");
+			printf("ERROR: out of range value %ld actually set!\n",
+					tx.freq);
+			pass = -1;
+			goto out;
+		}
+	}
+
+
+	if (sizeof(long) == 8) { /* this case only applies to 64bit systems */
+		for (i = 0; i < NUM_FREQ_INVALID; i++) {
+			tx.modes = ADJ_FREQUENCY;
+			tx.freq = invalid_freq[i];
+			ret = adjtimex(&tx);
+			if (ret >= 0) {
+				printf("[FAIL]\n");
+				printf("Error: No failure on invalid ADJ_FREQUENCY %ld\n",
+					invalid_freq[i]);
+				pass = -1;
+				goto out;
+			}
+		}
+	}
+
+	printf("[OK]\n");
+out:
+	/* reset freq to zero */
+	tx.modes = ADJ_FREQUENCY;
+	tx.freq = 0;
+	ret = adjtimex(&tx);
+
+	return pass;
+}
+
+
+int main(int argc, char **argv)
+{
+	if (validate_freq())
+		return ksft_exit_fail();
+
+	return ksft_exit_pass();
+}
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 11/19] selftests/timers: Add alarmtimer-suspend test from timetests suite
  2015-03-02 21:09 [PATCH 00/19 v3] Add timekeeping tests to kernel selftest John Stultz
                   ` (9 preceding siblings ...)
  2015-03-02 21:10 ` [PATCH 10/19] selftests/timers: Add adjtimex validation test from " John Stultz
@ 2015-03-02 21:10 ` John Stultz
  2015-03-02 21:10 ` [PATCH 12/19] selftests/timers: Add change_skew test from timetest suite John Stultz
                   ` (9 subsequent siblings)
  20 siblings, 0 replies; 25+ messages in thread
From: John Stultz @ 2015-03-02 21:10 UTC (permalink / raw)
  To: Linux Kernel Mailing List
  Cc: John Stultz, Shuah Khan, Prarit Bhargava, Thomas Gleixner,
	Richard Cochran

This adds the alarmtimer-suspend test from the timetests suite,
which tests that the alarmtimers wake the system up from suspend
shortly after the time they were set to fire.

Cc: Shuah Khan <shuahkh@osg.samsung.com>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Richard Cochran <richardcochran@gmail.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 tools/testing/selftests/timers/Makefile            |   6 +-
 .../testing/selftests/timers/alarmtimer-suspend.c  | 186 +++++++++++++++++++++
 2 files changed, 190 insertions(+), 2 deletions(-)
 create mode 100644 tools/testing/selftests/timers/alarmtimer-suspend.c

diff --git a/tools/testing/selftests/timers/Makefile b/tools/testing/selftests/timers/Makefile
index 01b5a2e..61a39ec 100644
--- a/tools/testing/selftests/timers/Makefile
+++ b/tools/testing/selftests/timers/Makefile
@@ -3,7 +3,8 @@ BUILD_FLAGS = -DKTEST
 CFLAGS += -O3 -Wl,-no-as-needed -Wall $(BUILD_FLAGS)
 LDFLAGS += -lrt -lpthread
 bins = posix_timers nanosleep inconsistency-check nsleep-lat raw_skew \
-	set-timer-lat threadtest mqueue-lat valid-adjtimex
+	set-timer-lat threadtest mqueue-lat valid-adjtimex \
+	alarmtimer-suspend
 
 all: ${bins}
 
@@ -22,7 +23,8 @@ run_tests: all
 # these tests require escalated privledges
 # and may modify the system time or trigger
 # other behavior like suspend
-run_destructive_tests: all
+run_destructive_tests: run_tests
+	./alarmtimer-suspend
 	./valid-adjtimex
 
 clean:
diff --git a/tools/testing/selftests/timers/alarmtimer-suspend.c b/tools/testing/selftests/timers/alarmtimer-suspend.c
new file mode 100644
index 0000000..ec2f1d6
--- /dev/null
+++ b/tools/testing/selftests/timers/alarmtimer-suspend.c
@@ -0,0 +1,186 @@
+/* alarmtimer suspend test
+ *		John Stultz (john.stultz@linaro.org)
+ *              (C) Copyright Linaro 2013
+ *              Licensed under the GPLv2
+ *
+ *   This test makes sure the alarmtimer & RTC wakeup code is
+ *   functioning.
+ *
+ *  To build:
+ *	$ gcc alarmtimer-suspend.c -o alarmtimer-suspend -lrt
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ */
+
+
+#include <stdio.h>
+#include <unistd.h>
+#include <time.h>
+#include <string.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <pthread.h>
+#ifdef KTEST
+#include "../kselftest.h"
+#else
+static inline int ksft_exit_pass(void)
+{
+	exit(0);
+}
+static inline int ksft_exit_fail(void)
+{
+	exit(1);
+}
+#endif
+
+#define CLOCK_REALTIME			0
+#define CLOCK_MONOTONIC			1
+#define CLOCK_PROCESS_CPUTIME_ID	2
+#define CLOCK_THREAD_CPUTIME_ID		3
+#define CLOCK_MONOTONIC_RAW		4
+#define CLOCK_REALTIME_COARSE		5
+#define CLOCK_MONOTONIC_COARSE		6
+#define CLOCK_BOOTTIME			7
+#define CLOCK_REALTIME_ALARM		8
+#define CLOCK_BOOTTIME_ALARM		9
+#define CLOCK_HWSPECIFIC		10
+#define CLOCK_TAI			11
+#define NR_CLOCKIDS			12
+
+
+#define NSEC_PER_SEC 1000000000ULL
+#define UNREASONABLE_LAT (NSEC_PER_SEC * 4) /* hopefully we resume in 4secs */
+
+#define SUSPEND_SECS 15
+int alarmcount;
+int alarm_clock_id;
+struct timespec start_time;
+
+
+char *clockstring(int clockid)
+{
+	switch (clockid) {
+	case CLOCK_REALTIME:
+		return "CLOCK_REALTIME";
+	case CLOCK_MONOTONIC:
+		return "CLOCK_MONOTONIC";
+	case CLOCK_PROCESS_CPUTIME_ID:
+		return "CLOCK_PROCESS_CPUTIME_ID";
+	case CLOCK_THREAD_CPUTIME_ID:
+		return "CLOCK_THREAD_CPUTIME_ID";
+	case CLOCK_MONOTONIC_RAW:
+		return "CLOCK_MONOTONIC_RAW";
+	case CLOCK_REALTIME_COARSE:
+		return "CLOCK_REALTIME_COARSE";
+	case CLOCK_MONOTONIC_COARSE:
+		return "CLOCK_MONOTONIC_COARSE";
+	case CLOCK_BOOTTIME:
+		return "CLOCK_BOOTTIME";
+	case CLOCK_REALTIME_ALARM:
+		return "CLOCK_REALTIME_ALARM";
+	case CLOCK_BOOTTIME_ALARM:
+		return "CLOCK_BOOTTIME_ALARM";
+	case CLOCK_TAI:
+		return "CLOCK_TAI";
+	};
+	return "UNKNOWN_CLOCKID";
+}
+
+
+long long timespec_sub(struct timespec a, struct timespec b)
+{
+	long long ret = NSEC_PER_SEC * b.tv_sec + b.tv_nsec;
+
+	ret -= NSEC_PER_SEC * a.tv_sec + a.tv_nsec;
+	return ret;
+}
+
+int final_ret = 0;
+
+void sigalarm(int signo)
+{
+	long long delta_ns;
+	struct timespec ts;
+
+	clock_gettime(alarm_clock_id, &ts);
+	alarmcount++;
+
+	delta_ns = timespec_sub(start_time, ts);
+	delta_ns -= NSEC_PER_SEC * SUSPEND_SECS * alarmcount;
+
+	printf("ALARM(%i): %ld:%ld latency: %lld ns ", alarmcount, ts.tv_sec,
+							ts.tv_nsec, delta_ns);
+
+	if (delta_ns > UNREASONABLE_LAT) {
+		printf("[FAIL]\n");
+		final_ret = -1;
+	} else
+		printf("[OK]\n");
+
+}
+
+int main(void)
+{
+	timer_t tm1;
+	struct itimerspec its1, its2;
+	struct sigevent se;
+	struct sigaction act;
+	int signum = SIGRTMAX;
+
+	/* Set up signal handler: */
+	sigfillset(&act.sa_mask);
+	act.sa_flags = 0;
+	act.sa_handler = sigalarm;
+	sigaction(signum, &act, NULL);
+
+	/* Set up timer: */
+	memset(&se, 0, sizeof(se));
+	se.sigev_notify = SIGEV_SIGNAL;
+	se.sigev_signo = signum;
+	se.sigev_value.sival_int = 0;
+
+	for (alarm_clock_id = CLOCK_REALTIME_ALARM;
+			alarm_clock_id <= CLOCK_BOOTTIME_ALARM;
+			alarm_clock_id++) {
+
+		alarmcount = 0;
+		timer_create(alarm_clock_id, &se, &tm1);
+
+		clock_gettime(alarm_clock_id, &start_time);
+		printf("Start time (%s): %ld:%ld\n", clockstring(alarm_clock_id),
+				start_time.tv_sec, start_time.tv_nsec);
+		printf("Setting alarm for every %i seconds\n", SUSPEND_SECS);
+		its1.it_value = start_time;
+		its1.it_value.tv_sec += SUSPEND_SECS;
+		its1.it_interval.tv_sec = SUSPEND_SECS;
+		its1.it_interval.tv_nsec = 0;
+
+		timer_settime(tm1, TIMER_ABSTIME, &its1, &its2);
+
+		while (alarmcount < 5)
+			sleep(1); /* First 5 alarms, do nothing */
+
+		printf("Starting suspend loops\n");
+		while (alarmcount < 10) {
+			int ret;
+
+			sleep(1);
+			ret = system("echo mem > /sys/power/state");
+			if (ret)
+				break;
+		}
+		timer_delete(tm1);
+	}
+	if (final_ret)
+		return ksft_exit_fail();
+	return ksft_exit_pass();
+}
+
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 12/19] selftests/timers: Add change_skew test from timetest suite
  2015-03-02 21:09 [PATCH 00/19 v3] Add timekeeping tests to kernel selftest John Stultz
                   ` (10 preceding siblings ...)
  2015-03-02 21:10 ` [PATCH 11/19] selftests/timers: Add alarmtimer-suspend test from timetests suite John Stultz
@ 2015-03-02 21:10 ` John Stultz
  2015-03-02 21:10 ` [PATCH 13/19] selftests/timers: Add skew_consistency test from the timetests suite John Stultz
                   ` (8 subsequent siblings)
  20 siblings, 0 replies; 25+ messages in thread
From: John Stultz @ 2015-03-02 21:10 UTC (permalink / raw)
  To: Linux Kernel Mailing List
  Cc: John Stultz, Shuah Khan, Prarit Bhargava, Thomas Gleixner,
	Richard Cochran

This patch adds the change_skew test which validates the
adjtimex freq can be set to various values and then using
the inconsistency-check, raw_skew, and nanosleep tests
ensures time behaves properly.

Cc: Shuah Khan <shuahkh@osg.samsung.com>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Richard Cochran <richardcochran@gmail.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 tools/testing/selftests/timers/Makefile      |   3 +-
 tools/testing/selftests/timers/change_skew.c | 107 +++++++++++++++++++++++++++
 2 files changed, 109 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/timers/change_skew.c

diff --git a/tools/testing/selftests/timers/Makefile b/tools/testing/selftests/timers/Makefile
index 61a39ec..55b74cc 100644
--- a/tools/testing/selftests/timers/Makefile
+++ b/tools/testing/selftests/timers/Makefile
@@ -4,7 +4,7 @@ CFLAGS += -O3 -Wl,-no-as-needed -Wall $(BUILD_FLAGS)
 LDFLAGS += -lrt -lpthread
 bins = posix_timers nanosleep inconsistency-check nsleep-lat raw_skew \
 	set-timer-lat threadtest mqueue-lat valid-adjtimex \
-	alarmtimer-suspend
+	alarmtimer-suspend change_skew
 
 all: ${bins}
 
@@ -26,6 +26,7 @@ run_tests: all
 run_destructive_tests: run_tests
 	./alarmtimer-suspend
 	./valid-adjtimex
+	./change_skew
 
 clean:
 	rm -f ${bins}
diff --git a/tools/testing/selftests/timers/change_skew.c b/tools/testing/selftests/timers/change_skew.c
new file mode 100644
index 0000000..cb19689
--- /dev/null
+++ b/tools/testing/selftests/timers/change_skew.c
@@ -0,0 +1,107 @@
+/* ADJ_FREQ Skew change test
+ *		by: john stultz (johnstul@us.ibm.com)
+ *		(C) Copyright IBM 2012
+ *		Licensed under the GPLv2
+ *
+ *  NOTE: This is a meta-test which cranks the ADJ_FREQ knob and
+ *  then uses other tests to detect problems. Thus this test requires
+ *  that the raw_skew, inconsistency-check and nanosleep tests be
+ *  present in the same directory it is run from.
+ *
+ *  To build:
+ *	$ gcc change_skew.c -o change_skew -lrt
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <sys/timex.h>
+#include <time.h>
+#ifdef KTEST
+#include "../kselftest.h"
+#else
+static inline int ksft_exit_pass(void)
+{
+	exit(0);
+}
+static inline int ksft_exit_fail(void)
+{
+	exit(1);
+}
+#endif
+
+#define NSEC_PER_SEC 1000000000LL
+
+
+int change_skew_test(int ppm)
+{
+	struct timex tx;
+	int ret;
+
+	tx.modes = ADJ_FREQUENCY;
+	tx.freq = ppm << 16;
+
+	ret = adjtimex(&tx);
+	if (ret < 0) {
+		printf("Error adjusting freq\n");
+		return ret;
+	}
+
+	ret = system("./raw_skew");
+	ret |= system("./inconsistency-check");
+	ret |= system("./nanosleep");
+
+	return ret;
+}
+
+
+int main(int argv, char **argc)
+{
+	struct timex tx;
+	int i, ret;
+
+	int ppm[5] = {0, 250, 500, -250, -500};
+
+	/* Kill ntpd */
+	ret = system("killall -9 ntpd");
+
+	/* Make sure there's no offset adjustment going on */
+	tx.modes = ADJ_OFFSET;
+	tx.offset = 0;
+	ret = adjtimex(&tx);
+
+	if (ret < 0) {
+		printf("Maybe you're not running as root?\n");
+		return -1;
+	}
+
+	for (i = 0; i < 5; i++) {
+		printf("Using %i ppm adjustment\n", ppm[i]);
+		ret = change_skew_test(ppm[i]);
+		if (ret)
+			break;
+	}
+
+	/* Set things back */
+	tx.modes = ADJ_FREQUENCY;
+	tx.offset = 0;
+	adjtimex(&tx);
+
+	if (ret) {
+		printf("[FAIL]");
+		return ksft_exit_fail();
+	}
+	printf("[OK]");
+	return ksft_exit_pass();
+}
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 13/19] selftests/timers: Add skew_consistency test from the timetests suite
  2015-03-02 21:09 [PATCH 00/19 v3] Add timekeeping tests to kernel selftest John Stultz
                   ` (11 preceding siblings ...)
  2015-03-02 21:10 ` [PATCH 12/19] selftests/timers: Add change_skew test from timetest suite John Stultz
@ 2015-03-02 21:10 ` John Stultz
  2015-03-02 21:10 ` [PATCH 14/19] selftests/timers: Add clocksource-switch test from timetest suite John Stultz
                   ` (7 subsequent siblings)
  20 siblings, 0 replies; 25+ messages in thread
From: John Stultz @ 2015-03-02 21:10 UTC (permalink / raw)
  To: Linux Kernel Mailing List
  Cc: John Stultz, Shuah Khan, Prarit Bhargava, Thomas Gleixner,
	Richard Cochran

This change adds the skew_consistency test, which twists the
ADJ_FREQUENCY knob back and forth and watches for timekeeping
inconsistencies.

Cc: Shuah Khan <shuahkh@osg.samsung.com>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Richard Cochran <richardcochran@gmail.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 tools/testing/selftests/timers/Makefile           |  3 +-
 tools/testing/selftests/timers/skew_consistency.c | 89 +++++++++++++++++++++++
 2 files changed, 91 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/timers/skew_consistency.c

diff --git a/tools/testing/selftests/timers/Makefile b/tools/testing/selftests/timers/Makefile
index 55b74cc..4b6b5c3 100644
--- a/tools/testing/selftests/timers/Makefile
+++ b/tools/testing/selftests/timers/Makefile
@@ -4,7 +4,7 @@ CFLAGS += -O3 -Wl,-no-as-needed -Wall $(BUILD_FLAGS)
 LDFLAGS += -lrt -lpthread
 bins = posix_timers nanosleep inconsistency-check nsleep-lat raw_skew \
 	set-timer-lat threadtest mqueue-lat valid-adjtimex \
-	alarmtimer-suspend change_skew
+	alarmtimer-suspend change_skew skew_consistency
 
 all: ${bins}
 
@@ -27,6 +27,7 @@ run_destructive_tests: run_tests
 	./alarmtimer-suspend
 	./valid-adjtimex
 	./change_skew
+	./skew_consistency
 
 clean:
 	rm -f ${bins}
diff --git a/tools/testing/selftests/timers/skew_consistency.c b/tools/testing/selftests/timers/skew_consistency.c
new file mode 100644
index 0000000..5562f84
--- /dev/null
+++ b/tools/testing/selftests/timers/skew_consistency.c
@@ -0,0 +1,89 @@
+/* ADJ_FREQ Skew consistency test
+ *		by: john stultz (johnstul@us.ibm.com)
+ *		(C) Copyright IBM 2012
+ *		Licensed under the GPLv2
+ *
+ *  NOTE: This is a meta-test which cranks the ADJ_FREQ knob back
+ *  and forth and watches for consistency problems. Thus this test requires
+ *  that the inconsistency-check tests be present in the same directory it
+ *  is run from.
+ *
+ *  To build:
+ *	$ gcc skew_consistency.c -o skew_consistency -lrt
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/time.h>
+#include <sys/timex.h>
+#include <time.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/wait.h>
+#ifdef KTEST
+#include "../kselftest.h"
+#else
+static inline int ksft_exit_pass(void)
+{
+	exit(0);
+}
+static inline int ksft_exit_fail(void)
+{
+	exit(1);
+}
+#endif
+
+#define NSEC_PER_SEC 1000000000LL
+
+int main(int argv, char **argc)
+{
+	struct timex tx;
+	int ret, ppm;
+	pid_t pid;
+
+
+	printf("Running Asyncrhonous Frequency Changing Tests...\n");
+
+	pid = fork();
+	if (!pid)
+		return system("./inconsistency-check -c 1 -t 600");
+
+	ppm = 500;
+	ret = 0;
+
+	while (pid != waitpid(pid, &ret, WNOHANG)) {
+		ppm = -ppm;
+		tx.modes = ADJ_FREQUENCY;
+		tx.freq = ppm << 16;
+		adjtimex(&tx);
+		usleep(500000);
+	}
+
+	/* Set things back */
+	tx.modes = ADJ_FREQUENCY;
+	tx.offset = 0;
+	adjtimex(&tx);
+
+
+	if (ret) {
+		printf("[FAILED]\n");
+		return ksft_exit_fail();
+	}
+	printf("[OK]\n");
+	return ksft_exit_pass();
+}
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 14/19] selftests/timers: Add clocksource-switch test from timetest suite
  2015-03-02 21:09 [PATCH 00/19 v3] Add timekeeping tests to kernel selftest John Stultz
                   ` (12 preceding siblings ...)
  2015-03-02 21:10 ` [PATCH 13/19] selftests/timers: Add skew_consistency test from the timetests suite John Stultz
@ 2015-03-02 21:10 ` John Stultz
  2015-03-02 21:10 ` [PATCH 15/19] selftests/timers: Add leap-a-day " John Stultz
                   ` (6 subsequent siblings)
  20 siblings, 0 replies; 25+ messages in thread
From: John Stultz @ 2015-03-02 21:10 UTC (permalink / raw)
  To: Linux Kernel Mailing List
  Cc: John Stultz, Shuah Khan, Prarit Bhargava, Thomas Gleixner,
	Richard Cochran

Adds the clocksource-switch tests which continually switches the
current clocksource between all the available ones, watching for
any timekeeping inconsistencies.

Cc: Shuah Khan <shuahkh@osg.samsung.com>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Richard Cochran <richardcochran@gmail.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 tools/testing/selftests/timers/Makefile            |   3 +-
 .../testing/selftests/timers/clocksource-switch.c  | 179 +++++++++++++++++++++
 2 files changed, 181 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/timers/clocksource-switch.c

diff --git a/tools/testing/selftests/timers/Makefile b/tools/testing/selftests/timers/Makefile
index 4b6b5c3..4a006d7 100644
--- a/tools/testing/selftests/timers/Makefile
+++ b/tools/testing/selftests/timers/Makefile
@@ -4,7 +4,7 @@ CFLAGS += -O3 -Wl,-no-as-needed -Wall $(BUILD_FLAGS)
 LDFLAGS += -lrt -lpthread
 bins = posix_timers nanosleep inconsistency-check nsleep-lat raw_skew \
 	set-timer-lat threadtest mqueue-lat valid-adjtimex \
-	alarmtimer-suspend change_skew skew_consistency
+	alarmtimer-suspend change_skew skew_consistency clocksource-switch \
 
 all: ${bins}
 
@@ -28,6 +28,7 @@ run_destructive_tests: run_tests
 	./valid-adjtimex
 	./change_skew
 	./skew_consistency
+	./clocksource-switch
 
 clean:
 	rm -f ${bins}
diff --git a/tools/testing/selftests/timers/clocksource-switch.c b/tools/testing/selftests/timers/clocksource-switch.c
new file mode 100644
index 0000000..627ec74
--- /dev/null
+++ b/tools/testing/selftests/timers/clocksource-switch.c
@@ -0,0 +1,179 @@
+/* Clocksource change test
+ *		by: john stultz (johnstul@us.ibm.com)
+ *		(C) Copyright IBM 2012
+ *		Licensed under the GPLv2
+ *
+ *  NOTE: This is a meta-test which quickly changes the clocksourc and
+ *  then uses other tests to detect problems. Thus this test requires
+ *  that the inconsistency-check and nanosleep tests be present in the
+ *  same directory it is run from.
+ *
+ *  To build:
+ *	$ gcc clocksource-switch.c -o clocksource-switch -lrt
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ */
+
+
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <sys/timex.h>
+#include <time.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <string.h>
+#include <sys/wait.h>
+#ifdef KTEST
+#include "../kselftest.h"
+#else
+static inline int ksft_exit_pass(void)
+{
+	exit(0);
+}
+static inline int ksft_exit_fail(void)
+{
+	exit(1);
+}
+#endif
+
+
+int get_clocksources(char list[][30])
+{
+	int fd, i;
+	size_t size;
+	char buf[512];
+	char *head, *tmp;
+
+	fd = open("/sys/devices/system/clocksource/clocksource0/available_clocksource", O_RDONLY);
+
+	size = read(fd, buf, 512);
+
+	close(fd);
+
+	for (i = 0; i < 30; i++)
+		list[i][0] = '\0';
+
+	head = buf;
+	i = 0;
+	while (head - buf < size) {
+		/* Find the next space */
+		for (tmp = head; *tmp != ' '; tmp++) {
+			if (*tmp == '\n')
+				break;
+			if (*tmp == '\0')
+				break;
+		}
+		*tmp = '\0';
+		strcpy(list[i], head);
+		head = tmp + 1;
+		i++;
+	}
+
+	return i-1;
+}
+
+int get_cur_clocksource(char *buf, size_t size)
+{
+	int fd;
+
+	fd = open("/sys/devices/system/clocksource/clocksource0/current_clocksource", O_RDONLY);
+
+	size = read(fd, buf, size);
+
+	return 0;
+}
+
+int change_clocksource(char *clocksource)
+{
+	int fd;
+	size_t size;
+
+	fd = open("/sys/devices/system/clocksource/clocksource0/current_clocksource", O_WRONLY);
+
+	if (fd < 0)
+		return -1;
+
+	size = write(fd, clocksource, strlen(clocksource));
+
+	if (size < 0)
+		return -1;
+
+	close(fd);
+	return 0;
+}
+
+
+int run_tests(int secs)
+{
+	int ret;
+	char buf[255];
+
+	sprintf(buf, "./inconsistency-check -t %i", secs);
+	ret = system(buf);
+	if (ret)
+		return ret;
+	ret = system("./nanosleep");
+	return ret;
+}
+
+
+char clocksource_list[10][30];
+
+int main(int argv, char **argc)
+{
+	char orig_clk[512];
+	int count, i, status;
+	pid_t pid;
+
+	get_cur_clocksource(orig_clk, 512);
+
+	count = get_clocksources(clocksource_list);
+
+	if (change_clocksource(clocksource_list[0])) {
+		printf("Error: You probably need to run this as root\n");
+		return -1;
+	}
+
+	/* Check everything is sane before we start switching asyncrhonously */
+	for (i = 0; i < count; i++) {
+		printf("Validating clocksource %s\n", clocksource_list[i]);
+		if (change_clocksource(clocksource_list[i])) {
+			status = -1;
+			goto out;
+		}
+		if (run_tests(5)) {
+			status = -1;
+			goto out;
+		}
+	}
+
+
+	printf("Running Asyncrhonous Switching Tests...\n");
+	pid = fork();
+	if (!pid)
+		return run_tests(60);
+
+	while (pid != waitpid(pid, &status, WNOHANG))
+		for (i = 0; i < count; i++)
+			if (change_clocksource(clocksource_list[i])) {
+				status = -1;
+				goto out;
+			}
+out:
+	change_clocksource(orig_clk);
+
+	if (status)
+		return ksft_exit_fail();
+	return ksft_exit_pass();
+}
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 15/19] selftests/timers: Add leap-a-day test from timetest suite
  2015-03-02 21:09 [PATCH 00/19 v3] Add timekeeping tests to kernel selftest John Stultz
                   ` (13 preceding siblings ...)
  2015-03-02 21:10 ` [PATCH 14/19] selftests/timers: Add clocksource-switch test from timetest suite John Stultz
@ 2015-03-02 21:10 ` John Stultz
  2015-03-02 21:10 ` [PATCH 16/19] selftests/timers: Add leapcrash test from the " John Stultz
                   ` (5 subsequent siblings)
  20 siblings, 0 replies; 25+ messages in thread
From: John Stultz @ 2015-03-02 21:10 UTC (permalink / raw)
  To: Linux Kernel Mailing List
  Cc: John Stultz, Shuah Khan, Prarit Bhargava, Thomas Gleixner,
	Richard Cochran

This change adds the leap-a-day test which sets STA_INS and
STA_DEL each day to trigger leapseconds each day. It also
has a mode to jump the time to right before the end of the
day each iteration.

Cc: Shuah Khan <shuahkh@osg.samsung.com>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Richard Cochran <richardcochran@gmail.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 tools/testing/selftests/timers/Makefile     |   2 +
 tools/testing/selftests/timers/leap-a-day.c | 323 ++++++++++++++++++++++++++++
 2 files changed, 325 insertions(+)
 create mode 100644 tools/testing/selftests/timers/leap-a-day.c

diff --git a/tools/testing/selftests/timers/Makefile b/tools/testing/selftests/timers/Makefile
index 4a006d7..da35ddd 100644
--- a/tools/testing/selftests/timers/Makefile
+++ b/tools/testing/selftests/timers/Makefile
@@ -5,6 +5,7 @@ LDFLAGS += -lrt -lpthread
 bins = posix_timers nanosleep inconsistency-check nsleep-lat raw_skew \
 	set-timer-lat threadtest mqueue-lat valid-adjtimex \
 	alarmtimer-suspend change_skew skew_consistency clocksource-switch \
+	leap-a-day
 
 all: ${bins}
 
@@ -29,6 +30,7 @@ run_destructive_tests: run_tests
 	./change_skew
 	./skew_consistency
 	./clocksource-switch
+	./leap-a-day -s -i 10
 
 clean:
 	rm -f ${bins}
diff --git a/tools/testing/selftests/timers/leap-a-day.c b/tools/testing/selftests/timers/leap-a-day.c
new file mode 100644
index 0000000..869dcfe
--- /dev/null
+++ b/tools/testing/selftests/timers/leap-a-day.c
@@ -0,0 +1,323 @@
+/* Leap second stress test
+ *              by: John Stultz (john.stultz@linaro.org)
+ *              (C) Copyright IBM 2012
+ *              (C) Copyright 2013, 2015 Linaro Limited
+ *              Licensed under the GPLv2
+ *
+ *  This test signals the kernel to insert a leap second
+ *  every day at midnight GMT. This allows for stessing the
+ *  kernel's leap-second behavior, as well as how well applications
+ *  handle the leap-second discontinuity.
+ *
+ *  Usage: leap-a-day [-s] [-i <num>]
+ *
+ *  Options:
+ *	-s:	Each iteration, set the date to 10 seconds before midnight GMT.
+ *		This speeds up the number of leapsecond transitions tested,
+ *		but because it calls settimeofday frequently, advancing the
+ *		time by 24 hours every ~16 seconds, it may cause application
+ *		disruption.
+ *
+ *	-i:	Number of iterations to run (default: infinite)
+ *
+ *  Other notes: Disabling NTP prior to running this is advised, as the two
+ *		 may conflict in their commands to the kernel.
+ *
+ *  To build:
+ *	$ gcc leap-a-day.c -o leap-a-day -lrt
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ */
+
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <sys/time.h>
+#include <sys/timex.h>
+#include <string.h>
+#include <signal.h>
+#include <unistd.h>
+#ifdef KTEST
+#include "../kselftest.h"
+#else
+static inline int ksft_exit_pass(void)
+{
+	exit(0);
+}
+static inline int ksft_exit_fail(void)
+{
+	exit(1);
+}
+#endif
+
+
+
+extern char *optarg;
+
+#define NSEC_PER_SEC 1000000000ULL
+#define CLOCK_TAI 11
+
+/* returns 1 if a <= b, 0 otherwise */
+static inline int in_order(struct timespec a, struct timespec b)
+{
+	if (a.tv_sec < b.tv_sec)
+		return 1;
+	if (a.tv_sec > b.tv_sec)
+		return 0;
+	if (a.tv_nsec > b.tv_nsec)
+		return 0;
+	return 1;
+}
+
+struct timespec timespec_add(struct timespec ts, unsigned long long ns)
+{
+	ts.tv_nsec += ns;
+	while (ts.tv_nsec >= NSEC_PER_SEC) {
+		ts.tv_nsec -= NSEC_PER_SEC;
+		ts.tv_sec++;
+	}
+	return ts;
+}
+
+char *time_state_str(int state)
+{
+	switch (state) {
+	case TIME_OK:	return "TIME_OK";
+	case TIME_INS:	return "TIME_INS";
+	case TIME_DEL:	return "TIME_DEL";
+	case TIME_OOP:	return "TIME_OOP";
+	case TIME_WAIT:	return "TIME_WAIT";
+	case TIME_BAD:	return "TIME_BAD";
+	}
+	return "ERROR";
+}
+
+/* clear NTP time_status & time_state */
+int clear_time_state(void)
+{
+	struct timex tx;
+	int ret;
+
+	/*
+	 * We have to call adjtime twice here, as kernels
+	 * prior to 6b1859dba01c7 (included in 3.5 and
+	 * -stable), had an issue with the state machine
+	 * and wouldn't clear the STA_INS/DEL flag directly.
+	 */
+	tx.modes = ADJ_STATUS;
+	tx.status = STA_PLL;
+	ret = adjtimex(&tx);
+
+	/* Clear maxerror, as it can cause UNSYNC to be set */
+	tx.modes = ADJ_MAXERROR;
+	tx.maxerror = 0;
+	ret = adjtimex(&tx);
+
+	/* Clear the status */
+	tx.modes = ADJ_STATUS;
+	tx.status = 0;
+	ret = adjtimex(&tx);
+
+	return ret;
+}
+
+/* Make sure we cleanup on ctrl-c */
+void handler(int unused)
+{
+	clear_time_state();
+	exit(0);
+}
+
+/* Test for known hrtimer failure */
+void test_hrtimer_failure(void)
+{
+	struct timespec now, target;
+
+	clock_gettime(CLOCK_REALTIME, &now);
+	target = timespec_add(now, NSEC_PER_SEC/2);
+	clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &target, NULL);
+	clock_gettime(CLOCK_REALTIME, &now);
+
+	if (!in_order(target, now))
+		printf("ERROR: hrtimer early expiration failure observed.\n");
+}
+
+int main(int argc, char **argv)
+{
+	int settime = 0;
+	int tai_time = 0;
+	int insert = 1;
+	int iterations = -1;
+	int opt;
+
+	/* Process arguments */
+	while ((opt = getopt(argc, argv, "sti:")) != -1) {
+		switch (opt) {
+		case 's':
+			printf("Setting time to speed up testing\n");
+			settime = 1;
+			break;
+		case 'i':
+			iterations = atoi(optarg);
+			break;
+		case 't':
+			tai_time = 1;
+			break;
+		default:
+			printf("Usage: %s [-s] [-i <iterations>]\n", argv[0]);
+			printf("	-s: Set time to right before leap second each iteration\n");
+			printf("	-i: Number of iterations\n");
+			printf("	-t: Print TAI time\n");
+			exit(-1);
+		}
+	}
+
+	/* Make sure TAI support is present if -t was used */
+	if (tai_time) {
+		struct timespec ts;
+
+		if (clock_gettime(CLOCK_TAI, &ts)) {
+			printf("System doesn't support CLOCK_TAI\n");
+			ksft_exit_fail();
+		}
+	}
+
+	signal(SIGINT, handler);
+	signal(SIGKILL, handler);
+
+	if (iterations < 0)
+		printf("This runs continuously. Press ctrl-c to stop\n");
+	else
+		printf("Running for %i iterations. Press ctrl-c to stop\n", iterations);
+
+	printf("\n");
+	while (1) {
+		int ret;
+		struct timespec ts;
+		struct timex tx;
+		time_t now, next_leap;
+
+		/* Get the current time */
+		clock_gettime(CLOCK_REALTIME, &ts);
+
+		/* Calculate the next possible leap second 23:59:60 GMT */
+		next_leap = ts.tv_sec;
+		next_leap += 86400 - (next_leap % 86400);
+
+		if (settime) {
+			struct timeval tv;
+
+			tv.tv_sec = next_leap - 10;
+			tv.tv_usec = 0;
+			settimeofday(&tv, NULL);
+			printf("Setting time to %s", ctime(&tv.tv_sec));
+		}
+
+		/* Reset NTP time state */
+		clear_time_state();
+
+		/* Set the leap second insert flag */
+		tx.modes = ADJ_STATUS;
+		if (insert)
+			tx.status = STA_INS;
+		else
+			tx.status = STA_DEL;
+		ret = adjtimex(&tx);
+		if (ret < 0) {
+			printf("Error: Problem setting STA_INS/STA_DEL!: %s\n",
+							time_state_str(ret));
+			return ksft_exit_fail();
+		}
+
+		/* Validate STA_INS was set */
+		tx.modes = 0;
+		ret = adjtimex(&tx);
+		if (tx.status != STA_INS && tx.status != STA_DEL) {
+			printf("Error: STA_INS/STA_DEL not set!: %s\n",
+							time_state_str(ret));
+			return ksft_exit_fail();
+		}
+
+		if (tai_time) {
+			printf("Using TAI time,"
+				" no inconsistencies should be seen!\n");
+		}
+
+		printf("Scheduling leap second for %s", ctime(&next_leap));
+
+		/* Wake up 3 seconds before leap */
+		ts.tv_sec = next_leap - 3;
+		ts.tv_nsec = 0;
+
+		while (clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &ts, NULL))
+			printf("Something woke us up, returning to sleep\n");
+
+		/* Validate STA_INS is still set */
+		tx.modes = 0;
+		ret = adjtimex(&tx);
+		if (tx.status != STA_INS && tx.status != STA_DEL) {
+			printf("Something cleared STA_INS/STA_DEL, setting it again.\n");
+			tx.modes = ADJ_STATUS;
+			if (insert)
+				tx.status = STA_INS;
+			else
+				tx.status = STA_DEL;
+			ret = adjtimex(&tx);
+		}
+
+		/* Check adjtimex output every half second */
+		now = tx.time.tv_sec;
+		while (now < next_leap + 2) {
+			char buf[26];
+			struct timespec tai;
+
+			tx.modes = 0;
+			ret = adjtimex(&tx);
+
+			if (tai_time) {
+				clock_gettime(CLOCK_TAI, &tai);
+				printf("%ld sec, %9ld ns\t%s\n",
+						tai.tv_sec,
+						tai.tv_nsec,
+						time_state_str(ret));
+			} else {
+				ctime_r(&tx.time.tv_sec, buf);
+				buf[strlen(buf)-1] = 0; /*remove trailing\n */
+
+				printf("%s + %6ld us (%i)\t%s\n",
+						buf,
+						tx.time.tv_usec,
+						tx.tai,
+						time_state_str(ret));
+			}
+			now = tx.time.tv_sec;
+			/* Sleep for another half second */
+			ts.tv_sec = 0;
+			ts.tv_nsec = NSEC_PER_SEC / 2;
+			clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, NULL);
+		}
+		/* Switch to using other mode */
+		insert = !insert;
+
+		/* Note if kernel has known hrtimer failure */
+		test_hrtimer_failure();
+
+		printf("Leap complete\n\n");
+
+		if ((iterations != -1) && !(--iterations))
+			break;
+	}
+
+	clear_time_state();
+	return ksft_exit_pass();
+}
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 16/19] selftests/timers: Add leapcrash test from the timetest suite
  2015-03-02 21:09 [PATCH 00/19 v3] Add timekeeping tests to kernel selftest John Stultz
                   ` (14 preceding siblings ...)
  2015-03-02 21:10 ` [PATCH 15/19] selftests/timers: Add leap-a-day " John Stultz
@ 2015-03-02 21:10 ` John Stultz
  2015-03-02 21:10 ` [PATCH 17/19] selftests/timers: Add set-tai " John Stultz
                   ` (4 subsequent siblings)
  20 siblings, 0 replies; 25+ messages in thread
From: John Stultz @ 2015-03-02 21:10 UTC (permalink / raw)
  To: Linux Kernel Mailing List
  Cc: John Stultz, Shuah Khan, Prarit Bhargava, Thomas Gleixner,
	Richard Cochran

This change adds the leapcrash test which tests to see if a
leapsecond deadlock which was observed from 2.6.26 to 3.3
is present on this system.

Cc: Shuah Khan <shuahkh@osg.samsung.com>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Richard Cochran <richardcochran@gmail.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 tools/testing/selftests/timers/Makefile    |   3 +-
 tools/testing/selftests/timers/leapcrash.c | 120 +++++++++++++++++++++++++++++
 2 files changed, 122 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/timers/leapcrash.c

diff --git a/tools/testing/selftests/timers/Makefile b/tools/testing/selftests/timers/Makefile
index da35ddd..d733324 100644
--- a/tools/testing/selftests/timers/Makefile
+++ b/tools/testing/selftests/timers/Makefile
@@ -5,7 +5,7 @@ LDFLAGS += -lrt -lpthread
 bins = posix_timers nanosleep inconsistency-check nsleep-lat raw_skew \
 	set-timer-lat threadtest mqueue-lat valid-adjtimex \
 	alarmtimer-suspend change_skew skew_consistency clocksource-switch \
-	leap-a-day
+	leap-a-day leapcrash
 
 all: ${bins}
 
@@ -31,6 +31,7 @@ run_destructive_tests: run_tests
 	./skew_consistency
 	./clocksource-switch
 	./leap-a-day -s -i 10
+	./leapcrash
 
 clean:
 	rm -f ${bins}
diff --git a/tools/testing/selftests/timers/leapcrash.c b/tools/testing/selftests/timers/leapcrash.c
new file mode 100644
index 0000000..a1071bd
--- /dev/null
+++ b/tools/testing/selftests/timers/leapcrash.c
@@ -0,0 +1,120 @@
+/* Demo leapsecond deadlock
+ *              by: John Stultz (john.stultz@linaro.org)
+ *              (C) Copyright IBM 2012
+ *              (C) Copyright 2013, 2015 Linaro Limited
+ *              Licensed under the GPL
+ *
+ * This test demonstrates leapsecond deadlock that is possibe
+ * on kernels from 2.6.26 to 3.3.
+ *
+ * WARNING: THIS WILL LIKELY HARDHANG SYSTEMS AND MAY LOSE DATA
+ * RUN AT YOUR OWN RISK!
+ *  To build:
+ *	$ gcc leapcrash.c -o leapcrash -lrt
+ */
+
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <sys/time.h>
+#include <sys/timex.h>
+#include <string.h>
+#include <signal.h>
+#ifdef KTEST
+#include "../kselftest.h"
+#else
+static inline int ksft_exit_pass(void)
+{
+	exit(0);
+}
+static inline int ksft_exit_fail(void)
+{
+	exit(1);
+}
+#endif
+
+
+
+/* clear NTP time_status & time_state */
+int clear_time_state(void)
+{
+	struct timex tx;
+	int ret;
+
+	/*
+	 * We have to call adjtime twice here, as kernels
+	 * prior to 6b1859dba01c7 (included in 3.5 and
+	 * -stable), had an issue with the state machine
+	 * and wouldn't clear the STA_INS/DEL flag directly.
+	 */
+	tx.modes = ADJ_STATUS;
+	tx.status = STA_PLL;
+	ret = adjtimex(&tx);
+
+	tx.modes = ADJ_STATUS;
+	tx.status = 0;
+	ret = adjtimex(&tx);
+
+	return ret;
+}
+
+/* Make sure we cleanup on ctrl-c */
+void handler(int unused)
+{
+	clear_time_state();
+	exit(0);
+}
+
+
+int main(void)
+{
+	struct timex tx;
+	struct timespec ts;
+	time_t next_leap;
+	int count = 0;
+
+	setbuf(stdout, NULL);
+
+	signal(SIGINT, handler);
+	signal(SIGKILL, handler);
+	printf("This runs for a few minutes. Press ctrl-c to stop\n");
+
+	clear_time_state();
+
+
+	/* Get the current time */
+	clock_gettime(CLOCK_REALTIME, &ts);
+
+	/* Calculate the next possible leap second 23:59:60 GMT */
+	next_leap = ts.tv_sec;
+	next_leap += 86400 - (next_leap % 86400);
+
+	for (count = 0; count < 20; count++) {
+		struct timeval tv;
+
+
+		/* set the time to 2 seconds before the leap */
+		tv.tv_sec = next_leap - 2;
+		tv.tv_usec = 0;
+		if (settimeofday(&tv, NULL)) {
+			printf("Error: You're likely not running with proper (ie: root) permissions\n");
+			return ksft_exit_fail();
+		}
+		tx.modes = 0;
+		adjtimex(&tx);
+
+		/* hammer on adjtime w/ STA_INS */
+		while (tx.time.tv_sec < next_leap + 1) {
+			/* Set the leap second insert flag */
+			tx.modes = ADJ_STATUS;
+			tx.status = STA_INS;
+			adjtimex(&tx);
+		}
+		clear_time_state();
+		printf(".");
+	}
+	printf("[OK]\n");
+	return ksft_exit_pass();
+}
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 17/19] selftests/timers: Add set-tai from the timetest suite
  2015-03-02 21:09 [PATCH 00/19 v3] Add timekeeping tests to kernel selftest John Stultz
                   ` (15 preceding siblings ...)
  2015-03-02 21:10 ` [PATCH 16/19] selftests/timers: Add leapcrash test from the " John Stultz
@ 2015-03-02 21:10 ` John Stultz
  2015-03-02 21:10 ` [PATCH 18/19] selftests/timers: Add set-2038 test from " John Stultz
                   ` (3 subsequent siblings)
  20 siblings, 0 replies; 25+ messages in thread
From: John Stultz @ 2015-03-02 21:10 UTC (permalink / raw)
  To: Linux Kernel Mailing List
  Cc: John Stultz, Shuah Khan, Prarit Bhargava, Thomas Gleixner,
	Richard Cochran

This patch adds the set-tai test which ensures the tai offset
can be set properly from adjtimex.

Cc: Shuah Khan <shuahkh@osg.samsung.com>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Richard Cochran <richardcochran@gmail.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 tools/testing/selftests/timers/Makefile  |  3 +-
 tools/testing/selftests/timers/set-tai.c | 79 ++++++++++++++++++++++++++++++++
 2 files changed, 81 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/timers/set-tai.c

diff --git a/tools/testing/selftests/timers/Makefile b/tools/testing/selftests/timers/Makefile
index d733324..7e2fba7 100644
--- a/tools/testing/selftests/timers/Makefile
+++ b/tools/testing/selftests/timers/Makefile
@@ -5,7 +5,7 @@ LDFLAGS += -lrt -lpthread
 bins = posix_timers nanosleep inconsistency-check nsleep-lat raw_skew \
 	set-timer-lat threadtest mqueue-lat valid-adjtimex \
 	alarmtimer-suspend change_skew skew_consistency clocksource-switch \
-	leap-a-day leapcrash
+	leap-a-day leapcrash set-tai
 
 all: ${bins}
 
@@ -32,6 +32,7 @@ run_destructive_tests: run_tests
 	./clocksource-switch
 	./leap-a-day -s -i 10
 	./leapcrash
+	./set-tai
 
 clean:
 	rm -f ${bins}
diff --git a/tools/testing/selftests/timers/set-tai.c b/tools/testing/selftests/timers/set-tai.c
new file mode 100644
index 0000000..dc88dbc
--- /dev/null
+++ b/tools/testing/selftests/timers/set-tai.c
@@ -0,0 +1,79 @@
+/* Set tai offset
+ *              by: John Stultz <john.stultz@linaro.org>
+ *              (C) Copyright Linaro 2013
+ *              Licensed under the GPLv2
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <sys/time.h>
+#include <sys/timex.h>
+#include <string.h>
+#include <signal.h>
+#include <unistd.h>
+#ifdef KTEST
+#include "../kselftest.h"
+#else
+static inline int ksft_exit_pass(void)
+{
+	exit(0);
+}
+static inline int ksft_exit_fail(void)
+{
+	exit(1);
+}
+#endif
+
+int set_tai(int offset)
+{
+	struct timex tx;
+
+	memset(&tx, 0, sizeof(tx));
+
+	tx.modes = ADJ_TAI;
+	tx.constant = offset;
+
+	return adjtimex(&tx);
+}
+
+int get_tai(void)
+{
+	struct timex tx;
+
+	memset(&tx, 0, sizeof(tx));
+
+	adjtimex(&tx);
+	return tx.tai;
+}
+
+int main(int argc, char **argv)
+{
+	int i, ret;
+
+	ret = get_tai();
+	printf("tai offset started at %i\n", ret);
+
+	printf("Checking tai offsets can be properly set: ");
+	for (i = 1; i <= 60; i++) {
+		ret = set_tai(i);
+		ret = get_tai();
+		if (ret != i) {
+			printf("[FAILED] expected: %i got %i\n", i, ret);
+			return ksft_exit_fail();
+		}
+	}
+	printf("[OK]\n");
+	return ksft_exit_pass();
+}
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 18/19] selftests/timers: Add set-2038 test from timetest suite
  2015-03-02 21:09 [PATCH 00/19 v3] Add timekeeping tests to kernel selftest John Stultz
                   ` (16 preceding siblings ...)
  2015-03-02 21:10 ` [PATCH 17/19] selftests/timers: Add set-tai " John Stultz
@ 2015-03-02 21:10 ` John Stultz
  2015-03-02 21:10 ` [PATCH 19/19] MAINTAINERS: Add selftests/timers to the timekeeping maintainance list John Stultz
                   ` (2 subsequent siblings)
  20 siblings, 0 replies; 25+ messages in thread
From: John Stultz @ 2015-03-02 21:10 UTC (permalink / raw)
  To: Linux Kernel Mailing List
  Cc: John Stultz, Shuah Khan, Prarit Bhargava, Thomas Gleixner,
	Richard Cochran

Adds the set-2038 test which sets the time to near-edge cases
like the start and end of the 32 bit epoch and checks that
time behaves properly. There is also a dangerous mode, which
lets the clock roll over past 2038 on 32bit systems, which
on some older kernels will cause system hangs.

Cc: Shuah Khan <shuahkh@osg.samsung.com>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Richard Cochran <richardcochran@gmail.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 tools/testing/selftests/timers/Makefile   |   3 +-
 tools/testing/selftests/timers/set-2038.c | 147 ++++++++++++++++++++++++++++++
 2 files changed, 149 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/timers/set-2038.c

diff --git a/tools/testing/selftests/timers/Makefile b/tools/testing/selftests/timers/Makefile
index 7e2fba7..9da3498 100644
--- a/tools/testing/selftests/timers/Makefile
+++ b/tools/testing/selftests/timers/Makefile
@@ -5,7 +5,7 @@ LDFLAGS += -lrt -lpthread
 bins = posix_timers nanosleep inconsistency-check nsleep-lat raw_skew \
 	set-timer-lat threadtest mqueue-lat valid-adjtimex \
 	alarmtimer-suspend change_skew skew_consistency clocksource-switch \
-	leap-a-day leapcrash set-tai
+	leap-a-day leapcrash set-tai set-2038
 
 all: ${bins}
 
@@ -33,6 +33,7 @@ run_destructive_tests: run_tests
 	./leap-a-day -s -i 10
 	./leapcrash
 	./set-tai
+	./set-2038
 
 clean:
 	rm -f ${bins}
diff --git a/tools/testing/selftests/timers/set-2038.c b/tools/testing/selftests/timers/set-2038.c
new file mode 100644
index 0000000..0f23923
--- /dev/null
+++ b/tools/testing/selftests/timers/set-2038.c
@@ -0,0 +1,147 @@
+/* Time bounds setting test
+ *		by: john stultz (johnstul@us.ibm.com)
+ *		(C) Copyright IBM 2012
+ *		Licensed under the GPLv2
+ *
+ *  NOTE: This is a meta-test which sets the time to edge cases then
+ *  uses other tests to detect problems. Thus this test requires that
+ *  the inconsistency-check and nanosleep tests be present in the same
+ *  directory it is run from.
+ *
+ *  To build:
+ *	$ gcc set-2038.c -o set-2038 -lrt
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <time.h>
+#include <sys/time.h>
+#ifdef KTEST
+#include "../kselftest.h"
+#else
+static inline int ksft_exit_pass(void)
+{
+	exit(0);
+}
+static inline int ksft_exit_fail(void)
+{
+	exit(1);
+}
+#endif
+
+extern char *optarg;
+
+#define NSEC_PER_SEC 1000000000LL
+
+#define KTIME_MAX	((long long)~((unsigned long long)1 << 63))
+#define KTIME_SEC_MAX	(KTIME_MAX / NSEC_PER_SEC)
+
+#define YEAR_1901 (-0x7fffffffL)
+#define YEAR_1970 1
+#define YEAR_2038 0x7fffffffL			/*overflows 32bit time_t */
+#define YEAR_2262 KTIME_SEC_MAX			/*overflows 64bit ktime_t */
+#define YEAR_MAX  ((long long)((1ULL<<63)-1))	/*overflows 64bit time_t */
+
+int is32bits(void)
+{
+	return (sizeof(long) == 4);
+}
+
+int settime(long long time)
+{
+	struct timeval now;
+	int ret;
+
+	now.tv_sec = (time_t)time;
+	now.tv_usec  = 0;
+
+	ret = settimeofday(&now, NULL);
+
+	printf("Setting time to 0x%lx: %d\n", (long)time, ret);
+	return ret;
+}
+
+int do_tests(void)
+{
+	int ret;
+
+	ret = system("date");
+	ret = system("./inconsistency-check -c 0 -t 20");
+	ret |= system("./nanosleep");
+	ret |= system("./nsleep-lat");
+	return ret;
+
+}
+
+int main(int argc, char *argv[])
+{
+	int ret = 0;
+	int opt, dangerous = 0;
+	time_t start;
+
+	/* Process arguments */
+	while ((opt = getopt(argc, argv, "d")) != -1) {
+		switch (opt) {
+		case 'd':
+			dangerous = 1;
+		}
+	}
+
+	start = time(0);
+
+	/* First test that crazy values don't work */
+	if (!settime(YEAR_1901)) {
+		ret = -1;
+		goto out;
+	}
+	if (!settime(YEAR_MAX)) {
+		ret = -1;
+		goto out;
+	}
+	if (!is32bits() && !settime(YEAR_2262)) {
+		ret = -1;
+		goto out;
+	}
+
+	/* Now test behavior near edges */
+	settime(YEAR_1970);
+	ret = do_tests();
+	if (ret)
+		goto out;
+
+	settime(YEAR_2038 - 600);
+	ret = do_tests();
+	if (ret)
+		goto out;
+
+	/* The rest of the tests can blowup on 32bit systems */
+	if (is32bits() && !dangerous)
+		goto out;
+	/* Test rollover behavior 32bit edge */
+	settime(YEAR_2038 - 10);
+	ret = do_tests();
+	if (ret)
+		goto out;
+
+	settime(YEAR_2262 - 600);
+	ret = do_tests();
+
+out:
+	/* restore clock */
+	settime(start);
+	if (ret)
+		return ksft_exit_fail();
+	return ksft_exit_pass();
+}
+
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 19/19] MAINTAINERS: Add selftests/timers to the timekeeping maintainance list
  2015-03-02 21:09 [PATCH 00/19 v3] Add timekeeping tests to kernel selftest John Stultz
                   ` (17 preceding siblings ...)
  2015-03-02 21:10 ` [PATCH 18/19] selftests/timers: Add set-2038 test from " John Stultz
@ 2015-03-02 21:10 ` John Stultz
  2015-03-03 12:14 ` [PATCH 00/19 v3] Add timekeeping tests to kernel selftest Prarit Bhargava
  2015-03-11 16:43 ` Shuah Khan
  20 siblings, 0 replies; 25+ messages in thread
From: John Stultz @ 2015-03-02 21:10 UTC (permalink / raw)
  To: Linux Kernel Mailing List
  Cc: John Stultz, Shuah Khan, Prarit Bhargava, Thomas Gleixner,
	Richard Cochran

Since I'm adding a bunch of tests to selftests/timers, put me
on the hook in the maintainers file.

Cc: Shuah Khan <shuahkh@osg.samsung.com>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Richard Cochran <richardcochran@gmail.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index ddc5a8c..369f42e 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -8535,6 +8535,7 @@ F:	include/uapi/linux/timex.h
 F:	kernel/time/clocksource.c
 F:	kernel/time/time*.c
 F:	kernel/time/ntp.c
+F:	tools/testing/selftests/timers/
 
 SC1200 WDT DRIVER
 M:	Zwane Mwaikambo <zwanem@gmail.com>
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* Re: [PATCH 00/19 v3] Add timekeeping tests to kernel selftest
  2015-03-02 21:09 [PATCH 00/19 v3] Add timekeeping tests to kernel selftest John Stultz
                   ` (18 preceding siblings ...)
  2015-03-02 21:10 ` [PATCH 19/19] MAINTAINERS: Add selftests/timers to the timekeeping maintainance list John Stultz
@ 2015-03-03 12:14 ` Prarit Bhargava
  2015-03-11 16:43 ` Shuah Khan
  20 siblings, 0 replies; 25+ messages in thread
From: Prarit Bhargava @ 2015-03-03 12:14 UTC (permalink / raw)
  To: John Stultz
  Cc: Linux Kernel Mailing List, Shuah Khan, Thomas Gleixner, Richard Cochran



On 03/02/2015 04:09 PM, John Stultz wrote:
> I've hosted my timekeeping tests on github for the last few years:
> 	https://github.com/johnstultz-work/timetests
> 
> but I suspect not too many folks have actually used them.
> 
> I've been meaning to get them reworked and submitted into the
> selftest infrastructure, but haven't had much time until
> recently.
> 
> I've added both the non-desctructive and destructive tests
> (which set the time, possibly to strange values, or tries
> to trigger historical issues that could crash the machine).
> The destructive tests are run (as root, or with proper
> privledge) via:
> 	# make run_destructive_tests

I ran these across several systems including s390, powerpc, and x86 (64 bit
only).  I didn't see anything weird and AFAICT the tests work.

Tested-by: Prarit Bhargava <prarit@redhat.com>

P.
> 
> Changes in v3:
> * Lots of -Wall build warning fixups
> * Handle the CROSS_COMPILER build variable properly
>  (Thanks to LinusW for pointing that out)
> * Integrate w/ ksft_exit_* infrastructure
> 
> Let me know if there is any further comments or feedback!
> 
> thanks
> -john
> 
> Cc: Shuah Khan <shuahkh@osg.samsung.com>
> Cc: Prarit Bhargava <prarit@redhat.com>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Richard Cochran <richardcochran@gmail.com>
> 
> John Stultz (19):
>   selftests/timers: Cleanup Makefile to make it easier to add future
>     tests
>   selftests/timers: Quiet warning due to lack of return check on brk
>   selftests/timers: Add nanosleep test from timetest suite
>   selftests/timers: Add inconsistency-check test from timetests
>   selftests/timers: Add nsleep-lat test from timetest suite
>   selftests/timers: Add clock skew estimation test from timetest suite
>   selftests/timers: Add set-timer-lat test from timetest suite
>   selftests/timers: Add threaded time inconsistency test from timetest
>     suite
>   selftests/timers: Add mqueue latency test from the timetest suite
>   selftests/timers: Add adjtimex validation test from timetest suite
>   selftests/timers: Add alarmtimer-suspend test from timetests suite
>   selftests/timers: Add change_skew test from timetest suite
>   selftests/timers: Add skew_consistency test from the timetests suite
>   selftests/timers: Add clocksource-switch test from timetest suite
>   selftests/timers: Add leap-a-day test from timetest suite
>   selftests/timers: Add leapcrash test from the timetest suite
>   selftests/timers: Add set-tai from the timetest suite
>   selftests/timers: Add set-2038 test from timetest suite
>   MAINTAINERS: Add selftests/timers to the timekeeping maintainance list
> 
>  MAINTAINERS                                        |   1 +
>  tools/testing/selftests/timers/Makefile            |  37 ++-
>  .../testing/selftests/timers/alarmtimer-suspend.c  | 186 ++++++++++++
>  tools/testing/selftests/timers/change_skew.c       | 107 +++++++
>  .../testing/selftests/timers/clocksource-switch.c  | 179 ++++++++++++
>  .../testing/selftests/timers/inconsistency-check.c | 207 +++++++++++++
>  tools/testing/selftests/timers/leap-a-day.c        | 323 +++++++++++++++++++++
>  tools/testing/selftests/timers/leapcrash.c         | 120 ++++++++
>  tools/testing/selftests/timers/mqueue-lat.c        | 124 ++++++++
>  tools/testing/selftests/timers/nanosleep.c         | 174 +++++++++++
>  tools/testing/selftests/timers/nsleep-lat.c        | 190 ++++++++++++
>  tools/testing/selftests/timers/posix_timers.c      |   9 +-
>  tools/testing/selftests/timers/raw_skew.c          | 154 ++++++++++
>  tools/testing/selftests/timers/set-2038.c          | 147 ++++++++++
>  tools/testing/selftests/timers/set-tai.c           |  79 +++++
>  tools/testing/selftests/timers/set-timer-lat.c     | 210 ++++++++++++++
>  tools/testing/selftests/timers/skew_consistency.c  |  89 ++++++
>  tools/testing/selftests/timers/threadtest.c        | 202 +++++++++++++
>  tools/testing/selftests/timers/valid-adjtimex.c    | 204 +++++++++++++
>  19 files changed, 2734 insertions(+), 8 deletions(-)
>  create mode 100644 tools/testing/selftests/timers/alarmtimer-suspend.c
>  create mode 100644 tools/testing/selftests/timers/change_skew.c
>  create mode 100644 tools/testing/selftests/timers/clocksource-switch.c
>  create mode 100644 tools/testing/selftests/timers/inconsistency-check.c
>  create mode 100644 tools/testing/selftests/timers/leap-a-day.c
>  create mode 100644 tools/testing/selftests/timers/leapcrash.c
>  create mode 100644 tools/testing/selftests/timers/mqueue-lat.c
>  create mode 100644 tools/testing/selftests/timers/nanosleep.c
>  create mode 100644 tools/testing/selftests/timers/nsleep-lat.c
>  create mode 100644 tools/testing/selftests/timers/raw_skew.c
>  create mode 100644 tools/testing/selftests/timers/set-2038.c
>  create mode 100644 tools/testing/selftests/timers/set-tai.c
>  create mode 100644 tools/testing/selftests/timers/set-timer-lat.c
>  create mode 100644 tools/testing/selftests/timers/skew_consistency.c
>  create mode 100644 tools/testing/selftests/timers/threadtest.c
>  create mode 100644 tools/testing/selftests/timers/valid-adjtimex.c
> 

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 00/19 v3] Add timekeeping tests to kernel selftest
  2015-03-02 21:09 [PATCH 00/19 v3] Add timekeeping tests to kernel selftest John Stultz
                   ` (19 preceding siblings ...)
  2015-03-03 12:14 ` [PATCH 00/19 v3] Add timekeeping tests to kernel selftest Prarit Bhargava
@ 2015-03-11 16:43 ` Shuah Khan
  2015-03-11 16:53   ` John Stultz
  20 siblings, 1 reply; 25+ messages in thread
From: Shuah Khan @ 2015-03-11 16:43 UTC (permalink / raw)
  To: John Stultz, Linux Kernel Mailing List
  Cc: Prarit Bhargava, Thomas Gleixner, Richard Cochran

On 03/02/2015 02:09 PM, John Stultz wrote:
> I've hosted my timekeeping tests on github for the last few years:
> 	https://github.com/johnstultz-work/timetests
> 
> but I suspect not too many folks have actually used them.
> 
> I've been meaning to get them reworked and submitted into the
> selftest infrastructure, but haven't had much time until
> recently.
> 
> I've added both the non-desctructive and destructive tests
> (which set the time, possibly to strange values, or tries
> to trigger historical issues that could crash the machine).
> The destructive tests are run (as root, or with proper
> privledge) via:
> 	# make run_destructive_tests
> 
> Changes in v3:
> * Lots of -Wall build warning fixups
> * Handle the CROSS_COMPILER build variable properly
>  (Thanks to LinusW for pointing that out)
> * Integrate w/ ksft_exit_* infrastructure
> 
> Let me know if there is any further comments or feedback!
> 

Ran into several checkpatch warnings when I tried to queue
these up for 4.1. Could you please fix them and resend.

thanks,
-- Shuah

-- 
Shuah Khan
Sr. Linux Kernel Developer
Open Source Innovation Group
Samsung Research America (Silicon Valley)
shuahkh@osg.samsung.com | (970) 217-8978

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 00/19 v3] Add timekeeping tests to kernel selftest
  2015-03-11 16:43 ` Shuah Khan
@ 2015-03-11 16:53   ` John Stultz
  2015-03-11 17:04     ` Shuah Khan
  0 siblings, 1 reply; 25+ messages in thread
From: John Stultz @ 2015-03-11 16:53 UTC (permalink / raw)
  To: Shuah Khan
  Cc: Linux Kernel Mailing List, Prarit Bhargava, Thomas Gleixner,
	Richard Cochran

On Wed, Mar 11, 2015 at 9:43 AM, Shuah Khan <shuahkh@osg.samsung.com> wrote:
> On 03/02/2015 02:09 PM, John Stultz wrote:
>> I've hosted my timekeeping tests on github for the last few years:
>>       https://github.com/johnstultz-work/timetests
>>
>> but I suspect not too many folks have actually used them.
>>
>> I've been meaning to get them reworked and submitted into the
>> selftest infrastructure, but haven't had much time until
>> recently.
>>
>> I've added both the non-desctructive and destructive tests
>> (which set the time, possibly to strange values, or tries
>> to trigger historical issues that could crash the machine).
>> The destructive tests are run (as root, or with proper
>> privledge) via:
>>       # make run_destructive_tests
>>
>> Changes in v3:
>> * Lots of -Wall build warning fixups
>> * Handle the CROSS_COMPILER build variable properly
>>  (Thanks to LinusW for pointing that out)
>> * Integrate w/ ksft_exit_* infrastructure
>>
>> Let me know if there is any further comments or feedback!
>>
>
> Ran into several checkpatch warnings when I tried to queue
> these up for 4.1. Could you please fix them and resend.

So the only few items I saw were:
1) Lines over 80 col, usually do to long string output
2) String output split over multiple lines (result of trying to fix #1
in a few spots)
     - And here I did try to split the string sanely so I didn't break
up the messages, so they're still grepable
3) The extern char *optarg, warning. This one I can probably kill
since I'm including unistd.h.

I'll take a look at #3, but #1 and #2 are basically contrary at a
certain point. Or do you have other ideas for resolving those
warnings?

thanks
-john

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 00/19 v3] Add timekeeping tests to kernel selftest
  2015-03-11 16:53   ` John Stultz
@ 2015-03-11 17:04     ` Shuah Khan
  2015-03-11 17:10       ` John Stultz
  0 siblings, 1 reply; 25+ messages in thread
From: Shuah Khan @ 2015-03-11 17:04 UTC (permalink / raw)
  To: John Stultz
  Cc: Linux Kernel Mailing List, Prarit Bhargava, Thomas Gleixner,
	Richard Cochran

On 03/11/2015 10:53 AM, John Stultz wrote:
> On Wed, Mar 11, 2015 at 9:43 AM, Shuah Khan <shuahkh@osg.samsung.com> wrote:
>> On 03/02/2015 02:09 PM, John Stultz wrote:
>>> I've hosted my timekeeping tests on github for the last few years:
>>>       https://github.com/johnstultz-work/timetests
>>>
>>> but I suspect not too many folks have actually used them.
>>>
>>> I've been meaning to get them reworked and submitted into the
>>> selftest infrastructure, but haven't had much time until
>>> recently.
>>>
>>> I've added both the non-desctructive and destructive tests
>>> (which set the time, possibly to strange values, or tries
>>> to trigger historical issues that could crash the machine).
>>> The destructive tests are run (as root, or with proper
>>> privledge) via:
>>>       # make run_destructive_tests
>>>
>>> Changes in v3:
>>> * Lots of -Wall build warning fixups
>>> * Handle the CROSS_COMPILER build variable properly
>>>  (Thanks to LinusW for pointing that out)
>>> * Integrate w/ ksft_exit_* infrastructure
>>>
>>> Let me know if there is any further comments or feedback!
>>>
>>
>> Ran into several checkpatch warnings when I tried to queue
>> these up for 4.1. Could you please fix them and resend.
> 
> So the only few items I saw were:
> 1) Lines over 80 col, usually do to long string output
> 2) String output split over multiple lines (result of trying to fix #1
> in a few spots)
>      - And here I did try to split the string sanely so I didn't break
> up the messages, so they're still grepable
> 3) The extern char *optarg, warning. This one I can probably kill
> since I'm including unistd.h.
> 
> I'll take a look at #3, but #1 and #2 are basically contrary at a
> certain point. Or do you have other ideas for resolving those
> warnings?

Here are the errors git am flagged:

Patch07:
Applying: selftests/timers: Add set-timer-lat test from timetest suite
/lkml/linux_4.0/.git/rebase-apply/patch:246: new blank line at EOF.
+
warning: 1 line adds whitespace errors.

Patch11
Applying: selftests/timers: Add alarmtimer-suspend test from timetests suite
/lkml/linux_4.0/.git/rebase-apply/patch:222: new blank line at EOF.
+
warning: 1 line adds whitespace errors.

Patch18
Applying: selftests/timers: Add set-2038 test from timetest suite
/lkml/linux_4.0/.git/rebase-apply/patch:180: new blank line at EOF.
+
warning: 1 line adds whitespace errors.

thanks,
-- Shuah

-- 
Shuah Khan
Sr. Linux Kernel Developer
Open Source Innovation Group
Samsung Research America (Silicon Valley)
shuahkh@osg.samsung.com | (970) 217-8978

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 00/19 v3] Add timekeeping tests to kernel selftest
  2015-03-11 17:04     ` Shuah Khan
@ 2015-03-11 17:10       ` John Stultz
  0 siblings, 0 replies; 25+ messages in thread
From: John Stultz @ 2015-03-11 17:10 UTC (permalink / raw)
  To: Shuah Khan
  Cc: Linux Kernel Mailing List, Prarit Bhargava, Thomas Gleixner,
	Richard Cochran

On Wed, Mar 11, 2015 at 10:04 AM, Shuah Khan <shuahkh@osg.samsung.com> wrote:
> On 03/11/2015 10:53 AM, John Stultz wrote:
>> On Wed, Mar 11, 2015 at 9:43 AM, Shuah Khan <shuahkh@osg.samsung.com> wrote:
>>> On 03/02/2015 02:09 PM, John Stultz wrote:
>>>> I've hosted my timekeeping tests on github for the last few years:
>>>>       https://github.com/johnstultz-work/timetests
>>>>
>>>> but I suspect not too many folks have actually used them.
>>>>
>>>> I've been meaning to get them reworked and submitted into the
>>>> selftest infrastructure, but haven't had much time until
>>>> recently.
>>>>
>>>> I've added both the non-desctructive and destructive tests
>>>> (which set the time, possibly to strange values, or tries
>>>> to trigger historical issues that could crash the machine).
>>>> The destructive tests are run (as root, or with proper
>>>> privledge) via:
>>>>       # make run_destructive_tests
>>>>
>>>> Changes in v3:
>>>> * Lots of -Wall build warning fixups
>>>> * Handle the CROSS_COMPILER build variable properly
>>>>  (Thanks to LinusW for pointing that out)
>>>> * Integrate w/ ksft_exit_* infrastructure
>>>>
>>>> Let me know if there is any further comments or feedback!
>>>>
>>>
>>> Ran into several checkpatch warnings when I tried to queue
>>> these up for 4.1. Could you please fix them and resend.
>>
>> So the only few items I saw were:
>> 1) Lines over 80 col, usually do to long string output
>> 2) String output split over multiple lines (result of trying to fix #1
>> in a few spots)
>>      - And here I did try to split the string sanely so I didn't break
>> up the messages, so they're still grepable
>> 3) The extern char *optarg, warning. This one I can probably kill
>> since I'm including unistd.h.
>>
>> I'll take a look at #3, but #1 and #2 are basically contrary at a
>> certain point. Or do you have other ideas for resolving those
>> warnings?
>
> Here are the errors git am flagged:
>
> Patch07:
> Applying: selftests/timers: Add set-timer-lat test from timetest suite
> /lkml/linux_4.0/.git/rebase-apply/patch:246: new blank line at EOF.
> +
> warning: 1 line adds whitespace errors.
>
> Patch11
> Applying: selftests/timers: Add alarmtimer-suspend test from timetests suite
> /lkml/linux_4.0/.git/rebase-apply/patch:222: new blank line at EOF.
> +
> warning: 1 line adds whitespace errors.
>
> Patch18
> Applying: selftests/timers: Add set-2038 test from timetest suite
> /lkml/linux_4.0/.git/rebase-apply/patch:180: new blank line at EOF.
> +
> warning: 1 line adds whitespace errors.
>

Hrm.. Not sure why I didn't see those earlier.  My apologies, I will
definitely fix those up. Thanks for letting me know!

thanks
-john

^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2015-03-11 17:10 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-02 21:09 [PATCH 00/19 v3] Add timekeeping tests to kernel selftest John Stultz
2015-03-02 21:09 ` [PATCH 01/19] selftests/timers: Cleanup Makefile to make it easier to add future tests John Stultz
2015-03-02 21:09 ` [PATCH 02/19] selftests/timers: Quiet warning due to lack of return check on brk John Stultz
2015-03-02 21:09 ` [PATCH 03/19] selftests/timers: Add nanosleep test from timetest suite John Stultz
2015-03-02 21:09 ` [PATCH 04/19] selftests/timers: Add inconsistency-check test from timetests John Stultz
2015-03-02 21:09 ` [PATCH 05/19] selftests/timers: Add nsleep-lat test from timetest suite John Stultz
2015-03-02 21:09 ` [PATCH 06/19] selftests/timers: Add clock skew estimation " John Stultz
2015-03-02 21:10 ` [PATCH 07/19] selftests/timers: Add set-timer-lat " John Stultz
2015-03-02 21:10 ` [PATCH 08/19] selftests/timers: Add threaded time inconsistency " John Stultz
2015-03-02 21:10 ` [PATCH 09/19] selftests/timers: Add mqueue latency test from the " John Stultz
2015-03-02 21:10 ` [PATCH 10/19] selftests/timers: Add adjtimex validation test from " John Stultz
2015-03-02 21:10 ` [PATCH 11/19] selftests/timers: Add alarmtimer-suspend test from timetests suite John Stultz
2015-03-02 21:10 ` [PATCH 12/19] selftests/timers: Add change_skew test from timetest suite John Stultz
2015-03-02 21:10 ` [PATCH 13/19] selftests/timers: Add skew_consistency test from the timetests suite John Stultz
2015-03-02 21:10 ` [PATCH 14/19] selftests/timers: Add clocksource-switch test from timetest suite John Stultz
2015-03-02 21:10 ` [PATCH 15/19] selftests/timers: Add leap-a-day " John Stultz
2015-03-02 21:10 ` [PATCH 16/19] selftests/timers: Add leapcrash test from the " John Stultz
2015-03-02 21:10 ` [PATCH 17/19] selftests/timers: Add set-tai " John Stultz
2015-03-02 21:10 ` [PATCH 18/19] selftests/timers: Add set-2038 test from " John Stultz
2015-03-02 21:10 ` [PATCH 19/19] MAINTAINERS: Add selftests/timers to the timekeeping maintainance list John Stultz
2015-03-03 12:14 ` [PATCH 00/19 v3] Add timekeeping tests to kernel selftest Prarit Bhargava
2015-03-11 16:43 ` Shuah Khan
2015-03-11 16:53   ` John Stultz
2015-03-11 17:04     ` Shuah Khan
2015-03-11 17:10       ` John Stultz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).