timestress.c
1.95 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include "testlib.c"
char pname[256];
char fname[256];
char *myname;
char *dname = "/dev/usb/bbrdb0";
void
handler(int sig)
{
printf("got signal %d\n", sig);
signal(sig, handler);
}
int
main(int argc, char **argv)
{
BBCHandle h;
int loops = 0;
int cardsize, freeblks, reservedblks, badblks;
time_t curtime;
struct stat sb;
char *buf;
int len;
int fd;
int rv;
int i = 0;
myname = argv[0];
strncpy(pname, myname, sizeof(pname));
if (argc > 1)
dname = argv[argc - 1];
printf("%s: stress test BBCSetTime and file operations\n", pname);
h = BBCInit(dname, BBC_SYNC);
printf("%s: BBCInit(%s) returns %d\n", pname, dname, h);
if (h < 0) exit(1);
while (!BBCCardPresent(h)) {
if ((++i & 0x1ff) == 0)
printf("%s: no card present ... wait\n", pname);
}
printf("%s: card is present\n", pname);
if ((rv = BBCStats(h, &cardsize, &reservedblks, &freeblks, &badblks)) < 0) {
printf("%s: BBCStats returns %d\n", pname, rv);
exit(1);
}
printf("%s: BBCStats cardsize %d, freeblks %d\n", pname, cardsize, freeblks);
/*
* Create one block file
*/
sprintf(fname, "tstest.%d", getpid());
mkfile(fname, BLK_SIZE);
if ((fd = open(fname, O_RDONLY)) < 0) {
perror(fname);
exit(1);
}
if (fstat(fd, &sb) < 0) {
perror(fname);
exit(1);
}
len = sb.st_size;
if ((buf = malloc(len)) == NULL) {
perror("malloc");
exit(1);
}
if ((rv = read(fd, buf, len)) < len) {
fprintf(stderr, "read %s len %d returns %d\n", fname, len, rv);
exit(1);
}
close(fd);
unlink(fname);
/* Test receipt of signals during nanosleep in BBCSetTime */
signal(SIGUSR1, handler);
while (1) {
loops++;
curtime = time(NULL);
if ((rv = BBCSetTime(h, curtime)) < 0) {
printf("%s: BBCSetTime returns %d (loops %d)\n", pname, rv, loops);
exit(1);
}
if ((rv = BBCStoreUserData(h, buf, len)) < 0) {
printf("%s: BBCStoreUserData fails: %d\n", pname, rv);
exit(1);
}
if ((loops & 0xf) == 0)
printf("%s: completed loops %d\n", pname, loops);
}
exit(0);
}