Chromium Code Reviews| 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 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 520 ASSERT_EQ(4, ki_write(dup_fd, "more", 4)); | 520 ASSERT_EQ(4, ki_write(dup_fd, "more", 4)); |
| 521 | 521 |
| 522 ASSERT_EQ(0, ki_close(dup2_fd)); | 522 ASSERT_EQ(0, ki_close(dup2_fd)); |
| 523 // fd, new_fd -> "/bar" | 523 // fd, new_fd -> "/bar" |
| 524 // dup_fd -> "/foo" | 524 // dup_fd -> "/foo" |
| 525 | 525 |
| 526 ASSERT_EQ(dup_fd, ki_dup2(fd, dup_fd)); | 526 ASSERT_EQ(dup_fd, ki_dup2(fd, dup_fd)); |
| 527 // fd, new_fd, dup_fd -> "/bar" | 527 // fd, new_fd, dup_fd -> "/bar" |
| 528 } | 528 } |
| 529 | 529 |
| 530 TEST_F(KernelProxyTest, Dup2Allocation) { | |
|
Sam Clegg
2014/12/12 00:44:40
Comment here? I would like a better test name bu
bradn
2014/12/12 22:58:18
Added more.
| |
| 531 int fd = ki_open("/foo", O_CREAT | O_RDWR, 0777); | |
| 532 ASSERT_GT(fd, -1); | |
| 533 | |
| 534 int dup_fd = ki_dup(fd); | |
| 535 ASSERT_EQ(fd + 1, dup_fd); | |
|
binji
2014/12/12 18:55:20
Is this guaranteed to be true? The fd returned sho
bradn
2014/12/12 22:58:18
Commented more verbosely.
The test assumes the ini
| |
| 536 | |
| 537 ASSERT_EQ(100, ki_dup2(fd, 100)); | |
| 538 | |
| 539 int dup_fd2 = ki_dup(fd); | |
| 540 ASSERT_EQ(fd + 2, dup_fd2); | |
| 541 } | |
| 542 | |
| 530 TEST_F(KernelProxyTest, Lstat) { | 543 TEST_F(KernelProxyTest, Lstat) { |
| 531 int fd = ki_open("/foo", O_CREAT | O_RDWR, 0777); | 544 int fd = ki_open("/foo", O_CREAT | O_RDWR, 0777); |
| 532 ASSERT_GT(fd, -1); | 545 ASSERT_GT(fd, -1); |
| 533 ASSERT_EQ(0, ki_mkdir("/bar", S_IREAD | S_IWRITE)); | 546 ASSERT_EQ(0, ki_mkdir("/bar", S_IREAD | S_IWRITE)); |
| 534 | 547 |
| 535 struct stat buf; | 548 struct stat buf; |
| 536 EXPECT_EQ(0, ki_lstat("/foo", &buf)); | 549 EXPECT_EQ(0, ki_lstat("/foo", &buf)); |
| 537 EXPECT_EQ(0, buf.st_size); | 550 EXPECT_EQ(0, buf.st_size); |
| 538 EXPECT_TRUE(S_ISREG(buf.st_mode)); | 551 EXPECT_TRUE(S_ISREG(buf.st_mode)); |
| 539 | 552 |
| (...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1005 | 1018 |
| 1006 int fd = ki_open("/dummy", O_RDONLY, 0); | 1019 int fd = ki_open("/dummy", O_RDONLY, 0); |
| 1007 EXPECT_NE(0, fd); | 1020 EXPECT_NE(0, fd); |
| 1008 | 1021 |
| 1009 char buf[20]; | 1022 char buf[20]; |
| 1010 EXPECT_EQ(-1, ki_read(fd, &buf[0], 20)); | 1023 EXPECT_EQ(-1, ki_read(fd, &buf[0], 20)); |
| 1011 // The Filesystem should be able to return whatever error it wants and have it | 1024 // The Filesystem should be able to return whatever error it wants and have it |
| 1012 // propagate through. | 1025 // propagate through. |
| 1013 EXPECT_EQ(1234, errno); | 1026 EXPECT_EQ(1234, errno); |
| 1014 } | 1027 } |
| OLD | NEW |