| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <errno.h> | 5 #include <errno.h> |
| 6 #include <fcntl.h> | 6 #include <fcntl.h> |
| 7 #include <pthread.h> | 7 #include <pthread.h> |
| 8 #include <stdio.h> | 8 #include <stdio.h> |
| 9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
| 10 #include <sys/types.h> | 10 #include <sys/types.h> |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 } | 67 } |
| 68 | 68 |
| 69 void TearDown() { ki_uninit(); } | 69 void TearDown() { ki_uninit(); } |
| 70 | 70 |
| 71 protected: | 71 protected: |
| 72 KernelProxyTest_KernelProxy kp_; | 72 KernelProxyTest_KernelProxy kp_; |
| 73 }; | 73 }; |
| 74 | 74 |
| 75 } // namespace | 75 } // namespace |
| 76 | 76 |
| 77 // Helper function for calling ki_fcntl without having |
| 78 // to construct a va_list. |
| 77 static int ki_fcntl_wrapper(int fd, int request, ...) { | 79 static int ki_fcntl_wrapper(int fd, int request, ...) { |
| 78 va_list ap; | 80 va_list ap; |
| 79 va_start(ap, request); | 81 va_start(ap, request); |
| 80 int rtn = ki_fcntl(fd, request, ap); | 82 int rtn = ki_fcntl(fd, request, ap); |
| 81 va_end(ap); | 83 va_end(ap); |
| 82 return rtn; | 84 return rtn; |
| 83 } | 85 } |
| 84 | 86 |
| 85 /** | 87 // Helper function for calling ki_ioctl without having |
| 86 * Test for fcntl commands F_SETFD and F_GETFD. This | 88 // to construct a va_list. |
| 87 * is tested here rather than in the mount_node tests | 89 static int ki_ioctl_wrapper(int fd, int request, ...) { |
| 88 * since the fd flags are not stored in the kernel_handle | 90 va_list ap; |
| 89 * or the filesystem node but directly in the FD mapping. | 91 va_start(ap, request); |
| 90 */ | 92 int rtn = ki_ioctl(fd, request, ap); |
| 93 va_end(ap); |
| 94 return rtn; |
| 95 } |
| 96 |
| 97 // Helper to verify directory contents using ki_getdents. |
| 98 // Verified that each of the 'count' elements in the 'expected' array |
| 99 // are present in the directory and that no other entries are present. |
| 100 // If count is -1 then no checking is done and enties are printed using |
| 101 // printf. |
| 102 static void CheckDirContents(const char* dirname, const char** expected, |
| 103 int count) { |
| 104 int dir = ki_open(dirname, O_RDONLY, 0); |
| 105 ASSERT_GE(dir, 0); |
| 106 while (1) { |
| 107 size_t sz = sizeof(struct dirent) * 10; |
| 108 char* buf = (char*)alloca(sz); |
| 109 int rtn = ki_getdents(dir, (struct dirent*)buf, sz); |
| 110 if (rtn <= 0) |
| 111 break; |
| 112 int offset = 0; |
| 113 while (offset < rtn) { |
| 114 struct dirent* entry = (struct dirent*)(buf + offset); |
| 115 offset += entry->d_reclen; |
| 116 if (count == -1) { |
| 117 nacl_io_log("directory entry: %s\n", entry->d_name); |
| 118 continue; |
| 119 } |
| 120 int j; |
| 121 for (j = 0; j < count; j++) { |
| 122 if (expected[j] && strcmp(expected[j], entry->d_name) == 0) { |
| 123 expected[j] = NULL; |
| 124 break; |
| 125 } |
| 126 } |
| 127 if (j == count) { |
| 128 FAIL() << "Unexpeected entry '" << entry->d_name |
| 129 << "' in directory: " << dirname; |
| 130 } |
| 131 } |
| 132 } |
| 133 |
| 134 ASSERT_EQ(0, ki_close(dir)); |
| 135 |
| 136 if (count != -1) { |
| 137 for (int i = 0; i < count; i++) { |
| 138 if (expected[i] != NULL) { |
| 139 FAIL() << "Expected entry '" << expected[i] |
| 140 << "' not found in directory: " << dirname; |
| 141 } |
| 142 } |
| 143 } |
| 144 } |
| 145 |
| 146 // Test for fcntl commands F_SETFD and F_GETFD. This |
| 147 // is tested here rather than in the mount_node tests |
| 148 // since the fd flags are not stored in the kernel_handle |
| 149 // or the filesystem node but directly in the FD mapping. |
| 91 TEST_F(KernelProxyTest, Fcntl_GETFD) { | 150 TEST_F(KernelProxyTest, Fcntl_GETFD) { |
| 92 int fd = ki_open("/test", O_RDWR | O_CREAT, 0777); | 151 int fd = ki_open("/test", O_RDWR | O_CREAT, 0777); |
| 93 ASSERT_NE(-1, fd); | 152 ASSERT_NE(-1, fd); |
| 94 | 153 |
| 95 // FD flags should start as zero. | 154 // FD flags should start as zero. |
| 96 ASSERT_EQ(0, ki_fcntl_wrapper(fd, F_GETFD)); | 155 ASSERT_EQ(0, ki_fcntl_wrapper(fd, F_GETFD)); |
| 97 | 156 |
| 98 // Check that setting FD_CLOEXEC works | 157 // Check that setting FD_CLOEXEC works |
| 99 int flags = FD_CLOEXEC; | 158 int flags = FD_CLOEXEC; |
| 100 ASSERT_EQ(0, ki_fcntl_wrapper(fd, F_SETFD, flags)) | 159 ASSERT_EQ(0, ki_fcntl_wrapper(fd, F_SETFD, flags)) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 114 | 173 |
| 115 MemFs* filesystem = (MemFs*)kp_.RootFs(); | 174 MemFs* filesystem = (MemFs*)kp_.RootFs(); |
| 116 ScopedNode root; | 175 ScopedNode root; |
| 117 | 176 |
| 118 ASSERT_EQ(0, filesystem->Open(Path("/"), O_RDONLY, &root)); | 177 ASSERT_EQ(0, filesystem->Open(Path("/"), O_RDONLY, &root)); |
| 119 ASSERT_EQ(0, root->ChildCount()); | 178 ASSERT_EQ(0, root->ChildCount()); |
| 120 | 179 |
| 121 for (int file_num = 0; file_num < 4096; file_num++) { | 180 for (int file_num = 0; file_num < 4096; file_num++) { |
| 122 sprintf(filename, "/foo%i.tmp", file_num++); | 181 sprintf(filename, "/foo%i.tmp", file_num++); |
| 123 int fd = ki_open(filename, O_WRONLY | O_CREAT, 0777); | 182 int fd = ki_open(filename, O_WRONLY | O_CREAT, 0777); |
| 124 ASSERT_GT(fd, -1); | 183 ASSERT_GE(fd, 0); |
| 125 ASSERT_EQ(1, root->ChildCount()); | 184 ASSERT_EQ(1, root->ChildCount()); |
| 126 ASSERT_EQ(buffer_size, ki_write(fd, garbage, buffer_size)); | 185 ASSERT_EQ(buffer_size, ki_write(fd, garbage, buffer_size)); |
| 127 ki_close(fd); | 186 ki_close(fd); |
| 128 ASSERT_EQ(0, ki_remove(filename)); | 187 ASSERT_EQ(0, ki_remove(filename)); |
| 129 } | 188 } |
| 130 ASSERT_EQ(0, root->ChildCount()); | 189 ASSERT_EQ(0, root->ChildCount()); |
| 131 } | 190 } |
| 132 | 191 |
| 133 static bool g_handler_called = false; | 192 static bool g_handler_called = false; |
| 134 static void sighandler(int) { g_handler_called = true; } | 193 static void sighandler(int) { g_handler_called = true; } |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 // Restore existing handler | 289 // Restore existing handler |
| 231 oldsig = ki_signal(SIGWINCH, oldsig); | 290 oldsig = ki_signal(SIGWINCH, oldsig); |
| 232 | 291 |
| 233 // Verify the our newsig was returned as previous handler | 292 // Verify the our newsig was returned as previous handler |
| 234 ASSERT_EQ(oldsig, newsig); | 293 ASSERT_EQ(oldsig, newsig); |
| 235 } | 294 } |
| 236 | 295 |
| 237 TEST_F(KernelProxyTest, Rename) { | 296 TEST_F(KernelProxyTest, Rename) { |
| 238 // Create a dummy file | 297 // Create a dummy file |
| 239 int file1 = ki_open("/test1.txt", O_RDWR | O_CREAT, 0777); | 298 int file1 = ki_open("/test1.txt", O_RDWR | O_CREAT, 0777); |
| 240 ASSERT_GT(file1, -1); | 299 ASSERT_GE(file1, 0); |
| 241 ASSERT_EQ(0, ki_close(file1)); | 300 ASSERT_EQ(0, ki_close(file1)); |
| 242 | 301 |
| 243 // Test the renaming works | 302 // Test the renaming works |
| 244 ASSERT_EQ(0, ki_rename("/test1.txt", "/test2.txt")); | 303 ASSERT_EQ(0, ki_rename("/test1.txt", "/test2.txt")); |
| 245 | 304 |
| 246 // Test that renaming across mount points fails | 305 // Test that renaming across mount points fails |
| 247 ASSERT_EQ(0, ki_mount("", "/foo", "memfs", 0, "")); | 306 ASSERT_EQ(0, ki_mount("", "/foo", "memfs", 0, "")); |
| 248 ASSERT_EQ(-1, ki_rename("/test2.txt", "/foo/test2.txt")); | 307 ASSERT_EQ(-1, ki_rename("/test2.txt", "/foo/test2.txt")); |
| 249 ASSERT_EQ(EXDEV, errno); | 308 ASSERT_EQ(EXDEV, errno); |
| 250 } | 309 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 280 | 339 |
| 281 memset(text, 0, sizeof(text)); | 340 memset(text, 0, sizeof(text)); |
| 282 EXPECT_EQ(-1, ki_chdir("foo")); | 341 EXPECT_EQ(-1, ki_chdir("foo")); |
| 283 EXPECT_EQ(ENOENT, errno); | 342 EXPECT_EQ(ENOENT, errno); |
| 284 EXPECT_EQ(0, ki_chdir("..")); | 343 EXPECT_EQ(0, ki_chdir("..")); |
| 285 EXPECT_EQ(0, ki_chdir("/foo")); | 344 EXPECT_EQ(0, ki_chdir("/foo")); |
| 286 EXPECT_EQ(text, ki_getcwd(text, sizeof(text))); | 345 EXPECT_EQ(text, ki_getcwd(text, sizeof(text))); |
| 287 EXPECT_STREQ("/foo", text); | 346 EXPECT_STREQ("/foo", text); |
| 288 } | 347 } |
| 289 | 348 |
| 349 TEST_F(KernelProxyTest, Mkdir) { |
| 350 ASSERT_EQ(0, ki_mkdir("/foo", S_IREAD | S_IWRITE)); |
| 351 ASSERT_EQ(-1, ki_mkdir("/foo", S_IREAD | S_IWRITE)); |
| 352 ASSERT_EQ(EEXIST, errno); |
| 353 |
| 354 // Some component of parent directory does not exist |
| 355 ASSERT_EQ(-1, ki_mkdir("/does_not_exist/foo", S_IREAD | S_IWRITE)); |
| 356 ASSERT_EQ(ENOENT, errno); |
| 357 |
| 358 int fd = ki_open("/filename", O_CREAT | O_RDWR, 0777); |
| 359 ASSERT_GE(fd, 0); |
| 360 |
| 361 // Some component of parent directory is not actually a directory |
| 362 ASSERT_EQ(-1, ki_mkdir("/filename/foo", S_IREAD | S_IWRITE)); |
| 363 ASSERT_EQ(ENOTDIR, errno); |
| 364 } |
| 365 |
| 366 TEST_F(KernelProxyTest, Rmdir) { |
| 367 ASSERT_EQ(-1, ki_rmdir("/dev/fs")); |
| 368 ASSERT_EQ(EPERM, errno); |
| 369 |
| 370 ASSERT_EQ(-1, ki_rmdir("/foo")); |
| 371 ASSERT_EQ(ENOENT, errno); |
| 372 } |
| 373 |
| 290 TEST_F(KernelProxyTest, FDPathMapping) { | 374 TEST_F(KernelProxyTest, FDPathMapping) { |
| 291 char text[1024]; | 375 char text[1024]; |
| 292 | 376 |
| 293 int fd1, fd2, fd3, fd4, fd5; | 377 int fd1, fd2, fd3, fd4, fd5; |
| 294 | 378 |
| 295 EXPECT_EQ(0, ki_mkdir("/foo", S_IRUSR | S_IWUSR)); | 379 EXPECT_EQ(0, ki_mkdir("/foo", S_IRUSR | S_IWUSR)); |
| 296 EXPECT_EQ(0, ki_mkdir("/foo/bar", S_IRUSR | S_IWUSR)); | 380 EXPECT_EQ(0, ki_mkdir("/foo/bar", S_IRUSR | S_IWUSR)); |
| 297 EXPECT_EQ(0, ki_mkdir("/example", S_IRUSR | S_IWUSR)); | 381 EXPECT_EQ(0, ki_mkdir("/example", S_IRUSR | S_IWUSR)); |
| 298 ki_chdir("/foo"); | 382 ki_chdir("/foo"); |
| 299 | 383 |
| 300 fd1 = ki_open("/example", O_RDONLY, 0); | 384 fd1 = ki_open("/example", O_RDONLY, 0); |
| 301 EXPECT_NE(-1, fd1); | 385 ASSERT_GT(fd1, 0); |
| 302 EXPECT_EQ(ki_fchdir(fd1), 0); | 386 EXPECT_EQ(ki_fchdir(fd1), 0); |
| 303 EXPECT_EQ(text, ki_getcwd(text, sizeof(text))); | 387 EXPECT_EQ(text, ki_getcwd(text, sizeof(text))); |
| 304 EXPECT_STREQ("/example", text); | 388 EXPECT_STREQ("/example", text); |
| 305 | 389 |
| 306 EXPECT_EQ(0, ki_chdir("/foo")); | 390 EXPECT_EQ(0, ki_chdir("/foo")); |
| 307 fd2 = ki_open("../example", O_RDONLY, 0); | 391 fd2 = ki_open("../example", O_RDONLY, 0); |
| 308 EXPECT_NE(-1, fd2); | 392 ASSERT_GE(fd2, 0); |
| 309 EXPECT_EQ(0, ki_fchdir(fd2)); | 393 EXPECT_EQ(0, ki_fchdir(fd2)); |
| 310 EXPECT_EQ(text, ki_getcwd(text, sizeof(text))); | 394 EXPECT_EQ(text, ki_getcwd(text, sizeof(text))); |
| 311 EXPECT_STREQ("/example", text); | 395 EXPECT_STREQ("/example", text); |
| 312 | 396 |
| 313 EXPECT_EQ(0, ki_chdir("/foo")); | 397 EXPECT_EQ(0, ki_chdir("/foo")); |
| 314 fd3 = ki_open("../test", O_CREAT | O_RDWR, 0777); | 398 fd3 = ki_open("../test", O_CREAT | O_RDWR, 0777); |
| 315 EXPECT_NE(-1, fd3); | 399 ASSERT_GE(fd3, 0); |
| 316 EXPECT_EQ(-1, ki_fchdir(fd3)); | 400 EXPECT_EQ(-1, ki_fchdir(fd3)); |
| 317 EXPECT_EQ(ENOTDIR, errno); | 401 EXPECT_EQ(ENOTDIR, errno); |
| 318 | 402 |
| 319 EXPECT_EQ(0, ki_chdir("/foo")); | 403 EXPECT_EQ(0, ki_chdir("/foo")); |
| 320 fd4 = ki_open("bar", O_RDONLY, 0); | 404 fd4 = ki_open("bar", O_RDONLY, 0); |
| 405 ASSERT_GE(fd4, 0); |
| 321 EXPECT_EQ(0, ki_fchdir(fd4)); | 406 EXPECT_EQ(0, ki_fchdir(fd4)); |
| 322 EXPECT_EQ(text, ki_getcwd(text, sizeof(text))); | 407 EXPECT_EQ(text, ki_getcwd(text, sizeof(text))); |
| 323 EXPECT_STREQ("/foo/bar", text); | 408 EXPECT_STREQ("/foo/bar", text); |
| 324 EXPECT_EQ(0, ki_chdir("/example")); | 409 EXPECT_EQ(0, ki_chdir("/example")); |
| 325 EXPECT_EQ(0, ki_fchdir(fd4)); | 410 EXPECT_EQ(0, ki_fchdir(fd4)); |
| 326 EXPECT_EQ(text, ki_getcwd(text, sizeof(text))); | 411 EXPECT_EQ(text, ki_getcwd(text, sizeof(text))); |
| 327 EXPECT_STREQ("/foo/bar", text); | 412 EXPECT_STREQ("/foo/bar", text); |
| 328 | 413 |
| 329 EXPECT_EQ(0, ki_chdir("/example")); | 414 EXPECT_EQ(0, ki_chdir("/example")); |
| 330 fd5 = ki_dup(fd4); | 415 fd5 = ki_dup(fd4); |
| 331 ASSERT_GT(fd5, -1); | 416 ASSERT_GE(fd5, 0); |
| 332 ASSERT_NE(fd4, fd5); | 417 ASSERT_NE(fd4, fd5); |
| 333 EXPECT_EQ(0, ki_fchdir(fd5)); | 418 EXPECT_EQ(0, ki_fchdir(fd5)); |
| 334 EXPECT_EQ(text, ki_getcwd(text, sizeof(text))); | 419 EXPECT_EQ(text, ki_getcwd(text, sizeof(text))); |
| 335 EXPECT_STREQ("/foo/bar", text); | 420 EXPECT_STREQ("/foo/bar", text); |
| 336 | 421 |
| 337 fd5 = 123; | 422 fd5 = 123; |
| 338 | 423 |
| 339 EXPECT_EQ(0, ki_chdir("/example")); | 424 EXPECT_EQ(0, ki_chdir("/example")); |
| 340 EXPECT_EQ(fd5, ki_dup2(fd4, fd5)); | 425 EXPECT_EQ(fd5, ki_dup2(fd4, fd5)); |
| 341 EXPECT_EQ(0, ki_fchdir(fd5)); | 426 EXPECT_EQ(0, ki_fchdir(fd5)); |
| 342 EXPECT_EQ(text, ki_getcwd(text, sizeof(text))); | 427 EXPECT_EQ(text, ki_getcwd(text, sizeof(text))); |
| 343 EXPECT_STREQ("/foo/bar", text); | 428 EXPECT_STREQ("/foo/bar", text); |
| 344 } | 429 } |
| 345 | 430 |
| 431 TEST_F(KernelProxyTest, Getdents) { |
| 432 const char* expected[] = { "..", "." }; |
| 433 CheckDirContents("/", expected, 2); |
| 434 |
| 435 ASSERT_GE(ki_open("/foo", O_RDWR | O_CREAT, 0777), 0); |
| 436 const char* expected1[] = { "foo", "..", "." }; |
| 437 CheckDirContents("/", expected1, 3); |
| 438 } |
| 439 |
| 346 TEST_F(KernelProxyTest, BasicReadWrite) { | 440 TEST_F(KernelProxyTest, BasicReadWrite) { |
| 347 char text[1024]; | 441 char text[1024]; |
| 348 int fd1, fd2, fd3; | 442 int fd1, fd2, fd3; |
| 349 int len; | 443 int len; |
| 350 | 444 |
| 351 // Fail to delete non existant "/foo" | 445 // Fail to delete non existant "/foo" |
| 352 EXPECT_EQ(-1, ki_rmdir("/foo")); | 446 EXPECT_EQ(-1, ki_rmdir("/foo")); |
| 353 EXPECT_EQ(ENOENT, errno); | 447 EXPECT_EQ(ENOENT, errno); |
| 354 | 448 |
| 355 // Create "/foo" | 449 // Create "/foo" |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 EXPECT_EQ(0, ki_close(fd1)); | 552 EXPECT_EQ(0, ki_close(fd1)); |
| 459 | 553 |
| 460 // Truncate should fail if the file is not writable. | 554 // Truncate should fail if the file is not writable. |
| 461 EXPECT_EQ(0, ki_chmod("/trunc", 0444)); | 555 EXPECT_EQ(0, ki_chmod("/trunc", 0444)); |
| 462 EXPECT_EQ(-1, ki_truncate("/trunc", 0)); | 556 EXPECT_EQ(-1, ki_truncate("/trunc", 0)); |
| 463 EXPECT_EQ(EACCES, errno); | 557 EXPECT_EQ(EACCES, errno); |
| 464 } | 558 } |
| 465 | 559 |
| 466 TEST_F(KernelProxyTest, Lseek) { | 560 TEST_F(KernelProxyTest, Lseek) { |
| 467 int fd = ki_open("/foo", O_CREAT | O_RDWR, 0777); | 561 int fd = ki_open("/foo", O_CREAT | O_RDWR, 0777); |
| 468 ASSERT_GT(fd, -1); | 562 ASSERT_GE(fd, 0); |
| 469 ASSERT_EQ(9, ki_write(fd, "Some text", 9)); | 563 ASSERT_EQ(9, ki_write(fd, "Some text", 9)); |
| 470 | 564 |
| 471 ASSERT_EQ(9, ki_lseek(fd, 0, SEEK_CUR)); | 565 ASSERT_EQ(9, ki_lseek(fd, 0, SEEK_CUR)); |
| 472 ASSERT_EQ(9, ki_lseek(fd, 0, SEEK_END)); | 566 ASSERT_EQ(9, ki_lseek(fd, 0, SEEK_END)); |
| 473 ASSERT_EQ(-1, ki_lseek(fd, -1, SEEK_SET)); | 567 ASSERT_EQ(-1, ki_lseek(fd, -1, SEEK_SET)); |
| 474 ASSERT_EQ(EINVAL, errno); | 568 ASSERT_EQ(EINVAL, errno); |
| 475 | 569 |
| 476 // Seek past end of file. | 570 // Seek past end of file. |
| 477 ASSERT_EQ(13, ki_lseek(fd, 13, SEEK_SET)); | 571 ASSERT_EQ(13, ki_lseek(fd, 13, SEEK_SET)); |
| 478 char buffer[4]; | 572 char buffer[4]; |
| 479 memset(&buffer[0], 0xfe, 4); | 573 memset(&buffer[0], 0xfe, 4); |
| 480 ASSERT_EQ(9, ki_lseek(fd, -4, SEEK_END)); | 574 ASSERT_EQ(9, ki_lseek(fd, -4, SEEK_END)); |
| 481 ASSERT_EQ(9, ki_lseek(fd, 0, SEEK_CUR)); | 575 ASSERT_EQ(9, ki_lseek(fd, 0, SEEK_CUR)); |
| 482 ASSERT_EQ(4, ki_read(fd, &buffer[0], 4)); | 576 ASSERT_EQ(4, ki_read(fd, &buffer[0], 4)); |
| 483 ASSERT_EQ(0, memcmp("\0\0\0\0", buffer, 4)); | 577 ASSERT_EQ(0, memcmp("\0\0\0\0", buffer, 4)); |
| 484 } | 578 } |
| 485 | 579 |
| 486 TEST_F(KernelProxyTest, CloseTwice) { | 580 TEST_F(KernelProxyTest, CloseTwice) { |
| 487 int fd = ki_open("/foo", O_CREAT | O_RDWR, 0777); | 581 int fd = ki_open("/foo", O_CREAT | O_RDWR, 0777); |
| 488 ASSERT_GT(fd, -1); | 582 ASSERT_GE(fd, 0); |
| 489 | 583 |
| 490 EXPECT_EQ(9, ki_write(fd, "Some text", 9)); | 584 EXPECT_EQ(9, ki_write(fd, "Some text", 9)); |
| 491 | 585 |
| 492 int fd2 = ki_dup(fd); | 586 int fd2 = ki_dup(fd); |
| 493 ASSERT_GT(fd2, -1); | 587 ASSERT_GE(fd2, 0); |
| 494 | 588 |
| 495 EXPECT_EQ(0, ki_close(fd)); | 589 EXPECT_EQ(0, ki_close(fd)); |
| 496 EXPECT_EQ(0, ki_close(fd2)); | 590 EXPECT_EQ(0, ki_close(fd2)); |
| 497 } | 591 } |
| 498 | 592 |
| 499 TEST_F(KernelProxyTest, Dup) { | 593 TEST_F(KernelProxyTest, Dup) { |
| 500 int fd = ki_open("/foo", O_CREAT | O_RDWR, 0777); | 594 int fd = ki_open("/foo", O_CREAT | O_RDWR, 0777); |
| 501 ASSERT_GT(fd, -1); | 595 ASSERT_GE(fd, 0); |
| 502 | 596 |
| 503 int dup_fd = ki_dup(fd); | 597 int dup_fd = ki_dup(fd); |
| 504 ASSERT_NE(-1, dup_fd); | 598 ASSERT_NE(-1, dup_fd); |
| 505 | 599 |
| 506 ASSERT_EQ(9, ki_write(fd, "Some text", 9)); | 600 ASSERT_EQ(9, ki_write(fd, "Some text", 9)); |
| 507 ASSERT_EQ(9, ki_lseek(fd, 0, SEEK_CUR)); | 601 ASSERT_EQ(9, ki_lseek(fd, 0, SEEK_CUR)); |
| 508 ASSERT_EQ(9, ki_lseek(dup_fd, 0, SEEK_CUR)); | 602 ASSERT_EQ(9, ki_lseek(dup_fd, 0, SEEK_CUR)); |
| 509 | 603 |
| 510 int dup2_fd = 123; | 604 int dup2_fd = 123; |
| 511 ASSERT_EQ(dup2_fd, ki_dup2(fd, dup2_fd)); | 605 ASSERT_EQ(dup2_fd, ki_dup2(fd, dup2_fd)); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 } | 670 } |
| 577 | 671 |
| 578 TEST_F(KernelProxyTest, DescriptorAllocationConsistency) { | 672 TEST_F(KernelProxyTest, DescriptorAllocationConsistency) { |
| 579 // Check that the descriptor free list returns the expected ones, | 673 // Check that the descriptor free list returns the expected ones, |
| 580 // as the order is mandated by POSIX. | 674 // as the order is mandated by POSIX. |
| 581 | 675 |
| 582 // Open a file to a get a descriptor to copy for this test. | 676 // Open a file to a get a descriptor to copy for this test. |
| 583 // The test makes the assumption at all descriptors | 677 // The test makes the assumption at all descriptors |
| 584 // open by default are contiguous starting from zero. | 678 // open by default are contiguous starting from zero. |
| 585 int fd = ki_open("/foo", O_CREAT | O_RDWR, 0777); | 679 int fd = ki_open("/foo", O_CREAT | O_RDWR, 0777); |
| 586 ASSERT_GT(fd, -1); | 680 ASSERT_GE(fd, 0); |
| 587 | 681 |
| 588 // The next descriptor allocated should follow the first. | 682 // The next descriptor allocated should follow the first. |
| 589 int dup_fd = ki_dup(fd); | 683 int dup_fd = ki_dup(fd); |
| 590 ASSERT_EQ(fd + 1, dup_fd); | 684 ASSERT_EQ(fd + 1, dup_fd); |
| 591 | 685 |
| 592 // Allocate a high descriptor number. | 686 // Allocate a high descriptor number. |
| 593 ASSERT_EQ(100, ki_dup2(fd, 100)); | 687 ASSERT_EQ(100, ki_dup2(fd, 100)); |
| 594 | 688 |
| 595 // The next descriptor allocate should still come 2 places | 689 // The next descriptor allocate should still come 2 places |
| 596 // after the first. | 690 // after the first. |
| 597 int dup_fd2 = ki_dup(fd); | 691 int dup_fd2 = ki_dup(fd); |
| 598 ASSERT_EQ(fd + 2, dup_fd2); | 692 ASSERT_EQ(fd + 2, dup_fd2); |
| 599 } | 693 } |
| 600 | 694 |
| 601 TEST_F(KernelProxyTest, Lstat) { | 695 TEST_F(KernelProxyTest, Lstat) { |
| 602 int fd = ki_open("/foo", O_CREAT | O_RDWR, 0777); | 696 int fd = ki_open("/foo", O_CREAT | O_RDWR, 0777); |
| 603 ASSERT_GT(fd, -1); | 697 ASSERT_GE(fd, 0); |
| 604 ASSERT_EQ(0, ki_mkdir("/bar", S_IRUSR | S_IWUSR)); | 698 ASSERT_EQ(0, ki_mkdir("/bar", S_IRUSR | S_IWUSR)); |
| 605 | 699 |
| 606 struct stat buf; | 700 struct stat buf; |
| 607 EXPECT_EQ(0, ki_lstat("/foo", &buf)); | 701 EXPECT_EQ(0, ki_lstat("/foo", &buf)); |
| 608 EXPECT_EQ(0, buf.st_size); | 702 EXPECT_EQ(0, buf.st_size); |
| 609 EXPECT_TRUE(S_ISREG(buf.st_mode)); | 703 EXPECT_TRUE(S_ISREG(buf.st_mode)); |
| 610 | 704 |
| 611 EXPECT_EQ(0, ki_lstat("/bar", &buf)); | 705 EXPECT_EQ(0, ki_lstat("/bar", &buf)); |
| 612 EXPECT_GT(buf.st_size, 0); | 706 EXPECT_GT(buf.st_size, 0); |
| 613 EXPECT_TRUE(S_ISDIR(buf.st_mode)); | 707 EXPECT_TRUE(S_ISDIR(buf.st_mode)); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 659 // is ignored. | 753 // is ignored. |
| 660 ASSERT_EQ(0, ki_fchmod(fd, S_IFBLK | 0222)); | 754 ASSERT_EQ(0, ki_fchmod(fd, S_IFBLK | 0222)); |
| 661 ASSERT_EQ(0, ki_stat("/foo", &buf)); | 755 ASSERT_EQ(0, ki_stat("/foo", &buf)); |
| 662 EXPECT_TRUE(S_ISREG(buf.st_mode)); | 756 EXPECT_TRUE(S_ISREG(buf.st_mode)); |
| 663 ASSERT_EQ(0222, buf.st_mode & 0777); | 757 ASSERT_EQ(0222, buf.st_mode & 0777); |
| 664 } | 758 } |
| 665 | 759 |
| 666 TEST_F(KernelProxyTest, OpenDirectory) { | 760 TEST_F(KernelProxyTest, OpenDirectory) { |
| 667 // Opening a directory for read should succeed. | 761 // Opening a directory for read should succeed. |
| 668 int fd = ki_open("/", O_RDONLY, 0); | 762 int fd = ki_open("/", O_RDONLY, 0); |
| 669 ASSERT_GT(fd, -1); | 763 ASSERT_GE(fd, 0); |
| 670 | 764 |
| 671 // Opening a directory for write should fail. | 765 // Opening a directory for write should fail. |
| 672 EXPECT_EQ(-1, ki_open("/", O_RDWR, 0)); | 766 EXPECT_EQ(-1, ki_open("/", O_RDWR, 0)); |
| 673 EXPECT_EQ(errno, EISDIR); | 767 EXPECT_EQ(errno, EISDIR); |
| 674 EXPECT_EQ(-1, ki_open("/", O_WRONLY, 0)); | 768 EXPECT_EQ(-1, ki_open("/", O_WRONLY, 0)); |
| 675 EXPECT_EQ(errno, EISDIR); | 769 EXPECT_EQ(errno, EISDIR); |
| 676 } | 770 } |
| 677 | 771 |
| 678 TEST_F(KernelProxyTest, OpenWithMode) { | 772 TEST_F(KernelProxyTest, OpenWithMode) { |
| 679 int fd = ki_open("/foo", O_CREAT | O_RDWR, 0723); | 773 int fd = ki_open("/foo", O_CREAT | O_RDWR, 0723); |
| 680 ASSERT_GT(fd, -1); | 774 ASSERT_GE(fd, 0); |
| 681 | 775 |
| 682 struct stat buf; | 776 struct stat buf; |
| 683 EXPECT_EQ(0, ki_lstat("/foo", &buf)); | 777 EXPECT_EQ(0, ki_lstat("/foo", &buf)); |
| 684 EXPECT_EQ(0723, buf.st_mode & 0777); | 778 EXPECT_EQ(0723, buf.st_mode & 0777); |
| 685 } | 779 } |
| 686 | 780 |
| 687 TEST_F(KernelProxyTest, CreateWronlyWithReadOnlyMode) { | 781 TEST_F(KernelProxyTest, CreateWronlyWithReadOnlyMode) { |
| 688 int fd = ki_open("/foo", O_CREAT | O_WRONLY, 0444); | 782 int fd = ki_open("/foo", O_CREAT | O_WRONLY, 0444); |
| 689 ASSERT_GT(fd, -1); | 783 ASSERT_GE(fd, 0); |
| 690 } | 784 } |
| 691 | 785 |
| 692 TEST_F(KernelProxyTest, UseAfterClose) { | 786 TEST_F(KernelProxyTest, UseAfterClose) { |
| 693 int fd = ki_open("/dummy", O_CREAT | O_WRONLY, 0777); | 787 int fd = ki_open("/dummy", O_CREAT | O_WRONLY, 0777); |
| 694 ASSERT_GT(fd, -1); | 788 ASSERT_GE(fd, 0); |
| 695 EXPECT_EQ(5, ki_write(fd, "hello", 5)); | 789 EXPECT_EQ(5, ki_write(fd, "hello", 5)); |
| 696 EXPECT_EQ(0, ki_close(fd)); | 790 EXPECT_EQ(0, ki_close(fd)); |
| 697 EXPECT_EQ(-1, ki_write(fd, "hello", 5)); | 791 EXPECT_EQ(-1, ki_write(fd, "hello", 5)); |
| 698 EXPECT_EQ(EBADF, errno); | 792 EXPECT_EQ(EBADF, errno); |
| 699 } | 793 } |
| 700 | 794 |
| 701 TEST_F(KernelProxyTest, Utimes) { | 795 TEST_F(KernelProxyTest, Utimes) { |
| 702 struct timeval times[2]; | 796 struct timeval times[2]; |
| 703 times[0].tv_sec = 1000; | 797 times[0].tv_sec = 1000; |
| 704 times[0].tv_usec = 2000; | 798 times[0].tv_usec = 2000; |
| 705 times[1].tv_sec = 3000; | 799 times[1].tv_sec = 3000; |
| 706 times[1].tv_usec = 4000; | 800 times[1].tv_usec = 4000; |
| 707 | 801 |
| 708 int fd = ki_open("/dummy", O_CREAT | O_WRONLY, 0222); | 802 int fd = ki_open("/dummy", O_CREAT | O_WRONLY, 0222); |
| 709 ASSERT_GT(fd, -1); | 803 ASSERT_GE(fd, 0); |
| 710 EXPECT_EQ(0, ki_close(fd)); | 804 EXPECT_EQ(0, ki_close(fd)); |
| 711 | 805 |
| 712 // utime should work if the file is write-only. | 806 // utime should work if the file is write-only. |
| 713 EXPECT_EQ(0, ki_utimes("/dummy", times)); | 807 EXPECT_EQ(0, ki_utimes("/dummy", times)); |
| 714 | 808 |
| 715 // utime should work on directories (which can never be opened for write) | 809 // utime should work on directories (which can never be opened for write) |
| 716 EXPECT_EQ(0, ki_utimes("/", times)); | 810 EXPECT_EQ(0, ki_utimes("/", times)); |
| 717 | 811 |
| 718 // or if the file is read-only. | 812 // or if the file is read-only. |
| 719 EXPECT_EQ(0, ki_chmod("/dummy", 0444)); | 813 EXPECT_EQ(0, ki_chmod("/dummy", 0444)); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 738 buf.st_mtime > tm.tv_sec || | 832 buf.st_mtime > tm.tv_sec || |
| 739 (buf.st_mtime == tm.tv_sec && buf.st_mtimensec >= tm.tv_usec * 1000)); | 833 (buf.st_mtime == tm.tv_sec && buf.st_mtimensec >= tm.tv_usec * 1000)); |
| 740 } | 834 } |
| 741 | 835 |
| 742 TEST_F(KernelProxyTest, Utime) { | 836 TEST_F(KernelProxyTest, Utime) { |
| 743 struct utimbuf times; | 837 struct utimbuf times; |
| 744 times.actime = 1000; | 838 times.actime = 1000; |
| 745 times.modtime = 2000; | 839 times.modtime = 2000; |
| 746 | 840 |
| 747 int fd = ki_open("/dummy", O_CREAT | O_WRONLY, 0222); | 841 int fd = ki_open("/dummy", O_CREAT | O_WRONLY, 0222); |
| 748 ASSERT_GT(fd, -1); | 842 ASSERT_GE(fd, 0); |
| 749 EXPECT_EQ(0, ki_close(fd)); | 843 EXPECT_EQ(0, ki_close(fd)); |
| 750 | 844 |
| 751 // utime should work if the file is write-only. | 845 // utime should work if the file is write-only. |
| 752 EXPECT_EQ(0, ki_utime("/dummy", ×)); | 846 EXPECT_EQ(0, ki_utime("/dummy", ×)); |
| 753 | 847 |
| 754 // or if the file is read-only. | 848 // or if the file is read-only. |
| 755 EXPECT_EQ(0, ki_chmod("/dummy", 0444)); | 849 EXPECT_EQ(0, ki_chmod("/dummy", 0444)); |
| 756 EXPECT_EQ(0, ki_utime("/dummy", ×)); | 850 EXPECT_EQ(0, ki_utime("/dummy", ×)); |
| 757 | 851 |
| 758 // times can be NULL. In that case the access/mod times will be set to the | 852 // times can be NULL. In that case the access/mod times will be set to the |
| (...skipping 14 matching lines...) Expand all Loading... |
| 773 EXPECT_TRUE( | 867 EXPECT_TRUE( |
| 774 buf.st_mtime > tm.tv_sec || | 868 buf.st_mtime > tm.tv_sec || |
| 775 (buf.st_mtime == tm.tv_sec && buf.st_mtimensec >= tm.tv_usec * 1000)); | 869 (buf.st_mtime == tm.tv_sec && buf.st_mtimensec >= tm.tv_usec * 1000)); |
| 776 } | 870 } |
| 777 | 871 |
| 778 TEST_F(KernelProxyTest, Umask) { | 872 TEST_F(KernelProxyTest, Umask) { |
| 779 mode_t oldmask = ki_umask(0222); | 873 mode_t oldmask = ki_umask(0222); |
| 780 EXPECT_EQ(0, oldmask); | 874 EXPECT_EQ(0, oldmask); |
| 781 | 875 |
| 782 int fd = ki_open("/foo", O_CREAT | O_RDONLY, 0666); | 876 int fd = ki_open("/foo", O_CREAT | O_RDONLY, 0666); |
| 783 ASSERT_GT(fd, -1); | 877 ASSERT_GE(fd, 0); |
| 784 ki_close(fd); | 878 ki_close(fd); |
| 785 | 879 |
| 786 EXPECT_EQ(0, ki_mkdir("/dir", 0777)); | 880 EXPECT_EQ(0, ki_mkdir("/dir", 0777)); |
| 787 | 881 |
| 788 struct stat buf; | 882 struct stat buf; |
| 789 EXPECT_EQ(0, ki_stat("/foo", &buf)); | 883 EXPECT_EQ(0, ki_stat("/foo", &buf)); |
| 790 EXPECT_EQ(0444, buf.st_mode & 0777); | 884 EXPECT_EQ(0444, buf.st_mode & 0777); |
| 791 | 885 |
| 792 EXPECT_EQ(0, ki_stat("/dir", &buf)); | 886 EXPECT_EQ(0, ki_stat("/dir", &buf)); |
| 793 EXPECT_EQ(0555, buf.st_mode & 0777); | 887 EXPECT_EQ(0555, buf.st_mode & 0777); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 845 | 939 |
| 846 void TearDown() { | 940 void TearDown() { |
| 847 g_string_map.clear(); | 941 g_string_map.clear(); |
| 848 ki_uninit(); | 942 ki_uninit(); |
| 849 } | 943 } |
| 850 | 944 |
| 851 protected: | 945 protected: |
| 852 KernelProxyMountTest_KernelProxy kp_; | 946 KernelProxyMountTest_KernelProxy kp_; |
| 853 }; | 947 }; |
| 854 | 948 |
| 855 // Helper function for calling ki_ioctl without having | |
| 856 // to construct a va_list. | |
| 857 int ki_ioctl_wrapper(int fd, int request, ...) { | |
| 858 va_list ap; | |
| 859 va_start(ap, request); | |
| 860 int rtn = ki_ioctl(fd, request, ap); | |
| 861 va_end(ap); | |
| 862 return rtn; | |
| 863 } | |
| 864 | |
| 865 } // namespace | 949 } // namespace |
| 866 | 950 |
| 867 TEST_F(KernelProxyMountTest, MountInit) { | 951 TEST_F(KernelProxyMountTest, MountInit) { |
| 868 int res1 = ki_mount("/", "/mnt1", "initfs", 0, "false,foo=bar"); | 952 ASSERT_EQ(0, ki_mkdir("/mnt1", 0777)); |
| 953 int res1 = ki_mount("", "/mnt1", "initfs", 0, "false,foo=bar"); |
| 869 | 954 |
| 870 EXPECT_EQ("bar", g_string_map["foo"]); | 955 EXPECT_EQ("bar", g_string_map["foo"]); |
| 871 EXPECT_EQ(-1, res1); | 956 EXPECT_EQ(-1, res1); |
| 872 EXPECT_EQ(EINVAL, errno); | 957 EXPECT_EQ(EINVAL, errno); |
| 873 | 958 |
| 874 int res2 = ki_mount("/", "/mnt2", "initfs", 0, "true,bar=foo,x=y"); | 959 ASSERT_EQ(0, ki_mkdir("/mnt2", 0777)); |
| 960 int res2 = ki_mount("", "/mnt2", "initfs", 0, "true,bar=foo,x=y"); |
| 875 EXPECT_NE(-1, res2); | 961 EXPECT_NE(-1, res2); |
| 876 EXPECT_EQ("y", g_string_map["x"]); | 962 EXPECT_EQ("y", g_string_map["x"]); |
| 963 |
| 964 } |
| 965 |
| 966 TEST_F(KernelProxyMountTest, Passthroughfs) { |
| 967 ASSERT_EQ(0, ki_mkdir("/passthrough", 0777)); |
| 968 int res1 = ki_mount("", "/passthrough", "passthroughfs", 0, ""); |
| 969 EXPECT_NE(-1, res1); |
| 970 CheckDirContents("/passthrough", NULL, -1); |
| 877 } | 971 } |
| 878 | 972 |
| 879 TEST_F(KernelProxyMountTest, MountAndIoctl) { | 973 TEST_F(KernelProxyMountTest, MountAndIoctl) { |
| 880 ASSERT_EQ(0, ki_mount("/", "/mnt1", "initfs", 0, "")); | 974 ASSERT_EQ(0, ki_mkdir("/mnt1", 0777)); |
| 975 ASSERT_EQ(0, ki_mount("", "/mnt1", "initfs", 0, "")); |
| 881 ASSERT_NE(-1, g_fs_dev); | 976 ASSERT_NE(-1, g_fs_dev); |
| 882 | 977 |
| 883 char path[100]; | 978 char path[100]; |
| 884 snprintf(path, 100, "dev/fs/%d", g_fs_dev); | 979 snprintf(path, 100, "/dev/fs/%d", g_fs_dev); |
| 885 | 980 |
| 886 int fd = ki_open(path, O_RDONLY, 0); | 981 int fd = ki_open(path, O_RDONLY, 0); |
| 887 ASSERT_GT(fd, -1); | 982 ASSERT_GE(fd, 0); |
| 888 | 983 |
| 889 EXPECT_EQ(0, ki_ioctl_wrapper(fd, 0xdeadbeef)); | 984 EXPECT_EQ(0, ki_ioctl_wrapper(fd, 0xdeadbeef)); |
| 890 EXPECT_EQ(true, g_fs_ioctl_called); | 985 EXPECT_EQ(true, g_fs_ioctl_called); |
| 891 } | 986 } |
| 892 | 987 |
| 893 static void mount_callback(const char* source, | 988 static void mount_callback(const char* source, |
| 894 const char* target, | 989 const char* target, |
| 895 const char* filesystemtype, | 990 const char* filesystemtype, |
| 896 unsigned long mountflags, | 991 unsigned long mountflags, |
| 897 const void* data, | 992 const void* data, |
| 898 dev_t dev, | 993 dev_t dev, |
| 899 void* user_data) { | 994 void* user_data) { |
| 900 EXPECT_STREQ("/", source); | 995 EXPECT_STREQ("dummy", source); |
| 901 EXPECT_STREQ("/mnt1", target); | 996 EXPECT_STREQ("/mnt1", target); |
| 902 EXPECT_STREQ("initfs", filesystemtype); | 997 EXPECT_STREQ("initfs", filesystemtype); |
| 903 EXPECT_EQ(0, mountflags); | 998 EXPECT_EQ(0, mountflags); |
| 904 EXPECT_STREQ("", (const char*) data); | 999 EXPECT_STREQ("", (const char*) data); |
| 905 EXPECT_EQ(g_fs_dev, dev); | 1000 EXPECT_EQ(g_fs_dev, dev); |
| 906 | 1001 |
| 907 bool* callback_called = static_cast<bool*>(user_data); | 1002 bool* callback_called = static_cast<bool*>(user_data); |
| 908 *callback_called = true; | 1003 *callback_called = true; |
| 909 } | 1004 } |
| 910 | 1005 |
| 911 TEST_F(KernelProxyMountTest, MountCallback) { | 1006 TEST_F(KernelProxyMountTest, MountCallback) { |
| 912 bool callback_called = false; | 1007 bool callback_called = false; |
| 913 kp_.SetMountCallback(&mount_callback, &callback_called); | 1008 kp_.SetMountCallback(&mount_callback, &callback_called); |
| 914 ASSERT_EQ(0, ki_mount("/", "/mnt1", "initfs", 0, "")); | 1009 ASSERT_EQ(0, ki_mkdir("/mnt1", 0777)); |
| 1010 ASSERT_EQ(0, ki_mount("dummy", "/mnt1", "initfs", 0, "")); |
| 915 ASSERT_NE(-1, g_fs_dev); | 1011 ASSERT_NE(-1, g_fs_dev); |
| 916 EXPECT_EQ(true, callback_called); | 1012 EXPECT_EQ(true, callback_called); |
| 917 } | 1013 } |
| 918 | 1014 |
| 919 namespace { | 1015 namespace { |
| 920 | 1016 |
| 921 int g_MMapCount = 0; | 1017 int g_MMapCount = 0; |
| 922 | 1018 |
| 923 class KernelProxyMMapTest_Node : public Node { | 1019 class KernelProxyMMapTest_Node : public Node { |
| 924 public: | 1020 public: |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 995 | 1091 |
| 996 void TearDown() { ki_uninit(); } | 1092 void TearDown() { ki_uninit(); } |
| 997 | 1093 |
| 998 private: | 1094 private: |
| 999 KernelProxyMMapTest_KernelProxy kp_; | 1095 KernelProxyMMapTest_KernelProxy kp_; |
| 1000 }; | 1096 }; |
| 1001 | 1097 |
| 1002 } // namespace | 1098 } // namespace |
| 1003 | 1099 |
| 1004 TEST_F(KernelProxyMMapTest, MMap) { | 1100 TEST_F(KernelProxyMMapTest, MMap) { |
| 1005 ASSERT_EQ(0, ki_umount("/")); | 1101 ASSERT_EQ(0, ki_mkdir("/mmap", 0777)); |
| 1006 ASSERT_EQ(0, ki_mount("", "/", "mmapfs", 0, NULL)); | 1102 ASSERT_EQ(0, ki_mount("", "/mmap", "mmapfs", 0, NULL)); |
| 1007 int fd = ki_open("/file", O_RDWR | O_CREAT, 0777); | 1103 int fd = ki_open("/mmap/file", O_RDWR | O_CREAT, 0777); |
| 1008 ASSERT_NE(-1, fd); | 1104 ASSERT_NE(-1, fd); |
| 1009 | 1105 |
| 1010 void* addr1 = ki_mmap(NULL, 0x800, PROT_READ, MAP_PRIVATE, fd, 0); | 1106 void* addr1 = ki_mmap(NULL, 0x800, PROT_READ, MAP_PRIVATE, fd, 0); |
| 1011 ASSERT_EQ(reinterpret_cast<void*>(0x1000), addr1); | 1107 ASSERT_EQ(reinterpret_cast<void*>(0x1000), addr1); |
| 1012 ASSERT_EQ(1, g_MMapCount); | 1108 ASSERT_EQ(1, g_MMapCount); |
| 1013 | 1109 |
| 1014 void* addr2 = ki_mmap(NULL, 0x800, PROT_READ, MAP_PRIVATE, fd, 0); | 1110 void* addr2 = ki_mmap(NULL, 0x800, PROT_READ, MAP_PRIVATE, fd, 0); |
| 1015 ASSERT_EQ(reinterpret_cast<void*>(0x2000), addr2); | 1111 ASSERT_EQ(reinterpret_cast<void*>(0x2000), addr2); |
| 1016 ASSERT_EQ(2, g_MMapCount); | 1112 ASSERT_EQ(2, g_MMapCount); |
| 1017 | 1113 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1061 ScopedRef<MockFs> fs_; | 1157 ScopedRef<MockFs> fs_; |
| 1062 }; | 1158 }; |
| 1063 | 1159 |
| 1064 class KernelProxyErrorTest : public ::testing::Test { | 1160 class KernelProxyErrorTest : public ::testing::Test { |
| 1065 public: | 1161 public: |
| 1066 KernelProxyErrorTest() {} | 1162 KernelProxyErrorTest() {} |
| 1067 | 1163 |
| 1068 void SetUp() { | 1164 void SetUp() { |
| 1069 ASSERT_EQ(0, ki_push_state_for_testing()); | 1165 ASSERT_EQ(0, ki_push_state_for_testing()); |
| 1070 ASSERT_EQ(0, ki_init(&kp_)); | 1166 ASSERT_EQ(0, ki_init(&kp_)); |
| 1071 // Unmount the passthrough FS and mount a testfs. | 1167 // Unmount root fs and mount a testfs. |
| 1072 EXPECT_EQ(0, kp_.umount("/")); | 1168 EXPECT_EQ(0, kp_.umount("/")); |
| 1073 EXPECT_EQ(0, kp_.mount("", "/", "testfs", 0, NULL)); | 1169 EXPECT_EQ(0, kp_.mount("", "/", "testfs", 0, NULL)); |
| 1074 } | 1170 } |
| 1075 | 1171 |
| 1076 void TearDown() { ki_uninit(); } | 1172 void TearDown() { ki_uninit(); } |
| 1077 | 1173 |
| 1078 ScopedRef<MockFs> fs() { return kp_.fs(); } | 1174 ScopedRef<MockFs> fs() { return kp_.fs(); } |
| 1079 | 1175 |
| 1080 private: | 1176 private: |
| 1081 KernelProxyErrorTest_KernelProxy kp_; | 1177 KernelProxyErrorTest_KernelProxy kp_; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1120 | 1216 |
| 1121 int fd = ki_open("/dummy", O_RDONLY, 0); | 1217 int fd = ki_open("/dummy", O_RDONLY, 0); |
| 1122 EXPECT_NE(0, fd); | 1218 EXPECT_NE(0, fd); |
| 1123 | 1219 |
| 1124 char buf[20]; | 1220 char buf[20]; |
| 1125 EXPECT_EQ(-1, ki_read(fd, &buf[0], 20)); | 1221 EXPECT_EQ(-1, ki_read(fd, &buf[0], 20)); |
| 1126 // The Filesystem should be able to return whatever error it wants and have it | 1222 // The Filesystem should be able to return whatever error it wants and have it |
| 1127 // propagate through. | 1223 // propagate through. |
| 1128 EXPECT_EQ(1234, errno); | 1224 EXPECT_EQ(1234, errno); |
| 1129 } | 1225 } |
| OLD | NEW |