All of lore.kernel.org
 help / color / mirror / Atom feed
From: John Stultz <john.stultz@linaro.org>
To: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Cc: John Stultz <john.stultz@linaro.org>,
	Shuah Khan <shuahkh@osg.samsung.com>,
	Prarit Bhargava <prarit@redhat.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Richard Cochran <richardcochran@gmail.com>
Subject: [PATCH 16/19] selftests/timers: Add leapcrash test from the timetest suite
Date: Mon,  2 Mar 2015 13:10:09 -0800	[thread overview]
Message-ID: <1425330612-24280-17-git-send-email-john.stultz@linaro.org> (raw)
In-Reply-To: <1425330612-24280-1-git-send-email-john.stultz@linaro.org>

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


  parent reply	other threads:[~2015-03-02 21:11 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` John Stultz [this message]
2015-03-02 21:10 ` [PATCH 17/19] selftests/timers: Add set-tai from the " 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
  -- strict thread matches above, loose matches on Subject: below --
2015-03-12  0:39 [PATCH 00/19 v4] Add timekeeping tests to kernel selftests John Stultz
2015-03-12  0:40 ` [PATCH 16/19] selftests/timers: Add leapcrash test from the timetest suite John Stultz
2015-02-25 22:32 [RFC][PATCH 00/19] Add timekeeping tests to kernel selftest John Stultz
2015-02-25 22:32 ` [PATCH 16/19] selftests/timers: Add leapcrash test from the timetest suite John Stultz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1425330612-24280-17-git-send-email-john.stultz@linaro.org \
    --to=john.stultz@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=prarit@redhat.com \
    --cc=richardcochran@gmail.com \
    --cc=shuahkh@osg.samsung.com \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.