mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Prarit Bhargava <prarit@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: Prarit Bhargava <prarit@redhat.com>,
	corbet@lwn.net, rtc-linux@googlegroups.com,
	linux-doc@vger.kernel.org, a.zummo@towertech.it,
	john.stultz@linaro.org, shuahkh@osg.samsung.com
Subject: [PATCH 2/2 v2] tools, update rtctest.c to verify passage of time
Date: Wed, 18 Mar 2015 15:46:33 -0400	[thread overview]
Message-ID: <1426707993-18714-3-git-send-email-prarit@redhat.com> (raw)
In-Reply-To: <1426707993-18714-1-git-send-email-prarit@redhat.com>

rtctest.c checks to see if PIE is functioning by testing if 20 interrupts occur
at rates from 2HZ to 64HZ.  While this check is good, it does not check to
see if the correct amount of time has actually passed.  This misses
situations where the RTC may be operating at a higher or lower frequency
than expected.

This patch introduces a simple check to verify if the time passed is
less than 10% of what was programmed into the RTC.

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
Cc: corbet@lwn.net
Cc: rtc-linux@googlegroups.com
Cc: linux-doc@vger.kernel.org
Cc: a.zummo@towertech.it
Cc: prarit@redhat.com
Cc: john.stultz@linaro.org
Cc: shuahkh@osg.samsung.com
---
 tools/testing/selftests/timers/rtctest.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/tools/testing/selftests/timers/rtctest.c b/tools/testing/selftests/timers/rtctest.c
index 1e06f46..d80ae85 100644
--- a/tools/testing/selftests/timers/rtctest.c
+++ b/tools/testing/selftests/timers/rtctest.c
@@ -36,6 +36,7 @@ int main(int argc, char **argv)
 	unsigned long tmp, data;
 	struct rtc_time rtc_tm;
 	const char *rtc = default_rtc;
+	struct timeval start, end, diff;
 
 	switch (argc) {
 	case 2:
@@ -230,12 +231,24 @@ test_PIE:
 		}
 
 		for (i=1; i<21; i++) {
+			gettimeofday(&start, NULL);
 			/* This blocks */
 			retval = read(fd, &data, sizeof(unsigned long));
 			if (retval == -1) {
 				perror("read");
 				exit(errno);
 			}
+			gettimeofday(&end, NULL);
+			timersub(&end, &start, &diff);
+			if (diff.tv_sec > 0 ||
+			    diff.tv_usec > ((1000000L / tmp) * 1.10)) {
+				fprintf(stderr, "\nPIE delta error: %ld.%06ld should be close to 0.%06ld\n",
+				       diff.tv_sec, diff.tv_usec,
+				       (1000000L / tmp));
+				fflush(stdout);
+				exit(-1);
+			}
+
 			fprintf(stderr, " %d",i);
 			fflush(stderr);
 			irqcount++;
-- 
1.8.3.1


  parent reply	other threads:[~2015-03-18 19:48 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-18 19:46 [PATCH 0/2 v2] Split Documentation/rtc.txt Prarit Bhargava
2015-03-18 19:46 ` [PATCH 1/2 v2] Documentation, split up rtc.txt into documentation and test file Prarit Bhargava
2015-03-18 20:05   ` John Stultz
2015-03-19 18:24   ` Shuah Khan
2015-03-19 19:00     ` John Stultz
2015-03-19 19:25       ` Shuah Khan
2015-03-19 20:25     ` Jonathan Corbet
2015-03-19 20:27       ` Shuah Khan
2015-03-19 21:36         ` Shuah Khan
2015-03-20 10:51           ` Prarit Bhargava
2015-03-23 20:32           ` Prarit Bhargava
2015-03-25  4:25             ` Shuah Khan
2015-03-18 19:46 ` Prarit Bhargava [this message]
2015-03-18 20:08   ` [PATCH 2/2 v2] tools, update rtctest.c to verify passage of time 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=1426707993-18714-3-git-send-email-prarit@redhat.com \
    --to=prarit@redhat.com \
    --cc=a.zummo@towertech.it \
    --cc=corbet@lwn.net \
    --cc=john.stultz@linaro.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rtc-linux@googlegroups.com \
    --cc=shuahkh@osg.samsung.com \
    /path/to/YOUR_REPLY

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

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

Powered by JetHome