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 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 EXPECT_TRUE(S_ISDIR(buf.st_mode)); | 542 EXPECT_TRUE(S_ISDIR(buf.st_mode)); |
543 | 543 |
544 EXPECT_EQ(-1, ki_lstat("/no-such-file", &buf)); | 544 EXPECT_EQ(-1, ki_lstat("/no-such-file", &buf)); |
545 EXPECT_EQ(ENOENT, errno); | 545 EXPECT_EQ(ENOENT, errno); |
546 | 546 |
547 // Still legal to stat a file that is write-only. | 547 // Still legal to stat a file that is write-only. |
548 EXPECT_EQ(0, ki_chmod("/foo", 0222)); | 548 EXPECT_EQ(0, ki_chmod("/foo", 0222)); |
549 EXPECT_EQ(0, ki_lstat("/foo", &buf)); | 549 EXPECT_EQ(0, ki_lstat("/foo", &buf)); |
550 } | 550 } |
551 | 551 |
| 552 TEST_F(KernelProxyTest, OpenDirectory) { |
| 553 // Opening a directory for read should succeed. |
| 554 int fd = ki_open("/", O_RDONLY, 0); |
| 555 ASSERT_GT(fd, -1); |
| 556 |
| 557 // Opening a directory for write should fail. |
| 558 EXPECT_EQ(-1, ki_open("/", O_RDWR, 0)); |
| 559 EXPECT_EQ(errno, EISDIR); |
| 560 EXPECT_EQ(-1, ki_open("/", O_WRONLY, 0)); |
| 561 EXPECT_EQ(errno, EISDIR); |
| 562 } |
| 563 |
552 TEST_F(KernelProxyTest, OpenWithMode) { | 564 TEST_F(KernelProxyTest, OpenWithMode) { |
553 int fd = ki_open("/foo", O_CREAT | O_RDWR, 0723); | 565 int fd = ki_open("/foo", O_CREAT | O_RDWR, 0723); |
554 ASSERT_GT(fd, -1); | 566 ASSERT_GT(fd, -1); |
555 | 567 |
556 struct stat buf; | 568 struct stat buf; |
557 EXPECT_EQ(0, ki_lstat("/foo", &buf)); | 569 EXPECT_EQ(0, ki_lstat("/foo", &buf)); |
558 EXPECT_EQ(0723, buf.st_mode & ~S_IFMT); | 570 EXPECT_EQ(0723, buf.st_mode & ~S_IFMT); |
559 } | 571 } |
560 | 572 |
561 TEST_F(KernelProxyTest, CreateWronlyWithReadOnlyMode) { | 573 TEST_F(KernelProxyTest, CreateWronlyWithReadOnlyMode) { |
(...skipping 17 matching lines...) Expand all Loading... |
579 times[1].tv_sec = 3000; | 591 times[1].tv_sec = 3000; |
580 times[1].tv_usec = 4000; | 592 times[1].tv_usec = 4000; |
581 | 593 |
582 int fd = ki_open("/dummy", O_CREAT | O_WRONLY, 0222); | 594 int fd = ki_open("/dummy", O_CREAT | O_WRONLY, 0222); |
583 ASSERT_GT(fd, -1); | 595 ASSERT_GT(fd, -1); |
584 EXPECT_EQ(0, ki_close(fd)); | 596 EXPECT_EQ(0, ki_close(fd)); |
585 | 597 |
586 // utime should work if the file is write-only. | 598 // utime should work if the file is write-only. |
587 EXPECT_EQ(0, ki_utimes("/dummy", times)); | 599 EXPECT_EQ(0, ki_utimes("/dummy", times)); |
588 | 600 |
| 601 // utime should work on directories (which can never be opened for write) |
| 602 EXPECT_EQ(0, ki_utimes("/", times)); |
| 603 |
589 // or if the file is read-only. | 604 // or if the file is read-only. |
590 EXPECT_EQ(0, ki_chmod("/dummy", 0444)); | 605 EXPECT_EQ(0, ki_chmod("/dummy", 0444)); |
591 EXPECT_EQ(0, ki_utimes("/dummy", times)); | 606 EXPECT_EQ(0, ki_utimes("/dummy", times)); |
592 | 607 |
593 // times can be NULL. In that case the access/mod times will be set to the | 608 // times can be NULL. In that case the access/mod times will be set to the |
594 // current time. | 609 // current time. |
595 struct timeval tm; | 610 struct timeval tm; |
596 EXPECT_EQ(0, gettimeofday(&tm, NULL)); | 611 EXPECT_EQ(0, gettimeofday(&tm, NULL)); |
597 | 612 |
598 EXPECT_EQ(0, ki_utimes("/dummy", NULL)); | 613 EXPECT_EQ(0, ki_utimes("/dummy", NULL)); |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
980 | 995 |
981 int fd = ki_open("/dummy", O_RDONLY, 0); | 996 int fd = ki_open("/dummy", O_RDONLY, 0); |
982 EXPECT_NE(0, fd); | 997 EXPECT_NE(0, fd); |
983 | 998 |
984 char buf[20]; | 999 char buf[20]; |
985 EXPECT_EQ(-1, ki_read(fd, &buf[0], 20)); | 1000 EXPECT_EQ(-1, ki_read(fd, &buf[0], 20)); |
986 // The Filesystem should be able to return whatever error it wants and have it | 1001 // The Filesystem should be able to return whatever error it wants and have it |
987 // propagate through. | 1002 // propagate through. |
988 EXPECT_EQ(1234, errno); | 1003 EXPECT_EQ(1234, errno); |
989 } | 1004 } |
OLD | NEW |