-
Notifications
You must be signed in to change notification settings - Fork 2
/
integrity_test2_read.c
116 lines (102 loc) · 2.28 KB
/
integrity_test2_read.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#define _GNU_SOURCE
#include<stdio.h>
#include<fcntl.h>
#include<unistd.h>
#include<time.h>
#include<string.h>
#include<malloc.h>
#include<stdlib.h>
#include<sys/mman.h>
#include<sys/time.h>
#define END_SIZE (4UL * 1024 * 1024)
const int start_size = 512;
int main(int argc, char **argv)
{
int fd, i;
unsigned long long FILE_SIZE;
size_t len;
char c;
char unit;
int size;
size_t ret;
unsigned long long count;
void *buf1 = NULL;
char *buf, *buf2;
FILE *output;
char fs_type[20];
char quill_enabled[40];
char file_size_num[20];
char filename[60];
int req_size;
if (argc < 6) {
printf("Usage: ./integrity_test2_read $FS $SCNEARIO $REQ_SIZE $FILE_SIZE $filename\n");
return 0;
}
strcpy(fs_type, argv[1]);
strcpy(quill_enabled, argv[2]);
strcpy(file_size_num, argv[4]);
len = strlen(file_size_num);
unit = file_size_num[len - 1];
file_size_num[len - 1] = '\0';
FILE_SIZE = atoll(file_size_num);
switch (unit) {
case 'K':
case 'k':
FILE_SIZE *= 1024;
break;
case 'M':
case 'm':
FILE_SIZE *= 1048576;
break;
case 'G':
case 'g':
FILE_SIZE *= 1073741824;
break;
default:
printf("ERROR: FILE_SIZE should be #K/M/G format.\n");
return 0;
break;
}
if (FILE_SIZE < 4096)
FILE_SIZE = 4096;
if (FILE_SIZE > 2147483648) // RAM disk size
FILE_SIZE = 2147483648;
strcpy(filename, argv[5]);
c = filename[0];
output = fopen(filename, "a");
if (posix_memalign(&buf1, END_SIZE, END_SIZE)) { // up to 64MB
printf("ERROR - POSIX NOMEM!\n");
return 0;
}
buf = (char *)buf1;
buf2 = malloc(END_SIZE);
fd = open("/mnt/ramdisk/test1", O_CREAT | O_RDWR, 0640);
// fd = open("/dev/null", O_WRONLY, 0640);
// fd = open("/dev/zero", O_RDONLY, 0640);
printf("fd: %d\n", fd);
req_size = atoi(argv[3]);
if (req_size > END_SIZE)
req_size = END_SIZE;
size = req_size;
memset(buf, c, size);
lseek(fd, 0, SEEK_SET);
count = FILE_SIZE / size;
printf("Start c: %c\n", c);
for (i = 0; i < count; i++) {
ret = read(fd, buf, size);
if (ret != size)
printf("ERROR: size incorrect: required %d, "
"returned %d\n", size, ret);
if (buf[0] != c || buf[size - 1] != c)
printf("ERROR: test char %c, buf start %c, buf end %c\n",
c, buf[0], buf[size - 1]);
c++;
if (c > 'z')
c = 'A';
}
close(fd);
fclose(output);
free(buf1);
free(buf2);
return 0;
}