Index: native_client_sdk/src/tests/nacl_io_test/kernel_wrap_test.cc |
diff --git a/native_client_sdk/src/tests/nacl_io_test/kernel_wrap_test.cc b/native_client_sdk/src/tests/nacl_io_test/kernel_wrap_test.cc |
index bbfa60047a31cc9bbb6afc3d3891f9b91308bd00..9cf4253cfa2f93188f8bf0409b8d27d91f96ea98 100644 |
--- a/native_client_sdk/src/tests/nacl_io_test/kernel_wrap_test.cc |
+++ b/native_client_sdk/src/tests/nacl_io_test/kernel_wrap_test.cc |
@@ -61,6 +61,10 @@ MATCHER_P(IsEqualToStatbuf, statbuf, "") { |
#undef COMPARE_FIELD |
+ACTION_P(SetErrno, value) { |
+ errno = value; |
+} |
+ |
ACTION_P(SetStat, statbuf) { |
memset(arg1, 0, sizeof(struct stat)); |
arg1->st_dev = statbuf->st_dev; |
@@ -92,6 +96,7 @@ void MakeDummyStatbuf(struct stat* statbuf) { |
} |
const mode_t kDummyMode = 0xbeef; |
+const int kDummyErrno = 0xfeeb; |
const int kDummyInt = 0xdedbeef; |
const int kDummyInt2 = 0xcabba6e; |
const int kDummyInt3 = 0xf00ba4; |
@@ -109,6 +114,10 @@ class KernelWrapTest : public ::testing::Test { |
KernelWrapTest() {} |
virtual void SetUp() { |
+ // Initialize the global errno value to a consistent value rather than |
+ // relying on its value from previous test runs. |
+ errno = 0; |
+ |
// Initializing the KernelProxy opens stdin/stdout/stderr. |
EXPECT_CALL(mock, open(_, _)) |
.WillOnce(Return(0)) |
@@ -129,26 +138,30 @@ class KernelWrapTest : public ::testing::Test { |
ki_uninit(); |
} |
- |
MockKernelProxy mock; |
}; |
} // namespace |
TEST_F(KernelWrapTest, access) { |
- EXPECT_CALL(mock, access(kDummyConstChar, kDummyInt)) .WillOnce(Return(-1)); |
- EXPECT_EQ(-1, access(kDummyConstChar, kDummyInt)); |
- |
EXPECT_CALL(mock, access(kDummyConstChar, kDummyInt)) .WillOnce(Return(0)); |
EXPECT_EQ(0, access(kDummyConstChar, kDummyInt)); |
+ |
+ EXPECT_CALL(mock, access(kDummyConstChar, kDummyInt)) |
+ .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1))); |
+ EXPECT_EQ(-1, access(kDummyConstChar, kDummyInt)); |
+ EXPECT_EQ(kDummyErrno, errno); |
+ |
} |
TEST_F(KernelWrapTest, chdir) { |
- EXPECT_CALL(mock, chdir(kDummyConstChar)).WillOnce(Return(-1)); |
- EXPECT_EQ(-1, chdir(kDummyConstChar)); |
- |
EXPECT_CALL(mock, chdir(kDummyConstChar)).WillOnce(Return(0)); |
EXPECT_EQ(0, chdir(kDummyConstChar)); |
+ |
+ EXPECT_CALL(mock, chdir(kDummyConstChar)) |
+ .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1))); |
+ EXPECT_EQ(-1, chdir(kDummyConstChar)); |
+ ASSERT_EQ(kDummyErrno, errno); |
} |
TEST_F(KernelWrapTest, chmod) { |
@@ -167,11 +180,14 @@ TEST_F(KernelWrapTest, close) { |
// The way we wrap close does not support returning arbitrary values, so we |
// test 0 and -1. |
EXPECT_CALL(mock, close(kDummyInt)) |
- .WillOnce(Return(0)) |
- .WillOnce(Return(-1)); |
+ .WillOnce(Return(0)); |
EXPECT_EQ(0, close(kDummyInt)); |
+ |
+ EXPECT_CALL(mock, close(kDummyInt)) |
+ .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1))); |
EXPECT_EQ(-1, close(kDummyInt)); |
+ ASSERT_EQ(kDummyErrno, errno); |
} |
TEST_F(KernelWrapTest, dup) { |
@@ -184,24 +200,29 @@ TEST_F(KernelWrapTest, dup2) { |
// or the value of the new fd. |
EXPECT_CALL(mock, dup2(kDummyInt, kDummyInt2)) |
.WillOnce(Return(kDummyInt2)) |
- .WillOnce(Return(-1)); |
+ .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1))); |
+ |
EXPECT_EQ(kDummyInt2, dup2(kDummyInt, kDummyInt2)); |
EXPECT_EQ(-1, dup2(kDummyInt, kDummyInt2)); |
+ ASSERT_EQ(kDummyErrno, errno); |
} |
TEST_F(KernelWrapTest, fchdir) { |
EXPECT_CALL(mock, fchdir(kDummyInt)) |
- .WillOnce(Return(-1)); |
+ .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1))); |
+ |
EXPECT_EQ(-1, fchdir(kDummyInt)); |
+ ASSERT_EQ(kDummyErrno, errno); |
} |
TEST_F(KernelWrapTest, fchmod) { |
EXPECT_CALL(mock, fchmod(kDummyInt, kDummyMode)) |
- .WillOnce(Return(-1)); |
- EXPECT_EQ(-1, fchmod(kDummyInt, kDummyMode)); |
+ .WillOnce(Return(0)) |
+ .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1))); |
- EXPECT_CALL(mock, fchmod(kDummyInt, kDummyMode)) .WillOnce(Return(0)); |
EXPECT_EQ(0, fchmod(kDummyInt, kDummyMode)); |
+ EXPECT_EQ(-1, fchmod(kDummyInt, kDummyMode)); |
+ ASSERT_EQ(kDummyErrno, errno); |
} |
TEST_F(KernelWrapTest, fchown) { |
@@ -218,11 +239,12 @@ TEST_F(KernelWrapTest, fcntl) { |
} |
TEST_F(KernelWrapTest, fdatasync) { |
- EXPECT_CALL(mock, fdatasync(kDummyInt)).WillOnce(Return(-1)); |
- EXPECT_EQ(-1, fdatasync(kDummyInt)); |
+ EXPECT_CALL(mock, fdatasync(kDummyInt)).WillOnce(Return(0)) |
+ .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1))); |
- EXPECT_CALL(mock, fdatasync(kDummyInt)).WillOnce(Return(0)); |
EXPECT_EQ(0, fdatasync(kDummyInt)); |
+ EXPECT_EQ(-1, fdatasync(kDummyInt)); |
+ ASSERT_EQ(kDummyErrno, errno); |
} |
TEST_F(KernelWrapTest, fstat) { |
@@ -232,11 +254,14 @@ TEST_F(KernelWrapTest, fstat) { |
MakeDummyStatbuf(&in_statbuf); |
EXPECT_CALL(mock, fstat(kDummyInt, _)) |
.WillOnce(DoAll(SetStat(&in_statbuf), Return(0))) |
- .WillOnce(Return(-1)); |
+ .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1))); |
struct stat out_statbuf; |
+ |
EXPECT_EQ(0, fstat(kDummyInt, &out_statbuf)); |
EXPECT_THAT(&in_statbuf, IsEqualToStatbuf(&out_statbuf)); |
+ |
EXPECT_EQ(-1, fstat(kDummyInt, &out_statbuf)); |
+ ASSERT_EQ(kDummyErrno, errno); |
} |
TEST_F(KernelWrapTest, ftruncate) { |
@@ -246,8 +271,10 @@ TEST_F(KernelWrapTest, ftruncate) { |
} |
TEST_F(KernelWrapTest, fsync) { |
- EXPECT_CALL(mock, fsync(kDummyInt)).WillOnce(Return(-1)); |
+ EXPECT_CALL(mock, fsync(kDummyInt)) |
+ .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1))); |
EXPECT_EQ(-1, fsync(kDummyInt)); |
+ ASSERT_EQ(kDummyErrno, errno); |
} |
TEST_F(KernelWrapTest, getcwd) { |
@@ -391,15 +418,13 @@ TEST_F(KernelWrapTest, munmap) { |
munmap(kDummyVoidPtr, kDummySizeT); |
} |
- |
TEST_F(KernelWrapTest, open) { |
// We pass O_RDONLY because we do not want an error in flags translation |
EXPECT_CALL(mock, open(kDummyConstChar, 0)) |
+ .WillOnce(Return(kDummyInt2)) |
.WillOnce(Return(kDummyInt2)); |
- EXPECT_EQ(kDummyInt2, open(kDummyConstChar, 0)); |
- EXPECT_CALL(mock, open(kDummyConstChar, 0)) |
- .WillOnce(Return(kDummyInt2)); |
+ EXPECT_EQ(kDummyInt2, open(kDummyConstChar, 0)); |
EXPECT_EQ(kDummyInt2, open(kDummyConstChar, 0)); |
} |
@@ -421,12 +446,12 @@ TEST_F(KernelWrapTest, readlink) { |
char buf[10]; |
EXPECT_CALL(mock, readlink(kDummyConstChar, buf, 10)) |
- .WillOnce(Return(-1)); |
- EXPECT_EQ(-1, readlink(kDummyConstChar, buf, 10)); |
+ .WillOnce(Return(kDummyInt)) |
+ .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1))); |
- EXPECT_CALL(mock, readlink(kDummyConstChar, buf, 10)) |
- .WillOnce(Return(kDummyInt)); |
EXPECT_EQ(kDummyInt, readlink(kDummyConstChar, buf, 10)); |
+ EXPECT_EQ(-1, readlink(kDummyConstChar, buf, 10)); |
+ ASSERT_EQ(kDummyErrno, errno); |
} |
#ifdef __GLIBC__ |
@@ -440,12 +465,12 @@ TEST_F(KernelWrapTest, remove) { |
TEST_F(KernelWrapTest, rename) { |
EXPECT_CALL(mock, rename(kDummyConstChar, kDummyConstChar2)) |
- .WillOnce(Return(-1)); |
- EXPECT_EQ(-1, rename(kDummyConstChar, kDummyConstChar2)); |
+ .WillOnce(Return(0)) |
+ .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1))); |
- EXPECT_CALL(mock, rename(kDummyConstChar, kDummyConstChar2)) |
- .WillOnce(Return(0)); |
EXPECT_EQ(0, rename(kDummyConstChar, kDummyConstChar2)); |
+ EXPECT_EQ(-1, rename(kDummyConstChar, kDummyConstChar2)); |
+ ASSERT_EQ(kDummyErrno, errno); |
} |
TEST_F(KernelWrapTest, rmdir) { |
@@ -483,11 +508,14 @@ TEST_F(KernelWrapTest, stat) { |
MakeDummyStatbuf(&in_statbuf); |
EXPECT_CALL(mock, stat(StrEq(kDummyConstChar), _)) |
.WillOnce(DoAll(SetStat(&in_statbuf), Return(0))) |
- .WillOnce(Return(-1)); |
+ .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1))); |
struct stat out_statbuf; |
+ |
EXPECT_EQ(0, stat(kDummyConstChar, &out_statbuf)); |
EXPECT_THAT(&in_statbuf, IsEqualToStatbuf(&out_statbuf)); |
+ |
EXPECT_EQ(-1, stat(kDummyConstChar, &out_statbuf)); |
+ ASSERT_EQ(kDummyErrno, errno); |
} |
TEST_F(KernelWrapTest, symlink) { |
@@ -523,11 +551,13 @@ TEST_F(KernelWrapTest, umount) { |
} |
TEST_F(KernelWrapTest, truncate) { |
- EXPECT_CALL(mock, truncate(kDummyConstChar, kDummyInt3)).WillOnce(Return(-1)); |
- EXPECT_EQ(-1, truncate(kDummyConstChar, kDummyInt3)); |
+ EXPECT_CALL(mock, truncate(kDummyConstChar, kDummyInt3)) |
+ .WillOnce(Return(0)) |
+ .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1))); |
- EXPECT_CALL(mock, truncate(kDummyConstChar, kDummyInt3)).WillOnce(Return(0)); |
EXPECT_EQ(0, truncate(kDummyConstChar, kDummyInt3)); |
+ |
+ EXPECT_EQ(-1, truncate(kDummyConstChar, kDummyInt3)); |
} |
TEST_F(KernelWrapTest, lstat) { |
@@ -535,11 +565,14 @@ TEST_F(KernelWrapTest, lstat) { |
MakeDummyStatbuf(&in_statbuf); |
EXPECT_CALL(mock, lstat(StrEq(kDummyConstChar), _)) |
.WillOnce(DoAll(SetStat(&in_statbuf), Return(0))) |
- .WillOnce(Return(-1)); |
+ .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1))); |
struct stat out_statbuf; |
+ |
EXPECT_EQ(0, lstat(kDummyConstChar, &out_statbuf)); |
EXPECT_THAT(&in_statbuf, IsEqualToStatbuf(&out_statbuf)); |
+ |
EXPECT_EQ(-1, lstat(kDummyConstChar, &out_statbuf)); |
+ ASSERT_EQ(kDummyErrno, errno); |
} |
TEST_F(KernelWrapTest, unlink) { |
@@ -555,8 +588,10 @@ TEST_F(KernelWrapTest, utime) { |
TEST_F(KernelWrapTest, utimes) { |
struct timeval* times = NULL; |
- EXPECT_CALL(mock, utimes(kDummyConstChar, times)).WillOnce(Return(-1)); |
+ EXPECT_CALL(mock, utimes(kDummyConstChar, times)) |
+ .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1))); |
EXPECT_EQ(-1, utimes(kDummyConstChar, times)); |
+ ASSERT_EQ(kDummyErrno, errno); |
} |
TEST_F(KernelWrapTest, write) { |