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