| 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 | 10 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 int garbage[buffer_size]; | 110 int garbage[buffer_size]; |
| 111 | 111 |
| 112 MountMem* mount = (MountMem*)kp_.RootMount(); | 112 MountMem* mount = (MountMem*)kp_.RootMount(); |
| 113 ScopedMountNode root; | 113 ScopedMountNode root; |
| 114 | 114 |
| 115 ASSERT_EQ(0, mount->Open(Path("/"), O_RDONLY, &root)); | 115 ASSERT_EQ(0, mount->Open(Path("/"), O_RDONLY, &root)); |
| 116 ASSERT_EQ(0, root->ChildCount()); | 116 ASSERT_EQ(0, root->ChildCount()); |
| 117 | 117 |
| 118 for (int file_num = 0; file_num < 4096; file_num++) { | 118 for (int file_num = 0; file_num < 4096; file_num++) { |
| 119 sprintf(filename, "/foo%i.tmp", file_num++); | 119 sprintf(filename, "/foo%i.tmp", file_num++); |
| 120 FILE* f = fopen(filename, "w"); | 120 int fd = ki_open(filename, O_WRONLY | O_CREAT); |
| 121 ASSERT_NE((FILE*)NULL, f); | 121 ASSERT_GT(fd, -1); |
| 122 ASSERT_EQ(1, root->ChildCount()); | 122 ASSERT_EQ(1, root->ChildCount()); |
| 123 ASSERT_EQ(buffer_size, fwrite(garbage, 1, buffer_size, f)); | 123 ASSERT_EQ(buffer_size, ki_write(fd, garbage, buffer_size)); |
| 124 fclose(f); | 124 ki_close(fd); |
| 125 ASSERT_EQ(0, remove(filename)); | 125 ASSERT_EQ(0, ki_remove(filename)); |
| 126 } | 126 } |
| 127 ASSERT_EQ(0, root->ChildCount()); | 127 ASSERT_EQ(0, root->ChildCount()); |
| 128 } | 128 } |
| 129 | 129 |
| 130 static bool g_handler_called = false; | 130 static bool g_handler_called = false; |
| 131 static void sighandler(int) { | 131 static void sighandler(int) { |
| 132 g_handler_called = true; | 132 g_handler_called = true; |
| 133 } | 133 } |
| 134 | 134 |
| 135 TEST_F(KernelProxyTest, Sigaction) { | 135 TEST_F(KernelProxyTest, Sigaction) { |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 len = ki_read(fd2, text, sizeof(text)); | 351 len = ki_read(fd2, text, sizeof(text)); |
| 352 if (len > 0) | 352 if (len > 0) |
| 353 text[len] = 0; | 353 text[len] = 0; |
| 354 EXPECT_EQ(10, len); | 354 EXPECT_EQ(10, len); |
| 355 EXPECT_STREQ("HELLOWORLD", text); | 355 EXPECT_STREQ("HELLOWORLD", text); |
| 356 } | 356 } |
| 357 | 357 |
| 358 TEST_F(KernelProxyTest, MemMountLseek) { | 358 TEST_F(KernelProxyTest, MemMountLseek) { |
| 359 int fd = ki_open("/foo", O_CREAT | O_RDWR); | 359 int fd = ki_open("/foo", O_CREAT | O_RDWR); |
| 360 ASSERT_GT(fd, -1); | 360 ASSERT_GT(fd, -1); |
| 361 EXPECT_EQ(9, ki_write(fd, "Some text", 9)); | 361 ASSERT_EQ(9, ki_write(fd, "Some text", 9)); |
| 362 | 362 |
| 363 EXPECT_EQ(9, ki_lseek(fd, 0, SEEK_CUR)); | 363 ASSERT_EQ(9, ki_lseek(fd, 0, SEEK_CUR)); |
| 364 EXPECT_EQ(9, ki_lseek(fd, 0, SEEK_END)); | 364 ASSERT_EQ(9, ki_lseek(fd, 0, SEEK_END)); |
| 365 EXPECT_EQ(-1, ki_lseek(fd, -1, SEEK_SET)); | 365 ASSERT_EQ(-1, ki_lseek(fd, -1, SEEK_SET)); |
| 366 EXPECT_EQ(EINVAL, errno); | 366 ASSERT_EQ(EINVAL, errno); |
| 367 | 367 |
| 368 /* |
| 368 // Seek past end of file. | 369 // Seek past end of file. |
| 369 EXPECT_EQ(13, ki_lseek(fd, 13, SEEK_SET)); | 370 ASSERT_EQ(13, ki_lseek(fd, 13, SEEK_SET)); |
| 370 char buffer[4]; | 371 char buffer[4]; |
| 371 memset(&buffer[0], 0xfe, 4); | 372 memset(&buffer[0], 0xfe, 4); |
| 372 EXPECT_EQ(9, ki_lseek(fd, -4, SEEK_END)); | 373 ASSERT_EQ(9, ki_lseek(fd, -4, SEEK_END)); |
| 373 EXPECT_EQ(9, ki_lseek(fd, 0, SEEK_CUR)); | 374 ASSERT_EQ(9, ki_lseek(fd, 0, SEEK_CUR)); |
| 374 EXPECT_EQ(4, ki_read(fd, &buffer[0], 4)); | 375 ASSERT_EQ(4, ki_read(fd, &buffer[0], 4)); |
| 375 EXPECT_EQ(0, memcmp("\0\0\0\0", buffer, 4)); | 376 ASSERT_EQ(0, memcmp("\0\0\0\0", buffer, 4)); |
| 377 */ |
| 376 } | 378 } |
| 377 | 379 |
| 378 TEST_F(KernelProxyTest, CloseTwice) { | 380 TEST_F(KernelProxyTest, CloseTwice) { |
| 379 int fd = ki_open("/foo", O_CREAT | O_RDWR); | 381 int fd = ki_open("/foo", O_CREAT | O_RDWR); |
| 380 ASSERT_GT(fd, -1); | 382 ASSERT_GT(fd, -1); |
| 381 | 383 |
| 382 EXPECT_EQ(9, ki_write(fd, "Some text", 9)); | 384 EXPECT_EQ(9, ki_write(fd, "Some text", 9)); |
| 383 | 385 |
| 384 int fd2 = ki_dup(fd); | 386 int fd2 = ki_dup(fd); |
| 385 ASSERT_GT(fd2, -1); | 387 ASSERT_GT(fd2, -1); |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 680 | 682 |
| 681 int fd = ki_open("/dummy", O_RDONLY); | 683 int fd = ki_open("/dummy", O_RDONLY); |
| 682 EXPECT_NE(0, fd); | 684 EXPECT_NE(0, fd); |
| 683 | 685 |
| 684 char buf[20]; | 686 char buf[20]; |
| 685 EXPECT_EQ(-1, ki_read(fd, &buf[0], 20)); | 687 EXPECT_EQ(-1, ki_read(fd, &buf[0], 20)); |
| 686 // The Mount should be able to return whatever error it wants and have it | 688 // The Mount should be able to return whatever error it wants and have it |
| 687 // propagate through. | 689 // propagate through. |
| 688 EXPECT_EQ(1234, errno); | 690 EXPECT_EQ(1234, errno); |
| 689 } | 691 } |
| OLD | NEW |