forked from adamacosta/rvm_tests
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrvm_test5.c
More file actions
85 lines (64 loc) · 1.67 KB
/
rvm_test5.c
File metadata and controls
85 lines (64 loc) · 1.67 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
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <fcntl.h>
#include "rvm.h"
/* proc1 writes some data, commits it, then exits */
void proc1() {
rvm_t rvm;
trans_t trans;
char* segs[1];
rvm = rvm_init("rvm_segments");
rvm_destroy(rvm, "testseg");
segs[0] = (char *) rvm_map(rvm, "testseg", 10000);
trans = rvm_begin_trans(rvm, 1, (void **) segs);
rvm_about_to_modify(trans, segs[0], 0, 100);
sprintf(segs[0], "hello, world");
rvm_about_to_modify(trans, segs[0], 1000, 100);
sprintf(segs[0]+1000, "hello, world");
rvm_abort_trans(trans);
trans = rvm_begin_trans(rvm, 1, (void **) segs);
rvm_about_to_modify(trans, segs[0], 0, 100);
sprintf(segs[0], "hello, world");
rvm_about_to_modify(trans, segs[0], 1000, 100);
sprintf(segs[0]+1000, "hello, world");
rvm_commit_trans(trans);
abort();
}
/* proc2 opens the segments and reads from them */
void proc2() {
char* segs[1];
rvm_t rvm;
rvm = rvm_init("rvm_segments");
segs[0] = (char *) rvm_map(rvm, "testseg", 10000);
if(strcmp(segs[0], "hello, world")) {
fprintf(stderr,
"A second process did not find what the first had written.\n");
fprintf(stderr, "found %s\n", segs[0]);
exit(2);
}
if(strcmp(segs[0]+1000, "hello, world")) {
fprintf(stderr,
"A second process did not find what the first had written.\n");
fprintf(stderr, "found %s\n", segs[0]+1000);
exit(3);
}
}
int main(int argc, char **argv) {
int pid;
pid = fork();
if(pid < 0) {
perror("fork");
exit(2);
}
if(pid == 0) {
proc1();
exit(EXIT_SUCCESS);
}
waitpid(pid, NULL, 0);
proc2();
printf("Ok\n");
return 0;
}