-
Notifications
You must be signed in to change notification settings - Fork 31
/
j-lang167.cpp
182 lines (145 loc) · 4.6 KB
/
j-lang167.cpp
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <string>
#include <iostream>
#include <dirent.h>
#include <cstring>
#include <errno.h>
#include <attr/xattr.h>
#include "../BaseTestCase.h"
#include "../../user_tools/api/workload.h"
#include "../../user_tools/api/actions.h"
using fs_testing::tests::DataTestResult;
using fs_testing::user_tools::api::WriteData;
using fs_testing::user_tools::api::WriteDataMmap;
using fs_testing::user_tools::api::Checkpoint;
using std::string;
#define TEST_FILE_PERMS ((mode_t) (S_IRWXU | S_IRWXG | S_IRWXO))
namespace fs_testing {
namespace tests {
class testName: public BaseTestCase {
public:
virtual int setup() override {
test_path = mnt_dir_ ;
A_path = mnt_dir_ + "/A";
AC_path = mnt_dir_ + "/A/C";
B_path = mnt_dir_ + "/B";
foo_path = mnt_dir_ + "/foo";
bar_path = mnt_dir_ + "/bar";
Afoo_path = mnt_dir_ + "/A/foo";
Abar_path = mnt_dir_ + "/A/bar";
Bfoo_path = mnt_dir_ + "/B/foo";
Bbar_path = mnt_dir_ + "/B/bar";
ACfoo_path = mnt_dir_ + "/A/C/foo";
ACbar_path = mnt_dir_ + "/A/C/bar";
return 0;
}
virtual int run( int checkpoint ) override {
test_path = mnt_dir_ ;
A_path = mnt_dir_ + "/A";
AC_path = mnt_dir_ + "/A/C";
B_path = mnt_dir_ + "/B";
foo_path = mnt_dir_ + "/foo";
bar_path = mnt_dir_ + "/bar";
Afoo_path = mnt_dir_ + "/A/foo";
Abar_path = mnt_dir_ + "/A/bar";
Bfoo_path = mnt_dir_ + "/B/foo";
Bbar_path = mnt_dir_ + "/B/bar";
ACfoo_path = mnt_dir_ + "/A/C/foo";
ACbar_path = mnt_dir_ + "/A/C/bar";
int local_checkpoint = 0 ;
if ( mkdir(A_path.c_str() , 0777) < 0){
return errno;
}
int fd_Afoo = cm_->CmOpen(Afoo_path.c_str() , O_RDWR|O_CREAT , 0777);
if ( fd_Afoo < 0 ) {
cm_->CmClose( fd_Afoo);
return errno;
}
cm_->CmClose(fd_Afoo);
fd_Afoo = cm_->CmOpen(Afoo_path.c_str() , O_RDWR|O_DIRECT|O_SYNC , 0777);
if ( fd_Afoo < 0 ) {
cm_->CmClose( fd_Afoo);
return errno;
}
void* data_Afoo;
if (posix_memalign(&data_Afoo , 4096, 32768 ) < 0) {
return errno;
}
int offset_Afoo = 0;
int to_write_Afoo = 32768 ;
const char *text_Afoo = "ddddddddddklmnopqrstuvwxyz123456";
while (offset_Afoo < 32768){
if (to_write_Afoo < 32){
memcpy((char *)data_Afoo+ offset_Afoo, text_Afoo, to_write_Afoo);
offset_Afoo += to_write_Afoo;
}
else {
memcpy((char *)data_Afoo+ offset_Afoo,text_Afoo, 32);
offset_Afoo += 32;
}
}
if ( pwrite ( fd_Afoo, data_Afoo, 32768, 0) < 0){
cm_->CmClose( fd_Afoo);
return errno;
}
cm_->CmClose(fd_Afoo);
int fd_Abar = cm_->CmOpen(Abar_path.c_str() , O_RDWR|O_CREAT , 0777);
if ( fd_Abar < 0 ) {
cm_->CmClose( fd_Abar);
return errno;
}
if ( cm_->CmFsync( fd_Abar) < 0){
return errno;
}
if ( cm_->CmCheckpoint() < 0){
return -1;
}
local_checkpoint += 1;
if (local_checkpoint == checkpoint) {
return 1;
}
if ( cm_->CmClose ( fd_Abar) < 0){
return errno;
}
return 0;
}
virtual int check_test( unsigned int last_checkpoint, DataTestResult *test_result) override {
test_path = mnt_dir_ ;
A_path = mnt_dir_ + "/A";
AC_path = mnt_dir_ + "/A/C";
B_path = mnt_dir_ + "/B";
foo_path = mnt_dir_ + "/foo";
bar_path = mnt_dir_ + "/bar";
Afoo_path = mnt_dir_ + "/A/foo";
Abar_path = mnt_dir_ + "/A/bar";
Bfoo_path = mnt_dir_ + "/B/foo";
Bbar_path = mnt_dir_ + "/B/bar";
ACfoo_path = mnt_dir_ + "/A/C/foo";
ACbar_path = mnt_dir_ + "/A/C/bar";
return 0;
}
private:
string test_path;
string A_path;
string AC_path;
string B_path;
string foo_path;
string bar_path;
string Afoo_path;
string Abar_path;
string Bfoo_path;
string Bbar_path;
string ACfoo_path;
string ACbar_path;
};
} // namespace tests
} // namespace fs_testing
extern "C" fs_testing::tests::BaseTestCase *test_case_get_instance() {
return new fs_testing::tests::testName;
}
extern "C" void test_case_delete_instance(fs_testing::tests::BaseTestCase *tc) {
delete tc;
}