/
rtc.c
62 lines (52 loc) · 1.12 KB
/
rtc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <stdio.h>
#include <linux/rtc.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/time.h>
#include <unistd.h>
#include <stdlib.h>
#include "zdtmtst.h"
#define TEST_HZ 4
#define NR_FAILS 10
int main(int argc, char **argv)
{
unsigned long data;
long delta;
int fd, fail = NR_FAILS, to_pass = NR_FAILS;
struct timeval start, end;
test_init(argc, argv);
fd = open("/dev/rtc", O_RDWR);
if (fd < 0) {
pr_perror("open");
return 1;
}
if (ioctl(fd, RTC_IRQP_SET, TEST_HZ) == -1) {
pr_perror("RTC_IRQP_SET");
return 1;
}
if (ioctl(fd, RTC_PIE_ON, 0) == -1) {
pr_perror("RTC_PIE_ON");
return 1;
}
test_daemon();
gettimeofday(&start, NULL);
start.tv_usec += start.tv_sec * 1000000;
while (test_go() || to_pass--) {
if (read(fd, &data, sizeof(unsigned long)) == -1)
return 1;
gettimeofday(&end, NULL);
end.tv_usec += end.tv_sec * 1000000;
delta = end.tv_usec - start.tv_usec;
if (labs(delta - 1000000 / TEST_HZ) > 100000) {
pr_perror("delta = %ld", delta);
fail--;
if (fail == 0)
return 1;
}
start = end;
}
pass();
return 0;
}