-
Notifications
You must be signed in to change notification settings - Fork 0
/
bigg.c
82 lines (75 loc) · 1.87 KB
/
bigg.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "types.h"
#include "stat.h"
#include "user.h"
#include "fs.h"
#include "fcntl.h"
int
main(int argc, char *argv[])
{
int fd, i, j;
int r;
int total;
char *path = (argc > 1) ? argv[1] : "hugefile";
char data[512];
char buf[512];
printf(1, "hugefiletest starting\n");
const int sz = sizeof(data);
for (i = 0; i < sz; i++) {
data[i] = i % 128;
}
printf(1, "1. create test\n");
fd = open(path, O_CREATE | O_RDWR);
for(i = 0; i < 1024; i++){
if (i % 100 == 0){
printf(1, "%d bytes written\n", i * 512);
}
if ((r = write(fd, data, sizeof(data))) != sizeof(data)){
printf(1, "write returned %d : failed\n", r);
exit();
}
}
printf(1, "%d bytes written\n", 1024 * 512);
close(fd);
printf(1, "2. read test\n");
fd = open(path, O_RDONLY);
for (i = 0; i < 1024; i++){
if (i % 100 == 0){
printf(1, "%d bytes read\n", i * 512);
}
if ((r = read(fd, buf, sizeof(data))) != sizeof(data)){
printf(1, "read returned %d : failed\n", r);
exit();
}
for (j = 0; j < sz; j++) {
if (buf[j] != data[j]) {
printf(1, "data inconsistency detected\n");
exit();
}
}
}
printf(1, "%d bytes read\n", 1024 * 512);
close(fd);
printf(1, "3. stress test\n");
total = 0;
for (i = 0; i < 20; i++) {
printf(1, "stress test...%d \n", i);
if(unlink(path) < 0){
printf(1, "rm: %s failed to delete\n", path);
exit();
}
fd = open(path, O_CREATE | O_RDWR);
for(j = 0; j < 1024; j++){
if (j % 100 == 0){
printf(1, "%d bytes totally written\n", total);
}
if ((r = write(fd, data, sizeof(data))) != sizeof(data)){
printf(1, "write returned %d : failed\n", r);
exit();
}
total += sizeof(data);
}
printf(1, "%d bytes written\n", total);
close(fd);
}
exit();
}