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

Unified Diff: native_client_sdk/src/tests/nacl_io_test/kernel_wrap_test.cc

Issue 271513002: [NaCl SDK] nacl_io: Make IRT intercepts (and their test code) more robust. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
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 d0f59b467caa5a5f9ff460662d2c7302e238557e..299592bb903582571259735622bde73cdc95d463 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
@@ -64,6 +64,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;
@@ -95,6 +99,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;
@@ -112,6 +117,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))
@@ -157,19 +166,24 @@ class KernelWrapTest : public ::testing::Test {
} // 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) {
@@ -188,11 +202,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) {
@@ -205,24 +222,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) {
@@ -239,11 +261,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) {
@@ -253,11 +276,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) {
@@ -267,8 +293,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) {
@@ -412,15 +440,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));
}
@@ -442,12 +468,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__
@@ -461,12 +487,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) {
@@ -504,11 +530,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) {
@@ -544,11 +573,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) {
@@ -556,11 +587,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) {
@@ -576,8 +610,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) {

Powered by Google App Engine
This is Rietveld 408576698