| 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 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 COMPARE_FIELD(st_ctime); | 61 COMPARE_FIELD(st_ctime); |
| 62 return true; | 62 return true; |
| 63 } | 63 } |
| 64 | 64 |
| 65 #undef COMPARE_FIELD | 65 #undef COMPARE_FIELD |
| 66 | 66 |
| 67 ACTION_P(SetErrno, value) { | 67 ACTION_P(SetErrno, value) { |
| 68 errno = value; | 68 errno = value; |
| 69 } | 69 } |
| 70 | 70 |
| 71 ACTION_P2(SetString, target, source) { |
| 72 strcpy(target, source); |
| 73 } |
| 74 |
| 71 ACTION_P(SetStat, statbuf) { | 75 ACTION_P(SetStat, statbuf) { |
| 72 memset(arg1, 0, sizeof(struct stat)); | 76 memset(arg1, 0, sizeof(struct stat)); |
| 73 arg1->st_dev = statbuf->st_dev; | 77 arg1->st_dev = statbuf->st_dev; |
| 74 arg1->st_ino = statbuf->st_ino; | 78 arg1->st_ino = statbuf->st_ino; |
| 75 arg1->st_mode = statbuf->st_mode; | 79 arg1->st_mode = statbuf->st_mode; |
| 76 arg1->st_nlink = statbuf->st_nlink; | 80 arg1->st_nlink = statbuf->st_nlink; |
| 77 arg1->st_uid = statbuf->st_uid; | 81 arg1->st_uid = statbuf->st_uid; |
| 78 arg1->st_gid = statbuf->st_gid; | 82 arg1->st_gid = statbuf->st_gid; |
| 79 arg1->st_rdev = statbuf->st_rdev; | 83 arg1->st_rdev = statbuf->st_rdev; |
| 80 arg1->st_size = statbuf->st_size; | 84 arg1->st_size = statbuf->st_size; |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 } | 293 } |
| 290 | 294 |
| 291 TEST_F(KernelWrapTest, fsync) { | 295 TEST_F(KernelWrapTest, fsync) { |
| 292 EXPECT_CALL(mock, fsync(kDummyInt)) | 296 EXPECT_CALL(mock, fsync(kDummyInt)) |
| 293 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1))); | 297 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1))); |
| 294 EXPECT_EQ(-1, fsync(kDummyInt)); | 298 EXPECT_EQ(-1, fsync(kDummyInt)); |
| 295 ASSERT_EQ(kDummyErrno, errno); | 299 ASSERT_EQ(kDummyErrno, errno); |
| 296 } | 300 } |
| 297 | 301 |
| 298 TEST_F(KernelWrapTest, getcwd) { | 302 TEST_F(KernelWrapTest, getcwd) { |
| 299 char result[] = "getcwd_result"; | 303 char buffer[PATH_MAX]; |
| 300 char buffer[] = "getcwd"; | 304 char result[PATH_MAX]; |
| 301 EXPECT_CALL(mock, getcwd(buffer, kDummySizeT)).WillOnce(Return(result)); | 305 memset(buffer, 0, PATH_MAX); |
| 302 EXPECT_EQ(result, getcwd(buffer, kDummySizeT)); | 306 strcpy(result, "getcwd_result"); |
| 307 EXPECT_CALL(mock, getcwd(buffer, kDummySizeT)) |
| 308 .WillOnce(DoAll(SetString(buffer, result), Return(buffer))); |
| 309 EXPECT_STREQ(result, getcwd(buffer, kDummySizeT)); |
| 303 } | 310 } |
| 304 | 311 |
| 305 TEST_F(KernelWrapTest, getdents) { | 312 TEST_F(KernelWrapTest, getdents) { |
| 306 #if !defined( __GLIBC__) && !defined(__BIONIC__) | 313 #if !defined( __GLIBC__) && !defined(__BIONIC__) |
| 307 // TODO(sbc): Find a way to test the getdents wrapper under glibc. | 314 // TODO(sbc): Find a way to test the getdents wrapper under glibc. |
| 308 // It looks like the only way to exercise it is to call readdir(2). | 315 // It looks like the only way to exercise it is to call readdir(2). |
| 309 // There is an internal glibc function __getdents that will call the | 316 // There is an internal glibc function __getdents that will call the |
| 310 // IRT but that cannot be accessed from here as glibc does not export it. | 317 // IRT but that cannot be accessed from here as glibc does not export it. |
| 311 int dummy_val; | 318 int dummy_val; |
| 312 void* void_ptr = &dummy_val; | 319 void* void_ptr = &dummy_val; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 .WillOnce(Return(kDummyInt4)); | 381 .WillOnce(Return(kDummyInt4)); |
| 375 EXPECT_EQ(kDummyInt4, lseek(kDummyInt, kDummyInt2, kDummyInt3)); | 382 EXPECT_EQ(kDummyInt4, lseek(kDummyInt, kDummyInt2, kDummyInt3)); |
| 376 } | 383 } |
| 377 | 384 |
| 378 TEST_F(KernelWrapTest, mkdir) { | 385 TEST_F(KernelWrapTest, mkdir) { |
| 379 #if defined(WIN32) | 386 #if defined(WIN32) |
| 380 EXPECT_CALL(mock, mkdir(kDummyConstChar, 0777)).WillOnce(Return(kDummyInt2)); | 387 EXPECT_CALL(mock, mkdir(kDummyConstChar, 0777)).WillOnce(Return(kDummyInt2)); |
| 381 EXPECT_EQ(kDummyInt2, mkdir(kDummyConstChar)); | 388 EXPECT_EQ(kDummyInt2, mkdir(kDummyConstChar)); |
| 382 #else | 389 #else |
| 383 EXPECT_CALL(mock, mkdir(kDummyConstChar, kDummyMode)) | 390 EXPECT_CALL(mock, mkdir(kDummyConstChar, kDummyMode)) |
| 384 .WillOnce(Return(kDummyInt2)); | 391 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1))); |
| 385 EXPECT_EQ(kDummyInt2, mkdir(kDummyConstChar, kDummyMode)); | 392 EXPECT_EQ(-1, mkdir(kDummyConstChar, kDummyMode)); |
| 393 ASSERT_EQ(kDummyErrno, errno); |
| 386 #endif | 394 #endif |
| 387 } | 395 } |
| 388 | 396 |
| 389 TEST_F(KernelWrapTest, mmap) { | 397 TEST_F(KernelWrapTest, mmap) { |
| 390 // We only wrap mmap if |flags| has the MAP_ANONYMOUS bit unset. | 398 // We only wrap mmap if |flags| has the MAP_ANONYMOUS bit unset. |
| 391 int flags = kDummyInt2 & ~MAP_ANONYMOUS; | 399 int flags = kDummyInt2 & ~MAP_ANONYMOUS; |
| 392 | 400 |
| 393 const size_t kDummySizeT2 = 0xbadf00d; | 401 const size_t kDummySizeT2 = 0xbadf00d; |
| 394 int dummy1 = 123; | 402 int dummy1 = 123; |
| 395 int dummy2 = 456; | 403 int dummy2 = 456; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 EXPECT_CALL(mock, rename(kDummyConstChar, kDummyConstChar2)) | 493 EXPECT_CALL(mock, rename(kDummyConstChar, kDummyConstChar2)) |
| 486 .WillOnce(Return(0)) | 494 .WillOnce(Return(0)) |
| 487 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1))); | 495 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1))); |
| 488 | 496 |
| 489 EXPECT_EQ(0, rename(kDummyConstChar, kDummyConstChar2)); | 497 EXPECT_EQ(0, rename(kDummyConstChar, kDummyConstChar2)); |
| 490 EXPECT_EQ(-1, rename(kDummyConstChar, kDummyConstChar2)); | 498 EXPECT_EQ(-1, rename(kDummyConstChar, kDummyConstChar2)); |
| 491 ASSERT_EQ(kDummyErrno, errno); | 499 ASSERT_EQ(kDummyErrno, errno); |
| 492 } | 500 } |
| 493 | 501 |
| 494 TEST_F(KernelWrapTest, rmdir) { | 502 TEST_F(KernelWrapTest, rmdir) { |
| 495 EXPECT_CALL(mock, rmdir(kDummyConstChar)).WillOnce(Return(kDummyInt)); | 503 EXPECT_CALL(mock, rmdir(kDummyConstChar)) |
| 496 EXPECT_EQ(kDummyInt, rmdir(kDummyConstChar)); | 504 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1))); |
| 505 EXPECT_EQ(-1, rmdir(kDummyConstChar)); |
| 506 ASSERT_EQ(kDummyErrno, errno); |
| 497 } | 507 } |
| 498 | 508 |
| 499 static void new_handler(int) {} | 509 static void new_handler(int) {} |
| 500 | 510 |
| 501 TEST_F(KernelWrapTest, sigaction) { | 511 TEST_F(KernelWrapTest, sigaction) { |
| 502 struct sigaction action; | 512 struct sigaction action; |
| 503 struct sigaction oaction; | 513 struct sigaction oaction; |
| 504 EXPECT_CALL(mock, sigaction(kDummyInt, &action, &oaction)) | 514 EXPECT_CALL(mock, sigaction(kDummyInt, &action, &oaction)) |
| 505 .WillOnce(Return(0)); | 515 .WillOnce(Return(0)); |
| 506 EXPECT_EQ(0, sigaction(kDummyInt, &action, &oaction)); | 516 EXPECT_EQ(0, sigaction(kDummyInt, &action, &oaction)); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 struct stat out_statbuf; | 597 struct stat out_statbuf; |
| 588 | 598 |
| 589 EXPECT_EQ(0, lstat(kDummyConstChar, &out_statbuf)); | 599 EXPECT_EQ(0, lstat(kDummyConstChar, &out_statbuf)); |
| 590 EXPECT_THAT(&in_statbuf, IsEqualToStatbuf(&out_statbuf)); | 600 EXPECT_THAT(&in_statbuf, IsEqualToStatbuf(&out_statbuf)); |
| 591 | 601 |
| 592 EXPECT_EQ(-1, lstat(kDummyConstChar, &out_statbuf)); | 602 EXPECT_EQ(-1, lstat(kDummyConstChar, &out_statbuf)); |
| 593 ASSERT_EQ(kDummyErrno, errno); | 603 ASSERT_EQ(kDummyErrno, errno); |
| 594 } | 604 } |
| 595 | 605 |
| 596 TEST_F(KernelWrapTest, unlink) { | 606 TEST_F(KernelWrapTest, unlink) { |
| 597 EXPECT_CALL(mock, unlink(kDummyConstChar)).WillOnce(Return(kDummyInt)); | 607 EXPECT_CALL(mock, unlink(kDummyConstChar)) |
| 598 EXPECT_EQ(kDummyInt, unlink(kDummyConstChar)); | 608 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1))); |
| 609 EXPECT_EQ(-1, unlink(kDummyConstChar)); |
| 610 ASSERT_EQ(kDummyErrno, errno); |
| 599 } | 611 } |
| 600 | 612 |
| 601 TEST_F(KernelWrapTest, utime) { | 613 TEST_F(KernelWrapTest, utime) { |
| 602 const struct utimbuf* times = NULL; | 614 const struct utimbuf* times = NULL; |
| 603 EXPECT_CALL(mock, utime(kDummyConstChar, times)).WillOnce(Return(kDummyInt)); | 615 EXPECT_CALL(mock, utime(kDummyConstChar, times)).WillOnce(Return(kDummyInt)); |
| 604 EXPECT_EQ(kDummyInt, utime(kDummyConstChar, times)); | 616 EXPECT_EQ(kDummyInt, utime(kDummyConstChar, times)); |
| 605 } | 617 } |
| 606 | 618 |
| 607 TEST_F(KernelWrapTest, utimes) { | 619 TEST_F(KernelWrapTest, utimes) { |
| 608 struct timeval* times = NULL; | 620 struct timeval* times = NULL; |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 843 .WillOnce(Return(0)) | 855 .WillOnce(Return(0)) |
| 844 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1))); | 856 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1))); |
| 845 EXPECT_EQ(0, socketpair(kDummyInt, kDummyInt2, kDummyInt3, &dummy_val)); | 857 EXPECT_EQ(0, socketpair(kDummyInt, kDummyInt2, kDummyInt3, &dummy_val)); |
| 846 EXPECT_EQ(-1, socketpair(kDummyInt, kDummyInt2, kDummyInt3, &dummy_val)); | 858 EXPECT_EQ(-1, socketpair(kDummyInt, kDummyInt2, kDummyInt3, &dummy_val)); |
| 847 EXPECT_EQ(kDummyErrno, errno); | 859 EXPECT_EQ(kDummyErrno, errno); |
| 848 } | 860 } |
| 849 | 861 |
| 850 #endif // PROVIDES_SOCKET_API | 862 #endif // PROVIDES_SOCKET_API |
| 851 | 863 |
| 852 #endif // __linux__ | 864 #endif // __linux__ |
| OLD | NEW |