| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 } | 66 } |
| 67 | 67 |
| 68 void TearDown() { ki_uninit(); } | 68 void TearDown() { ki_uninit(); } |
| 69 | 69 |
| 70 protected: | 70 protected: |
| 71 KernelProxyTest_KernelProxy kp_; | 71 KernelProxyTest_KernelProxy kp_; |
| 72 }; | 72 }; |
| 73 | 73 |
| 74 } // namespace | 74 } // namespace |
| 75 | 75 |
| 76 // Helper function for calling ki_fcntl without having |
| 77 // to construct a va_list. |
| 76 static int ki_fcntl_wrapper(int fd, int request, ...) { | 78 static int ki_fcntl_wrapper(int fd, int request, ...) { |
| 77 va_list ap; | 79 va_list ap; |
| 78 va_start(ap, request); | 80 va_start(ap, request); |
| 79 int rtn = ki_fcntl(fd, request, ap); | 81 int rtn = ki_fcntl(fd, request, ap); |
| 80 va_end(ap); | 82 va_end(ap); |
| 81 return rtn; | 83 return rtn; |
| 82 } | 84 } |
| 83 | 85 |
| 84 /** | 86 // Helper function for calling ki_ioctl without having |
| 85 * Test for fcntl commands F_SETFD and F_GETFD. This | 87 // to construct a va_list. |
| 86 * is tested here rather than in the mount_node tests | 88 static int ki_ioctl_wrapper(int fd, int request, ...) { |
| 87 * since the fd flags are not stored in the kernel_handle | 89 va_list ap; |
| 88 * or the filesystem node but directly in the FD mapping. | 90 va_start(ap, request); |
| 89 */ | 91 int rtn = ki_ioctl(fd, request, ap); |
| 92 va_end(ap); |
| 93 return rtn; |
| 94 } |
| 95 |
| 96 // Helper to verify directory contents using ki_getdents. |
| 97 // Verified that each of the 'count' elements in the 'expected' array |
| 98 // are present in the directory and that no other entries are present. |
| 99 // If count is -1 then no checking is done and enties are printed using |
| 100 // printf. |
| 101 static void CheckDirContents(const char* dirname, const char** expected, |
| 102 int count) { |
| 103 int dir = ki_open(dirname, O_RDONLY, 0); |
| 104 ASSERT_GE(dir, 0); |
| 105 while (1) { |
| 106 char buf[512]; |
| 107 int rtn = ki_getdents(dir, buf, sizeof(buf)); |
| 108 if (rtn <= 0) |
| 109 break; |
| 110 int offset = 0; |
| 111 while (offset < rtn) { |
| 112 struct dirent* entry = (struct dirent*)(buf + offset); |
| 113 if (count == -1) |
| 114 printf("entry: %s\n", entry->d_name); |
| 115 offset += entry->d_reclen; |
| 116 if (count == -1) |
| 117 continue; |
| 118 int i; |
| 119 for (i = 0; i < count; i++) { |
| 120 if (expected[i] && strcmp(expected[i], entry->d_name) == 0) { |
| 121 expected[i] = NULL; |
| 122 break; |
| 123 } |
| 124 } |
| 125 if (i == count) { |
| 126 FAIL() << "Unexpeected entry '" << entry->d_name |
| 127 << "' in directory: " << dirname; |
| 128 } |
| 129 } |
| 130 } |
| 131 |
| 132 ASSERT_EQ(0, ki_close(dir)); |
| 133 |
| 134 if (count != -1) { |
| 135 for (int i = 0; i < count; i++) { |
| 136 if (expected[i] != NULL) { |
| 137 FAIL() << "Expected entry '" << expected[i] |
| 138 << "' not found in directory: " << dirname; |
| 139 } |
| 140 } |
| 141 } |
| 142 } |
| 143 |
| 144 // Test for fcntl commands F_SETFD and F_GETFD. This |
| 145 // is tested here rather than in the mount_node tests |
| 146 // since the fd flags are not stored in the kernel_handle |
| 147 // or the filesystem node but directly in the FD mapping. |
| 90 TEST_F(KernelProxyTest, Fcntl_GETFD) { | 148 TEST_F(KernelProxyTest, Fcntl_GETFD) { |
| 91 int fd = ki_open("/test", O_RDWR | O_CREAT, 0777); | 149 int fd = ki_open("/test", O_RDWR | O_CREAT, 0777); |
| 92 ASSERT_NE(-1, fd); | 150 ASSERT_NE(-1, fd); |
| 93 | 151 |
| 94 // FD flags should start as zero. | 152 // FD flags should start as zero. |
| 95 ASSERT_EQ(0, ki_fcntl_wrapper(fd, F_GETFD)); | 153 ASSERT_EQ(0, ki_fcntl_wrapper(fd, F_GETFD)); |
| 96 | 154 |
| 97 // Check that setting FD_CLOEXEC works | 155 // Check that setting FD_CLOEXEC works |
| 98 int flags = FD_CLOEXEC; | 156 int flags = FD_CLOEXEC; |
| 99 ASSERT_EQ(0, ki_fcntl_wrapper(fd, F_SETFD, flags)) | 157 ASSERT_EQ(0, ki_fcntl_wrapper(fd, F_SETFD, flags)) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 113 | 171 |
| 114 MemFs* filesystem = (MemFs*)kp_.RootFs(); | 172 MemFs* filesystem = (MemFs*)kp_.RootFs(); |
| 115 ScopedNode root; | 173 ScopedNode root; |
| 116 | 174 |
| 117 ASSERT_EQ(0, filesystem->Open(Path("/"), O_RDONLY, &root)); | 175 ASSERT_EQ(0, filesystem->Open(Path("/"), O_RDONLY, &root)); |
| 118 ASSERT_EQ(0, root->ChildCount()); | 176 ASSERT_EQ(0, root->ChildCount()); |
| 119 | 177 |
| 120 for (int file_num = 0; file_num < 4096; file_num++) { | 178 for (int file_num = 0; file_num < 4096; file_num++) { |
| 121 sprintf(filename, "/foo%i.tmp", file_num++); | 179 sprintf(filename, "/foo%i.tmp", file_num++); |
| 122 int fd = ki_open(filename, O_WRONLY | O_CREAT, 0777); | 180 int fd = ki_open(filename, O_WRONLY | O_CREAT, 0777); |
| 123 ASSERT_GT(fd, -1); | 181 ASSERT_GE(fd, 0); |
| 124 ASSERT_EQ(1, root->ChildCount()); | 182 ASSERT_EQ(1, root->ChildCount()); |
| 125 ASSERT_EQ(buffer_size, ki_write(fd, garbage, buffer_size)); | 183 ASSERT_EQ(buffer_size, ki_write(fd, garbage, buffer_size)); |
| 126 ki_close(fd); | 184 ki_close(fd); |
| 127 ASSERT_EQ(0, ki_remove(filename)); | 185 ASSERT_EQ(0, ki_remove(filename)); |
| 128 } | 186 } |
| 129 ASSERT_EQ(0, root->ChildCount()); | 187 ASSERT_EQ(0, root->ChildCount()); |
| 130 } | 188 } |
| 131 | 189 |
| 132 static bool g_handler_called = false; | 190 static bool g_handler_called = false; |
| 133 static void sighandler(int) { g_handler_called = true; } | 191 static void sighandler(int) { g_handler_called = true; } |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 // Restore existing handler | 287 // Restore existing handler |
| 230 oldsig = ki_signal(SIGWINCH, oldsig); | 288 oldsig = ki_signal(SIGWINCH, oldsig); |
| 231 | 289 |
| 232 // Verify the our newsig was returned as previous handler | 290 // Verify the our newsig was returned as previous handler |
| 233 ASSERT_EQ(oldsig, newsig); | 291 ASSERT_EQ(oldsig, newsig); |
| 234 } | 292 } |
| 235 | 293 |
| 236 TEST_F(KernelProxyTest, Rename) { | 294 TEST_F(KernelProxyTest, Rename) { |
| 237 // Create a dummy file | 295 // Create a dummy file |
| 238 int file1 = ki_open("/test1.txt", O_RDWR | O_CREAT, 0777); | 296 int file1 = ki_open("/test1.txt", O_RDWR | O_CREAT, 0777); |
| 239 ASSERT_GT(file1, -1); | 297 ASSERT_GE(file1, 0); |
| 240 ASSERT_EQ(0, ki_close(file1)); | 298 ASSERT_EQ(0, ki_close(file1)); |
| 241 | 299 |
| 242 // Test the renaming works | 300 // Test the renaming works |
| 243 ASSERT_EQ(0, ki_rename("/test1.txt", "/test2.txt")); | 301 ASSERT_EQ(0, ki_rename("/test1.txt", "/test2.txt")); |
| 244 | 302 |
| 245 // Test that renaming across mount points fails | 303 // Test that renaming across mount points fails |
| 246 ASSERT_EQ(0, ki_mount("", "/foo", "memfs", 0, "")); | 304 ASSERT_EQ(0, ki_mount("", "/foo", "memfs", 0, "")); |
| 247 ASSERT_EQ(-1, ki_rename("/test2.txt", "/foo/test2.txt")); | 305 ASSERT_EQ(-1, ki_rename("/test2.txt", "/foo/test2.txt")); |
| 248 ASSERT_EQ(EXDEV, errno); | 306 ASSERT_EQ(EXDEV, errno); |
| 249 } | 307 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 279 | 337 |
| 280 memset(text, 0, sizeof(text)); | 338 memset(text, 0, sizeof(text)); |
| 281 EXPECT_EQ(-1, ki_chdir("foo")); | 339 EXPECT_EQ(-1, ki_chdir("foo")); |
| 282 EXPECT_EQ(ENOENT, errno); | 340 EXPECT_EQ(ENOENT, errno); |
| 283 EXPECT_EQ(0, ki_chdir("..")); | 341 EXPECT_EQ(0, ki_chdir("..")); |
| 284 EXPECT_EQ(0, ki_chdir("/foo")); | 342 EXPECT_EQ(0, ki_chdir("/foo")); |
| 285 EXPECT_EQ(text, ki_getcwd(text, sizeof(text))); | 343 EXPECT_EQ(text, ki_getcwd(text, sizeof(text))); |
| 286 EXPECT_STREQ("/foo", text); | 344 EXPECT_STREQ("/foo", text); |
| 287 } | 345 } |
| 288 | 346 |
| 347 TEST_F(KernelProxyTest, Mkdir) { |
| 348 ASSERT_EQ(0, ki_mkdir("/foo", S_IREAD | S_IWRITE)); |
| 349 ASSERT_EQ(-1, ki_mkdir("/foo", S_IREAD | S_IWRITE)); |
| 350 ASSERT_EQ(EEXIST, errno); |
| 351 |
| 352 // Some component of parent directory does not exist |
| 353 ASSERT_EQ(-1, ki_mkdir("/does_not_exist/foo", S_IREAD | S_IWRITE)); |
| 354 ASSERT_EQ(ENOENT, errno); |
| 355 |
| 356 int fd = ki_open("/filename", O_CREAT | O_RDWR, 0777); |
| 357 ASSERT_GE(fd, 0); |
| 358 |
| 359 // Some component of parent directory is not actually a directory |
| 360 ASSERT_EQ(-1, ki_mkdir("/filename/foo", S_IREAD | S_IWRITE)); |
| 361 ASSERT_EQ(ENOTDIR, errno); |
| 362 } |
| 363 |
| 364 TEST_F(KernelProxyTest, Rmdir) { |
| 365 ASSERT_EQ(-1, ki_rmdir("/dev/fs")); |
| 366 ASSERT_EQ(EPERM, errno); |
| 367 |
| 368 ASSERT_EQ(-1, ki_rmdir("/foo")); |
| 369 ASSERT_EQ(ENOENT, errno); |
| 370 } |
| 371 |
| 289 TEST_F(KernelProxyTest, FDPathMapping) { | 372 TEST_F(KernelProxyTest, FDPathMapping) { |
| 290 char text[1024]; | 373 char text[1024]; |
| 291 | 374 |
| 292 int fd1, fd2, fd3, fd4, fd5; | 375 int fd1, fd2, fd3, fd4, fd5; |
| 293 | 376 |
| 294 EXPECT_EQ(0, ki_mkdir("/foo", S_IREAD | S_IWRITE)); | 377 EXPECT_EQ(0, ki_mkdir("/foo", S_IREAD | S_IWRITE)); |
| 295 EXPECT_EQ(0, ki_mkdir("/foo/bar", S_IREAD | S_IWRITE)); | 378 EXPECT_EQ(0, ki_mkdir("/foo/bar", S_IREAD | S_IWRITE)); |
| 296 EXPECT_EQ(0, ki_mkdir("/example", S_IREAD | S_IWRITE)); | 379 EXPECT_EQ(0, ki_mkdir("/example", S_IREAD | S_IWRITE)); |
| 297 ki_chdir("/foo"); | 380 ki_chdir("/foo"); |
| 298 | 381 |
| 299 fd1 = ki_open("/example", O_RDONLY, 0); | 382 fd1 = ki_open("/example", O_RDONLY, 0); |
| 300 EXPECT_NE(-1, fd1); | 383 ASSERT_GT(fd1, 0); |
| 301 EXPECT_EQ(ki_fchdir(fd1), 0); | 384 EXPECT_EQ(ki_fchdir(fd1), 0); |
| 302 EXPECT_EQ(text, ki_getcwd(text, sizeof(text))); | 385 EXPECT_EQ(text, ki_getcwd(text, sizeof(text))); |
| 303 EXPECT_STREQ("/example", text); | 386 EXPECT_STREQ("/example", text); |
| 304 | 387 |
| 305 EXPECT_EQ(0, ki_chdir("/foo")); | 388 EXPECT_EQ(0, ki_chdir("/foo")); |
| 306 fd2 = ki_open("../example", O_RDONLY, 0); | 389 fd2 = ki_open("../example", O_RDONLY, 0); |
| 307 EXPECT_NE(-1, fd2); | 390 ASSERT_GE(fd2, 0); |
| 308 EXPECT_EQ(0, ki_fchdir(fd2)); | 391 EXPECT_EQ(0, ki_fchdir(fd2)); |
| 309 EXPECT_EQ(text, ki_getcwd(text, sizeof(text))); | 392 EXPECT_EQ(text, ki_getcwd(text, sizeof(text))); |
| 310 EXPECT_STREQ("/example", text); | 393 EXPECT_STREQ("/example", text); |
| 311 | 394 |
| 312 EXPECT_EQ(0, ki_chdir("/foo")); | 395 EXPECT_EQ(0, ki_chdir("/foo")); |
| 313 fd3 = ki_open("../test", O_CREAT | O_RDWR, 0777); | 396 fd3 = ki_open("../test", O_CREAT | O_RDWR, 0777); |
| 314 EXPECT_NE(-1, fd3); | 397 ASSERT_GE(fd3, 0); |
| 315 EXPECT_EQ(-1, ki_fchdir(fd3)); | 398 EXPECT_EQ(-1, ki_fchdir(fd3)); |
| 316 EXPECT_EQ(ENOTDIR, errno); | 399 EXPECT_EQ(ENOTDIR, errno); |
| 317 | 400 |
| 318 EXPECT_EQ(0, ki_chdir("/foo")); | 401 EXPECT_EQ(0, ki_chdir("/foo")); |
| 319 fd4 = ki_open("bar", O_RDONLY, 0); | 402 fd4 = ki_open("bar", O_RDONLY, 0); |
| 403 ASSERT_GE(fd4, 0); |
| 320 EXPECT_EQ(0, ki_fchdir(fd4)); | 404 EXPECT_EQ(0, ki_fchdir(fd4)); |
| 321 EXPECT_EQ(text, ki_getcwd(text, sizeof(text))); | 405 EXPECT_EQ(text, ki_getcwd(text, sizeof(text))); |
| 322 EXPECT_STREQ("/foo/bar", text); | 406 EXPECT_STREQ("/foo/bar", text); |
| 323 EXPECT_EQ(0, ki_chdir("/example")); | 407 EXPECT_EQ(0, ki_chdir("/example")); |
| 324 EXPECT_EQ(0, ki_fchdir(fd4)); | 408 EXPECT_EQ(0, ki_fchdir(fd4)); |
| 325 EXPECT_EQ(text, ki_getcwd(text, sizeof(text))); | 409 EXPECT_EQ(text, ki_getcwd(text, sizeof(text))); |
| 326 EXPECT_STREQ("/foo/bar", text); | 410 EXPECT_STREQ("/foo/bar", text); |
| 327 | 411 |
| 328 EXPECT_EQ(0, ki_chdir("/example")); | 412 EXPECT_EQ(0, ki_chdir("/example")); |
| 329 fd5 = ki_dup(fd4); | 413 fd5 = ki_dup(fd4); |
| 330 ASSERT_GT(fd5, -1); | 414 ASSERT_GE(fd5, 0); |
| 331 ASSERT_NE(fd4, fd5); | 415 ASSERT_NE(fd4, fd5); |
| 332 EXPECT_EQ(0, ki_fchdir(fd5)); | 416 EXPECT_EQ(0, ki_fchdir(fd5)); |
| 333 EXPECT_EQ(text, ki_getcwd(text, sizeof(text))); | 417 EXPECT_EQ(text, ki_getcwd(text, sizeof(text))); |
| 334 EXPECT_STREQ("/foo/bar", text); | 418 EXPECT_STREQ("/foo/bar", text); |
| 335 | 419 |
| 336 fd5 = 123; | 420 fd5 = 123; |
| 337 | 421 |
| 338 EXPECT_EQ(0, ki_chdir("/example")); | 422 EXPECT_EQ(0, ki_chdir("/example")); |
| 339 EXPECT_EQ(fd5, ki_dup2(fd4, fd5)); | 423 EXPECT_EQ(fd5, ki_dup2(fd4, fd5)); |
| 340 EXPECT_EQ(0, ki_fchdir(fd5)); | 424 EXPECT_EQ(0, ki_fchdir(fd5)); |
| 341 EXPECT_EQ(text, ki_getcwd(text, sizeof(text))); | 425 EXPECT_EQ(text, ki_getcwd(text, sizeof(text))); |
| 342 EXPECT_STREQ("/foo/bar", text); | 426 EXPECT_STREQ("/foo/bar", text); |
| 343 } | 427 } |
| 344 | 428 |
| 429 TEST_F(KernelProxyTest, Getdents) { |
| 430 const char* expected[] = { "..", "." }; |
| 431 CheckDirContents("/", expected, 2); |
| 432 |
| 433 ASSERT_GE(ki_open("/foo", O_RDWR | O_CREAT, 0777), 0); |
| 434 const char* expected1[] = { "foo", "..", "." }; |
| 435 CheckDirContents("/", expected1, 3); |
| 436 } |
| 437 |
| 345 TEST_F(KernelProxyTest, BasicReadWrite) { | 438 TEST_F(KernelProxyTest, BasicReadWrite) { |
| 346 char text[1024]; | 439 char text[1024]; |
| 347 int fd1, fd2, fd3; | 440 int fd1, fd2, fd3; |
| 348 int len; | 441 int len; |
| 349 | 442 |
| 350 // Fail to delete non existant "/foo" | 443 // Fail to delete non existant "/foo" |
| 351 EXPECT_EQ(-1, ki_rmdir("/foo")); | 444 EXPECT_EQ(-1, ki_rmdir("/foo")); |
| 352 EXPECT_EQ(ENOENT, errno); | 445 EXPECT_EQ(ENOENT, errno); |
| 353 | 446 |
| 354 // Create "/foo" | 447 // Create "/foo" |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 EXPECT_EQ(0, ki_close(fd1)); | 550 EXPECT_EQ(0, ki_close(fd1)); |
| 458 | 551 |
| 459 // Truncate should fail if the file is not writable. | 552 // Truncate should fail if the file is not writable. |
| 460 EXPECT_EQ(0, ki_chmod("/trunc", 0444)); | 553 EXPECT_EQ(0, ki_chmod("/trunc", 0444)); |
| 461 EXPECT_EQ(-1, ki_truncate("/trunc", 0)); | 554 EXPECT_EQ(-1, ki_truncate("/trunc", 0)); |
| 462 EXPECT_EQ(EACCES, errno); | 555 EXPECT_EQ(EACCES, errno); |
| 463 } | 556 } |
| 464 | 557 |
| 465 TEST_F(KernelProxyTest, Lseek) { | 558 TEST_F(KernelProxyTest, Lseek) { |
| 466 int fd = ki_open("/foo", O_CREAT | O_RDWR, 0777); | 559 int fd = ki_open("/foo", O_CREAT | O_RDWR, 0777); |
| 467 ASSERT_GT(fd, -1); | 560 ASSERT_GE(fd, 0); |
| 468 ASSERT_EQ(9, ki_write(fd, "Some text", 9)); | 561 ASSERT_EQ(9, ki_write(fd, "Some text", 9)); |
| 469 | 562 |
| 470 ASSERT_EQ(9, ki_lseek(fd, 0, SEEK_CUR)); | 563 ASSERT_EQ(9, ki_lseek(fd, 0, SEEK_CUR)); |
| 471 ASSERT_EQ(9, ki_lseek(fd, 0, SEEK_END)); | 564 ASSERT_EQ(9, ki_lseek(fd, 0, SEEK_END)); |
| 472 ASSERT_EQ(-1, ki_lseek(fd, -1, SEEK_SET)); | 565 ASSERT_EQ(-1, ki_lseek(fd, -1, SEEK_SET)); |
| 473 ASSERT_EQ(EINVAL, errno); | 566 ASSERT_EQ(EINVAL, errno); |
| 474 | 567 |
| 475 // Seek past end of file. | 568 // Seek past end of file. |
| 476 ASSERT_EQ(13, ki_lseek(fd, 13, SEEK_SET)); | 569 ASSERT_EQ(13, ki_lseek(fd, 13, SEEK_SET)); |
| 477 char buffer[4]; | 570 char buffer[4]; |
| 478 memset(&buffer[0], 0xfe, 4); | 571 memset(&buffer[0], 0xfe, 4); |
| 479 ASSERT_EQ(9, ki_lseek(fd, -4, SEEK_END)); | 572 ASSERT_EQ(9, ki_lseek(fd, -4, SEEK_END)); |
| 480 ASSERT_EQ(9, ki_lseek(fd, 0, SEEK_CUR)); | 573 ASSERT_EQ(9, ki_lseek(fd, 0, SEEK_CUR)); |
| 481 ASSERT_EQ(4, ki_read(fd, &buffer[0], 4)); | 574 ASSERT_EQ(4, ki_read(fd, &buffer[0], 4)); |
| 482 ASSERT_EQ(0, memcmp("\0\0\0\0", buffer, 4)); | 575 ASSERT_EQ(0, memcmp("\0\0\0\0", buffer, 4)); |
| 483 } | 576 } |
| 484 | 577 |
| 485 TEST_F(KernelProxyTest, CloseTwice) { | 578 TEST_F(KernelProxyTest, CloseTwice) { |
| 486 int fd = ki_open("/foo", O_CREAT | O_RDWR, 0777); | 579 int fd = ki_open("/foo", O_CREAT | O_RDWR, 0777); |
| 487 ASSERT_GT(fd, -1); | 580 ASSERT_GE(fd, 0); |
| 488 | 581 |
| 489 EXPECT_EQ(9, ki_write(fd, "Some text", 9)); | 582 EXPECT_EQ(9, ki_write(fd, "Some text", 9)); |
| 490 | 583 |
| 491 int fd2 = ki_dup(fd); | 584 int fd2 = ki_dup(fd); |
| 492 ASSERT_GT(fd2, -1); | 585 ASSERT_GE(fd2, 0); |
| 493 | 586 |
| 494 EXPECT_EQ(0, ki_close(fd)); | 587 EXPECT_EQ(0, ki_close(fd)); |
| 495 EXPECT_EQ(0, ki_close(fd2)); | 588 EXPECT_EQ(0, ki_close(fd2)); |
| 496 } | 589 } |
| 497 | 590 |
| 498 TEST_F(KernelProxyTest, Dup) { | 591 TEST_F(KernelProxyTest, Dup) { |
| 499 int fd = ki_open("/foo", O_CREAT | O_RDWR, 0777); | 592 int fd = ki_open("/foo", O_CREAT | O_RDWR, 0777); |
| 500 ASSERT_GT(fd, -1); | 593 ASSERT_GE(fd, 0); |
| 501 | 594 |
| 502 int dup_fd = ki_dup(fd); | 595 int dup_fd = ki_dup(fd); |
| 503 ASSERT_NE(-1, dup_fd); | 596 ASSERT_NE(-1, dup_fd); |
| 504 | 597 |
| 505 ASSERT_EQ(9, ki_write(fd, "Some text", 9)); | 598 ASSERT_EQ(9, ki_write(fd, "Some text", 9)); |
| 506 ASSERT_EQ(9, ki_lseek(fd, 0, SEEK_CUR)); | 599 ASSERT_EQ(9, ki_lseek(fd, 0, SEEK_CUR)); |
| 507 ASSERT_EQ(9, ki_lseek(dup_fd, 0, SEEK_CUR)); | 600 ASSERT_EQ(9, ki_lseek(dup_fd, 0, SEEK_CUR)); |
| 508 | 601 |
| 509 int dup2_fd = 123; | 602 int dup2_fd = 123; |
| 510 ASSERT_EQ(dup2_fd, ki_dup2(fd, dup2_fd)); | 603 ASSERT_EQ(dup2_fd, ki_dup2(fd, dup2_fd)); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 528 } | 621 } |
| 529 | 622 |
| 530 TEST_F(KernelProxyTest, DescriptorAllocationConsistency) { | 623 TEST_F(KernelProxyTest, DescriptorAllocationConsistency) { |
| 531 // Check that the descriptor free list returns the expected ones, | 624 // Check that the descriptor free list returns the expected ones, |
| 532 // as the order is mandated by POSIX. | 625 // as the order is mandated by POSIX. |
| 533 | 626 |
| 534 // Open a file to a get a descriptor to copy for this test. | 627 // Open a file to a get a descriptor to copy for this test. |
| 535 // The test makes the assumption at all descriptors | 628 // The test makes the assumption at all descriptors |
| 536 // open by default are contiguous starting from zero. | 629 // open by default are contiguous starting from zero. |
| 537 int fd = ki_open("/foo", O_CREAT | O_RDWR, 0777); | 630 int fd = ki_open("/foo", O_CREAT | O_RDWR, 0777); |
| 538 ASSERT_GT(fd, -1); | 631 ASSERT_GE(fd, 0); |
| 539 | 632 |
| 540 // The next descriptor allocated should follow the first. | 633 // The next descriptor allocated should follow the first. |
| 541 int dup_fd = ki_dup(fd); | 634 int dup_fd = ki_dup(fd); |
| 542 ASSERT_EQ(fd + 1, dup_fd); | 635 ASSERT_EQ(fd + 1, dup_fd); |
| 543 | 636 |
| 544 // Allocate a high descriptor number. | 637 // Allocate a high descriptor number. |
| 545 ASSERT_EQ(100, ki_dup2(fd, 100)); | 638 ASSERT_EQ(100, ki_dup2(fd, 100)); |
| 546 | 639 |
| 547 // The next descriptor allocate should still come 2 places | 640 // The next descriptor allocate should still come 2 places |
| 548 // after the first. | 641 // after the first. |
| 549 int dup_fd2 = ki_dup(fd); | 642 int dup_fd2 = ki_dup(fd); |
| 550 ASSERT_EQ(fd + 2, dup_fd2); | 643 ASSERT_EQ(fd + 2, dup_fd2); |
| 551 } | 644 } |
| 552 | 645 |
| 553 TEST_F(KernelProxyTest, Lstat) { | 646 TEST_F(KernelProxyTest, Lstat) { |
| 554 int fd = ki_open("/foo", O_CREAT | O_RDWR, 0777); | 647 int fd = ki_open("/foo", O_CREAT | O_RDWR, 0777); |
| 555 ASSERT_GT(fd, -1); | 648 ASSERT_GE(fd, 0); |
| 556 ASSERT_EQ(0, ki_mkdir("/bar", S_IREAD | S_IWRITE)); | 649 ASSERT_EQ(0, ki_mkdir("/bar", S_IREAD | S_IWRITE)); |
| 557 | 650 |
| 558 struct stat buf; | 651 struct stat buf; |
| 559 EXPECT_EQ(0, ki_lstat("/foo", &buf)); | 652 EXPECT_EQ(0, ki_lstat("/foo", &buf)); |
| 560 EXPECT_EQ(0, buf.st_size); | 653 EXPECT_EQ(0, buf.st_size); |
| 561 EXPECT_TRUE(S_ISREG(buf.st_mode)); | 654 EXPECT_TRUE(S_ISREG(buf.st_mode)); |
| 562 | 655 |
| 563 EXPECT_EQ(0, ki_lstat("/bar", &buf)); | 656 EXPECT_EQ(0, ki_lstat("/bar", &buf)); |
| 564 EXPECT_EQ(0, buf.st_size); | 657 EXPECT_EQ(0, buf.st_size); |
| 565 EXPECT_TRUE(S_ISDIR(buf.st_mode)); | 658 EXPECT_TRUE(S_ISDIR(buf.st_mode)); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 611 // is ignored. | 704 // is ignored. |
| 612 ASSERT_EQ(0, ki_fchmod(fd, S_IFBLK | 0222)); | 705 ASSERT_EQ(0, ki_fchmod(fd, S_IFBLK | 0222)); |
| 613 ASSERT_EQ(0, ki_stat("/foo", &buf)); | 706 ASSERT_EQ(0, ki_stat("/foo", &buf)); |
| 614 EXPECT_TRUE(S_ISREG(buf.st_mode)); | 707 EXPECT_TRUE(S_ISREG(buf.st_mode)); |
| 615 ASSERT_EQ(0222, buf.st_mode & 0777); | 708 ASSERT_EQ(0222, buf.st_mode & 0777); |
| 616 } | 709 } |
| 617 | 710 |
| 618 TEST_F(KernelProxyTest, OpenDirectory) { | 711 TEST_F(KernelProxyTest, OpenDirectory) { |
| 619 // Opening a directory for read should succeed. | 712 // Opening a directory for read should succeed. |
| 620 int fd = ki_open("/", O_RDONLY, 0); | 713 int fd = ki_open("/", O_RDONLY, 0); |
| 621 ASSERT_GT(fd, -1); | 714 ASSERT_GE(fd, 0); |
| 622 | 715 |
| 623 // Opening a directory for write should fail. | 716 // Opening a directory for write should fail. |
| 624 EXPECT_EQ(-1, ki_open("/", O_RDWR, 0)); | 717 EXPECT_EQ(-1, ki_open("/", O_RDWR, 0)); |
| 625 EXPECT_EQ(errno, EISDIR); | 718 EXPECT_EQ(errno, EISDIR); |
| 626 EXPECT_EQ(-1, ki_open("/", O_WRONLY, 0)); | 719 EXPECT_EQ(-1, ki_open("/", O_WRONLY, 0)); |
| 627 EXPECT_EQ(errno, EISDIR); | 720 EXPECT_EQ(errno, EISDIR); |
| 628 } | 721 } |
| 629 | 722 |
| 630 TEST_F(KernelProxyTest, OpenWithMode) { | 723 TEST_F(KernelProxyTest, OpenWithMode) { |
| 631 int fd = ki_open("/foo", O_CREAT | O_RDWR, 0723); | 724 int fd = ki_open("/foo", O_CREAT | O_RDWR, 0723); |
| 632 ASSERT_GT(fd, -1); | 725 ASSERT_GE(fd, 0); |
| 633 | 726 |
| 634 struct stat buf; | 727 struct stat buf; |
| 635 EXPECT_EQ(0, ki_lstat("/foo", &buf)); | 728 EXPECT_EQ(0, ki_lstat("/foo", &buf)); |
| 636 EXPECT_EQ(0723, buf.st_mode & 0777); | 729 EXPECT_EQ(0723, buf.st_mode & 0777); |
| 637 } | 730 } |
| 638 | 731 |
| 639 TEST_F(KernelProxyTest, CreateWronlyWithReadOnlyMode) { | 732 TEST_F(KernelProxyTest, CreateWronlyWithReadOnlyMode) { |
| 640 int fd = ki_open("/foo", O_CREAT | O_WRONLY, 0444); | 733 int fd = ki_open("/foo", O_CREAT | O_WRONLY, 0444); |
| 641 ASSERT_GT(fd, -1); | 734 ASSERT_GE(fd, 0); |
| 642 } | 735 } |
| 643 | 736 |
| 644 TEST_F(KernelProxyTest, UseAfterClose) { | 737 TEST_F(KernelProxyTest, UseAfterClose) { |
| 645 int fd = ki_open("/dummy", O_CREAT | O_WRONLY, 0777); | 738 int fd = ki_open("/dummy", O_CREAT | O_WRONLY, 0777); |
| 646 ASSERT_GT(fd, -1); | 739 ASSERT_GE(fd, 0); |
| 647 EXPECT_EQ(5, ki_write(fd, "hello", 5)); | 740 EXPECT_EQ(5, ki_write(fd, "hello", 5)); |
| 648 EXPECT_EQ(0, ki_close(fd)); | 741 EXPECT_EQ(0, ki_close(fd)); |
| 649 EXPECT_EQ(-1, ki_write(fd, "hello", 5)); | 742 EXPECT_EQ(-1, ki_write(fd, "hello", 5)); |
| 650 EXPECT_EQ(EBADF, errno); | 743 EXPECT_EQ(EBADF, errno); |
| 651 } | 744 } |
| 652 | 745 |
| 653 TEST_F(KernelProxyTest, Utimes) { | 746 TEST_F(KernelProxyTest, Utimes) { |
| 654 struct timeval times[2]; | 747 struct timeval times[2]; |
| 655 times[0].tv_sec = 1000; | 748 times[0].tv_sec = 1000; |
| 656 times[0].tv_usec = 2000; | 749 times[0].tv_usec = 2000; |
| 657 times[1].tv_sec = 3000; | 750 times[1].tv_sec = 3000; |
| 658 times[1].tv_usec = 4000; | 751 times[1].tv_usec = 4000; |
| 659 | 752 |
| 660 int fd = ki_open("/dummy", O_CREAT | O_WRONLY, 0222); | 753 int fd = ki_open("/dummy", O_CREAT | O_WRONLY, 0222); |
| 661 ASSERT_GT(fd, -1); | 754 ASSERT_GE(fd, 0); |
| 662 EXPECT_EQ(0, ki_close(fd)); | 755 EXPECT_EQ(0, ki_close(fd)); |
| 663 | 756 |
| 664 // utime should work if the file is write-only. | 757 // utime should work if the file is write-only. |
| 665 EXPECT_EQ(0, ki_utimes("/dummy", times)); | 758 EXPECT_EQ(0, ki_utimes("/dummy", times)); |
| 666 | 759 |
| 667 // utime should work on directories (which can never be opened for write) | 760 // utime should work on directories (which can never be opened for write) |
| 668 EXPECT_EQ(0, ki_utimes("/", times)); | 761 EXPECT_EQ(0, ki_utimes("/", times)); |
| 669 | 762 |
| 670 // or if the file is read-only. | 763 // or if the file is read-only. |
| 671 EXPECT_EQ(0, ki_chmod("/dummy", 0444)); | 764 EXPECT_EQ(0, ki_chmod("/dummy", 0444)); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 690 buf.st_mtime > tm.tv_sec || | 783 buf.st_mtime > tm.tv_sec || |
| 691 (buf.st_mtime == tm.tv_sec && buf.st_mtimensec >= tm.tv_usec * 1000)); | 784 (buf.st_mtime == tm.tv_sec && buf.st_mtimensec >= tm.tv_usec * 1000)); |
| 692 } | 785 } |
| 693 | 786 |
| 694 TEST_F(KernelProxyTest, Utime) { | 787 TEST_F(KernelProxyTest, Utime) { |
| 695 struct utimbuf times; | 788 struct utimbuf times; |
| 696 times.actime = 1000; | 789 times.actime = 1000; |
| 697 times.modtime = 2000; | 790 times.modtime = 2000; |
| 698 | 791 |
| 699 int fd = ki_open("/dummy", O_CREAT | O_WRONLY, 0222); | 792 int fd = ki_open("/dummy", O_CREAT | O_WRONLY, 0222); |
| 700 ASSERT_GT(fd, -1); | 793 ASSERT_GE(fd, 0); |
| 701 EXPECT_EQ(0, ki_close(fd)); | 794 EXPECT_EQ(0, ki_close(fd)); |
| 702 | 795 |
| 703 // utime should work if the file is write-only. | 796 // utime should work if the file is write-only. |
| 704 EXPECT_EQ(0, ki_utime("/dummy", ×)); | 797 EXPECT_EQ(0, ki_utime("/dummy", ×)); |
| 705 | 798 |
| 706 // or if the file is read-only. | 799 // or if the file is read-only. |
| 707 EXPECT_EQ(0, ki_chmod("/dummy", 0444)); | 800 EXPECT_EQ(0, ki_chmod("/dummy", 0444)); |
| 708 EXPECT_EQ(0, ki_utime("/dummy", ×)); | 801 EXPECT_EQ(0, ki_utime("/dummy", ×)); |
| 709 | 802 |
| 710 // times can be NULL. In that case the access/mod times will be set to the | 803 // times can be NULL. In that case the access/mod times will be set to the |
| (...skipping 14 matching lines...) Expand all Loading... |
| 725 EXPECT_TRUE( | 818 EXPECT_TRUE( |
| 726 buf.st_mtime > tm.tv_sec || | 819 buf.st_mtime > tm.tv_sec || |
| 727 (buf.st_mtime == tm.tv_sec && buf.st_mtimensec >= tm.tv_usec * 1000)); | 820 (buf.st_mtime == tm.tv_sec && buf.st_mtimensec >= tm.tv_usec * 1000)); |
| 728 } | 821 } |
| 729 | 822 |
| 730 TEST_F(KernelProxyTest, Umask) { | 823 TEST_F(KernelProxyTest, Umask) { |
| 731 mode_t oldmask = ki_umask(0222); | 824 mode_t oldmask = ki_umask(0222); |
| 732 EXPECT_EQ(0, oldmask); | 825 EXPECT_EQ(0, oldmask); |
| 733 | 826 |
| 734 int fd = ki_open("/foo", O_CREAT | O_RDONLY, 0666); | 827 int fd = ki_open("/foo", O_CREAT | O_RDONLY, 0666); |
| 735 ASSERT_GT(fd, -1); | 828 ASSERT_GE(fd, 0); |
| 736 ki_close(fd); | 829 ki_close(fd); |
| 737 | 830 |
| 738 EXPECT_EQ(0, ki_mkdir("/dir", 0777)); | 831 EXPECT_EQ(0, ki_mkdir("/dir", 0777)); |
| 739 | 832 |
| 740 struct stat buf; | 833 struct stat buf; |
| 741 EXPECT_EQ(0, ki_stat("/foo", &buf)); | 834 EXPECT_EQ(0, ki_stat("/foo", &buf)); |
| 742 EXPECT_EQ(0444, buf.st_mode & 0777); | 835 EXPECT_EQ(0444, buf.st_mode & 0777); |
| 743 | 836 |
| 744 EXPECT_EQ(0, ki_stat("/dir", &buf)); | 837 EXPECT_EQ(0, ki_stat("/dir", &buf)); |
| 745 EXPECT_EQ(0555, buf.st_mode & 0777); | 838 EXPECT_EQ(0555, buf.st_mode & 0777); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 797 | 890 |
| 798 void TearDown() { | 891 void TearDown() { |
| 799 g_string_map.clear(); | 892 g_string_map.clear(); |
| 800 ki_uninit(); | 893 ki_uninit(); |
| 801 } | 894 } |
| 802 | 895 |
| 803 protected: | 896 protected: |
| 804 KernelProxyMountTest_KernelProxy kp_; | 897 KernelProxyMountTest_KernelProxy kp_; |
| 805 }; | 898 }; |
| 806 | 899 |
| 807 // Helper function for calling ki_ioctl without having | |
| 808 // to construct a va_list. | |
| 809 int ki_ioctl_wrapper(int fd, int request, ...) { | |
| 810 va_list ap; | |
| 811 va_start(ap, request); | |
| 812 int rtn = ki_ioctl(fd, request, ap); | |
| 813 va_end(ap); | |
| 814 return rtn; | |
| 815 } | |
| 816 | |
| 817 } // namespace | 900 } // namespace |
| 818 | 901 |
| 819 TEST_F(KernelProxyMountTest, MountInit) { | 902 TEST_F(KernelProxyMountTest, MountInit) { |
| 820 int res1 = ki_mount("/", "/mnt1", "initfs", 0, "false,foo=bar"); | 903 ASSERT_EQ(0, ki_mkdir("/mnt1", 0777)); |
| 904 int res1 = ki_mount("", "/mnt1", "initfs", 0, "false,foo=bar"); |
| 821 | 905 |
| 822 EXPECT_EQ("bar", g_string_map["foo"]); | 906 EXPECT_EQ("bar", g_string_map["foo"]); |
| 823 EXPECT_EQ(-1, res1); | 907 EXPECT_EQ(-1, res1); |
| 824 EXPECT_EQ(EINVAL, errno); | 908 EXPECT_EQ(EINVAL, errno); |
| 825 | 909 |
| 826 int res2 = ki_mount("/", "/mnt2", "initfs", 0, "true,bar=foo,x=y"); | 910 ASSERT_EQ(0, ki_mkdir("/mnt2", 0777)); |
| 911 int res2 = ki_mount("", "/mnt2", "initfs", 0, "true,bar=foo,x=y"); |
| 827 EXPECT_NE(-1, res2); | 912 EXPECT_NE(-1, res2); |
| 828 EXPECT_EQ("y", g_string_map["x"]); | 913 EXPECT_EQ("y", g_string_map["x"]); |
| 914 |
| 915 } |
| 916 |
| 917 TEST_F(KernelProxyMountTest, Passthroughfs) { |
| 918 ASSERT_EQ(0, ki_mkdir("/passthrough", 0777)); |
| 919 int res1 = ki_mount("", "/passthrough", "passthroughfs", 0, ""); |
| 920 EXPECT_NE(-1, res1); |
| 921 CheckDirContents("/passthrough", NULL, -1); |
| 829 } | 922 } |
| 830 | 923 |
| 831 TEST_F(KernelProxyMountTest, MountAndIoctl) { | 924 TEST_F(KernelProxyMountTest, MountAndIoctl) { |
| 832 ASSERT_EQ(0, ki_mount("/", "/mnt1", "initfs", 0, "")); | 925 ASSERT_EQ(0, ki_mkdir("/mnt1", 0777)); |
| 926 ASSERT_EQ(0, ki_mount("", "/mnt1", "initfs", 0, "")); |
| 833 ASSERT_NE(-1, g_fs_dev); | 927 ASSERT_NE(-1, g_fs_dev); |
| 834 | 928 |
| 835 char path[100]; | 929 char path[100]; |
| 836 snprintf(path, 100, "dev/fs/%d", g_fs_dev); | 930 snprintf(path, 100, "/dev/fs/%d", g_fs_dev); |
| 837 | 931 |
| 838 int fd = ki_open(path, O_RDONLY, 0); | 932 int fd = ki_open(path, O_RDONLY, 0); |
| 839 ASSERT_GT(fd, -1); | 933 ASSERT_GE(fd, 0); |
| 840 | 934 |
| 841 EXPECT_EQ(0, ki_ioctl_wrapper(fd, 0xdeadbeef)); | 935 EXPECT_EQ(0, ki_ioctl_wrapper(fd, 0xdeadbeef)); |
| 842 EXPECT_EQ(true, g_fs_ioctl_called); | 936 EXPECT_EQ(true, g_fs_ioctl_called); |
| 843 } | 937 } |
| 844 | 938 |
| 845 static void mount_callback(const char* source, | 939 static void mount_callback(const char* source, |
| 846 const char* target, | 940 const char* target, |
| 847 const char* filesystemtype, | 941 const char* filesystemtype, |
| 848 unsigned long mountflags, | 942 unsigned long mountflags, |
| 849 const void* data, | 943 const void* data, |
| 850 dev_t dev, | 944 dev_t dev, |
| 851 void* user_data) { | 945 void* user_data) { |
| 852 EXPECT_STREQ("/", source); | 946 EXPECT_STREQ("dummy", source); |
| 853 EXPECT_STREQ("/mnt1", target); | 947 EXPECT_STREQ("/mnt1", target); |
| 854 EXPECT_STREQ("initfs", filesystemtype); | 948 EXPECT_STREQ("initfs", filesystemtype); |
| 855 EXPECT_EQ(0, mountflags); | 949 EXPECT_EQ(0, mountflags); |
| 856 EXPECT_STREQ("", (const char*) data); | 950 EXPECT_STREQ("", (const char*) data); |
| 857 EXPECT_EQ(g_fs_dev, dev); | 951 EXPECT_EQ(g_fs_dev, dev); |
| 858 | 952 |
| 859 bool* callback_called = static_cast<bool*>(user_data); | 953 bool* callback_called = static_cast<bool*>(user_data); |
| 860 *callback_called = true; | 954 *callback_called = true; |
| 861 } | 955 } |
| 862 | 956 |
| 863 TEST_F(KernelProxyMountTest, MountCallback) { | 957 TEST_F(KernelProxyMountTest, MountCallback) { |
| 864 bool callback_called = false; | 958 bool callback_called = false; |
| 865 kp_.SetMountCallback(&mount_callback, &callback_called); | 959 kp_.SetMountCallback(&mount_callback, &callback_called); |
| 866 ASSERT_EQ(0, ki_mount("/", "/mnt1", "initfs", 0, "")); | 960 ASSERT_EQ(0, ki_mkdir("/mnt1", 0777)); |
| 961 ASSERT_EQ(0, ki_mount("dummy", "/mnt1", "initfs", 0, "")); |
| 867 ASSERT_NE(-1, g_fs_dev); | 962 ASSERT_NE(-1, g_fs_dev); |
| 868 EXPECT_EQ(true, callback_called); | 963 EXPECT_EQ(true, callback_called); |
| 869 } | 964 } |
| 870 | 965 |
| 871 namespace { | 966 namespace { |
| 872 | 967 |
| 873 int g_MMapCount = 0; | 968 int g_MMapCount = 0; |
| 874 | 969 |
| 875 class KernelProxyMMapTest_Node : public Node { | 970 class KernelProxyMMapTest_Node : public Node { |
| 876 public: | 971 public: |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 947 | 1042 |
| 948 void TearDown() { ki_uninit(); } | 1043 void TearDown() { ki_uninit(); } |
| 949 | 1044 |
| 950 private: | 1045 private: |
| 951 KernelProxyMMapTest_KernelProxy kp_; | 1046 KernelProxyMMapTest_KernelProxy kp_; |
| 952 }; | 1047 }; |
| 953 | 1048 |
| 954 } // namespace | 1049 } // namespace |
| 955 | 1050 |
| 956 TEST_F(KernelProxyMMapTest, MMap) { | 1051 TEST_F(KernelProxyMMapTest, MMap) { |
| 957 ASSERT_EQ(0, ki_umount("/")); | 1052 ASSERT_EQ(0, ki_mkdir("/mmap", 0777)); |
| 958 ASSERT_EQ(0, ki_mount("", "/", "mmapfs", 0, NULL)); | 1053 ASSERT_EQ(0, ki_mount("", "/mmap", "mmapfs", 0, NULL)); |
| 959 int fd = ki_open("/file", O_RDWR | O_CREAT, 0777); | 1054 int fd = ki_open("/mmap/file", O_RDWR | O_CREAT, 0777); |
| 960 ASSERT_NE(-1, fd); | 1055 ASSERT_NE(-1, fd); |
| 961 | 1056 |
| 962 void* addr1 = ki_mmap(NULL, 0x800, PROT_READ, MAP_PRIVATE, fd, 0); | 1057 void* addr1 = ki_mmap(NULL, 0x800, PROT_READ, MAP_PRIVATE, fd, 0); |
| 963 ASSERT_EQ(reinterpret_cast<void*>(0x1000), addr1); | 1058 ASSERT_EQ(reinterpret_cast<void*>(0x1000), addr1); |
| 964 ASSERT_EQ(1, g_MMapCount); | 1059 ASSERT_EQ(1, g_MMapCount); |
| 965 | 1060 |
| 966 void* addr2 = ki_mmap(NULL, 0x800, PROT_READ, MAP_PRIVATE, fd, 0); | 1061 void* addr2 = ki_mmap(NULL, 0x800, PROT_READ, MAP_PRIVATE, fd, 0); |
| 967 ASSERT_EQ(reinterpret_cast<void*>(0x2000), addr2); | 1062 ASSERT_EQ(reinterpret_cast<void*>(0x2000), addr2); |
| 968 ASSERT_EQ(2, g_MMapCount); | 1063 ASSERT_EQ(2, g_MMapCount); |
| 969 | 1064 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1013 ScopedRef<MockFs> fs_; | 1108 ScopedRef<MockFs> fs_; |
| 1014 }; | 1109 }; |
| 1015 | 1110 |
| 1016 class KernelProxyErrorTest : public ::testing::Test { | 1111 class KernelProxyErrorTest : public ::testing::Test { |
| 1017 public: | 1112 public: |
| 1018 KernelProxyErrorTest() {} | 1113 KernelProxyErrorTest() {} |
| 1019 | 1114 |
| 1020 void SetUp() { | 1115 void SetUp() { |
| 1021 ASSERT_EQ(0, ki_push_state_for_testing()); | 1116 ASSERT_EQ(0, ki_push_state_for_testing()); |
| 1022 ASSERT_EQ(0, ki_init(&kp_)); | 1117 ASSERT_EQ(0, ki_init(&kp_)); |
| 1023 // Unmount the passthrough FS and mount a testfs. | 1118 // Unmount root fs and mount a testfs. |
| 1024 EXPECT_EQ(0, kp_.umount("/")); | 1119 EXPECT_EQ(0, kp_.umount("/")); |
| 1025 EXPECT_EQ(0, kp_.mount("", "/", "testfs", 0, NULL)); | 1120 EXPECT_EQ(0, kp_.mount("", "/", "testfs", 0, NULL)); |
| 1026 } | 1121 } |
| 1027 | 1122 |
| 1028 void TearDown() { ki_uninit(); } | 1123 void TearDown() { ki_uninit(); } |
| 1029 | 1124 |
| 1030 ScopedRef<MockFs> fs() { return kp_.fs(); } | 1125 ScopedRef<MockFs> fs() { return kp_.fs(); } |
| 1031 | 1126 |
| 1032 private: | 1127 private: |
| 1033 KernelProxyErrorTest_KernelProxy kp_; | 1128 KernelProxyErrorTest_KernelProxy kp_; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1072 | 1167 |
| 1073 int fd = ki_open("/dummy", O_RDONLY, 0); | 1168 int fd = ki_open("/dummy", O_RDONLY, 0); |
| 1074 EXPECT_NE(0, fd); | 1169 EXPECT_NE(0, fd); |
| 1075 | 1170 |
| 1076 char buf[20]; | 1171 char buf[20]; |
| 1077 EXPECT_EQ(-1, ki_read(fd, &buf[0], 20)); | 1172 EXPECT_EQ(-1, ki_read(fd, &buf[0], 20)); |
| 1078 // The Filesystem should be able to return whatever error it wants and have it | 1173 // The Filesystem should be able to return whatever error it wants and have it |
| 1079 // propagate through. | 1174 // propagate through. |
| 1080 EXPECT_EQ(1234, errno); | 1175 EXPECT_EQ(1234, errno); |
| 1081 } | 1176 } |
| OLD | NEW |