Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools, update rtctest.c to verify passage of time

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>
Acked-by: John Stultz <john.stultz@linaro.org>
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
Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>

authored by

Prarit Bhargava and committed by
Shuah Khan
0b63accf 4a5fd815

+13
+13
tools/testing/selftests/timers/rtctest.c
··· 36 36 unsigned long tmp, data; 37 37 struct rtc_time rtc_tm; 38 38 const char *rtc = default_rtc; 39 + struct timeval start, end, diff; 39 40 40 41 switch (argc) { 41 42 case 2: ··· 231 230 } 232 231 233 232 for (i=1; i<21; i++) { 233 + gettimeofday(&start, NULL); 234 234 /* This blocks */ 235 235 retval = read(fd, &data, sizeof(unsigned long)); 236 236 if (retval == -1) { 237 237 perror("read"); 238 238 exit(errno); 239 239 } 240 + gettimeofday(&end, NULL); 241 + timersub(&end, &start, &diff); 242 + if (diff.tv_sec > 0 || 243 + diff.tv_usec > ((1000000L / tmp) * 1.10)) { 244 + fprintf(stderr, "\nPIE delta error: %ld.%06ld should be close to 0.%06ld\n", 245 + diff.tv_sec, diff.tv_usec, 246 + (1000000L / tmp)); 247 + fflush(stdout); 248 + exit(-1); 249 + } 250 + 240 251 fprintf(stderr, " %d",i); 241 252 fflush(stderr); 242 253 irqcount++;