forked from sysprog21/fibdrv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.c
43 lines (38 loc) · 991 Bytes
/
test.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
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <time.h>
#include <unistd.h>
#define FIB_DEV "/dev/fibonacci"
long long sz, start, real_time, k_time;
static inline long long get_ns()
{
struct timespec t;
clock_gettime(CLOCK_REALTIME, &t);
return t.tv_nsec + t.tv_sec;
}
int main()
{
char buf[128];
char write_buf[] = "testing writing";
int offset = 92;
int fd = open(FIB_DEV, O_RDWR);
if (fd < 0) {
perror("Failed to open character device");
exit(1);
}
write(fd, write_buf, strlen(write_buf));
for (int i = 0; i <= offset; i++) {
lseek(fd, i, SEEK_SET);
start = get_ns();
sz = read(fd, buf, 1);
real_time = get_ns() - start;
k_time = write(fd, write_buf, strlen(write_buf));
printf("%d %lld %lld %lld\n", i, real_time, k_time, real_time - k_time);
// printf("%s\n", buf);
}
close(fd);
return 0;
}