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

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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 COMPARE_FIELD(st_rdev); 57 COMPARE_FIELD(st_rdev);
58 COMPARE_FIELD(st_size); 58 COMPARE_FIELD(st_size);
59 COMPARE_FIELD(st_atime); 59 COMPARE_FIELD(st_atime);
60 COMPARE_FIELD(st_mtime); 60 COMPARE_FIELD(st_mtime);
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) {
68 errno = value;
69 }
70
67 ACTION_P(SetStat, statbuf) { 71 ACTION_P(SetStat, statbuf) {
68 memset(arg1, 0, sizeof(struct stat)); 72 memset(arg1, 0, sizeof(struct stat));
69 arg1->st_dev = statbuf->st_dev; 73 arg1->st_dev = statbuf->st_dev;
70 arg1->st_ino = statbuf->st_ino; 74 arg1->st_ino = statbuf->st_ino;
71 arg1->st_mode = statbuf->st_mode; 75 arg1->st_mode = statbuf->st_mode;
72 arg1->st_nlink = statbuf->st_nlink; 76 arg1->st_nlink = statbuf->st_nlink;
73 arg1->st_uid = statbuf->st_uid; 77 arg1->st_uid = statbuf->st_uid;
74 arg1->st_gid = statbuf->st_gid; 78 arg1->st_gid = statbuf->st_gid;
75 arg1->st_rdev = statbuf->st_rdev; 79 arg1->st_rdev = statbuf->st_rdev;
76 arg1->st_size = statbuf->st_size; 80 arg1->st_size = statbuf->st_size;
(...skipping 11 matching lines...) Expand all
88 statbuf->st_uid = 5; 92 statbuf->st_uid = 5;
89 statbuf->st_gid = 6; 93 statbuf->st_gid = 6;
90 statbuf->st_rdev = 7; 94 statbuf->st_rdev = 7;
91 statbuf->st_size = 8; 95 statbuf->st_size = 8;
92 statbuf->st_atime = 9; 96 statbuf->st_atime = 9;
93 statbuf->st_mtime = 10; 97 statbuf->st_mtime = 10;
94 statbuf->st_ctime = 11; 98 statbuf->st_ctime = 11;
95 } 99 }
96 100
97 const mode_t kDummyMode = 0xbeef; 101 const mode_t kDummyMode = 0xbeef;
102 const int kDummyErrno = 0xfeeb;
98 const int kDummyInt = 0xdedbeef; 103 const int kDummyInt = 0xdedbeef;
99 const int kDummyInt2 = 0xcabba6e; 104 const int kDummyInt2 = 0xcabba6e;
100 const int kDummyInt3 = 0xf00ba4; 105 const int kDummyInt3 = 0xf00ba4;
101 const int kDummyInt4 = 0xabacdba; 106 const int kDummyInt4 = 0xabacdba;
102 const size_t kDummySizeT = 0x60067e; 107 const size_t kDummySizeT = 0x60067e;
103 const char* kDummyConstChar = "foobar"; 108 const char* kDummyConstChar = "foobar";
104 const char* kDummyConstChar2 = "g00gl3"; 109 const char* kDummyConstChar2 = "g00gl3";
105 const char* kDummyConstChar3 = "fr00gl3"; 110 const char* kDummyConstChar3 = "fr00gl3";
106 const void* kDummyVoidPtr = "blahblah"; 111 const void* kDummyVoidPtr = "blahblah";
107 const uid_t kDummyUid = 1001; 112 const uid_t kDummyUid = 1001;
108 const gid_t kDummyGid = 1002; 113 const gid_t kDummyGid = 1002;
109 114
110 class KernelWrapTest : public ::testing::Test { 115 class KernelWrapTest : public ::testing::Test {
111 public: 116 public:
112 KernelWrapTest() {} 117 KernelWrapTest() {}
113 118
114 virtual void SetUp() { 119 virtual void SetUp() {
120 // Initialize the global errno value to a consistent value rather than
121 // relying on its value from previous test runs.
122 errno = 0;
123
115 // Initializing the KernelProxy opens stdin/stdout/stderr. 124 // Initializing the KernelProxy opens stdin/stdout/stderr.
116 EXPECT_CALL(mock, open(_, _)) 125 EXPECT_CALL(mock, open(_, _))
117 .WillOnce(Return(0)) 126 .WillOnce(Return(0))
118 .WillOnce(Return(1)) 127 .WillOnce(Return(1))
119 .WillOnce(Return(2)); 128 .WillOnce(Return(2));
120 // And will call mount / and /dev. 129 // And will call mount / and /dev.
121 EXPECT_CALL(mock, mount(_, _, _, _, _)) 130 EXPECT_CALL(mock, mount(_, _, _, _, _))
122 .WillOnce(Return(0)) 131 .WillOnce(Return(0))
123 .WillOnce(Return(0)); 132 .WillOnce(Return(0));
124 133
(...skipping 25 matching lines...) Expand all
150 errno = rtn; 159 errno = rtn;
151 return -1; 160 return -1;
152 } 161 }
153 return nwrote; 162 return nwrote;
154 } 163 }
155 }; 164 };
156 165
157 } // namespace 166 } // namespace
158 167
159 TEST_F(KernelWrapTest, access) { 168 TEST_F(KernelWrapTest, access) {
160 EXPECT_CALL(mock, access(kDummyConstChar, kDummyInt)) .WillOnce(Return(-1));
161 EXPECT_EQ(-1, access(kDummyConstChar, kDummyInt));
162
163 EXPECT_CALL(mock, access(kDummyConstChar, kDummyInt)) .WillOnce(Return(0)); 169 EXPECT_CALL(mock, access(kDummyConstChar, kDummyInt)) .WillOnce(Return(0));
164 EXPECT_EQ(0, access(kDummyConstChar, kDummyInt)); 170 EXPECT_EQ(0, access(kDummyConstChar, kDummyInt));
171
172 EXPECT_CALL(mock, access(kDummyConstChar, kDummyInt))
173 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1)));
174 EXPECT_EQ(-1, access(kDummyConstChar, kDummyInt));
175 EXPECT_EQ(kDummyErrno, errno);
176
165 } 177 }
166 178
167 TEST_F(KernelWrapTest, chdir) { 179 TEST_F(KernelWrapTest, chdir) {
168 EXPECT_CALL(mock, chdir(kDummyConstChar)).WillOnce(Return(-1));
169 EXPECT_EQ(-1, chdir(kDummyConstChar));
170
171 EXPECT_CALL(mock, chdir(kDummyConstChar)).WillOnce(Return(0)); 180 EXPECT_CALL(mock, chdir(kDummyConstChar)).WillOnce(Return(0));
172 EXPECT_EQ(0, chdir(kDummyConstChar)); 181 EXPECT_EQ(0, chdir(kDummyConstChar));
182
183 EXPECT_CALL(mock, chdir(kDummyConstChar))
184 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1)));
185 EXPECT_EQ(-1, chdir(kDummyConstChar));
186 ASSERT_EQ(kDummyErrno, errno);
173 } 187 }
174 188
175 TEST_F(KernelWrapTest, chmod) { 189 TEST_F(KernelWrapTest, chmod) {
176 EXPECT_CALL(mock, chmod(kDummyConstChar, kDummyMode)) 190 EXPECT_CALL(mock, chmod(kDummyConstChar, kDummyMode))
177 .WillOnce(Return(kDummyInt2)); 191 .WillOnce(Return(kDummyInt2));
178 EXPECT_EQ(kDummyInt2,chmod(kDummyConstChar, kDummyMode)); 192 EXPECT_EQ(kDummyInt2,chmod(kDummyConstChar, kDummyMode));
179 } 193 }
180 194
181 TEST_F(KernelWrapTest, chown) { 195 TEST_F(KernelWrapTest, chown) {
182 EXPECT_CALL(mock, chown(kDummyConstChar, kDummyUid, kDummyGid)) 196 EXPECT_CALL(mock, chown(kDummyConstChar, kDummyUid, kDummyGid))
183 .WillOnce(Return(kDummyInt)); 197 .WillOnce(Return(kDummyInt));
184 EXPECT_EQ(kDummyInt, chown(kDummyConstChar, kDummyUid, kDummyGid)); 198 EXPECT_EQ(kDummyInt, chown(kDummyConstChar, kDummyUid, kDummyGid));
185 } 199 }
186 200
187 TEST_F(KernelWrapTest, close) { 201 TEST_F(KernelWrapTest, close) {
188 // The way we wrap close does not support returning arbitrary values, so we 202 // The way we wrap close does not support returning arbitrary values, so we
189 // test 0 and -1. 203 // test 0 and -1.
190 EXPECT_CALL(mock, close(kDummyInt)) 204 EXPECT_CALL(mock, close(kDummyInt))
191 .WillOnce(Return(0)) 205 .WillOnce(Return(0));
192 .WillOnce(Return(-1));
193 206
194 EXPECT_EQ(0, close(kDummyInt)); 207 EXPECT_EQ(0, close(kDummyInt));
208
209 EXPECT_CALL(mock, close(kDummyInt))
210 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1)));
195 EXPECT_EQ(-1, close(kDummyInt)); 211 EXPECT_EQ(-1, close(kDummyInt));
212 ASSERT_EQ(kDummyErrno, errno);
196 } 213 }
197 214
198 TEST_F(KernelWrapTest, dup) { 215 TEST_F(KernelWrapTest, dup) {
199 EXPECT_CALL(mock, dup(kDummyInt)).WillOnce(Return(kDummyInt2)); 216 EXPECT_CALL(mock, dup(kDummyInt)).WillOnce(Return(kDummyInt2));
200 EXPECT_EQ(kDummyInt2, dup(kDummyInt)); 217 EXPECT_EQ(kDummyInt2, dup(kDummyInt));
201 } 218 }
202 219
203 TEST_F(KernelWrapTest, dup2) { 220 TEST_F(KernelWrapTest, dup2) {
204 // The way we wrap dup2 does not support returning aribtrary values, only -1 221 // The way we wrap dup2 does not support returning aribtrary values, only -1
205 // or the value of the new fd. 222 // or the value of the new fd.
206 EXPECT_CALL(mock, dup2(kDummyInt, kDummyInt2)) 223 EXPECT_CALL(mock, dup2(kDummyInt, kDummyInt2))
207 .WillOnce(Return(kDummyInt2)) 224 .WillOnce(Return(kDummyInt2))
208 .WillOnce(Return(-1)); 225 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1)));
226
209 EXPECT_EQ(kDummyInt2, dup2(kDummyInt, kDummyInt2)); 227 EXPECT_EQ(kDummyInt2, dup2(kDummyInt, kDummyInt2));
210 EXPECT_EQ(-1, dup2(kDummyInt, kDummyInt2)); 228 EXPECT_EQ(-1, dup2(kDummyInt, kDummyInt2));
229 ASSERT_EQ(kDummyErrno, errno);
211 } 230 }
212 231
213 TEST_F(KernelWrapTest, fchdir) { 232 TEST_F(KernelWrapTest, fchdir) {
214 EXPECT_CALL(mock, fchdir(kDummyInt)) 233 EXPECT_CALL(mock, fchdir(kDummyInt))
215 .WillOnce(Return(-1)); 234 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1)));
235
216 EXPECT_EQ(-1, fchdir(kDummyInt)); 236 EXPECT_EQ(-1, fchdir(kDummyInt));
237 ASSERT_EQ(kDummyErrno, errno);
217 } 238 }
218 239
219 TEST_F(KernelWrapTest, fchmod) { 240 TEST_F(KernelWrapTest, fchmod) {
220 EXPECT_CALL(mock, fchmod(kDummyInt, kDummyMode)) 241 EXPECT_CALL(mock, fchmod(kDummyInt, kDummyMode))
221 .WillOnce(Return(-1)); 242 .WillOnce(Return(0))
243 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1)));
244
245 EXPECT_EQ(0, fchmod(kDummyInt, kDummyMode));
222 EXPECT_EQ(-1, fchmod(kDummyInt, kDummyMode)); 246 EXPECT_EQ(-1, fchmod(kDummyInt, kDummyMode));
223 247 ASSERT_EQ(kDummyErrno, errno);
224 EXPECT_CALL(mock, fchmod(kDummyInt, kDummyMode)) .WillOnce(Return(0));
225 EXPECT_EQ(0, fchmod(kDummyInt, kDummyMode));
226 } 248 }
227 249
228 TEST_F(KernelWrapTest, fchown) { 250 TEST_F(KernelWrapTest, fchown) {
229 EXPECT_CALL(mock, fchown(kDummyInt, kDummyUid, kDummyGid)) 251 EXPECT_CALL(mock, fchown(kDummyInt, kDummyUid, kDummyGid))
230 .WillOnce(Return(kDummyInt)); 252 .WillOnce(Return(kDummyInt));
231 EXPECT_EQ(kDummyInt, fchown(kDummyInt, kDummyUid, kDummyGid)); 253 EXPECT_EQ(kDummyInt, fchown(kDummyInt, kDummyUid, kDummyGid));
232 } 254 }
233 255
234 TEST_F(KernelWrapTest, fcntl) { 256 TEST_F(KernelWrapTest, fcntl) {
235 char buffer[] = "fcntl"; 257 char buffer[] = "fcntl";
236 EXPECT_CALL(mock, fcntl(kDummyInt, kDummyInt2, _)) 258 EXPECT_CALL(mock, fcntl(kDummyInt, kDummyInt2, _))
237 .WillOnce(Return(kDummyInt3)); 259 .WillOnce(Return(kDummyInt3));
238 EXPECT_EQ(kDummyInt3, fcntl(kDummyInt, kDummyInt2, buffer)); 260 EXPECT_EQ(kDummyInt3, fcntl(kDummyInt, kDummyInt2, buffer));
239 } 261 }
240 262
241 TEST_F(KernelWrapTest, fdatasync) { 263 TEST_F(KernelWrapTest, fdatasync) {
242 EXPECT_CALL(mock, fdatasync(kDummyInt)).WillOnce(Return(-1)); 264 EXPECT_CALL(mock, fdatasync(kDummyInt)).WillOnce(Return(0))
265 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1)));
266
267 EXPECT_EQ(0, fdatasync(kDummyInt));
243 EXPECT_EQ(-1, fdatasync(kDummyInt)); 268 EXPECT_EQ(-1, fdatasync(kDummyInt));
244 269 ASSERT_EQ(kDummyErrno, errno);
245 EXPECT_CALL(mock, fdatasync(kDummyInt)).WillOnce(Return(0));
246 EXPECT_EQ(0, fdatasync(kDummyInt));
247 } 270 }
248 271
249 TEST_F(KernelWrapTest, fstat) { 272 TEST_F(KernelWrapTest, fstat) {
250 // The way we wrap fstat does not support returning aribtrary values, only 0 273 // The way we wrap fstat does not support returning aribtrary values, only 0
251 // or -1. 274 // or -1.
252 struct stat in_statbuf; 275 struct stat in_statbuf;
253 MakeDummyStatbuf(&in_statbuf); 276 MakeDummyStatbuf(&in_statbuf);
254 EXPECT_CALL(mock, fstat(kDummyInt, _)) 277 EXPECT_CALL(mock, fstat(kDummyInt, _))
255 .WillOnce(DoAll(SetStat(&in_statbuf), Return(0))) 278 .WillOnce(DoAll(SetStat(&in_statbuf), Return(0)))
256 .WillOnce(Return(-1)); 279 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1)));
257 struct stat out_statbuf; 280 struct stat out_statbuf;
281
258 EXPECT_EQ(0, fstat(kDummyInt, &out_statbuf)); 282 EXPECT_EQ(0, fstat(kDummyInt, &out_statbuf));
259 EXPECT_THAT(&in_statbuf, IsEqualToStatbuf(&out_statbuf)); 283 EXPECT_THAT(&in_statbuf, IsEqualToStatbuf(&out_statbuf));
284
260 EXPECT_EQ(-1, fstat(kDummyInt, &out_statbuf)); 285 EXPECT_EQ(-1, fstat(kDummyInt, &out_statbuf));
286 ASSERT_EQ(kDummyErrno, errno);
261 } 287 }
262 288
263 TEST_F(KernelWrapTest, ftruncate) { 289 TEST_F(KernelWrapTest, ftruncate) {
264 EXPECT_CALL(mock, ftruncate(kDummyInt, kDummyInt2)) 290 EXPECT_CALL(mock, ftruncate(kDummyInt, kDummyInt2))
265 .WillOnce(Return(kDummyInt3)); 291 .WillOnce(Return(kDummyInt3));
266 EXPECT_EQ(kDummyInt3, ftruncate(kDummyInt, kDummyInt2)); 292 EXPECT_EQ(kDummyInt3, ftruncate(kDummyInt, kDummyInt2));
267 } 293 }
268 294
269 TEST_F(KernelWrapTest, fsync) { 295 TEST_F(KernelWrapTest, fsync) {
270 EXPECT_CALL(mock, fsync(kDummyInt)).WillOnce(Return(-1)); 296 EXPECT_CALL(mock, fsync(kDummyInt))
297 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1)));
271 EXPECT_EQ(-1, fsync(kDummyInt)); 298 EXPECT_EQ(-1, fsync(kDummyInt));
299 ASSERT_EQ(kDummyErrno, errno);
272 } 300 }
273 301
274 TEST_F(KernelWrapTest, getcwd) { 302 TEST_F(KernelWrapTest, getcwd) {
275 char result[] = "getcwd_result"; 303 char result[] = "getcwd_result";
276 char buffer[] = "getcwd"; 304 char buffer[] = "getcwd";
277 EXPECT_CALL(mock, getcwd(buffer, kDummySizeT)).WillOnce(Return(result)); 305 EXPECT_CALL(mock, getcwd(buffer, kDummySizeT)).WillOnce(Return(result));
278 EXPECT_EQ(result, getcwd(buffer, kDummySizeT)); 306 EXPECT_EQ(result, getcwd(buffer, kDummySizeT));
279 } 307 }
280 308
281 TEST_F(KernelWrapTest, getdents) { 309 TEST_F(KernelWrapTest, getdents) {
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 TEST_F(KernelWrapTest, munmap) { 433 TEST_F(KernelWrapTest, munmap) {
406 // The way we wrap munmap, calls the "real" mmap as well as the intercepted 434 // The way we wrap munmap, calls the "real" mmap as well as the intercepted
407 // one. The result returned is from the "real" mmap. 435 // one. The result returned is from the "real" mmap.
408 int dummy1 = 123; 436 int dummy1 = 123;
409 void* kDummyVoidPtr = &dummy1; 437 void* kDummyVoidPtr = &dummy1;
410 size_t kDummySizeT = sizeof(kDummyVoidPtr); 438 size_t kDummySizeT = sizeof(kDummyVoidPtr);
411 EXPECT_CALL(mock, munmap(kDummyVoidPtr, kDummySizeT)); 439 EXPECT_CALL(mock, munmap(kDummyVoidPtr, kDummySizeT));
412 munmap(kDummyVoidPtr, kDummySizeT); 440 munmap(kDummyVoidPtr, kDummySizeT);
413 } 441 }
414 442
415
416 TEST_F(KernelWrapTest, open) { 443 TEST_F(KernelWrapTest, open) {
417 // We pass O_RDONLY because we do not want an error in flags translation 444 // We pass O_RDONLY because we do not want an error in flags translation
418 EXPECT_CALL(mock, open(kDummyConstChar, 0)) 445 EXPECT_CALL(mock, open(kDummyConstChar, 0))
446 .WillOnce(Return(kDummyInt2))
419 .WillOnce(Return(kDummyInt2)); 447 .WillOnce(Return(kDummyInt2));
448
420 EXPECT_EQ(kDummyInt2, open(kDummyConstChar, 0)); 449 EXPECT_EQ(kDummyInt2, open(kDummyConstChar, 0));
421
422 EXPECT_CALL(mock, open(kDummyConstChar, 0))
423 .WillOnce(Return(kDummyInt2));
424 EXPECT_EQ(kDummyInt2, open(kDummyConstChar, 0)); 450 EXPECT_EQ(kDummyInt2, open(kDummyConstChar, 0));
425 } 451 }
426 452
427 TEST_F(KernelWrapTest, pipe) { 453 TEST_F(KernelWrapTest, pipe) {
428 int fds[] = {1, 2}; 454 int fds[] = {1, 2};
429 EXPECT_CALL(mock, pipe(fds)).WillOnce(Return(kDummyInt)); 455 EXPECT_CALL(mock, pipe(fds)).WillOnce(Return(kDummyInt));
430 EXPECT_EQ(kDummyInt, pipe(fds)); 456 EXPECT_EQ(kDummyInt, pipe(fds));
431 } 457 }
432 458
433 TEST_F(KernelWrapTest, read) { 459 TEST_F(KernelWrapTest, read) {
434 int dummy_value; 460 int dummy_value;
435 void* dummy_void_ptr = &dummy_value; 461 void* dummy_void_ptr = &dummy_value;
436 EXPECT_CALL(mock, read(kDummyInt, dummy_void_ptr, kDummyInt2)) 462 EXPECT_CALL(mock, read(kDummyInt, dummy_void_ptr, kDummyInt2))
437 .WillOnce(Return(kDummyInt3)); 463 .WillOnce(Return(kDummyInt3));
438 EXPECT_EQ(kDummyInt3, read(kDummyInt, dummy_void_ptr, kDummyInt2)); 464 EXPECT_EQ(kDummyInt3, read(kDummyInt, dummy_void_ptr, kDummyInt2));
439 } 465 }
440 466
441 TEST_F(KernelWrapTest, readlink) { 467 TEST_F(KernelWrapTest, readlink) {
442 char buf[10]; 468 char buf[10];
443 469
444 EXPECT_CALL(mock, readlink(kDummyConstChar, buf, 10)) 470 EXPECT_CALL(mock, readlink(kDummyConstChar, buf, 10))
445 .WillOnce(Return(-1)); 471 .WillOnce(Return(kDummyInt))
472 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1)));
473
474 EXPECT_EQ(kDummyInt, readlink(kDummyConstChar, buf, 10));
446 EXPECT_EQ(-1, readlink(kDummyConstChar, buf, 10)); 475 EXPECT_EQ(-1, readlink(kDummyConstChar, buf, 10));
447 476 ASSERT_EQ(kDummyErrno, errno);
448 EXPECT_CALL(mock, readlink(kDummyConstChar, buf, 10))
449 .WillOnce(Return(kDummyInt));
450 EXPECT_EQ(kDummyInt, readlink(kDummyConstChar, buf, 10));
451 } 477 }
452 478
453 #ifdef __GLIBC__ 479 #ifdef __GLIBC__
454 // Under newlib there is no remove syscall. Instead it is implemented 480 // Under newlib there is no remove syscall. Instead it is implemented
455 // in terms of unlink()/rmdir(). 481 // in terms of unlink()/rmdir().
456 TEST_F(KernelWrapTest, remove) { 482 TEST_F(KernelWrapTest, remove) {
457 EXPECT_CALL(mock, remove(kDummyConstChar)).WillOnce(Return(-1)); 483 EXPECT_CALL(mock, remove(kDummyConstChar)).WillOnce(Return(-1));
458 EXPECT_EQ(-1, remove(kDummyConstChar)); 484 EXPECT_EQ(-1, remove(kDummyConstChar));
459 } 485 }
460 #endif 486 #endif
461 487
462 TEST_F(KernelWrapTest, rename) { 488 TEST_F(KernelWrapTest, rename) {
463 EXPECT_CALL(mock, rename(kDummyConstChar, kDummyConstChar2)) 489 EXPECT_CALL(mock, rename(kDummyConstChar, kDummyConstChar2))
464 .WillOnce(Return(-1)); 490 .WillOnce(Return(0))
491 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1)));
492
493 EXPECT_EQ(0, rename(kDummyConstChar, kDummyConstChar2));
465 EXPECT_EQ(-1, rename(kDummyConstChar, kDummyConstChar2)); 494 EXPECT_EQ(-1, rename(kDummyConstChar, kDummyConstChar2));
466 495 ASSERT_EQ(kDummyErrno, errno);
467 EXPECT_CALL(mock, rename(kDummyConstChar, kDummyConstChar2))
468 .WillOnce(Return(0));
469 EXPECT_EQ(0, rename(kDummyConstChar, kDummyConstChar2));
470 } 496 }
471 497
472 TEST_F(KernelWrapTest, rmdir) { 498 TEST_F(KernelWrapTest, rmdir) {
473 EXPECT_CALL(mock, rmdir(kDummyConstChar)).WillOnce(Return(kDummyInt)); 499 EXPECT_CALL(mock, rmdir(kDummyConstChar)).WillOnce(Return(kDummyInt));
474 EXPECT_EQ(kDummyInt, rmdir(kDummyConstChar)); 500 EXPECT_EQ(kDummyInt, rmdir(kDummyConstChar));
475 } 501 }
476 502
477 static void new_handler(int) {} 503 static void new_handler(int) {}
478 504
479 TEST_F(KernelWrapTest, sigaction) { 505 TEST_F(KernelWrapTest, sigaction) {
(...skipping 17 matching lines...) Expand all
497 EXPECT_EQ(NULL, signal(kDummyInt, new_handler)); 523 EXPECT_EQ(NULL, signal(kDummyInt, new_handler));
498 } 524 }
499 525
500 TEST_F(KernelWrapTest, stat) { 526 TEST_F(KernelWrapTest, stat) {
501 // The way we wrap stat does not support returning aribtrary values, only 0 527 // The way we wrap stat does not support returning aribtrary values, only 0
502 // or -1. 528 // or -1.
503 struct stat in_statbuf; 529 struct stat in_statbuf;
504 MakeDummyStatbuf(&in_statbuf); 530 MakeDummyStatbuf(&in_statbuf);
505 EXPECT_CALL(mock, stat(StrEq(kDummyConstChar), _)) 531 EXPECT_CALL(mock, stat(StrEq(kDummyConstChar), _))
506 .WillOnce(DoAll(SetStat(&in_statbuf), Return(0))) 532 .WillOnce(DoAll(SetStat(&in_statbuf), Return(0)))
507 .WillOnce(Return(-1)); 533 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1)));
508 struct stat out_statbuf; 534 struct stat out_statbuf;
535
509 EXPECT_EQ(0, stat(kDummyConstChar, &out_statbuf)); 536 EXPECT_EQ(0, stat(kDummyConstChar, &out_statbuf));
510 EXPECT_THAT(&in_statbuf, IsEqualToStatbuf(&out_statbuf)); 537 EXPECT_THAT(&in_statbuf, IsEqualToStatbuf(&out_statbuf));
538
511 EXPECT_EQ(-1, stat(kDummyConstChar, &out_statbuf)); 539 EXPECT_EQ(-1, stat(kDummyConstChar, &out_statbuf));
540 ASSERT_EQ(kDummyErrno, errno);
512 } 541 }
513 542
514 TEST_F(KernelWrapTest, symlink) { 543 TEST_F(KernelWrapTest, symlink) {
515 EXPECT_CALL(mock, symlink(kDummyConstChar, kDummyConstChar2)) 544 EXPECT_CALL(mock, symlink(kDummyConstChar, kDummyConstChar2))
516 .WillOnce(Return(kDummyInt)); 545 .WillOnce(Return(kDummyInt));
517 EXPECT_EQ(kDummyInt, symlink(kDummyConstChar, kDummyConstChar2)); 546 EXPECT_EQ(kDummyInt, symlink(kDummyConstChar, kDummyConstChar2));
518 } 547 }
519 548
520 #ifndef __BIONIC__ 549 #ifndef __BIONIC__
521 TEST_F(KernelWrapTest, tcflush) { 550 TEST_F(KernelWrapTest, tcflush) {
(...skipping 15 matching lines...) Expand all
537 EXPECT_EQ(kDummyInt3, tcsetattr(kDummyInt, kDummyInt2, &term)); 566 EXPECT_EQ(kDummyInt3, tcsetattr(kDummyInt, kDummyInt2, &term));
538 } 567 }
539 #endif 568 #endif
540 569
541 TEST_F(KernelWrapTest, umount) { 570 TEST_F(KernelWrapTest, umount) {
542 EXPECT_CALL(mock, umount(kDummyConstChar)).WillOnce(Return(kDummyInt)); 571 EXPECT_CALL(mock, umount(kDummyConstChar)).WillOnce(Return(kDummyInt));
543 EXPECT_EQ(kDummyInt, umount(kDummyConstChar)); 572 EXPECT_EQ(kDummyInt, umount(kDummyConstChar));
544 } 573 }
545 574
546 TEST_F(KernelWrapTest, truncate) { 575 TEST_F(KernelWrapTest, truncate) {
547 EXPECT_CALL(mock, truncate(kDummyConstChar, kDummyInt3)).WillOnce(Return(-1)); 576 EXPECT_CALL(mock, truncate(kDummyConstChar, kDummyInt3))
577 .WillOnce(Return(0))
578 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1)));
579
580 EXPECT_EQ(0, truncate(kDummyConstChar, kDummyInt3));
581
548 EXPECT_EQ(-1, truncate(kDummyConstChar, kDummyInt3)); 582 EXPECT_EQ(-1, truncate(kDummyConstChar, kDummyInt3));
549
550 EXPECT_CALL(mock, truncate(kDummyConstChar, kDummyInt3)).WillOnce(Return(0));
551 EXPECT_EQ(0, truncate(kDummyConstChar, kDummyInt3));
552 } 583 }
553 584
554 TEST_F(KernelWrapTest, lstat) { 585 TEST_F(KernelWrapTest, lstat) {
555 struct stat in_statbuf; 586 struct stat in_statbuf;
556 MakeDummyStatbuf(&in_statbuf); 587 MakeDummyStatbuf(&in_statbuf);
557 EXPECT_CALL(mock, lstat(StrEq(kDummyConstChar), _)) 588 EXPECT_CALL(mock, lstat(StrEq(kDummyConstChar), _))
558 .WillOnce(DoAll(SetStat(&in_statbuf), Return(0))) 589 .WillOnce(DoAll(SetStat(&in_statbuf), Return(0)))
559 .WillOnce(Return(-1)); 590 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1)));
560 struct stat out_statbuf; 591 struct stat out_statbuf;
592
561 EXPECT_EQ(0, lstat(kDummyConstChar, &out_statbuf)); 593 EXPECT_EQ(0, lstat(kDummyConstChar, &out_statbuf));
562 EXPECT_THAT(&in_statbuf, IsEqualToStatbuf(&out_statbuf)); 594 EXPECT_THAT(&in_statbuf, IsEqualToStatbuf(&out_statbuf));
595
563 EXPECT_EQ(-1, lstat(kDummyConstChar, &out_statbuf)); 596 EXPECT_EQ(-1, lstat(kDummyConstChar, &out_statbuf));
597 ASSERT_EQ(kDummyErrno, errno);
564 } 598 }
565 599
566 TEST_F(KernelWrapTest, unlink) { 600 TEST_F(KernelWrapTest, unlink) {
567 EXPECT_CALL(mock, unlink(kDummyConstChar)).WillOnce(Return(kDummyInt)); 601 EXPECT_CALL(mock, unlink(kDummyConstChar)).WillOnce(Return(kDummyInt));
568 EXPECT_EQ(kDummyInt, unlink(kDummyConstChar)); 602 EXPECT_EQ(kDummyInt, unlink(kDummyConstChar));
569 } 603 }
570 604
571 TEST_F(KernelWrapTest, utime) { 605 TEST_F(KernelWrapTest, utime) {
572 const struct utimbuf* times = NULL; 606 const struct utimbuf* times = NULL;
573 EXPECT_CALL(mock, utime(kDummyConstChar, times)).WillOnce(Return(kDummyInt)); 607 EXPECT_CALL(mock, utime(kDummyConstChar, times)).WillOnce(Return(kDummyInt));
574 EXPECT_EQ(kDummyInt, utime(kDummyConstChar, times)); 608 EXPECT_EQ(kDummyInt, utime(kDummyConstChar, times));
575 } 609 }
576 610
577 TEST_F(KernelWrapTest, utimes) { 611 TEST_F(KernelWrapTest, utimes) {
578 struct timeval* times = NULL; 612 struct timeval* times = NULL;
579 EXPECT_CALL(mock, utimes(kDummyConstChar, times)).WillOnce(Return(-1)); 613 EXPECT_CALL(mock, utimes(kDummyConstChar, times))
614 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1)));
580 EXPECT_EQ(-1, utimes(kDummyConstChar, times)); 615 EXPECT_EQ(-1, utimes(kDummyConstChar, times));
616 ASSERT_EQ(kDummyErrno, errno);
581 } 617 }
582 618
583 TEST_F(KernelWrapTest, write) { 619 TEST_F(KernelWrapTest, write) {
584 EXPECT_CALL(mock, write(kDummyInt, kDummyVoidPtr, kDummyInt2)) 620 EXPECT_CALL(mock, write(kDummyInt, kDummyVoidPtr, kDummyInt2))
585 .WillOnce(Return(kDummyInt3)); 621 .WillOnce(Return(kDummyInt3));
586 EXPECT_EQ(kDummyInt3, write(kDummyInt, kDummyVoidPtr, kDummyInt2)); 622 EXPECT_EQ(kDummyInt3, write(kDummyInt, kDummyVoidPtr, kDummyInt2));
587 } 623 }
588 624
589 #if defined(PROVIDES_SOCKET_API) and !defined(__BIONIC__) 625 #if defined(PROVIDES_SOCKET_API) and !defined(__BIONIC__)
590 TEST_F(KernelWrapTest, poll) { 626 TEST_F(KernelWrapTest, poll) {
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 .WillOnce(Return(-1)); 839 .WillOnce(Return(-1));
804 EXPECT_EQ(0, 840 EXPECT_EQ(0,
805 socketpair(kDummyInt, kDummyInt2, kDummyInt3, &dummy_val)); 841 socketpair(kDummyInt, kDummyInt2, kDummyInt3, &dummy_val));
806 EXPECT_EQ(-1, 842 EXPECT_EQ(-1,
807 socketpair(kDummyInt, kDummyInt2, kDummyInt3, &dummy_val)); 843 socketpair(kDummyInt, kDummyInt2, kDummyInt3, &dummy_val));
808 } 844 }
809 845
810 #endif // PROVIDES_SOCKET_API 846 #endif // PROVIDES_SOCKET_API
811 847
812 #endif // __linux__ 848 #endif // __linux__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698