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

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

Issue 304013002: [NaCl SDK] Create Filesystem nodes in /dev/fs/... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
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 10
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 ASSERT_GT(fd, -1); 535 ASSERT_GT(fd, -1);
536 EXPECT_EQ(5, ki_write(fd, "hello", 5)); 536 EXPECT_EQ(5, ki_write(fd, "hello", 5));
537 EXPECT_EQ(0, ki_close(fd)); 537 EXPECT_EQ(0, ki_close(fd));
538 EXPECT_EQ(-1, ki_write(fd, "hello", 5)); 538 EXPECT_EQ(-1, ki_write(fd, "hello", 5));
539 EXPECT_EQ(EBADF, errno); 539 EXPECT_EQ(EBADF, errno);
540 } 540 }
541 541
542 namespace { 542 namespace {
543 543
544 StringMap_t g_string_map; 544 StringMap_t g_string_map;
545 bool g_fs_ioctl_called;
546 int g_fs_dev;
545 547
546 class KernelProxyMountTest_Filesystem : public MemFs { 548 class KernelProxyMountTest_Filesystem : public MemFs {
547 public: 549 public:
548 using MemFs::Init; 550 virtual Error Init(const FsInitArgs& args) {
551 MemFs::Init(args);
549 552
550 virtual Error Init(const FsInitArgs& args) {
551 g_string_map = args.string_map; 553 g_string_map = args.string_map;
554 g_fs_dev = args.dev;
555
552 if (g_string_map.find("false") != g_string_map.end()) 556 if (g_string_map.find("false") != g_string_map.end())
553 return EINVAL; 557 return EINVAL;
554 return 0; 558 return 0;
555 } 559 }
556 560
561 virtual Error Filesystem_VIoctl(int request, va_list arglist) {
562 g_fs_ioctl_called = true;
563 return 0;
564 }
565
557 friend class TypedFsFactory<KernelProxyMountTest_Filesystem>; 566 friend class TypedFsFactory<KernelProxyMountTest_Filesystem>;
558 }; 567 };
559 568
560 class KernelProxyMountTest_KernelProxy : public KernelProxy { 569 class KernelProxyMountTest_KernelProxy : public KernelProxy {
561 virtual Error Init(PepperInterface* ppapi) { 570 virtual Error Init(PepperInterface* ppapi) {
562 KernelProxy::Init(NULL); 571 KernelProxy::Init(NULL);
563 factories_["initfs"] = new TypedFsFactory<KernelProxyMountTest_Filesystem>; 572 factories_["initfs"] = new TypedFsFactory<KernelProxyMountTest_Filesystem>;
564 return 0; 573 return 0;
565 } 574 }
566 }; 575 };
567 576
568 class KernelProxyMountTest : public ::testing::Test { 577 class KernelProxyMountTest : public ::testing::Test {
569 public: 578 public:
570 KernelProxyMountTest() {} 579 KernelProxyMountTest() {}
571 580
572 void SetUp() { 581 void SetUp() {
582 g_string_map.clear();
583 g_fs_dev = -1;
584 g_fs_ioctl_called = false;
585
573 ASSERT_EQ(0, ki_push_state_for_testing()); 586 ASSERT_EQ(0, ki_push_state_for_testing());
574 ASSERT_EQ(0, ki_init(&kp_)); 587 ASSERT_EQ(0, ki_init(&kp_));
575 } 588 }
576 589
577 void TearDown() { ki_uninit(); } 590 void TearDown() {
591 g_string_map.clear();
592 ki_uninit();
593 }
578 594
579 private: 595 private:
580 KernelProxyMountTest_KernelProxy kp_; 596 KernelProxyMountTest_KernelProxy kp_;
581 }; 597 };
582 598
599 // Helper function for calling ki_ioctl without having
600 // to construct a va_list.
601 int ki_ioctl_wrapper(int fd, int request, ...) {
602 va_list ap;
603 va_start(ap, request);
604 int rtn = ki_ioctl(fd, request, ap);
605 va_end(ap);
606 return rtn;
607 }
608
583 } // namespace 609 } // namespace
584 610
585 TEST_F(KernelProxyMountTest, MountInit) { 611 TEST_F(KernelProxyMountTest, MountInit) {
586 int res1 = ki_mount("/", "/mnt1", "initfs", 0, "false,foo=bar"); 612 int res1 = ki_mount("/", "/mnt1", "initfs", 0, "false,foo=bar");
587 613
588 EXPECT_EQ("bar", g_string_map["foo"]); 614 EXPECT_EQ("bar", g_string_map["foo"]);
589 EXPECT_EQ(-1, res1); 615 EXPECT_EQ(-1, res1);
590 EXPECT_EQ(EINVAL, errno); 616 EXPECT_EQ(EINVAL, errno);
591 617
592 int res2 = ki_mount("/", "/mnt2", "initfs", 0, "true,bar=foo,x=y"); 618 int res2 = ki_mount("/", "/mnt2", "initfs", 0, "true,bar=foo,x=y");
593 EXPECT_NE(-1, res2); 619 EXPECT_NE(-1, res2);
594 EXPECT_EQ("y", g_string_map["x"]); 620 EXPECT_EQ("y", g_string_map["x"]);
595 } 621 }
596 622
623 TEST_F(KernelProxyMountTest, MountAndIoctl) {
624 ASSERT_EQ(0, ki_mount("/", "/mnt1", "initfs", 0, ""));
625 ASSERT_NE(-1, g_fs_dev);
626
627 char path[100];
628 snprintf(path, 100, "dev/fs/%d", g_fs_dev);
629
630 int fd = ki_open(path, O_RDONLY);
631 ASSERT_GT(fd, -1);
632
633 EXPECT_EQ(0, ki_ioctl_wrapper(fd, 0xdeadbeef));
634 EXPECT_EQ(true, g_fs_ioctl_called);
635 }
636
597 namespace { 637 namespace {
598 638
599 int g_MMapCount = 0; 639 int g_MMapCount = 0;
600 640
601 class KernelProxyMMapTest_Node : public Node { 641 class KernelProxyMMapTest_Node : public Node {
602 public: 642 public:
603 KernelProxyMMapTest_Node(Filesystem* filesystem) 643 KernelProxyMMapTest_Node(Filesystem* filesystem)
604 : Node(filesystem), node_mmap_count_(0) { 644 : Node(filesystem), node_mmap_count_(0) {
605 EXPECT_EQ(0, Init(0)); 645 EXPECT_EQ(0, Init(0));
606 } 646 }
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 837
798 int fd = ki_open("/dummy", O_RDONLY); 838 int fd = ki_open("/dummy", O_RDONLY);
799 EXPECT_NE(0, fd); 839 EXPECT_NE(0, fd);
800 840
801 char buf[20]; 841 char buf[20];
802 EXPECT_EQ(-1, ki_read(fd, &buf[0], 20)); 842 EXPECT_EQ(-1, ki_read(fd, &buf[0], 20));
803 // The Filesystem should be able to return whatever error it wants and have it 843 // The Filesystem should be able to return whatever error it wants and have it
804 // propagate through. 844 // propagate through.
805 EXPECT_EQ(1234, errno); 845 EXPECT_EQ(1234, errno);
806 } 846 }
OLDNEW
« no previous file with comments | « native_client_sdk/src/libraries/sdk_util/scoped_ref.h ('k') | native_client_sdk/src/tests/nacl_io_test/kernel_wrap_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698