1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2019 The FreeBSD Foundation 5 * 6 * This software was developed by BFF Storage Systems, LLC under sponsorship 7 * from the FreeBSD Foundation. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 */ 30 31 extern "C" { 32 #include <sys/param.h> 33 #include <sys/mman.h> 34 #include <sys/module.h> 35 #include <sys/sysctl.h> 36 #include <sys/wait.h> 37 38 #include <dirent.h> 39 #include <fcntl.h> 40 #include <grp.h> 41 #include <pwd.h> 42 #include <semaphore.h> 43 #include <unistd.h> 44 } 45 46 #include <gtest/gtest.h> 47 48 #include "mockfs.hh" 49 #include "utils.hh" 50 51 using namespace testing; 52 53 /* 54 * The default max_write is set to this formula in libfuse, though 55 * individual filesystems can lower it. The "- 4096" was added in 56 * commit 154ffe2, with the commit message "fix". 57 */ 58 const uint32_t libfuse_max_write = 32 * getpagesize() + 0x1000 - 4096; 59 60 /* Check that fusefs(4) is accessible and the current user can mount(2) */ 61 void check_environment() 62 { 63 const char *devnode = "/dev/fuse"; 64 const char *bsdextended_node = "security.mac.bsdextended.enabled"; 65 int bsdextended_val = 0; 66 size_t bsdextended_size = sizeof(bsdextended_val); 67 int bsdextended_found; 68 const char *usermount_node = "vfs.usermount"; 69 int usermount_val = 0; 70 size_t usermount_size = sizeof(usermount_val); 71 if (eaccess(devnode, R_OK | W_OK)) { 72 if (errno == ENOENT) { 73 GTEST_SKIP() << devnode << " does not exist"; 74 } else if (errno == EACCES) { 75 GTEST_SKIP() << devnode << 76 " is not accessible by the current user"; 77 } else { 78 GTEST_SKIP() << strerror(errno); 79 } 80 } 81 // mac_bsdextended(4), when enabled, generates many more GETATTR 82 // operations. The fusefs tests' expectations don't account for those, 83 // and adding extra code to handle them obfuscates the real purpose of 84 // the tests. Better just to skip the fusefs tests if mac_bsdextended 85 // is enabled. 86 bsdextended_found = sysctlbyname(bsdextended_node, &bsdextended_val, 87 &bsdextended_size, NULL, 0); 88 if (bsdextended_found == 0 && bsdextended_val != 0) 89 GTEST_SKIP() << 90 "The fusefs tests are incompatible with mac_bsdextended."; 91 ASSERT_EQ(sysctlbyname(usermount_node, &usermount_val, &usermount_size, 92 NULL, 0), 93 0); 94 if (geteuid() != 0 && !usermount_val) 95 GTEST_SKIP() << "current user is not allowed to mount"; 96 } 97 98 const char *cache_mode_to_s(enum cache_mode cm) { 99 switch (cm) { 100 case Uncached: 101 return "Uncached"; 102 case Writethrough: 103 return "Writethrough"; 104 case Writeback: 105 return "Writeback"; 106 case WritebackAsync: 107 return "WritebackAsync"; 108 default: 109 return "Unknown"; 110 } 111 } 112 113 bool is_unsafe_aio_enabled(void) { 114 const char *node = "vfs.aio.enable_unsafe"; 115 int val = 0; 116 size_t size = sizeof(val); 117 118 if (sysctlbyname(node, &val, &size, NULL, 0)) { 119 perror("sysctlbyname"); 120 return (false); 121 } 122 return (val != 0); 123 } 124 125 class FuseEnv: public Environment { 126 virtual void SetUp() { 127 check_environment(); 128 } 129 }; 130 131 void FuseTest::SetUp() { 132 const char *maxbcachebuf_node = "vfs.maxbcachebuf"; 133 const char *maxphys_node = "kern.maxphys"; 134 size_t size; 135 136 size = sizeof(m_maxbcachebuf); 137 ASSERT_EQ(0, sysctlbyname(maxbcachebuf_node, &m_maxbcachebuf, &size, 138 NULL, 0)) << strerror(errno); 139 size = sizeof(m_maxphys); 140 ASSERT_EQ(0, sysctlbyname(maxphys_node, &m_maxphys, &size, NULL, 0)) 141 << strerror(errno); 142 /* 143 * Set the default max_write to a distinct value from MAXPHYS to catch 144 * bugs that confuse the two. 145 */ 146 if (m_maxwrite == 0) 147 m_maxwrite = MIN(libfuse_max_write, (uint32_t)m_maxphys / 2); 148 149 try { 150 m_mock = new MockFS(m_maxread, m_maxreadahead, m_allow_other, 151 m_default_permissions, m_push_symlinks_in, m_ro, 152 m_pm, m_init_flags, m_kernel_minor_version, 153 m_maxwrite, m_async, m_noclusterr, m_time_gran, 154 m_nointr, m_noatime, m_fsname, m_subtype, 155 m_no_auto_init, m_auto_unmount); 156 /* 157 * FUSE_ACCESS is called almost universally. Expecting it in 158 * each test case would be super-annoying. Instead, set a 159 * default expectation for FUSE_ACCESS and return ENOSYS. 160 * 161 * Individual test cases can override this expectation since 162 * googlemock evaluates expectations in LIFO order. 163 */ 164 EXPECT_CALL(*m_mock, process( 165 ResultOf([=](auto in) { 166 return (in.header.opcode == FUSE_ACCESS); 167 }, Eq(true)), 168 _) 169 ).Times(AnyNumber()) 170 .WillRepeatedly(Invoke(ReturnErrno(ENOSYS))); 171 /* 172 * FUSE_BMAP is called for most test cases that read data. Set 173 * a default expectation and return ENOSYS. 174 * 175 * Individual test cases can override this expectation since 176 * googlemock evaluates expectations in LIFO order. 177 */ 178 EXPECT_CALL(*m_mock, process( 179 ResultOf([=](auto in) { 180 return (in.header.opcode == FUSE_BMAP); 181 }, Eq(true)), 182 _) 183 ).Times(AnyNumber()) 184 .WillRepeatedly(Invoke(ReturnErrno(ENOSYS))); 185 } catch (std::system_error err) { 186 FAIL() << err.what(); 187 } 188 } 189 190 void 191 FuseTest::expect_access(uint64_t ino, mode_t access_mode, int error) 192 { 193 EXPECT_CALL(*m_mock, process( 194 ResultOf([=](auto in) { 195 return (in.header.opcode == FUSE_ACCESS && 196 in.header.nodeid == ino && 197 in.body.access.mask == access_mode); 198 }, Eq(true)), 199 _) 200 ).WillOnce(Invoke(ReturnErrno(error))); 201 } 202 203 void 204 FuseTest::expect_destroy(int error) 205 { 206 EXPECT_CALL(*m_mock, process( 207 ResultOf([=](auto in) { 208 return (in.header.opcode == FUSE_DESTROY); 209 }, Eq(true)), 210 _) 211 ).WillOnce(Invoke(ReturnImmediate([=](auto in, auto& out) { 212 m_mock->m_quit = true; 213 out.header.len = sizeof(out.header); 214 out.header.unique = in.header.unique; 215 out.header.error = -error; 216 }))); 217 } 218 219 void 220 FuseTest::expect_fallocate(uint64_t ino, uint64_t offset, uint64_t length, 221 uint32_t mode, int error, int times) 222 { 223 EXPECT_CALL(*m_mock, process( 224 ResultOf([=](auto in) { 225 return (in.header.opcode == FUSE_FALLOCATE && 226 in.header.nodeid == ino && 227 in.body.fallocate.offset == offset && 228 in.body.fallocate.length == length && 229 in.body.fallocate.mode == mode); 230 }, Eq(true)), 231 _) 232 ).Times(times) 233 .WillRepeatedly(Invoke(ReturnErrno(error))); 234 } 235 236 void 237 FuseTest::expect_flush(uint64_t ino, int times, ProcessMockerT r) 238 { 239 EXPECT_CALL(*m_mock, process( 240 ResultOf([=](auto in) { 241 return (in.header.opcode == FUSE_FLUSH && 242 in.header.nodeid == ino); 243 }, Eq(true)), 244 _) 245 ).Times(times) 246 .WillRepeatedly(Invoke(r)); 247 } 248 249 void 250 FuseTest::expect_forget(uint64_t ino, uint64_t nlookup, sem_t *sem) 251 { 252 EXPECT_CALL(*m_mock, process( 253 ResultOf([=](auto in) { 254 return (in.header.opcode == FUSE_FORGET && 255 in.header.nodeid == ino && 256 in.body.forget.nlookup == nlookup); 257 }, Eq(true)), 258 _) 259 ).WillOnce(Invoke([=](auto in __unused, auto &out __unused) { 260 if (sem != NULL) 261 sem_post(sem); 262 /* FUSE_FORGET has no response! */ 263 })); 264 } 265 266 void FuseTest::expect_getattr(uint64_t ino, uint64_t size) 267 { 268 EXPECT_CALL(*m_mock, process( 269 ResultOf([=](auto in) { 270 return (in.header.opcode == FUSE_GETATTR && 271 in.header.nodeid == ino); 272 }, Eq(true)), 273 _) 274 ).WillOnce(Invoke(ReturnImmediate([=](auto i __unused, auto& out) { 275 SET_OUT_HEADER_LEN(out, attr); 276 out.body.attr.attr.ino = ino; // Must match nodeid 277 out.body.attr.attr.mode = S_IFREG | 0644; 278 out.body.attr.attr.size = size; 279 out.body.attr.attr_valid = UINT64_MAX; 280 }))); 281 } 282 283 void FuseTest::expect_getxattr(uint64_t ino, const char *attr, ProcessMockerT r) 284 { 285 EXPECT_CALL(*m_mock, process( 286 ResultOf([=](auto in) { 287 const char *a = (const char*)in.body.bytes + 288 sizeof(fuse_getxattr_in); 289 return (in.header.opcode == FUSE_GETXATTR && 290 in.header.nodeid == ino && 291 0 == strcmp(attr, a)); 292 }, Eq(true)), 293 _) 294 ).WillOnce(Invoke(r)); 295 } 296 297 void FuseTest::expect_lookup(const char *relpath, uint64_t ino, mode_t mode, 298 uint64_t size, int times, uint64_t attr_valid, uid_t uid, gid_t gid) 299 { 300 EXPECT_LOOKUP(FUSE_ROOT_ID, relpath) 301 .Times(times) 302 .WillRepeatedly(Invoke( 303 ReturnImmediate([=](auto in __unused, auto& out) { 304 SET_OUT_HEADER_LEN(out, entry); 305 out.body.entry.attr.mode = mode; 306 out.body.entry.nodeid = ino; 307 out.body.entry.attr.nlink = 1; 308 out.body.entry.attr_valid = attr_valid; 309 out.body.entry.attr.size = size; 310 out.body.entry.attr.uid = uid; 311 out.body.entry.attr.gid = gid; 312 }))); 313 } 314 315 void FuseTest::expect_lookup_7_8(const char *relpath, uint64_t ino, mode_t mode, 316 uint64_t size, int times, uint64_t attr_valid, uid_t uid, gid_t gid) 317 { 318 EXPECT_LOOKUP(FUSE_ROOT_ID, relpath) 319 .Times(times) 320 .WillRepeatedly(Invoke( 321 ReturnImmediate([=](auto in __unused, auto& out) { 322 SET_OUT_HEADER_LEN(out, entry_7_8); 323 out.body.entry.attr.mode = mode; 324 out.body.entry.nodeid = ino; 325 out.body.entry.attr.nlink = 1; 326 out.body.entry.attr_valid = attr_valid; 327 out.body.entry.attr.size = size; 328 out.body.entry.attr.uid = uid; 329 out.body.entry.attr.gid = gid; 330 }))); 331 } 332 333 void FuseTest::expect_open(uint64_t ino, uint32_t flags, int times) 334 { 335 EXPECT_CALL(*m_mock, process( 336 ResultOf([=](auto in) { 337 return (in.header.opcode == FUSE_OPEN && 338 in.header.nodeid == ino); 339 }, Eq(true)), 340 _) 341 ).Times(times) 342 .WillRepeatedly(Invoke( 343 ReturnImmediate([=](auto in __unused, auto& out) { 344 out.header.len = sizeof(out.header); 345 SET_OUT_HEADER_LEN(out, open); 346 out.body.open.fh = FH; 347 out.body.open.open_flags = flags; 348 }))); 349 } 350 351 void FuseTest::expect_opendir(uint64_t ino) 352 { 353 /* opendir(3) calls fstatfs */ 354 EXPECT_CALL(*m_mock, process( 355 ResultOf([](auto in) { 356 return (in.header.opcode == FUSE_STATFS); 357 }, Eq(true)), 358 _) 359 ).WillRepeatedly(Invoke( 360 ReturnImmediate([=](auto i __unused, auto& out) { 361 SET_OUT_HEADER_LEN(out, statfs); 362 }))); 363 364 EXPECT_CALL(*m_mock, process( 365 ResultOf([=](auto in) { 366 return (in.header.opcode == FUSE_OPENDIR && 367 in.header.nodeid == ino); 368 }, Eq(true)), 369 _) 370 ).WillOnce(Invoke(ReturnImmediate([=](auto in __unused, auto& out) { 371 out.header.len = sizeof(out.header); 372 SET_OUT_HEADER_LEN(out, open); 373 out.body.open.fh = FH; 374 }))); 375 } 376 377 void FuseTest::expect_read(uint64_t ino, uint64_t offset, uint64_t isize, 378 uint64_t osize, const void *contents, int flags, uint64_t fh) 379 { 380 EXPECT_CALL(*m_mock, process( 381 ResultOf([=](auto in) { 382 return (in.header.opcode == FUSE_READ && 383 in.header.nodeid == ino && 384 in.body.read.fh == fh && 385 in.body.read.offset == offset && 386 in.body.read.size == isize && 387 (flags == -1 ? 388 (in.body.read.flags == O_RDONLY || 389 in.body.read.flags == O_RDWR || 390 in.body.read.flags == O_EXEC) 391 : in.body.read.flags == (uint32_t)flags)); 392 }, Eq(true)), 393 _) 394 ).WillOnce(Invoke(ReturnImmediate([=](auto in __unused, auto& out) { 395 assert(osize <= sizeof(out.body.bytes)); 396 out.header.len = sizeof(struct fuse_out_header) + osize; 397 memmove(out.body.bytes, contents, osize); 398 }))).RetiresOnSaturation(); 399 } 400 401 void FuseTest::expect_readdir(uint64_t ino, uint64_t off, 402 std::vector<struct dirent> &ents) 403 { 404 EXPECT_CALL(*m_mock, process( 405 ResultOf([=](auto in) { 406 return (in.header.opcode == FUSE_READDIR && 407 in.header.nodeid == ino && 408 in.body.readdir.fh == FH && 409 in.body.readdir.offset == off); 410 }, Eq(true)), 411 _) 412 ).WillRepeatedly(Invoke(ReturnImmediate([=](auto in, auto& out) { 413 struct fuse_dirent *fde = (struct fuse_dirent*)&(out.body); 414 int i = 0; 415 416 out.header.error = 0; 417 out.header.len = 0; 418 419 for (const auto& it: ents) { 420 size_t entlen, entsize; 421 422 fde->ino = it.d_fileno; 423 fde->off = it.d_off; 424 fde->type = it.d_type; 425 fde->namelen = it.d_namlen; 426 strncpy(fde->name, it.d_name, it.d_namlen); 427 entlen = FUSE_NAME_OFFSET + fde->namelen; 428 entsize = FUSE_DIRENT_SIZE(fde); 429 /* 430 * The FUSE protocol does not require zeroing out the 431 * unused portion of the name. But it's a good 432 * practice to prevent information disclosure to the 433 * FUSE client, even though the client is usually the 434 * kernel 435 */ 436 memset(fde->name + fde->namelen, 0, entsize - entlen); 437 if (out.header.len + entsize > in.body.read.size) { 438 printf("Overflow in readdir expectation: i=%d\n" 439 , i); 440 break; 441 } 442 out.header.len += entsize; 443 fde = (struct fuse_dirent*) 444 ((intmax_t*)fde + entsize / sizeof(intmax_t)); 445 i++; 446 } 447 out.header.len += sizeof(out.header); 448 }))); 449 450 } 451 void FuseTest::expect_release(uint64_t ino, uint64_t fh) 452 { 453 EXPECT_CALL(*m_mock, process( 454 ResultOf([=](auto in) { 455 return (in.header.opcode == FUSE_RELEASE && 456 in.header.nodeid == ino && 457 in.body.release.fh == fh); 458 }, Eq(true)), 459 _) 460 ).WillOnce(Invoke(ReturnErrno(0))); 461 } 462 463 void FuseTest::expect_releasedir(uint64_t ino, ProcessMockerT r) 464 { 465 EXPECT_CALL(*m_mock, process( 466 ResultOf([=](auto in) { 467 return (in.header.opcode == FUSE_RELEASEDIR && 468 in.header.nodeid == ino && 469 in.body.release.fh == FH); 470 }, Eq(true)), 471 _) 472 ).WillOnce(Invoke(r)); 473 } 474 475 void FuseTest::expect_unlink(uint64_t parent, const char *path, int error) 476 { 477 EXPECT_CALL(*m_mock, process( 478 ResultOf([=](auto in) { 479 return (in.header.opcode == FUSE_UNLINK && 480 0 == strcmp(path, in.body.unlink) && 481 in.header.nodeid == parent); 482 }, Eq(true)), 483 _) 484 ).WillOnce(Invoke(ReturnErrno(error))); 485 } 486 487 void FuseTest::expect_write(uint64_t ino, uint64_t offset, uint64_t isize, 488 uint64_t osize, uint32_t flags_set, uint32_t flags_unset, 489 const void *contents) 490 { 491 EXPECT_CALL(*m_mock, process( 492 ResultOf([=](auto in) { 493 const char *buf = (const char*)in.body.bytes + 494 sizeof(struct fuse_write_in); 495 bool pid_ok; 496 uint32_t wf = in.body.write.write_flags; 497 498 assert(isize <= sizeof(in.body.bytes) - 499 sizeof(struct fuse_write_in)); 500 if (wf & FUSE_WRITE_CACHE) 501 pid_ok = true; 502 else 503 pid_ok = (pid_t)in.header.pid == getpid(); 504 505 return (in.header.opcode == FUSE_WRITE && 506 in.header.nodeid == ino && 507 in.body.write.fh == FH && 508 in.body.write.offset == offset && 509 in.body.write.size == isize && 510 pid_ok && 511 (wf & flags_set) == flags_set && 512 (wf & flags_unset) == 0 && 513 (in.body.write.flags == O_WRONLY || 514 in.body.write.flags == O_RDWR) && 515 0 == bcmp(buf, contents, isize)); 516 }, Eq(true)), 517 _) 518 ).WillOnce(Invoke(ReturnImmediate([=](auto in __unused, auto& out) { 519 SET_OUT_HEADER_LEN(out, write); 520 out.body.write.size = osize; 521 }))); 522 } 523 524 void FuseTest::expect_write_7_8(uint64_t ino, uint64_t offset, uint64_t isize, 525 uint64_t osize, const void *contents) 526 { 527 EXPECT_CALL(*m_mock, process( 528 ResultOf([=](auto in) { 529 const char *buf = (const char*)in.body.bytes + 530 FUSE_COMPAT_WRITE_IN_SIZE; 531 bool pid_ok = (pid_t)in.header.pid == getpid(); 532 533 assert(isize <= sizeof(in.body.bytes) - 534 FUSE_COMPAT_WRITE_IN_SIZE); 535 return (in.header.opcode == FUSE_WRITE && 536 in.header.nodeid == ino && 537 in.body.write.fh == FH && 538 in.body.write.offset == offset && 539 in.body.write.size == isize && 540 pid_ok && 541 0 == bcmp(buf, contents, isize)); 542 }, Eq(true)), 543 _) 544 ).WillOnce(Invoke(ReturnImmediate([=](auto in __unused, auto& out) { 545 SET_OUT_HEADER_LEN(out, write); 546 out.body.write.size = osize; 547 }))); 548 } 549 550 void 551 get_unprivileged_id(uid_t *uid, gid_t *gid) 552 { 553 struct passwd *pw; 554 struct group *gr; 555 556 /* 557 * First try "tests", Kyua's default unprivileged user. XXX after 558 * GoogleTest gains a proper Kyua wrapper, get this with the Kyua API 559 */ 560 pw = getpwnam("tests"); 561 if (pw == NULL) { 562 /* Fall back to "nobody" */ 563 pw = getpwnam("nobody"); 564 } 565 if (pw == NULL) 566 GTEST_SKIP() << "Test requires an unprivileged user"; 567 /* Use group "nobody", which is Kyua's default unprivileged group */ 568 gr = getgrnam("nobody"); 569 if (gr == NULL) 570 GTEST_SKIP() << "Test requires an unprivileged group"; 571 *uid = pw->pw_uid; 572 *gid = gr->gr_gid; 573 } 574 575 int 576 FuseTest::dup_dev_fuse() 577 { 578 return (m_mock->dup_dev_fuse()); 579 } 580 581 void 582 FuseTest::fork(bool drop_privs, int *child_status, 583 std::function<void()> parent_func, 584 std::function<int()> child_func) 585 { 586 sem_t *sem; 587 int mprot = PROT_READ | PROT_WRITE; 588 int mflags = MAP_ANON | MAP_SHARED; 589 pid_t child; 590 uid_t uid; 591 gid_t gid; 592 593 if (drop_privs) { 594 get_unprivileged_id(&uid, &gid); 595 if (IsSkipped()) 596 return; 597 } 598 599 sem = (sem_t*)mmap(NULL, sizeof(*sem), mprot, mflags, -1, 0); 600 ASSERT_NE(MAP_FAILED, sem) << strerror(errno); 601 ASSERT_EQ(0, sem_init(sem, 1, 0)) << strerror(errno); 602 603 if ((child = ::fork()) == 0) { 604 /* In child */ 605 int err = 0; 606 607 if (sem_wait(sem)) { 608 perror("sem_wait"); 609 err = 1; 610 goto out; 611 } 612 613 if (drop_privs && 0 != setegid(gid)) { 614 perror("setegid"); 615 err = 1; 616 goto out; 617 } 618 if (drop_privs && 0 != setreuid(-1, uid)) { 619 perror("setreuid"); 620 err = 1; 621 goto out; 622 } 623 err = child_func(); 624 625 out: 626 sem_destroy(sem); 627 _exit(err); 628 } else if (child > 0) { 629 /* 630 * In parent. Cleanup must happen here, because it's still 631 * privileged. 632 */ 633 m_mock->m_child_pid = child; 634 ASSERT_NO_FATAL_FAILURE(parent_func()); 635 636 /* Signal the child process to go */ 637 ASSERT_EQ(0, sem_post(sem)) << strerror(errno); 638 639 ASSERT_LE(0, wait(child_status)) << strerror(errno); 640 } else { 641 FAIL() << strerror(errno); 642 } 643 munmap(sem, sizeof(*sem)); 644 return; 645 } 646 647 void 648 FuseTest::reclaim_vnode(const char *path) 649 { 650 int err; 651 652 err = sysctlbyname(reclaim_mib, NULL, 0, path, strlen(path) + 1); 653 ASSERT_EQ(0, err) << strerror(errno); 654 } 655 656 static void usage(char* progname) { 657 fprintf(stderr, "Usage: %s [-v]\n\t-v increase verbosity\n", progname); 658 exit(2); 659 } 660 661 int main(int argc, char **argv) { 662 int ch; 663 FuseEnv *fuse_env = new FuseEnv; 664 665 InitGoogleTest(&argc, argv); 666 AddGlobalTestEnvironment(fuse_env); 667 668 while ((ch = getopt(argc, argv, "v")) != -1) { 669 switch (ch) { 670 case 'v': 671 verbosity++; 672 break; 673 default: 674 usage(argv[0]); 675 break; 676 } 677 } 678 679 return (RUN_ALL_TESTS()); 680 } 681