Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(257)

Side by Side Diff: native_client_sdk/src/tests/nacl_io_test/kernel_proxy_test.cc

Issue 660353003: [NaCl SDK] nacl_io: Fix utime() on directories. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 & 0777);
559 } 571 }
560 572
561 TEST_F(KernelProxyTest, CreateWronlyWithReadOnlyMode) { 573 TEST_F(KernelProxyTest, CreateWronlyWithReadOnlyMode) {
562 int fd = ki_open("/foo", O_CREAT | O_WRONLY, 0444); 574 int fd = ki_open("/foo", O_CREAT | O_WRONLY, 0444);
563 ASSERT_GT(fd, -1); 575 ASSERT_GT(fd, -1);
564 } 576 }
565 577
566 TEST_F(KernelProxyTest, UseAfterClose) { 578 TEST_F(KernelProxyTest, UseAfterClose) {
567 int fd = ki_open("/dummy", O_CREAT | O_WRONLY, 0777); 579 int fd = ki_open("/dummy", O_CREAT | O_WRONLY, 0777);
568 ASSERT_GT(fd, -1); 580 ASSERT_GT(fd, -1);
(...skipping 10 matching lines...) Expand all
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 directories (we 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 EXPECT_EQ(0, oldmask); 656 EXPECT_EQ(0, oldmask);
642 657
643 int fd = ki_open("/foo", O_CREAT | O_RDONLY, 0666); 658 int fd = ki_open("/foo", O_CREAT | O_RDONLY, 0666);
644 ASSERT_GT(fd, -1); 659 ASSERT_GT(fd, -1);
645 ki_close(fd); 660 ki_close(fd);
646 661
647 EXPECT_EQ(0, ki_mkdir("/dir", 0777)); 662 EXPECT_EQ(0, ki_mkdir("/dir", 0777));
648 663
649 struct stat buf; 664 struct stat buf;
650 EXPECT_EQ(0, ki_stat("/foo", &buf)); 665 EXPECT_EQ(0, ki_stat("/foo", &buf));
651 EXPECT_EQ(0444, buf.st_mode & ~S_IFMT); 666 EXPECT_EQ(0444, buf.st_mode & 0777);
652 667
653 EXPECT_EQ(0, ki_stat("/dir", &buf)); 668 EXPECT_EQ(0, ki_stat("/dir", &buf));
654 EXPECT_EQ(0555, buf.st_mode & ~S_IFMT); 669 EXPECT_EQ(0555, buf.st_mode & 0777);
655 670
656 EXPECT_EQ(0222, ki_umask(0)); 671 EXPECT_EQ(0222, ki_umask(0));
657 } 672 }
658 673
659 namespace { 674 namespace {
660 675
661 StringMap_t g_string_map; 676 StringMap_t g_string_map;
662 bool g_fs_ioctl_called; 677 bool g_fs_ioctl_called;
663 int g_fs_dev; 678 int g_fs_dev;
664 679
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698