kernel_wrap_test.cc revision 4e180b6a0b4720a9b8e9e959a882386f690f08ff
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
3// found in the LICENSE file.
4
5#include <string>
6#include <vector>
7
8#include "gtest/gtest.h"
9#include "kernel_proxy_mock.h"
10#include "nacl_io/kernel_intercept.h"
11#include "nacl_io/kernel_wrap.h"
12#include "nacl_io/osmman.h"
13#include "nacl_io/ossocket.h"
14#include "nacl_io/ostermios.h"
15
16using namespace nacl_io;
17
18using ::testing::_;
19using ::testing::DoAll;
20using ::testing::Return;
21using ::testing::StrEq;
22
23namespace {
24
25#define COMPARE_FIELD(f)                                                     \
26  if (arg->f != statbuf->f) {                                                \
27    *result_listener << "mismatch of field \"" #f                            \
28                        "\". "                                               \
29                        "expected: " << statbuf->f << " actual: " << arg->f; \
30    return false;                                                            \
31  }
32
33MATCHER_P(IsEqualToStatbuf, statbuf, "") {
34  COMPARE_FIELD(st_dev);
35  COMPARE_FIELD(st_ino);
36  COMPARE_FIELD(st_mode);
37  COMPARE_FIELD(st_nlink);
38  COMPARE_FIELD(st_uid);
39  COMPARE_FIELD(st_gid);
40  COMPARE_FIELD(st_rdev);
41  COMPARE_FIELD(st_size);
42  COMPARE_FIELD(st_atime);
43  COMPARE_FIELD(st_mtime);
44  COMPARE_FIELD(st_ctime);
45  return true;
46}
47
48#undef COMPARE_FIELD
49
50ACTION_P(SetStat, statbuf) {
51  memset(arg1, 0, sizeof(struct stat));
52  arg1->st_dev = statbuf->st_dev;
53  arg1->st_ino = statbuf->st_ino;
54  arg1->st_mode = statbuf->st_mode;
55  arg1->st_nlink = statbuf->st_nlink;
56  arg1->st_uid = statbuf->st_uid;
57  arg1->st_gid = statbuf->st_gid;
58  arg1->st_rdev = statbuf->st_rdev;
59  arg1->st_size = statbuf->st_size;
60  arg1->st_atime = statbuf->st_atime;
61  arg1->st_mtime = statbuf->st_mtime;
62  arg1->st_ctime = statbuf->st_ctime;
63}
64
65void MakeDummyStatbuf(struct stat* statbuf) {
66  memset(&statbuf[0], 0, sizeof(struct stat));
67  statbuf->st_dev = 1;
68  statbuf->st_ino = 2;
69  statbuf->st_mode = 3;
70  statbuf->st_nlink = 4;
71  statbuf->st_uid = 5;
72  statbuf->st_gid = 6;
73  statbuf->st_rdev = 7;
74  statbuf->st_size = 8;
75  statbuf->st_atime = 9;
76  statbuf->st_mtime = 10;
77  statbuf->st_ctime = 11;
78}
79
80const int kDummyInt = 0xdedbeef;
81const int kDummyInt2 = 0xcabba6e;
82const int kDummyInt3 = 0xf00ba4;
83const int kDummyInt4 = 0xabacdba;
84const size_t kDummySizeT = 0x60067e;
85const char* kDummyConstChar = "foobar";
86const char* kDummyConstChar2 = "g00gl3";
87const char* kDummyConstChar3 = "fr00gl3";
88const void* kDummyVoidPtr = "blahblah";
89const uid_t kDummyUid = 1001;
90const gid_t kDummyGid = 1002;
91
92class KernelWrapTest : public ::testing::Test {
93 public:
94  KernelWrapTest() {}
95
96  virtual void SetUp() {
97    // Initializing the KernelProxy opens stdin/stdout/stderr.
98    EXPECT_CALL(mock, open(_, _))
99        .WillOnce(Return(0))
100        .WillOnce(Return(1))
101        .WillOnce(Return(2));
102    // And will call mount / and /dev.
103    EXPECT_CALL(mock, mount(_, _, _, _, _))
104        .WillOnce(Return(0))
105        .WillOnce(Return(0));
106
107    ki_init(&mock);
108  }
109
110  virtual void TearDown() { ki_uninit(); }
111
112  KernelProxyMock mock;
113};
114
115}  // namespace
116
117TEST_F(KernelWrapTest, access) {
118  EXPECT_CALL(mock, access(kDummyConstChar, kDummyInt))
119      .WillOnce(Return(kDummyInt2));
120  EXPECT_EQ(kDummyInt2, access(kDummyConstChar, kDummyInt));
121}
122
123TEST_F(KernelWrapTest, chdir) {
124  EXPECT_CALL(mock, chdir(kDummyConstChar)).WillOnce(Return(kDummyInt));
125  EXPECT_EQ(kDummyInt, chdir(kDummyConstChar));
126}
127
128TEST_F(KernelWrapTest, chmod) {
129  EXPECT_CALL(mock, chmod(kDummyConstChar, kDummyInt))
130      .WillOnce(Return(kDummyInt2));
131  EXPECT_EQ(kDummyInt2, chmod(kDummyConstChar, kDummyInt));
132}
133
134TEST_F(KernelWrapTest, chown) {
135  EXPECT_CALL(mock, chown(kDummyConstChar, kDummyUid, kDummyGid))
136      .WillOnce(Return(kDummyInt));
137  EXPECT_EQ(kDummyInt, chown(kDummyConstChar, kDummyUid, kDummyGid));
138}
139
140TEST_F(KernelWrapTest, close) {
141  // The way we wrap close does not support returning arbitrary values, so we
142  // test 0 and -1.
143  EXPECT_CALL(mock, close(kDummyInt))
144      .WillOnce(Return(0))
145      .WillOnce(Return(-1));
146
147  EXPECT_EQ(0, close(kDummyInt));
148  EXPECT_EQ(-1, close(kDummyInt));
149}
150
151TEST_F(KernelWrapTest, dup) {
152  EXPECT_CALL(mock, dup(kDummyInt)).WillOnce(Return(kDummyInt2));
153  EXPECT_EQ(kDummyInt2, dup(kDummyInt));
154}
155
156TEST_F(KernelWrapTest, dup2) {
157  // The way we wrap dup2 does not support returning aribtrary values, only -1
158  // or the value of the new fd.
159  EXPECT_CALL(mock, dup2(kDummyInt, kDummyInt2))
160      .WillOnce(Return(kDummyInt2))
161      .WillOnce(Return(-1));
162  EXPECT_EQ(kDummyInt2, dup2(kDummyInt, kDummyInt2));
163  EXPECT_EQ(-1, dup2(kDummyInt, kDummyInt2));
164}
165
166TEST_F(KernelWrapTest, fchmod) {
167  EXPECT_CALL(mock, fchmod(kDummyInt, kDummyInt2))
168      .WillOnce(Return(kDummyInt3));
169  EXPECT_EQ(kDummyInt3, fchmod(kDummyInt, kDummyInt2));
170}
171
172TEST_F(KernelWrapTest, fchown) {
173  EXPECT_CALL(mock, fchown(kDummyInt, kDummyUid, kDummyGid))
174      .WillOnce(Return(kDummyInt));
175  EXPECT_EQ(kDummyInt, fchown(kDummyInt, kDummyUid, kDummyGid));
176}
177
178TEST_F(KernelWrapTest, fcntl) {
179  char buffer[] = "fcntl";
180  EXPECT_CALL(mock, fcntl(kDummyInt, kDummyInt2, _))
181      .WillOnce(Return(kDummyInt3));
182  EXPECT_EQ(kDummyInt3, fcntl(kDummyInt, kDummyInt2, buffer));
183}
184
185TEST_F(KernelWrapTest, fstat) {
186  // The way we wrap fstat does not support returning aribtrary values, only 0
187  // or -1.
188  struct stat in_statbuf;
189  MakeDummyStatbuf(&in_statbuf);
190  EXPECT_CALL(mock, fstat(kDummyInt, _))
191      .WillOnce(DoAll(SetStat(&in_statbuf), Return(0)))
192      .WillOnce(Return(-1));
193  struct stat out_statbuf;
194  EXPECT_EQ(0, fstat(kDummyInt, &out_statbuf));
195  EXPECT_THAT(&in_statbuf, IsEqualToStatbuf(&out_statbuf));
196  EXPECT_EQ(-1, fstat(kDummyInt, &out_statbuf));
197}
198
199TEST_F(KernelWrapTest, ftruncate) {
200  EXPECT_CALL(mock, ftruncate(kDummyInt, kDummyInt2))
201      .WillOnce(Return(kDummyInt3));
202  EXPECT_EQ(kDummyInt3, ftruncate(kDummyInt, kDummyInt2));
203}
204
205TEST_F(KernelWrapTest, fsync) {
206  EXPECT_CALL(mock, fsync(kDummyInt)).WillOnce(Return(kDummyInt2));
207  EXPECT_EQ(kDummyInt2, fsync(kDummyInt));
208}
209
210TEST_F(KernelWrapTest, getcwd) {
211  char result[] = "getcwd_result";
212  char buffer[] = "getcwd";
213  EXPECT_CALL(mock, getcwd(buffer, kDummySizeT)).WillOnce(Return(result));
214  EXPECT_EQ(result, getcwd(buffer, kDummySizeT));
215}
216
217TEST_F(KernelWrapTest, getdents) {
218#ifndef __GLIBC__
219  // TODO(sbc): Find a way to test the getdents wrapper under glibc.
220  // It looks like the only way to exercise it is to call readdir(2).
221  // There is an internal glibc function __getdents that will call the
222  // IRT but that cannot be accessed from here as glibc does not export it.
223  int dummy_val;
224  void* void_ptr = &dummy_val;
225  EXPECT_CALL(mock, getdents(kDummyInt, void_ptr, kDummyInt2))
226      .WillOnce(Return(kDummyInt2));
227  EXPECT_EQ(kDummyInt2, getdents(kDummyInt, void_ptr, kDummyInt2));
228#endif
229}
230
231// gcc gives error: getwd is deprecated.
232#if defined(__GNUC__)
233#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
234#endif
235TEST_F(KernelWrapTest, getwd) {
236  char result[] = "getwd_result";
237  char buffer[] = "getwd";
238  EXPECT_CALL(mock, getwd(buffer)).WillOnce(Return(result));
239  EXPECT_EQ(result, getwd(buffer));
240}
241#if defined(__GNUC__)
242#pragma GCC diagnostic warning "-Wdeprecated-declarations"
243#endif
244
245TEST_F(KernelWrapTest, ioctl) {
246  char buffer[] = "ioctl";
247  EXPECT_CALL(mock, ioctl(kDummyInt, kDummyInt2, _))
248      .WillOnce(Return(kDummyInt3));
249  EXPECT_EQ(kDummyInt3, ioctl(kDummyInt, kDummyInt2, buffer));
250}
251
252TEST_F(KernelWrapTest, isatty) {
253  EXPECT_CALL(mock, isatty(kDummyInt)).WillOnce(Return(kDummyInt2));
254  EXPECT_EQ(kDummyInt2, isatty(kDummyInt));
255}
256
257TEST_F(KernelWrapTest, kill) {
258  EXPECT_CALL(mock, kill(kDummyInt, kDummyInt2)).WillOnce(Return(kDummyInt3));
259  EXPECT_EQ(kDummyInt3, kill(kDummyInt, kDummyInt2));
260}
261
262TEST_F(KernelWrapTest, lchown) {
263  EXPECT_CALL(mock, lchown(kDummyConstChar, kDummyUid, kDummyGid))
264      .WillOnce(Return(kDummyInt));
265  EXPECT_EQ(kDummyInt, lchown(kDummyConstChar, kDummyUid, kDummyGid));
266}
267
268TEST_F(KernelWrapTest, link) {
269  EXPECT_CALL(mock, link(kDummyConstChar, kDummyConstChar2))
270      .WillOnce(Return(kDummyInt));
271  EXPECT_EQ(kDummyInt, link(kDummyConstChar, kDummyConstChar2));
272}
273
274TEST_F(KernelWrapTest, lseek) {
275  EXPECT_CALL(mock, lseek(kDummyInt, kDummyInt2, kDummyInt3))
276      .WillOnce(Return(kDummyInt4));
277  EXPECT_EQ(kDummyInt4, lseek(kDummyInt, kDummyInt2, kDummyInt3));
278}
279
280TEST_F(KernelWrapTest, mkdir) {
281#if defined(WIN32)
282  EXPECT_CALL(mock, mkdir(kDummyConstChar, 0777)).WillOnce(Return(kDummyInt2));
283  EXPECT_EQ(kDummyInt2, mkdir(kDummyConstChar));
284#else
285  EXPECT_CALL(mock, mkdir(kDummyConstChar, kDummyInt))
286      .WillOnce(Return(kDummyInt2));
287  EXPECT_EQ(kDummyInt2, mkdir(kDummyConstChar, kDummyInt));
288#endif
289}
290
291TEST_F(KernelWrapTest, mmap) {
292  // We only wrap mmap if |flags| has the MAP_ANONYMOUS bit unset.
293  int flags = kDummyInt2 & ~MAP_ANONYMOUS;
294
295  const size_t kDummySizeT2 = 0xbadf00d;
296  int dummy1 = 123;
297  int dummy2 = 456;
298  void* kDummyVoidPtr1 = &dummy1;
299  void* kDummyVoidPtr2 = &dummy2;
300  EXPECT_CALL(mock,
301              mmap(kDummyVoidPtr1,
302                   kDummySizeT,
303                   kDummyInt,
304                   flags,
305                   kDummyInt3,
306                   kDummySizeT2)).WillOnce(Return(kDummyVoidPtr2));
307  EXPECT_EQ(kDummyVoidPtr2,
308            mmap(kDummyVoidPtr1,
309                 kDummySizeT,
310                 kDummyInt,
311                 flags,
312                 kDummyInt3,
313                 kDummySizeT2));
314}
315
316TEST_F(KernelWrapTest, mount) {
317  EXPECT_CALL(mock,
318              mount(kDummyConstChar,
319                    kDummyConstChar2,
320                    kDummyConstChar3,
321                    kDummyInt,
322                    kDummyVoidPtr)).WillOnce(Return(kDummyInt2));
323  EXPECT_EQ(kDummyInt2,
324            mount(kDummyConstChar,
325                  kDummyConstChar2,
326                  kDummyConstChar3,
327                  kDummyInt,
328                  kDummyVoidPtr));
329}
330
331TEST_F(KernelWrapTest, munmap) {
332  // The way we wrap munmap, calls the "real" mmap as well as the intercepted
333  // one. The result returned is from the "real" mmap.
334  int dummy1 = 123;
335  void* kDummyVoidPtr = &dummy1;
336  size_t kDummySizeT = sizeof(kDummyVoidPtr);
337  EXPECT_CALL(mock, munmap(kDummyVoidPtr, kDummySizeT));
338  munmap(kDummyVoidPtr, kDummySizeT);
339}
340
341
342TEST_F(KernelWrapTest, open) {
343  EXPECT_CALL(mock, open(kDummyConstChar, kDummyInt))
344      .WillOnce(Return(kDummyInt2));
345  EXPECT_EQ(kDummyInt2, open(kDummyConstChar, kDummyInt));
346}
347
348TEST_F(KernelWrapTest, pipe) {
349  int fds[] = {1, 2};
350  EXPECT_CALL(mock, pipe(fds)).WillOnce(Return(kDummyInt));
351  EXPECT_EQ(kDummyInt, pipe(fds));
352}
353
354TEST_F(KernelWrapTest, read) {
355  int dummy_value;
356  void* dummy_void_ptr = &dummy_value;
357  EXPECT_CALL(mock, read(kDummyInt, dummy_void_ptr, kDummyInt2))
358      .WillOnce(Return(kDummyInt3));
359  EXPECT_EQ(kDummyInt3, read(kDummyInt, dummy_void_ptr, kDummyInt2));
360}
361
362#ifdef __GLIBC__
363TEST_F(KernelWrapTest, remove) {
364  EXPECT_CALL(mock, remove(kDummyConstChar)).WillOnce(Return(kDummyInt));
365  EXPECT_EQ(kDummyInt, remove(kDummyConstChar));
366}
367#endif
368
369TEST_F(KernelWrapTest, rmdir) {
370  EXPECT_CALL(mock, rmdir(kDummyConstChar)).WillOnce(Return(kDummyInt));
371  EXPECT_EQ(kDummyInt, rmdir(kDummyConstChar));
372}
373
374static void new_handler(int) {}
375static void old_handler(int) {}
376
377TEST_F(KernelWrapTest, sigset) {
378  EXPECT_CALL(mock, sigset(kDummyInt, new_handler))
379      .WillOnce(Return(old_handler));
380  EXPECT_EQ(&old_handler, sigset(kDummyInt, new_handler));
381}
382
383TEST_F(KernelWrapTest, signal) {
384  // KernelIntercept forwards calls to signal to KernelProxy::sigset.
385  EXPECT_CALL(mock, sigset(kDummyInt, new_handler))
386      .WillOnce(Return(old_handler));
387  EXPECT_EQ(&old_handler, signal(kDummyInt, new_handler));
388}
389
390TEST_F(KernelWrapTest, stat) {
391  // The way we wrap stat does not support returning aribtrary values, only 0
392  // or -1.
393  struct stat in_statbuf;
394  MakeDummyStatbuf(&in_statbuf);
395  EXPECT_CALL(mock, stat(StrEq(kDummyConstChar), _))
396      .WillOnce(DoAll(SetStat(&in_statbuf), Return(0)))
397      .WillOnce(Return(-1));
398  struct stat out_statbuf;
399  EXPECT_EQ(0, stat(kDummyConstChar, &out_statbuf));
400  EXPECT_THAT(&in_statbuf, IsEqualToStatbuf(&out_statbuf));
401  EXPECT_EQ(-1, stat(kDummyConstChar, &out_statbuf));
402}
403
404TEST_F(KernelWrapTest, symlink) {
405  EXPECT_CALL(mock, symlink(kDummyConstChar, kDummyConstChar2))
406      .WillOnce(Return(kDummyInt));
407  EXPECT_EQ(kDummyInt, symlink(kDummyConstChar, kDummyConstChar2));
408}
409
410TEST_F(KernelWrapTest, tcflush) {
411  EXPECT_CALL(mock, tcflush(kDummyInt, kDummyInt2))
412      .WillOnce(Return(kDummyInt3));
413  EXPECT_EQ(kDummyInt3, tcflush(kDummyInt, kDummyInt2));
414}
415
416TEST_F(KernelWrapTest, tcgetattr) {
417  struct termios term;
418  EXPECT_CALL(mock, tcgetattr(kDummyInt, &term)).WillOnce(Return(kDummyInt2));
419  EXPECT_EQ(kDummyInt2, tcgetattr(kDummyInt, &term));
420}
421
422TEST_F(KernelWrapTest, tcsetattr) {
423  struct termios term;
424  EXPECT_CALL(mock, tcsetattr(kDummyInt, kDummyInt2, &term))
425      .WillOnce(Return(kDummyInt3));
426  EXPECT_EQ(kDummyInt3, tcsetattr(kDummyInt, kDummyInt2, &term));
427}
428
429TEST_F(KernelWrapTest, umount) {
430  EXPECT_CALL(mock, umount(kDummyConstChar)).WillOnce(Return(kDummyInt));
431  EXPECT_EQ(kDummyInt, umount(kDummyConstChar));
432}
433
434TEST_F(KernelWrapTest, unlink) {
435  EXPECT_CALL(mock, unlink(kDummyConstChar)).WillOnce(Return(kDummyInt));
436  EXPECT_EQ(kDummyInt, unlink(kDummyConstChar));
437}
438
439TEST_F(KernelWrapTest, utime) {
440  const struct utimbuf* times = NULL;
441  EXPECT_CALL(mock, utime(kDummyConstChar, times)).WillOnce(Return(kDummyInt));
442  EXPECT_EQ(kDummyInt, utime(kDummyConstChar, times));
443}
444
445TEST_F(KernelWrapTest, write) {
446  EXPECT_CALL(mock, write(kDummyInt, kDummyVoidPtr, kDummyInt2))
447      .WillOnce(Return(kDummyInt3));
448  EXPECT_EQ(kDummyInt3, write(kDummyInt, kDummyVoidPtr, kDummyInt2));
449}
450
451#ifdef PROVIDES_SOCKET_API
452TEST_F(KernelWrapTest, poll) {
453  struct pollfd fds;
454  EXPECT_CALL(mock, poll(&fds, kDummyInt, kDummyInt2))
455      .WillOnce(Return(kDummyInt3));
456  EXPECT_EQ(kDummyInt3, poll(&fds, kDummyInt, kDummyInt2));
457}
458
459TEST_F(KernelWrapTest, select) {
460  fd_set readfds;
461  fd_set writefds;
462  fd_set exceptfds;
463  EXPECT_CALL(mock, select(kDummyInt, &readfds, &writefds, &exceptfds, NULL))
464      .WillOnce(Return(kDummyInt2));
465  EXPECT_EQ(kDummyInt2,
466            select(kDummyInt, &readfds, &writefds, &exceptfds, NULL));
467}
468
469// Socket Functions
470TEST_F(KernelWrapTest, accept) {
471  struct sockaddr addr;
472  socklen_t len;
473  EXPECT_CALL(mock, accept(kDummyInt, &addr, &len))
474      .WillOnce(Return(kDummyInt2));
475  EXPECT_EQ(kDummyInt2, accept(kDummyInt, &addr, &len));
476}
477
478TEST_F(KernelWrapTest, bind) {
479  struct sockaddr addr;
480  EXPECT_CALL(mock, bind(kDummyInt, &addr, kDummyInt2))
481      .WillOnce(Return(kDummyInt2));
482  EXPECT_EQ(kDummyInt2, bind(kDummyInt, &addr, kDummyInt2));
483}
484
485TEST_F(KernelWrapTest, connect) {
486  struct sockaddr addr;
487  EXPECT_CALL(mock, connect(kDummyInt, &addr, kDummyInt2))
488      .WillOnce(Return(kDummyInt2));
489  EXPECT_EQ(kDummyInt2, connect(kDummyInt, &addr, kDummyInt2));
490}
491
492TEST_F(KernelWrapTest, gethostbyname) {
493  struct hostent result;
494  EXPECT_CALL(mock, gethostbyname(kDummyConstChar)).WillOnce(Return(&result));
495  EXPECT_EQ(&result, gethostbyname(kDummyConstChar));
496}
497
498TEST_F(KernelWrapTest, getpeername) {
499  struct sockaddr addr;
500  socklen_t len;
501  EXPECT_CALL(mock, getpeername(kDummyInt, &addr, &len))
502      .WillOnce(Return(kDummyInt2));
503  EXPECT_EQ(kDummyInt2, getpeername(kDummyInt, &addr, &len));
504}
505
506TEST_F(KernelWrapTest, getsockname) {
507  struct sockaddr addr;
508  socklen_t len;
509  EXPECT_CALL(mock, getsockname(kDummyInt, &addr, &len))
510      .WillOnce(Return(kDummyInt2));
511  EXPECT_EQ(kDummyInt2, getsockname(kDummyInt, &addr, &len));
512}
513
514TEST_F(KernelWrapTest, getsockopt) {
515  int dummy_val;
516  void* dummy_void_ptr = &dummy_val;
517  socklen_t len;
518  EXPECT_CALL(
519      mock, getsockopt(kDummyInt, kDummyInt2, kDummyInt3, dummy_void_ptr, &len))
520      .WillOnce(Return(kDummyInt4));
521  EXPECT_EQ(
522      kDummyInt4,
523      getsockopt(kDummyInt, kDummyInt2, kDummyInt3, dummy_void_ptr, &len));
524}
525
526TEST_F(KernelWrapTest, listen) {
527  EXPECT_CALL(mock, listen(kDummyInt, kDummyInt2)).WillOnce(Return(kDummyInt3));
528  EXPECT_EQ(kDummyInt3, listen(kDummyInt, kDummyInt2));
529}
530
531TEST_F(KernelWrapTest, recv) {
532  int dummy_val;
533  void* dummy_void_ptr = &dummy_val;
534  EXPECT_CALL(mock, recv(kDummyInt, dummy_void_ptr, kDummySizeT, kDummyInt2))
535      .WillOnce(Return(kDummyInt3));
536  EXPECT_EQ(kDummyInt3,
537            recv(kDummyInt, dummy_void_ptr, kDummySizeT, kDummyInt2));
538}
539
540TEST_F(KernelWrapTest, recvfrom) {
541  int dummy_val;
542  void* dummy_void_ptr = &dummy_val;
543  struct sockaddr addr;
544  socklen_t len;
545  EXPECT_CALL(
546      mock,
547      recvfrom(kDummyInt, dummy_void_ptr, kDummyInt2, kDummyInt3, &addr, &len))
548      .WillOnce(Return(kDummyInt4));
549  EXPECT_EQ(
550      kDummyInt4,
551      recvfrom(kDummyInt, dummy_void_ptr, kDummyInt2, kDummyInt3, &addr, &len));
552}
553
554TEST_F(KernelWrapTest, recvmsg) {
555  struct msghdr msg;
556  EXPECT_CALL(mock, recvmsg(kDummyInt, &msg, kDummyInt2))
557      .WillOnce(Return(kDummyInt3));
558  EXPECT_EQ(kDummyInt3, recvmsg(kDummyInt, &msg, kDummyInt2));
559}
560
561TEST_F(KernelWrapTest, send) {
562  EXPECT_CALL(mock, send(kDummyInt, kDummyVoidPtr, kDummySizeT, kDummyInt2))
563      .WillOnce(Return(kDummyInt3));
564  EXPECT_EQ(kDummyInt3,
565            send(kDummyInt, kDummyVoidPtr, kDummySizeT, kDummyInt2));
566}
567
568TEST_F(KernelWrapTest, sendto) {
569  const socklen_t kDummySockLen = 0x50cc5;
570  struct sockaddr addr;
571  EXPECT_CALL(mock,
572              sendto(kDummyInt,
573                     kDummyVoidPtr,
574                     kDummyInt2,
575                     kDummyInt3,
576                     &addr,
577                     kDummySockLen)).WillOnce(Return(kDummyInt4));
578  EXPECT_EQ(kDummyInt4,
579            sendto(kDummyInt,
580                   kDummyVoidPtr,
581                   kDummyInt2,
582                   kDummyInt3,
583                   &addr,
584                   kDummySockLen));
585}
586
587TEST_F(KernelWrapTest, sendmsg) {
588  struct msghdr msg;
589  EXPECT_CALL(mock, sendmsg(kDummyInt, &msg, kDummyInt2))
590      .WillOnce(Return(kDummyInt3));
591  EXPECT_EQ(kDummyInt3, sendmsg(kDummyInt, &msg, kDummyInt2));
592}
593
594TEST_F(KernelWrapTest, setsockopt) {
595  const socklen_t kDummySockLen = 0x50cc5;
596  EXPECT_CALL(
597      mock,
598      setsockopt(
599          kDummyInt, kDummyInt2, kDummyInt3, kDummyVoidPtr, kDummySockLen))
600      .WillOnce(Return(kDummyInt4));
601  EXPECT_EQ(
602      kDummyInt4,
603      setsockopt(
604          kDummyInt, kDummyInt2, kDummyInt3, kDummyVoidPtr, kDummySockLen));
605}
606
607TEST_F(KernelWrapTest, shutdown) {
608  EXPECT_CALL(mock, shutdown(kDummyInt, kDummyInt2))
609      .WillOnce(Return(kDummyInt3));
610  EXPECT_EQ(kDummyInt3, shutdown(kDummyInt, kDummyInt2));
611}
612
613TEST_F(KernelWrapTest, socket) {
614  EXPECT_CALL(mock, socket(kDummyInt, kDummyInt2, kDummyInt3))
615      .WillOnce(Return(kDummyInt4));
616  EXPECT_EQ(kDummyInt4, socket(kDummyInt, kDummyInt2, kDummyInt3));
617}
618
619TEST_F(KernelWrapTest, socketpair) {
620  int dummy_val;
621  EXPECT_CALL(mock, socketpair(kDummyInt, kDummyInt2, kDummyInt3, &dummy_val))
622      .WillOnce(Return(kDummyInt4));
623  EXPECT_EQ(kDummyInt4,
624            socketpair(kDummyInt, kDummyInt2, kDummyInt3, &dummy_val));
625}
626
627#endif  // PROVIDES_SOCKET_API
628