forked from checkpoint-restore/criu
/
file-validation-chksm03.c
74 lines (59 loc) · 1.42 KB
/
file-validation-chksm03.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
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "zdtmtst.h"
const char *test_doc = "File validation test for checksum (checksum-first) with checksum parameter less than CHSKM_CHUNK_SIZE (10MB)";
const char *test_author = "Ajay Bharadwaj <ajayrbharadwaj@gmail.com>";
char *filename;
TEST_OPTION(filename, string, "file name", 1);
#define BUF_SIZE 104857600
int main(int argc, char **argv)
{
int fd;
void *buf;
uint32_t crc;
test_init(argc, argv);
fd = open(filename, O_RDWR | O_CREAT, 0666);
if (fd < 0) {
pr_perror("Can't open %s", filename);
return 1;
}
buf = mmap(NULL, BUF_SIZE, PROT_WRITE | PROT_READ,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (buf == MAP_FAILED) {
pr_perror("mmap() failed");
return 1;
}
crc = ~0;
datagen(buf, BUF_SIZE, &crc);
if (write_data(fd, buf, BUF_SIZE)) {
pr_perror("write() failed");
return 1;
}
test_daemon();
test_waitsig();
if (lseek(fd, 0, SEEK_SET) < 0)
{
pr_perror("lseek() failed");
return -1;
}
if (read_data(fd, buf, BUF_SIZE)) {
pr_perror("read() failed");
return 1;
}
crc = ~0;
if (datachk(buf, BUF_SIZE, &crc)) {
fail("Data in file has been changed\n");
return 1;
}
if (close(fd) < 0) {
pr_perror("Can't close %s", filename);
return 1;
}
pass();
return 0;
}