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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 COMPARE_FIELD(st_rdev); 54 COMPARE_FIELD(st_rdev);
55 COMPARE_FIELD(st_size); 55 COMPARE_FIELD(st_size);
56 COMPARE_FIELD(st_atime); 56 COMPARE_FIELD(st_atime);
57 COMPARE_FIELD(st_mtime); 57 COMPARE_FIELD(st_mtime);
58 COMPARE_FIELD(st_ctime); 58 COMPARE_FIELD(st_ctime);
59 return true; 59 return true;
60 } 60 }
61 61
62 #undef COMPARE_FIELD 62 #undef COMPARE_FIELD
63 63
64 ACTION_P(SetErrno, value) {
65 errno = value;
66 }
67
64 ACTION_P(SetStat, statbuf) { 68 ACTION_P(SetStat, statbuf) {
65 memset(arg1, 0, sizeof(struct stat)); 69 memset(arg1, 0, sizeof(struct stat));
66 arg1->st_dev = statbuf->st_dev; 70 arg1->st_dev = statbuf->st_dev;
67 arg1->st_ino = statbuf->st_ino; 71 arg1->st_ino = statbuf->st_ino;
68 arg1->st_mode = statbuf->st_mode; 72 arg1->st_mode = statbuf->st_mode;
69 arg1->st_nlink = statbuf->st_nlink; 73 arg1->st_nlink = statbuf->st_nlink;
70 arg1->st_uid = statbuf->st_uid; 74 arg1->st_uid = statbuf->st_uid;
71 arg1->st_gid = statbuf->st_gid; 75 arg1->st_gid = statbuf->st_gid;
72 arg1->st_rdev = statbuf->st_rdev; 76 arg1->st_rdev = statbuf->st_rdev;
73 arg1->st_size = statbuf->st_size; 77 arg1->st_size = statbuf->st_size;
(...skipping 11 matching lines...) Expand all
85 statbuf->st_uid = 5; 89 statbuf->st_uid = 5;
86 statbuf->st_gid = 6; 90 statbuf->st_gid = 6;
87 statbuf->st_rdev = 7; 91 statbuf->st_rdev = 7;
88 statbuf->st_size = 8; 92 statbuf->st_size = 8;
89 statbuf->st_atime = 9; 93 statbuf->st_atime = 9;
90 statbuf->st_mtime = 10; 94 statbuf->st_mtime = 10;
91 statbuf->st_ctime = 11; 95 statbuf->st_ctime = 11;
92 } 96 }
93 97
94 const mode_t kDummyMode = 0xbeef; 98 const mode_t kDummyMode = 0xbeef;
99 const int kDummyErrno = 0xfeeb;
95 const int kDummyInt = 0xdedbeef; 100 const int kDummyInt = 0xdedbeef;
96 const int kDummyInt2 = 0xcabba6e; 101 const int kDummyInt2 = 0xcabba6e;
97 const int kDummyInt3 = 0xf00ba4; 102 const int kDummyInt3 = 0xf00ba4;
98 const int kDummyInt4 = 0xabacdba; 103 const int kDummyInt4 = 0xabacdba;
99 const size_t kDummySizeT = 0x60067e; 104 const size_t kDummySizeT = 0x60067e;
100 const char* kDummyConstChar = "foobar"; 105 const char* kDummyConstChar = "foobar";
101 const char* kDummyConstChar2 = "g00gl3"; 106 const char* kDummyConstChar2 = "g00gl3";
102 const char* kDummyConstChar3 = "fr00gl3"; 107 const char* kDummyConstChar3 = "fr00gl3";
103 const void* kDummyVoidPtr = "blahblah"; 108 const void* kDummyVoidPtr = "blahblah";
104 const uid_t kDummyUid = 1001; 109 const uid_t kDummyUid = 1001;
105 const gid_t kDummyGid = 1002; 110 const gid_t kDummyGid = 1002;
106 111
107 class KernelWrapTest : public ::testing::Test { 112 class KernelWrapTest : public ::testing::Test {
108 public: 113 public:
109 KernelWrapTest() {} 114 KernelWrapTest() {}
110 115
111 virtual void SetUp() { 116 virtual void SetUp() {
117 // Initialize the global errno value to a consistent value rather than
118 // relying on its value from previous test runs.
119 errno = 0;
120
112 // Initializing the KernelProxy opens stdin/stdout/stderr. 121 // Initializing the KernelProxy opens stdin/stdout/stderr.
113 EXPECT_CALL(mock, open(_, _)) 122 EXPECT_CALL(mock, open(_, _))
114 .WillOnce(Return(0)) 123 .WillOnce(Return(0))
115 .WillOnce(Return(1)) 124 .WillOnce(Return(1))
116 .WillOnce(Return(2)); 125 .WillOnce(Return(2));
117 // And will call mount / and /dev. 126 // And will call mount / and /dev.
118 EXPECT_CALL(mock, mount(_, _, _, _, _)) 127 EXPECT_CALL(mock, mount(_, _, _, _, _))
119 .WillOnce(Return(0)) 128 .WillOnce(Return(0))
120 .WillOnce(Return(0)); 129 .WillOnce(Return(0));
121 130
122 ASSERT_EQ(0, ki_push_state_for_testing()); 131 ASSERT_EQ(0, ki_push_state_for_testing());
123 ASSERT_EQ(0, ki_init(&mock)); 132 ASSERT_EQ(0, ki_init(&mock));
124 } 133 }
125 134
126 void TearDown() { 135 void TearDown() {
127 // Uninitialize the kernel proxy so wrapped functions passthrough to their 136 // Uninitialize the kernel proxy so wrapped functions passthrough to their
128 // unwrapped versions. 137 // unwrapped versions.
129 ki_uninit(); 138 ki_uninit();
130 } 139 }
131 140
132
133 MockKernelProxy mock; 141 MockKernelProxy mock;
134 }; 142 };
135 143
136 } // namespace 144 } // namespace
137 145
138 TEST_F(KernelWrapTest, access) { 146 TEST_F(KernelWrapTest, access) {
139 EXPECT_CALL(mock, access(kDummyConstChar, kDummyInt)) .WillOnce(Return(-1));
140 EXPECT_EQ(-1, access(kDummyConstChar, kDummyInt));
141
142 EXPECT_CALL(mock, access(kDummyConstChar, kDummyInt)) .WillOnce(Return(0)); 147 EXPECT_CALL(mock, access(kDummyConstChar, kDummyInt)) .WillOnce(Return(0));
143 EXPECT_EQ(0, access(kDummyConstChar, kDummyInt)); 148 EXPECT_EQ(0, access(kDummyConstChar, kDummyInt));
149
150 EXPECT_CALL(mock, access(kDummyConstChar, kDummyInt))
151 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1)));
152 EXPECT_EQ(-1, access(kDummyConstChar, kDummyInt));
153 EXPECT_EQ(kDummyErrno, errno);
154
144 } 155 }
145 156
146 TEST_F(KernelWrapTest, chdir) { 157 TEST_F(KernelWrapTest, chdir) {
147 EXPECT_CALL(mock, chdir(kDummyConstChar)).WillOnce(Return(-1));
148 EXPECT_EQ(-1, chdir(kDummyConstChar));
149
150 EXPECT_CALL(mock, chdir(kDummyConstChar)).WillOnce(Return(0)); 158 EXPECT_CALL(mock, chdir(kDummyConstChar)).WillOnce(Return(0));
151 EXPECT_EQ(0, chdir(kDummyConstChar)); 159 EXPECT_EQ(0, chdir(kDummyConstChar));
160
161 EXPECT_CALL(mock, chdir(kDummyConstChar))
162 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1)));
163 EXPECT_EQ(-1, chdir(kDummyConstChar));
164 ASSERT_EQ(kDummyErrno, errno);
152 } 165 }
153 166
154 TEST_F(KernelWrapTest, chmod) { 167 TEST_F(KernelWrapTest, chmod) {
155 EXPECT_CALL(mock, chmod(kDummyConstChar, kDummyMode)) 168 EXPECT_CALL(mock, chmod(kDummyConstChar, kDummyMode))
156 .WillOnce(Return(kDummyInt2)); 169 .WillOnce(Return(kDummyInt2));
157 EXPECT_EQ(kDummyInt2,chmod(kDummyConstChar, kDummyMode)); 170 EXPECT_EQ(kDummyInt2,chmod(kDummyConstChar, kDummyMode));
158 } 171 }
159 172
160 TEST_F(KernelWrapTest, chown) { 173 TEST_F(KernelWrapTest, chown) {
161 EXPECT_CALL(mock, chown(kDummyConstChar, kDummyUid, kDummyGid)) 174 EXPECT_CALL(mock, chown(kDummyConstChar, kDummyUid, kDummyGid))
162 .WillOnce(Return(kDummyInt)); 175 .WillOnce(Return(kDummyInt));
163 EXPECT_EQ(kDummyInt, chown(kDummyConstChar, kDummyUid, kDummyGid)); 176 EXPECT_EQ(kDummyInt, chown(kDummyConstChar, kDummyUid, kDummyGid));
164 } 177 }
165 178
166 TEST_F(KernelWrapTest, close) { 179 TEST_F(KernelWrapTest, close) {
167 // The way we wrap close does not support returning arbitrary values, so we 180 // The way we wrap close does not support returning arbitrary values, so we
168 // test 0 and -1. 181 // test 0 and -1.
169 EXPECT_CALL(mock, close(kDummyInt)) 182 EXPECT_CALL(mock, close(kDummyInt))
170 .WillOnce(Return(0)) 183 .WillOnce(Return(0));
171 .WillOnce(Return(-1));
172 184
173 EXPECT_EQ(0, close(kDummyInt)); 185 EXPECT_EQ(0, close(kDummyInt));
186
187 EXPECT_CALL(mock, close(kDummyInt))
188 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1)));
174 EXPECT_EQ(-1, close(kDummyInt)); 189 EXPECT_EQ(-1, close(kDummyInt));
190 ASSERT_EQ(kDummyErrno, errno);
175 } 191 }
176 192
177 TEST_F(KernelWrapTest, dup) { 193 TEST_F(KernelWrapTest, dup) {
178 EXPECT_CALL(mock, dup(kDummyInt)).WillOnce(Return(kDummyInt2)); 194 EXPECT_CALL(mock, dup(kDummyInt)).WillOnce(Return(kDummyInt2));
179 EXPECT_EQ(kDummyInt2, dup(kDummyInt)); 195 EXPECT_EQ(kDummyInt2, dup(kDummyInt));
180 } 196 }
181 197
182 TEST_F(KernelWrapTest, dup2) { 198 TEST_F(KernelWrapTest, dup2) {
183 // The way we wrap dup2 does not support returning aribtrary values, only -1 199 // The way we wrap dup2 does not support returning aribtrary values, only -1
184 // or the value of the new fd. 200 // or the value of the new fd.
185 EXPECT_CALL(mock, dup2(kDummyInt, kDummyInt2)) 201 EXPECT_CALL(mock, dup2(kDummyInt, kDummyInt2))
186 .WillOnce(Return(kDummyInt2)) 202 .WillOnce(Return(kDummyInt2))
187 .WillOnce(Return(-1)); 203 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1)));
204
188 EXPECT_EQ(kDummyInt2, dup2(kDummyInt, kDummyInt2)); 205 EXPECT_EQ(kDummyInt2, dup2(kDummyInt, kDummyInt2));
189 EXPECT_EQ(-1, dup2(kDummyInt, kDummyInt2)); 206 EXPECT_EQ(-1, dup2(kDummyInt, kDummyInt2));
207 ASSERT_EQ(kDummyErrno, errno);
190 } 208 }
191 209
192 TEST_F(KernelWrapTest, fchdir) { 210 TEST_F(KernelWrapTest, fchdir) {
193 EXPECT_CALL(mock, fchdir(kDummyInt)) 211 EXPECT_CALL(mock, fchdir(kDummyInt))
194 .WillOnce(Return(-1)); 212 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1)));
213
195 EXPECT_EQ(-1, fchdir(kDummyInt)); 214 EXPECT_EQ(-1, fchdir(kDummyInt));
215 ASSERT_EQ(kDummyErrno, errno);
196 } 216 }
197 217
198 TEST_F(KernelWrapTest, fchmod) { 218 TEST_F(KernelWrapTest, fchmod) {
199 EXPECT_CALL(mock, fchmod(kDummyInt, kDummyMode)) 219 EXPECT_CALL(mock, fchmod(kDummyInt, kDummyMode))
200 .WillOnce(Return(-1)); 220 .WillOnce(Return(0))
221 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1)));
222
223 EXPECT_EQ(0, fchmod(kDummyInt, kDummyMode));
201 EXPECT_EQ(-1, fchmod(kDummyInt, kDummyMode)); 224 EXPECT_EQ(-1, fchmod(kDummyInt, kDummyMode));
202 225 ASSERT_EQ(kDummyErrno, errno);
203 EXPECT_CALL(mock, fchmod(kDummyInt, kDummyMode)) .WillOnce(Return(0));
204 EXPECT_EQ(0, fchmod(kDummyInt, kDummyMode));
205 } 226 }
206 227
207 TEST_F(KernelWrapTest, fchown) { 228 TEST_F(KernelWrapTest, fchown) {
208 EXPECT_CALL(mock, fchown(kDummyInt, kDummyUid, kDummyGid)) 229 EXPECT_CALL(mock, fchown(kDummyInt, kDummyUid, kDummyGid))
209 .WillOnce(Return(kDummyInt)); 230 .WillOnce(Return(kDummyInt));
210 EXPECT_EQ(kDummyInt, fchown(kDummyInt, kDummyUid, kDummyGid)); 231 EXPECT_EQ(kDummyInt, fchown(kDummyInt, kDummyUid, kDummyGid));
211 } 232 }
212 233
213 TEST_F(KernelWrapTest, fcntl) { 234 TEST_F(KernelWrapTest, fcntl) {
214 char buffer[] = "fcntl"; 235 char buffer[] = "fcntl";
215 EXPECT_CALL(mock, fcntl(kDummyInt, kDummyInt2, _)) 236 EXPECT_CALL(mock, fcntl(kDummyInt, kDummyInt2, _))
216 .WillOnce(Return(kDummyInt3)); 237 .WillOnce(Return(kDummyInt3));
217 EXPECT_EQ(kDummyInt3, fcntl(kDummyInt, kDummyInt2, buffer)); 238 EXPECT_EQ(kDummyInt3, fcntl(kDummyInt, kDummyInt2, buffer));
218 } 239 }
219 240
220 TEST_F(KernelWrapTest, fdatasync) { 241 TEST_F(KernelWrapTest, fdatasync) {
221 EXPECT_CALL(mock, fdatasync(kDummyInt)).WillOnce(Return(-1)); 242 EXPECT_CALL(mock, fdatasync(kDummyInt)).WillOnce(Return(0))
243 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1)));
244
245 EXPECT_EQ(0, fdatasync(kDummyInt));
222 EXPECT_EQ(-1, fdatasync(kDummyInt)); 246 EXPECT_EQ(-1, fdatasync(kDummyInt));
223 247 ASSERT_EQ(kDummyErrno, errno);
224 EXPECT_CALL(mock, fdatasync(kDummyInt)).WillOnce(Return(0));
225 EXPECT_EQ(0, fdatasync(kDummyInt));
226 } 248 }
227 249
228 TEST_F(KernelWrapTest, fstat) { 250 TEST_F(KernelWrapTest, fstat) {
229 // The way we wrap fstat does not support returning aribtrary values, only 0 251 // The way we wrap fstat does not support returning aribtrary values, only 0
230 // or -1. 252 // or -1.
231 struct stat in_statbuf; 253 struct stat in_statbuf;
232 MakeDummyStatbuf(&in_statbuf); 254 MakeDummyStatbuf(&in_statbuf);
233 EXPECT_CALL(mock, fstat(kDummyInt, _)) 255 EXPECT_CALL(mock, fstat(kDummyInt, _))
234 .WillOnce(DoAll(SetStat(&in_statbuf), Return(0))) 256 .WillOnce(DoAll(SetStat(&in_statbuf), Return(0)))
235 .WillOnce(Return(-1)); 257 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1)));
236 struct stat out_statbuf; 258 struct stat out_statbuf;
259
237 EXPECT_EQ(0, fstat(kDummyInt, &out_statbuf)); 260 EXPECT_EQ(0, fstat(kDummyInt, &out_statbuf));
238 EXPECT_THAT(&in_statbuf, IsEqualToStatbuf(&out_statbuf)); 261 EXPECT_THAT(&in_statbuf, IsEqualToStatbuf(&out_statbuf));
262
239 EXPECT_EQ(-1, fstat(kDummyInt, &out_statbuf)); 263 EXPECT_EQ(-1, fstat(kDummyInt, &out_statbuf));
264 ASSERT_EQ(kDummyErrno, errno);
240 } 265 }
241 266
242 TEST_F(KernelWrapTest, ftruncate) { 267 TEST_F(KernelWrapTest, ftruncate) {
243 EXPECT_CALL(mock, ftruncate(kDummyInt, kDummyInt2)) 268 EXPECT_CALL(mock, ftruncate(kDummyInt, kDummyInt2))
244 .WillOnce(Return(kDummyInt3)); 269 .WillOnce(Return(kDummyInt3));
245 EXPECT_EQ(kDummyInt3, ftruncate(kDummyInt, kDummyInt2)); 270 EXPECT_EQ(kDummyInt3, ftruncate(kDummyInt, kDummyInt2));
246 } 271 }
247 272
248 TEST_F(KernelWrapTest, fsync) { 273 TEST_F(KernelWrapTest, fsync) {
249 EXPECT_CALL(mock, fsync(kDummyInt)).WillOnce(Return(-1)); 274 EXPECT_CALL(mock, fsync(kDummyInt))
275 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1)));
250 EXPECT_EQ(-1, fsync(kDummyInt)); 276 EXPECT_EQ(-1, fsync(kDummyInt));
277 ASSERT_EQ(kDummyErrno, errno);
251 } 278 }
252 279
253 TEST_F(KernelWrapTest, getcwd) { 280 TEST_F(KernelWrapTest, getcwd) {
254 char result[] = "getcwd_result"; 281 char result[] = "getcwd_result";
255 char buffer[] = "getcwd"; 282 char buffer[] = "getcwd";
256 EXPECT_CALL(mock, getcwd(buffer, kDummySizeT)).WillOnce(Return(result)); 283 EXPECT_CALL(mock, getcwd(buffer, kDummySizeT)).WillOnce(Return(result));
257 EXPECT_EQ(result, getcwd(buffer, kDummySizeT)); 284 EXPECT_EQ(result, getcwd(buffer, kDummySizeT));
258 } 285 }
259 286
260 TEST_F(KernelWrapTest, getdents) { 287 TEST_F(KernelWrapTest, getdents) {
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 TEST_F(KernelWrapTest, munmap) { 411 TEST_F(KernelWrapTest, munmap) {
385 // The way we wrap munmap, calls the "real" mmap as well as the intercepted 412 // The way we wrap munmap, calls the "real" mmap as well as the intercepted
386 // one. The result returned is from the "real" mmap. 413 // one. The result returned is from the "real" mmap.
387 int dummy1 = 123; 414 int dummy1 = 123;
388 void* kDummyVoidPtr = &dummy1; 415 void* kDummyVoidPtr = &dummy1;
389 size_t kDummySizeT = sizeof(kDummyVoidPtr); 416 size_t kDummySizeT = sizeof(kDummyVoidPtr);
390 EXPECT_CALL(mock, munmap(kDummyVoidPtr, kDummySizeT)); 417 EXPECT_CALL(mock, munmap(kDummyVoidPtr, kDummySizeT));
391 munmap(kDummyVoidPtr, kDummySizeT); 418 munmap(kDummyVoidPtr, kDummySizeT);
392 } 419 }
393 420
394
395 TEST_F(KernelWrapTest, open) { 421 TEST_F(KernelWrapTest, open) {
396 // We pass O_RDONLY because we do not want an error in flags translation 422 // We pass O_RDONLY because we do not want an error in flags translation
397 EXPECT_CALL(mock, open(kDummyConstChar, 0)) 423 EXPECT_CALL(mock, open(kDummyConstChar, 0))
424 .WillOnce(Return(kDummyInt2))
398 .WillOnce(Return(kDummyInt2)); 425 .WillOnce(Return(kDummyInt2));
426
399 EXPECT_EQ(kDummyInt2, open(kDummyConstChar, 0)); 427 EXPECT_EQ(kDummyInt2, open(kDummyConstChar, 0));
400
401 EXPECT_CALL(mock, open(kDummyConstChar, 0))
402 .WillOnce(Return(kDummyInt2));
403 EXPECT_EQ(kDummyInt2, open(kDummyConstChar, 0)); 428 EXPECT_EQ(kDummyInt2, open(kDummyConstChar, 0));
404 } 429 }
405 430
406 TEST_F(KernelWrapTest, pipe) { 431 TEST_F(KernelWrapTest, pipe) {
407 int fds[] = {1, 2}; 432 int fds[] = {1, 2};
408 EXPECT_CALL(mock, pipe(fds)).WillOnce(Return(kDummyInt)); 433 EXPECT_CALL(mock, pipe(fds)).WillOnce(Return(kDummyInt));
409 EXPECT_EQ(kDummyInt, pipe(fds)); 434 EXPECT_EQ(kDummyInt, pipe(fds));
410 } 435 }
411 436
412 TEST_F(KernelWrapTest, read) { 437 TEST_F(KernelWrapTest, read) {
413 int dummy_value; 438 int dummy_value;
414 void* dummy_void_ptr = &dummy_value; 439 void* dummy_void_ptr = &dummy_value;
415 EXPECT_CALL(mock, read(kDummyInt, dummy_void_ptr, kDummyInt2)) 440 EXPECT_CALL(mock, read(kDummyInt, dummy_void_ptr, kDummyInt2))
416 .WillOnce(Return(kDummyInt3)); 441 .WillOnce(Return(kDummyInt3));
417 EXPECT_EQ(kDummyInt3, read(kDummyInt, dummy_void_ptr, kDummyInt2)); 442 EXPECT_EQ(kDummyInt3, read(kDummyInt, dummy_void_ptr, kDummyInt2));
418 } 443 }
419 444
420 TEST_F(KernelWrapTest, readlink) { 445 TEST_F(KernelWrapTest, readlink) {
421 char buf[10]; 446 char buf[10];
422 447
423 EXPECT_CALL(mock, readlink(kDummyConstChar, buf, 10)) 448 EXPECT_CALL(mock, readlink(kDummyConstChar, buf, 10))
424 .WillOnce(Return(-1)); 449 .WillOnce(Return(kDummyInt))
450 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1)));
451
452 EXPECT_EQ(kDummyInt, readlink(kDummyConstChar, buf, 10));
425 EXPECT_EQ(-1, readlink(kDummyConstChar, buf, 10)); 453 EXPECT_EQ(-1, readlink(kDummyConstChar, buf, 10));
426 454 ASSERT_EQ(kDummyErrno, errno);
427 EXPECT_CALL(mock, readlink(kDummyConstChar, buf, 10))
428 .WillOnce(Return(kDummyInt));
429 EXPECT_EQ(kDummyInt, readlink(kDummyConstChar, buf, 10));
430 } 455 }
431 456
432 #ifdef __GLIBC__ 457 #ifdef __GLIBC__
433 // Under newlib there is no remove syscall. Instead it is implemented 458 // Under newlib there is no remove syscall. Instead it is implemented
434 // in terms of unlink()/rmdir(). 459 // in terms of unlink()/rmdir().
435 TEST_F(KernelWrapTest, remove) { 460 TEST_F(KernelWrapTest, remove) {
436 EXPECT_CALL(mock, remove(kDummyConstChar)).WillOnce(Return(-1)); 461 EXPECT_CALL(mock, remove(kDummyConstChar)).WillOnce(Return(-1));
437 EXPECT_EQ(-1, remove(kDummyConstChar)); 462 EXPECT_EQ(-1, remove(kDummyConstChar));
438 } 463 }
439 #endif 464 #endif
440 465
441 TEST_F(KernelWrapTest, rename) { 466 TEST_F(KernelWrapTest, rename) {
442 EXPECT_CALL(mock, rename(kDummyConstChar, kDummyConstChar2)) 467 EXPECT_CALL(mock, rename(kDummyConstChar, kDummyConstChar2))
443 .WillOnce(Return(-1)); 468 .WillOnce(Return(0))
469 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1)));
470
471 EXPECT_EQ(0, rename(kDummyConstChar, kDummyConstChar2));
444 EXPECT_EQ(-1, rename(kDummyConstChar, kDummyConstChar2)); 472 EXPECT_EQ(-1, rename(kDummyConstChar, kDummyConstChar2));
445 473 ASSERT_EQ(kDummyErrno, errno);
446 EXPECT_CALL(mock, rename(kDummyConstChar, kDummyConstChar2))
447 .WillOnce(Return(0));
448 EXPECT_EQ(0, rename(kDummyConstChar, kDummyConstChar2));
449 } 474 }
450 475
451 TEST_F(KernelWrapTest, rmdir) { 476 TEST_F(KernelWrapTest, rmdir) {
452 EXPECT_CALL(mock, rmdir(kDummyConstChar)).WillOnce(Return(kDummyInt)); 477 EXPECT_CALL(mock, rmdir(kDummyConstChar)).WillOnce(Return(kDummyInt));
453 EXPECT_EQ(kDummyInt, rmdir(kDummyConstChar)); 478 EXPECT_EQ(kDummyInt, rmdir(kDummyConstChar));
454 } 479 }
455 480
456 static void new_handler(int) {} 481 static void new_handler(int) {}
457 482
458 TEST_F(KernelWrapTest, sigaction) { 483 TEST_F(KernelWrapTest, sigaction) {
(...skipping 17 matching lines...) Expand all
476 EXPECT_EQ(NULL, signal(kDummyInt, new_handler)); 501 EXPECT_EQ(NULL, signal(kDummyInt, new_handler));
477 } 502 }
478 503
479 TEST_F(KernelWrapTest, stat) { 504 TEST_F(KernelWrapTest, stat) {
480 // The way we wrap stat does not support returning aribtrary values, only 0 505 // The way we wrap stat does not support returning aribtrary values, only 0
481 // or -1. 506 // or -1.
482 struct stat in_statbuf; 507 struct stat in_statbuf;
483 MakeDummyStatbuf(&in_statbuf); 508 MakeDummyStatbuf(&in_statbuf);
484 EXPECT_CALL(mock, stat(StrEq(kDummyConstChar), _)) 509 EXPECT_CALL(mock, stat(StrEq(kDummyConstChar), _))
485 .WillOnce(DoAll(SetStat(&in_statbuf), Return(0))) 510 .WillOnce(DoAll(SetStat(&in_statbuf), Return(0)))
486 .WillOnce(Return(-1)); 511 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1)));
487 struct stat out_statbuf; 512 struct stat out_statbuf;
513
488 EXPECT_EQ(0, stat(kDummyConstChar, &out_statbuf)); 514 EXPECT_EQ(0, stat(kDummyConstChar, &out_statbuf));
489 EXPECT_THAT(&in_statbuf, IsEqualToStatbuf(&out_statbuf)); 515 EXPECT_THAT(&in_statbuf, IsEqualToStatbuf(&out_statbuf));
516
490 EXPECT_EQ(-1, stat(kDummyConstChar, &out_statbuf)); 517 EXPECT_EQ(-1, stat(kDummyConstChar, &out_statbuf));
518 ASSERT_EQ(kDummyErrno, errno);
491 } 519 }
492 520
493 TEST_F(KernelWrapTest, symlink) { 521 TEST_F(KernelWrapTest, symlink) {
494 EXPECT_CALL(mock, symlink(kDummyConstChar, kDummyConstChar2)) 522 EXPECT_CALL(mock, symlink(kDummyConstChar, kDummyConstChar2))
495 .WillOnce(Return(kDummyInt)); 523 .WillOnce(Return(kDummyInt));
496 EXPECT_EQ(kDummyInt, symlink(kDummyConstChar, kDummyConstChar2)); 524 EXPECT_EQ(kDummyInt, symlink(kDummyConstChar, kDummyConstChar2));
497 } 525 }
498 526
499 #ifndef __BIONIC__ 527 #ifndef __BIONIC__
500 TEST_F(KernelWrapTest, tcflush) { 528 TEST_F(KernelWrapTest, tcflush) {
(...skipping 15 matching lines...) Expand all
516 EXPECT_EQ(kDummyInt3, tcsetattr(kDummyInt, kDummyInt2, &term)); 544 EXPECT_EQ(kDummyInt3, tcsetattr(kDummyInt, kDummyInt2, &term));
517 } 545 }
518 #endif 546 #endif
519 547
520 TEST_F(KernelWrapTest, umount) { 548 TEST_F(KernelWrapTest, umount) {
521 EXPECT_CALL(mock, umount(kDummyConstChar)).WillOnce(Return(kDummyInt)); 549 EXPECT_CALL(mock, umount(kDummyConstChar)).WillOnce(Return(kDummyInt));
522 EXPECT_EQ(kDummyInt, umount(kDummyConstChar)); 550 EXPECT_EQ(kDummyInt, umount(kDummyConstChar));
523 } 551 }
524 552
525 TEST_F(KernelWrapTest, truncate) { 553 TEST_F(KernelWrapTest, truncate) {
526 EXPECT_CALL(mock, truncate(kDummyConstChar, kDummyInt3)).WillOnce(Return(-1)); 554 EXPECT_CALL(mock, truncate(kDummyConstChar, kDummyInt3))
555 .WillOnce(Return(0))
556 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1)));
557
558 EXPECT_EQ(0, truncate(kDummyConstChar, kDummyInt3));
559
527 EXPECT_EQ(-1, truncate(kDummyConstChar, kDummyInt3)); 560 EXPECT_EQ(-1, truncate(kDummyConstChar, kDummyInt3));
528
529 EXPECT_CALL(mock, truncate(kDummyConstChar, kDummyInt3)).WillOnce(Return(0));
530 EXPECT_EQ(0, truncate(kDummyConstChar, kDummyInt3));
531 } 561 }
532 562
533 TEST_F(KernelWrapTest, lstat) { 563 TEST_F(KernelWrapTest, lstat) {
534 struct stat in_statbuf; 564 struct stat in_statbuf;
535 MakeDummyStatbuf(&in_statbuf); 565 MakeDummyStatbuf(&in_statbuf);
536 EXPECT_CALL(mock, lstat(StrEq(kDummyConstChar), _)) 566 EXPECT_CALL(mock, lstat(StrEq(kDummyConstChar), _))
537 .WillOnce(DoAll(SetStat(&in_statbuf), Return(0))) 567 .WillOnce(DoAll(SetStat(&in_statbuf), Return(0)))
538 .WillOnce(Return(-1)); 568 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1)));
539 struct stat out_statbuf; 569 struct stat out_statbuf;
570
540 EXPECT_EQ(0, lstat(kDummyConstChar, &out_statbuf)); 571 EXPECT_EQ(0, lstat(kDummyConstChar, &out_statbuf));
541 EXPECT_THAT(&in_statbuf, IsEqualToStatbuf(&out_statbuf)); 572 EXPECT_THAT(&in_statbuf, IsEqualToStatbuf(&out_statbuf));
573
542 EXPECT_EQ(-1, lstat(kDummyConstChar, &out_statbuf)); 574 EXPECT_EQ(-1, lstat(kDummyConstChar, &out_statbuf));
575 ASSERT_EQ(kDummyErrno, errno);
543 } 576 }
544 577
545 TEST_F(KernelWrapTest, unlink) { 578 TEST_F(KernelWrapTest, unlink) {
546 EXPECT_CALL(mock, unlink(kDummyConstChar)).WillOnce(Return(kDummyInt)); 579 EXPECT_CALL(mock, unlink(kDummyConstChar)).WillOnce(Return(kDummyInt));
547 EXPECT_EQ(kDummyInt, unlink(kDummyConstChar)); 580 EXPECT_EQ(kDummyInt, unlink(kDummyConstChar));
548 } 581 }
549 582
550 TEST_F(KernelWrapTest, utime) { 583 TEST_F(KernelWrapTest, utime) {
551 const struct utimbuf* times = NULL; 584 const struct utimbuf* times = NULL;
552 EXPECT_CALL(mock, utime(kDummyConstChar, times)).WillOnce(Return(kDummyInt)); 585 EXPECT_CALL(mock, utime(kDummyConstChar, times)).WillOnce(Return(kDummyInt));
553 EXPECT_EQ(kDummyInt, utime(kDummyConstChar, times)); 586 EXPECT_EQ(kDummyInt, utime(kDummyConstChar, times));
554 } 587 }
555 588
556 TEST_F(KernelWrapTest, utimes) { 589 TEST_F(KernelWrapTest, utimes) {
557 struct timeval* times = NULL; 590 struct timeval* times = NULL;
558 EXPECT_CALL(mock, utimes(kDummyConstChar, times)).WillOnce(Return(-1)); 591 EXPECT_CALL(mock, utimes(kDummyConstChar, times))
592 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1)));
559 EXPECT_EQ(-1, utimes(kDummyConstChar, times)); 593 EXPECT_EQ(-1, utimes(kDummyConstChar, times));
594 ASSERT_EQ(kDummyErrno, errno);
560 } 595 }
561 596
562 TEST_F(KernelWrapTest, write) { 597 TEST_F(KernelWrapTest, write) {
563 EXPECT_CALL(mock, write(kDummyInt, kDummyVoidPtr, kDummyInt2)) 598 EXPECT_CALL(mock, write(kDummyInt, kDummyVoidPtr, kDummyInt2))
564 .WillOnce(Return(kDummyInt3)); 599 .WillOnce(Return(kDummyInt3));
565 EXPECT_EQ(kDummyInt3, write(kDummyInt, kDummyVoidPtr, kDummyInt2)); 600 EXPECT_EQ(kDummyInt3, write(kDummyInt, kDummyVoidPtr, kDummyInt2));
566 } 601 }
567 602
568 #if defined(PROVIDES_SOCKET_API) and !defined(__BIONIC__) 603 #if defined(PROVIDES_SOCKET_API) and !defined(__BIONIC__)
569 TEST_F(KernelWrapTest, poll) { 604 TEST_F(KernelWrapTest, poll) {
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 int dummy_val; 774 int dummy_val;
740 EXPECT_CALL(mock, socketpair(kDummyInt, kDummyInt2, kDummyInt3, &dummy_val)) 775 EXPECT_CALL(mock, socketpair(kDummyInt, kDummyInt2, kDummyInt3, &dummy_val))
741 .WillOnce(Return(kDummyInt4)); 776 .WillOnce(Return(kDummyInt4));
742 EXPECT_EQ(kDummyInt4, 777 EXPECT_EQ(kDummyInt4,
743 socketpair(kDummyInt, kDummyInt2, kDummyInt3, &dummy_val)); 778 socketpair(kDummyInt, kDummyInt2, kDummyInt3, &dummy_val));
744 } 779 }
745 780
746 #endif // PROVIDES_SOCKET_API 781 #endif // PROVIDES_SOCKET_API
747 782
748 #endif // __linux__ 783 #endif // __linux__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698