summaryrefslogtreecommitdiff
path: root/emulators/rtc/files/test.c
blob: 664441c20663b07ac821919ca84dda7cd88e1600 (plain) (blame)
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
#include <sys/types.h>
#include <sys/time.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <sys/ioccom.h>

#include "rtc.h"


int main(void)
{
	int rtc;
	fd_set rset;
	int i,rc;
	int ntests=100;
	struct timeval tv;
	struct timeval begin,end,delta;


	rtc = open("/dev/rtc", O_RDONLY);	
	if (rtc<0) {
		perror("/dec/rtc");
		return 1;
	}

	rc = ioctl(rtc, RTCIO_IRQP_SET, 512);
	if (rc<0) {
		perror("/dev/rtc");
		return 1;
	}

	rc = ioctl(rtc, RTCIO_PIE_ON, NULL);
	if (rc<0) {
		perror("/dev/rtc");
		return 1;
	}
	
	gettimeofday(&begin, NULL);	
	for (i=0; i<ntests; i++) {
		FD_ZERO(&rset);
		FD_SET(rtc, &rset);
		tv.tv_sec=0;
		tv.tv_usec=10000;
		rc=select(rtc+1, &rset, NULL, NULL, &tv);
	}	
	gettimeofday(&end, NULL);
	timersub(&end, &begin, &delta);
	printf("time %ld msec per test\n", (delta.tv_sec*1000+delta.tv_usec/1000)/ntests);
	return 0;
}