| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 // The linux host build of nacl_io can't do wrapping of syscalls so all | 5 // The linux host build of nacl_io can't do wrapping of syscalls so all |
| 6 // these tests must be disabled. | 6 // these tests must be disabled. |
| 7 #if !defined(__linux__) | 7 #if !defined(__linux__) |
| 8 | 8 |
| 9 #include <unistd.h> | 9 #include <unistd.h> |
| 10 | 10 |
| 11 #include <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "gtest/gtest.h" | 14 #include "gtest/gtest.h" |
| 15 #include "mock_kernel_proxy.h" | 15 #include "mock_kernel_proxy.h" |
| 16 #include "nacl_io/kernel_intercept.h" | 16 #include "nacl_io/kernel_intercept.h" |
| 17 #include "nacl_io/kernel_wrap.h" | 17 #include "nacl_io/kernel_wrap.h" |
| 18 #include "nacl_io/kernel_wrap_real.h" | 18 #include "nacl_io/kernel_wrap_real.h" |
| 19 #include "nacl_io/osmman.h" | 19 #include "nacl_io/osmman.h" |
| 20 #include "nacl_io/ossocket.h" | 20 #include "nacl_io/ossocket.h" |
| 21 #include "nacl_io/ostermios.h" | 21 #include "nacl_io/ostermios.h" |
| 22 #include "nacl_io/ostime.h" |
| 22 #include "ppapi_simple/ps.h" | 23 #include "ppapi_simple/ps.h" |
| 23 | 24 |
| 24 #if defined(__native_client__) && !defined(__GLIBC__) | 25 #if defined(__native_client__) && !defined(__GLIBC__) |
| 25 extern "C" { | 26 extern "C" { |
| 26 // TODO(sbc): remove once these get added to the newlib toolchain headers. | 27 // TODO(sbc): remove once this gets added to the newlib toolchain headers. |
| 27 int fchdir(int fd); | 28 int fchdir(int fd); |
| 28 int utimes(const char *filename, const struct timeval times[2]); | |
| 29 } | 29 } |
| 30 #endif | 30 #endif |
| 31 | 31 |
| 32 using namespace nacl_io; | 32 using namespace nacl_io; |
| 33 | 33 |
| 34 using ::testing::_; | 34 using ::testing::_; |
| 35 using ::testing::AnyNumber; | 35 using ::testing::AnyNumber; |
| 36 using ::testing::DoAll; | 36 using ::testing::DoAll; |
| 37 using ::testing::Invoke; | 37 using ::testing::Invoke; |
| 38 using ::testing::Return; | 38 using ::testing::Return; |
| 39 using ::testing::StrEq; | 39 using ::testing::StrEq; |
| 40 | 40 |
| 41 namespace { | 41 namespace { |
| 42 | 42 |
| 43 #define COMPARE_FIELD(f) \ | 43 #define COMPARE_FIELD(actual, expected, f) \ |
| 44 if (arg->f != statbuf->f) { \ | 44 if (actual != expected) { \ |
| 45 *result_listener << "mismatch of field \"" #f \ | 45 *result_listener << "mismatch of field \"" f \ |
| 46 "\". " \ | 46 "\". " \ |
| 47 "expected: " << statbuf->f << " actual: " << arg->f; \ | 47 "expected: " << expected << " actual: " << actual; \ |
| 48 return false; \ | 48 return false; \ |
| 49 } | 49 } |
| 50 | 50 |
| 51 MATCHER_P(IsEqualToStatbuf, statbuf, "") { | 51 #define COMPARE_FIELD_SIMPLE(f) COMPARE_FIELD(arg->f, other->f, #f) |
| 52 COMPARE_FIELD(st_dev); | 52 |
| 53 COMPARE_FIELD(st_ino); | 53 MATCHER_P(IsEqualToStatbuf, other, "") { |
| 54 COMPARE_FIELD(st_mode); | 54 COMPARE_FIELD_SIMPLE(st_dev); |
| 55 COMPARE_FIELD(st_nlink); | 55 COMPARE_FIELD_SIMPLE(st_ino); |
| 56 COMPARE_FIELD(st_uid); | 56 COMPARE_FIELD_SIMPLE(st_mode); |
| 57 COMPARE_FIELD(st_gid); | 57 COMPARE_FIELD_SIMPLE(st_nlink); |
| 58 COMPARE_FIELD(st_rdev); | 58 COMPARE_FIELD_SIMPLE(st_uid); |
| 59 COMPARE_FIELD(st_size); | 59 COMPARE_FIELD_SIMPLE(st_gid); |
| 60 COMPARE_FIELD(st_atime); | 60 COMPARE_FIELD_SIMPLE(st_rdev); |
| 61 COMPARE_FIELD(st_mtime); | 61 COMPARE_FIELD_SIMPLE(st_size); |
| 62 COMPARE_FIELD(st_ctime); | 62 COMPARE_FIELD_SIMPLE(st_atime); |
| 63 COMPARE_FIELD_SIMPLE(st_mtime); |
| 64 COMPARE_FIELD_SIMPLE(st_ctime); |
| 65 return true; |
| 66 } |
| 67 |
| 68 MATCHER_P(IsEqualToUtimbuf, other, "") { |
| 69 COMPARE_FIELD(arg[0].tv_sec, other->actime, "actime"); |
| 70 COMPARE_FIELD(arg[1].tv_sec, other->modtime, "modtime"); |
| 71 return true; |
| 72 } |
| 73 |
| 74 MATCHER_P(IsEqualToTimeval, other, "") { |
| 75 COMPARE_FIELD(arg[0].tv_sec, other[0].tv_sec, "[0].tv_sec"); |
| 76 COMPARE_FIELD(arg[0].tv_nsec, other[0].tv_usec * 1000, "[0].tv_usec"); |
| 77 COMPARE_FIELD(arg[1].tv_sec, other[1].tv_sec, "[1].tv_sec"); |
| 78 COMPARE_FIELD(arg[1].tv_nsec, other[1].tv_usec * 1000, "[1].tv_usec"); |
| 63 return true; | 79 return true; |
| 64 } | 80 } |
| 65 | 81 |
| 66 #undef COMPARE_FIELD | 82 #undef COMPARE_FIELD |
| 83 #undef COMPARE_FIELD_SIMPLE |
| 84 |
| 67 | 85 |
| 68 ACTION_P(SetErrno, value) { | 86 ACTION_P(SetErrno, value) { |
| 69 errno = value; | 87 errno = value; |
| 70 } | 88 } |
| 71 | 89 |
| 72 ACTION_P2(SetString, target, source) { | 90 ACTION_P2(SetString, target, source) { |
| 73 strcpy(target, source); | 91 strcpy(target, source); |
| 74 } | 92 } |
| 75 | 93 |
| 76 ACTION_P(SetStat, statbuf) { | 94 ACTION_P(SetStat, statbuf) { |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 EXPECT_EQ(kDummyInt3, ftruncate(kDummyInt, kDummyInt2)); | 313 EXPECT_EQ(kDummyInt3, ftruncate(kDummyInt, kDummyInt2)); |
| 296 } | 314 } |
| 297 | 315 |
| 298 TEST_F(KernelWrapTest, fsync) { | 316 TEST_F(KernelWrapTest, fsync) { |
| 299 EXPECT_CALL(mock, fsync(kDummyInt)) | 317 EXPECT_CALL(mock, fsync(kDummyInt)) |
| 300 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1))); | 318 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1))); |
| 301 EXPECT_EQ(-1, fsync(kDummyInt)); | 319 EXPECT_EQ(-1, fsync(kDummyInt)); |
| 302 ASSERT_EQ(kDummyErrno, errno); | 320 ASSERT_EQ(kDummyErrno, errno); |
| 303 } | 321 } |
| 304 | 322 |
| 323 TEST_F(KernelWrapTest, futimes) { |
| 324 struct timeval times[2] = {{123, 234}, {345, 456}}; |
| 325 EXPECT_CALL(mock, futimens(kDummyInt, IsEqualToTimeval(times))) |
| 326 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1))); |
| 327 EXPECT_EQ(-1, futimes(kDummyInt, times)); |
| 328 ASSERT_EQ(kDummyErrno, errno); |
| 329 } |
| 330 |
| 305 TEST_F(KernelWrapTest, getcwd) { | 331 TEST_F(KernelWrapTest, getcwd) { |
| 306 char buffer[PATH_MAX]; | 332 char buffer[PATH_MAX]; |
| 307 char result[PATH_MAX]; | 333 char result[PATH_MAX]; |
| 308 memset(buffer, 0, PATH_MAX); | 334 memset(buffer, 0, PATH_MAX); |
| 309 strcpy(result, "getcwd_result"); | 335 strcpy(result, "getcwd_result"); |
| 310 EXPECT_CALL(mock, getcwd(buffer, kDummySizeT)) | 336 EXPECT_CALL(mock, getcwd(buffer, kDummySizeT)) |
| 311 .WillOnce(DoAll(SetString(buffer, result), Return(buffer))); | 337 .WillOnce(DoAll(SetString(buffer, result), Return(buffer))); |
| 312 EXPECT_STREQ(result, getcwd(buffer, kDummySizeT)); | 338 EXPECT_STREQ(result, getcwd(buffer, kDummySizeT)); |
| 313 } | 339 } |
| 314 | 340 |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 } | 634 } |
| 609 | 635 |
| 610 TEST_F(KernelWrapTest, unlink) { | 636 TEST_F(KernelWrapTest, unlink) { |
| 611 EXPECT_CALL(mock, unlink(kDummyConstChar)) | 637 EXPECT_CALL(mock, unlink(kDummyConstChar)) |
| 612 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1))); | 638 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1))); |
| 613 EXPECT_EQ(-1, unlink(kDummyConstChar)); | 639 EXPECT_EQ(-1, unlink(kDummyConstChar)); |
| 614 ASSERT_EQ(kDummyErrno, errno); | 640 ASSERT_EQ(kDummyErrno, errno); |
| 615 } | 641 } |
| 616 | 642 |
| 617 TEST_F(KernelWrapTest, utime) { | 643 TEST_F(KernelWrapTest, utime) { |
| 618 const struct utimbuf* times = NULL; | 644 const struct utimbuf times = {123, 456}; |
| 619 EXPECT_CALL(mock, utime(kDummyConstChar, times)).WillOnce(Return(kDummyInt)); | 645 EXPECT_CALL(mock, utimens(kDummyConstChar, IsEqualToUtimbuf(×))) |
| 620 EXPECT_EQ(kDummyInt, utime(kDummyConstChar, times)); | 646 .WillOnce(Return(kDummyInt)); |
| 647 EXPECT_EQ(kDummyInt, utime(kDummyConstChar, ×)); |
| 621 } | 648 } |
| 622 | 649 |
| 623 TEST_F(KernelWrapTest, utimes) { | 650 TEST_F(KernelWrapTest, utimes) { |
| 624 struct timeval* times = NULL; | 651 struct timeval times[2] = {{123, 234}, {345, 456}}; |
| 625 EXPECT_CALL(mock, utimes(kDummyConstChar, times)) | 652 EXPECT_CALL(mock, utimens(kDummyConstChar, IsEqualToTimeval(times))) |
| 626 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1))); | 653 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1))); |
| 627 EXPECT_EQ(-1, utimes(kDummyConstChar, times)); | 654 EXPECT_EQ(-1, utimes(kDummyConstChar, times)); |
| 628 ASSERT_EQ(kDummyErrno, errno); | 655 ASSERT_EQ(kDummyErrno, errno); |
| 629 } | 656 } |
| 630 | 657 |
| 631 TEST_F(KernelWrapTest, write) { | 658 TEST_F(KernelWrapTest, write) { |
| 632 EXPECT_CALL(mock, write(kDummyInt, kDummyVoidPtr, kDummyInt2)) | 659 EXPECT_CALL(mock, write(kDummyInt, kDummyVoidPtr, kDummyInt2)) |
| 633 .WillOnce(Return(kDummyInt3)); | 660 .WillOnce(Return(kDummyInt3)); |
| 634 EXPECT_EQ(kDummyInt3, write(kDummyInt, kDummyVoidPtr, kDummyInt2)); | 661 EXPECT_EQ(kDummyInt3, write(kDummyInt, kDummyVoidPtr, kDummyInt2)); |
| 635 } | 662 } |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 893 .WillOnce(Return(0)) | 920 .WillOnce(Return(0)) |
| 894 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1))); | 921 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1))); |
| 895 EXPECT_EQ(0, socketpair(kDummyInt, kDummyInt2, kDummyInt3, &dummy_val)); | 922 EXPECT_EQ(0, socketpair(kDummyInt, kDummyInt2, kDummyInt3, &dummy_val)); |
| 896 EXPECT_EQ(-1, socketpair(kDummyInt, kDummyInt2, kDummyInt3, &dummy_val)); | 923 EXPECT_EQ(-1, socketpair(kDummyInt, kDummyInt2, kDummyInt3, &dummy_val)); |
| 897 EXPECT_EQ(kDummyErrno, errno); | 924 EXPECT_EQ(kDummyErrno, errno); |
| 898 } | 925 } |
| 899 | 926 |
| 900 #endif // PROVIDES_SOCKET_API | 927 #endif // PROVIDES_SOCKET_API |
| 901 | 928 |
| 902 #endif // __linux__ | 929 #endif // __linux__ |
| OLD | NEW |