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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
|
#define BOOST_TEST_MODULE GitFS_Core
#include <boost/test/unit_test.hpp>
#include <boost/test/data/test_case.hpp>
#include "mockDefs.h"
#include "sys/stat.h"
#include "sys/fcntl.h"
using namespace GitFS;
using namespace GitFS::Test;
namespace std {
std::ostream & operator<<(std::ostream & strm, const std::tuple<std::string, int> &)
{
return strm;
}
template<typename T>
std::ostream & operator<<(std::ostream & strm, const std::vector<T> & v)
{
strm << "[ ";
for (const auto & e : v) {
if (&e != &v.front()) {
strm << ", ";
}
strm << e;
}
strm << " ]";
return strm;
}
}
#define BOOST_CHECK_THROW_SYSTEMERROR(CODE, ERRNO) \
try { \
BOOST_TEST_CHECKPOINT(""); \
[&](){ CODE ; }(); \
BOOST_ERROR("No exception thrown, NetFS::SystemError expected"); \
} catch (const NetFS::SystemError & se) { \
BOOST_CHECK_EQUAL(se.syserrno, ERRNO); \
} catch (...) { \
BOOST_ERROR("NetFS::SystemError not thrown"); \
}\
BOOST_TEST_GLOBAL_FIXTURE(Service);
BOOST_FIXTURE_TEST_SUITE(client, Client);
// TODO
BOOST_AUTO_TEST_SUITE_END();
BOOST_FIXTURE_TEST_SUITE(volume, VolumeClient);
BOOST_AUTO_TEST_CASE( unsupported_rofs_ops )
{
BOOST_CHECK_THROW_SYSTEMERROR(v->create(env, {}, {}, {}), EROFS);
BOOST_CHECK_THROW_SYSTEMERROR(v->truncate(env, {}, {}), EROFS);
BOOST_CHECK_THROW_SYSTEMERROR(v->unlink(env, {}), EROFS);
BOOST_CHECK_THROW_SYSTEMERROR(v->mkdir(env, {}, {}), EROFS);
BOOST_CHECK_THROW_SYSTEMERROR(v->rmdir(env, {}), EROFS);
BOOST_CHECK_THROW_SYSTEMERROR(v->mknod(env, {}, {}, {}), EROFS);
BOOST_CHECK_THROW_SYSTEMERROR(v->symlink(env, {}, {}), EROFS);
BOOST_CHECK_THROW_SYSTEMERROR(v->link(env, {}, {}), EROFS);
BOOST_CHECK_THROW_SYSTEMERROR(v->rename(env, {}, {}), EROFS);
BOOST_CHECK_THROW_SYSTEMERROR(v->chmod(env, {}, {}), EROFS);
BOOST_CHECK_THROW_SYSTEMERROR(v->chown(env, {}, {}, {}), EROFS);
BOOST_CHECK_THROW_SYSTEMERROR(v->utimens(env, {}, {}, {}, {}, {}), EROFS);
}
BOOST_AUTO_TEST_CASE( statfs )
{
// Don't know what this should return, but it shouldn't error given a valid path
BOOST_CHECK_THROW_SYSTEMERROR(v->statfs(env, ""), EINVAL);
BOOST_CHECK_NO_THROW(v->statfs(env, "/"));
}
namespace btdata = boost::unit_test::data;
const auto INVALIDPATHS = btdata::make({
""
});
const auto BADPATHS = btdata::make({
"/.",
"/../",
".",
"..",
"../",
});
const auto DIRPATHS = btdata::make({
"/",
"/src",
"/unittests",
"/unittests/fixtures",
});
const auto REGPATHS = btdata::make({
"/.gitignore",
"/Jamroot.jam",
"/src/Jamfile.jam",
"/unittests/Jamfile.jam",
});
const auto EXECPATHS = btdata::make({
"/unittests/fixtures/executable",
});
const auto LINKPATHS = btdata::make({
"/unittests/fixtures/symlink",
});
const auto MISSINGPATHS = btdata::make({
"/.missing",
"/missing",
"/src/missing",
"/unittests/fixtures/missing",
});
BOOST_DATA_TEST_CASE(accessWrite, INVALIDPATHS + DIRPATHS + REGPATHS + EXECPATHS + LINKPATHS + MISSINGPATHS + BADPATHS, path)
{
BOOST_CHECK_EQUAL(EACCES, v->access(env, path, W_OK));
}
BOOST_DATA_TEST_CASE(accessDirs, DIRPATHS, path)
{
BOOST_CHECK_EQUAL(0, v->access(env, path, R_OK));
BOOST_CHECK_EQUAL(0, v->access(env, path, X_OK));
}
BOOST_DATA_TEST_CASE(accessRead, REGPATHS, path)
{
BOOST_CHECK_EQUAL(0, v->access(env, path, R_OK));
BOOST_CHECK_EQUAL(EACCES, v->access(env, path, X_OK));
}
BOOST_DATA_TEST_CASE(accessLink, LINKPATHS, path)
{
BOOST_CHECK_EQUAL(0, v->access(env, path, R_OK));
BOOST_CHECK_EQUAL(0, v->access(env, path, X_OK));
}
BOOST_DATA_TEST_CASE(accessExec, EXECPATHS, path)
{
BOOST_CHECK_EQUAL(0, v->access(env, path, R_OK));
BOOST_CHECK_EQUAL(0, v->access(env, path, X_OK));
}
BOOST_DATA_TEST_CASE( accessInval, INVALIDPATHS * btdata::make({ R_OK, X_OK }), path, mode)
{
BOOST_CHECK_EQUAL(EINVAL, v->access(env, path, mode));
}
BOOST_DATA_TEST_CASE( accessBad, BADPATHS * btdata::make({ R_OK, X_OK }), path, mode)
{
BOOST_CHECK_EQUAL(ENOENT, v->access(env, path, mode));
}
BOOST_DATA_TEST_CASE( statInval, INVALIDPATHS, path )
{
BOOST_CHECK_THROW_SYSTEMERROR(v->getattr(env, path), EINVAL);
}
BOOST_DATA_TEST_CASE( statBad, BADPATHS, path )
{
BOOST_CHECK_THROW_SYSTEMERROR(v->getattr(env, path), ENOENT);
}
const auto DIRMODE = S_IFDIR | S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
const auto FILEMODE = S_IFREG | S_IRUSR | S_IRGRP | S_IROTH;
const auto EXECMODE = FILEMODE | S_IXUSR | S_IXGRP | S_IXOTH;
const auto LINKMODE = S_IFLNK | S_IRUSR | S_IRGRP | S_IROTH;
const time_t COMMIT_TIME = 1563621030;
const std::string USER = "root";
const std::string GROUP = "root";
BOOST_DATA_TEST_CASE( statDirs, DIRPATHS, path )
{
const auto attr = v->getattr(env, path);
BOOST_CHECK_EQUAL(DIRMODE, attr.mode);
BOOST_CHECK_EQUAL(COMMIT_TIME, attr.mtime);
BOOST_CHECK_EQUAL(COMMIT_TIME, attr.ctime);
BOOST_CHECK_EQUAL(COMMIT_TIME, attr.atime);
BOOST_CHECK_EQUAL(0, attr.size);
BOOST_CHECK_EQUAL(USER, attr.uid);
BOOST_CHECK_EQUAL(GROUP, attr.gid);
}
BOOST_DATA_TEST_CASE( statFiles, REGPATHS, path )
{
const auto attr = v->getattr(env, path);
BOOST_CHECK_EQUAL(FILEMODE, attr.mode);
BOOST_CHECK_EQUAL(COMMIT_TIME, attr.mtime);
BOOST_CHECK_EQUAL(COMMIT_TIME, attr.ctime);
BOOST_CHECK_EQUAL(COMMIT_TIME, attr.atime);
BOOST_CHECK_LE(4, attr.size);
BOOST_CHECK_EQUAL(USER, attr.uid);
BOOST_CHECK_EQUAL(GROUP, attr.gid);
}
BOOST_DATA_TEST_CASE( statExecs, EXECPATHS, path )
{
const auto attr = v->getattr(env, path);
BOOST_CHECK_EQUAL(EXECMODE, attr.mode);
BOOST_CHECK_EQUAL(COMMIT_TIME, attr.mtime);
BOOST_CHECK_EQUAL(COMMIT_TIME, attr.ctime);
BOOST_CHECK_EQUAL(COMMIT_TIME, attr.atime);
BOOST_CHECK_LE(4, attr.size);
BOOST_CHECK_EQUAL(USER, attr.uid);
BOOST_CHECK_EQUAL(GROUP, attr.gid);
}
BOOST_DATA_TEST_CASE( statSymlink, LINKPATHS, path )
{
const auto attr = v->getattr(env, path);
BOOST_CHECK_EQUAL(LINKMODE, attr.mode);
BOOST_CHECK_EQUAL(COMMIT_TIME, attr.mtime);
BOOST_CHECK_EQUAL(COMMIT_TIME, attr.ctime);
BOOST_CHECK_EQUAL(COMMIT_TIME, attr.atime);
BOOST_CHECK_EQUAL(0, attr.size);
BOOST_CHECK_EQUAL(USER, attr.uid);
BOOST_CHECK_EQUAL(GROUP, attr.gid);
}
BOOST_DATA_TEST_CASE( readlinkInval, INVALIDPATHS + DIRPATHS + REGPATHS + EXECPATHS, path )
{
BOOST_CHECK_THROW_SYSTEMERROR(v->readlink(env, path), EINVAL);
}
BOOST_DATA_TEST_CASE( readlinkBad, BADPATHS + MISSINGPATHS, path )
{
BOOST_CHECK_THROW_SYSTEMERROR(v->readlink(env, path), ENOENT);
}
BOOST_DATA_TEST_CASE( readlink, LINKPATHS ^ btdata::make({ "executable" }), path, target )
{
BOOST_CHECK_EQUAL(target, v->readlink(env, path));
}
BOOST_DATA_TEST_CASE( openDirInval, INVALIDPATHS, path )
{
BOOST_CHECK_THROW_SYSTEMERROR(v->opendir(env, path), EINVAL);
}
BOOST_DATA_TEST_CASE( openDirBad, BADPATHS + MISSINGPATHS, path )
{
BOOST_CHECK_THROW_SYSTEMERROR(v->opendir(env, path), ENOENT);
}
BOOST_DATA_TEST_CASE( openDirNotDir, REGPATHS + LINKPATHS + EXECPATHS, path )
{
BOOST_CHECK_THROW_SYSTEMERROR(v->opendir(env, path), ENOTDIR);
}
const auto DIRCONTENTS = btdata::make<std::vector<std::string>>({
{".gitignore", "Jamroot.jam", "src", "unittests"},
{"Jamfile.jam", "blob.cpp", "blob.h", "dir.cpp", "dir.h", "git.cpp", "git.h", "main.cpp", "repo.cpp", "repo.h", "repoList.cpp", "repoList.h"},
{"Jamfile.jam", "core.cpp", "fixtures", "mockDefs.cpp", "mockDefs.h"},
{"executable", "symlink"},
});
BOOST_DATA_TEST_CASE( openDirRead, DIRPATHS ^ DIRCONTENTS, path, contents )
{
auto dir = v->opendir(env, path);
BOOST_REQUIRE(dir);
auto names = dir->readdir();
std::sort(names.begin(), names.end());
BOOST_CHECK_EQUAL_COLLECTIONS(names.begin(), names.end(), contents.begin(), contents.end());
dir->close();
}
const auto DIRCONTENTMODES = btdata::make<std::vector<std::tuple<std::string, int>>>({
{{".gitignore", FILEMODE}, {"Jamroot.jam", FILEMODE}, {"src",DIRMODE}, {"unittests", DIRMODE}},
{{"Jamfile.jam", FILEMODE}, {"blob.cpp", FILEMODE}, {"blob.h", FILEMODE}, {"dir.cpp", FILEMODE}, {"dir.h", FILEMODE}, {"git.cpp", FILEMODE}, {"git.h", FILEMODE}, {"main.cpp", FILEMODE}, {"repo.cpp", FILEMODE}, {"repo.h", FILEMODE}, {"repoList.cpp", FILEMODE}, {"repoList.h", FILEMODE}},
{{"Jamfile.jam", FILEMODE}, {"core.cpp", FILEMODE}, {"fixtures", DIRMODE}, {"mockDefs.cpp", FILEMODE}, {"mockDefs.h", FILEMODE}},
{{"executable", EXECMODE}, {"symlink", LINKMODE}},
});
BOOST_DATA_TEST_CASE( openDirList, DIRPATHS ^ DIRCONTENTMODES, path, contents )
{
auto dir = v->opendir(env, path);
BOOST_REQUIRE(dir);
auto dir2 = Ice::checkedCast<NetFS::DirectoryV2Prx>(dir);
BOOST_REQUIRE(dir2);
auto list = dir2->listdir();
BOOST_REQUIRE_EQUAL(contents.size(), list.size());
for (const auto & c : contents) {
auto li = list.find(std::get<0>(c));
BOOST_REQUIRE(li != list.end());
BOOST_CHECK_EQUAL(li->second.mode, std::get<1>(c));
BOOST_CHECK_EQUAL(COMMIT_TIME, li->second.mtime);
BOOST_CHECK_EQUAL(COMMIT_TIME, li->second.ctime);
BOOST_CHECK_EQUAL(COMMIT_TIME, li->second.atime);
BOOST_CHECK_EQUAL(USER, li->second.uid);
BOOST_CHECK_EQUAL(GROUP, li->second.gid);
if (S_ISREG(li->second.mode)) {
BOOST_CHECK_LE(4, li->second.size);
}
}
dir->close();
}
BOOST_DATA_TEST_CASE( openInval, INVALIDPATHS, path )
{
BOOST_CHECK_THROW_SYSTEMERROR(v->open(env, path, O_RDONLY), EINVAL);
}
BOOST_DATA_TEST_CASE( openBad, BADPATHS + MISSINGPATHS, path )
{
BOOST_CHECK_THROW_SYSTEMERROR(v->open(env, path, O_RDONLY), ENOENT);
}
BOOST_DATA_TEST_CASE( openNotFileDir, DIRPATHS, path )
{
BOOST_CHECK_THROW_SYSTEMERROR(v->open(env, path, O_RDONLY), EISDIR);
}
BOOST_DATA_TEST_CASE( openNotFileLink, LINKPATHS, path )
{
BOOST_CHECK_THROW_SYSTEMERROR(v->open(env, path, O_RDONLY), ELOOP);
}
BOOST_DATA_TEST_CASE( openFileROFSOps, REGPATHS + EXECPATHS, path )
{
auto f = v->open(env, path, O_RDONLY);
BOOST_REQUIRE(f);
BOOST_CHECK_THROW_SYSTEMERROR(f->ftruncate(env, {}), EROFS);
BOOST_CHECK_THROW_SYSTEMERROR(f->write({}, {}, {}), EROFS);
f->close();
}
BOOST_DATA_TEST_CASE( openFileGetAttr, REGPATHS + EXECPATHS, path )
{
auto f = v->open(env, path, O_RDONLY);
BOOST_REQUIRE(f);
const auto attr = f->fgetattr(env);
BOOST_CHECK(S_ISREG(attr.mode));
BOOST_CHECK_EQUAL(attr.size, attr.blocks);
BOOST_CHECK_EQUAL(1, attr.blockSize);
BOOST_CHECK_LE(4, attr.size);
BOOST_CHECK_EQUAL(USER, attr.uid);
BOOST_CHECK_EQUAL(GROUP, attr.gid);
f->close();
}
BOOST_DATA_TEST_CASE( openFileRead, REGPATHS + EXECPATHS, path )
{
auto f = v->open(env, path, O_RDONLY);
BOOST_REQUIRE(f);
const auto attr = f->fgetattr(env);
const auto readAll = f->read(0, attr.size);
BOOST_CHECK_EQUAL(attr.size, readAll.size());
const auto readTrunc = f->read(0, BUFSIZ);
BOOST_CHECK_EQUAL(attr.size, readTrunc.size());
const auto readBeyond = f->read(BUFSIZ, BUFSIZ);
BOOST_CHECK(readBeyond.empty());
f->close();
}
BOOST_AUTO_TEST_SUITE_END();
|