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

Side by Side Diff: native_client_sdk/src/libraries/nacl_mounts_test/kernel_wrap_test.cc

Issue 11066105: [NaCl SDK] nacl_mounts: wrap functions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: win fix Created 8 years, 2 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
(Empty)
1 /* Copyright (c) 2012 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
6 #include <string>
7 #include <vector>
8 #include "gtest/gtest.h"
9 #include "nacl_mounts/kernel_proxy.h"
10 #include "nacl_mounts/kernel_intercept.h"
11 #include "nacl_mounts/kernel_wrap.h"
12 #include "kernel_proxy_mock.h"
13
14 using ::testing::StrEq;
15 using ::testing::_;
16
17 namespace {
18
19 #define COMPARE_FIELD(f) \
20 if (arg->f != statbuf->f) { \
21 *result_listener << "mismatch of field \""#f"\". " \
22 "expected: " << statbuf->f << \
23 " actual: " << arg->f; \
24 return false; \
25 }
26
27 MATCHER_P(IsEqualToStatbuf, statbuf, "") {
28 COMPARE_FIELD(st_dev);
29 COMPARE_FIELD(st_ino);
30 COMPARE_FIELD(st_mode);
31 COMPARE_FIELD(st_nlink);
32 COMPARE_FIELD(st_uid);
33 COMPARE_FIELD(st_gid);
34 COMPARE_FIELD(st_rdev);
35 COMPARE_FIELD(st_size);
36 COMPARE_FIELD(st_atime);
37 COMPARE_FIELD(st_mtime);
38 COMPARE_FIELD(st_ctime);
39 return true;
40 }
41
42 #undef COMPARE_FIELD
43
44 ACTION_P(SetStat, statbuf) {
45 memset(arg1, 0, sizeof(struct stat));
46 arg1->st_dev = statbuf->st_dev;
47 arg1->st_ino = statbuf->st_ino;
48 arg1->st_mode = statbuf->st_mode;
49 arg1->st_nlink = statbuf->st_nlink;
50 arg1->st_uid = statbuf->st_uid;
51 arg1->st_gid = statbuf->st_gid;
52 arg1->st_rdev = statbuf->st_rdev;
53 arg1->st_size = statbuf->st_size;
54 arg1->st_atime = statbuf->st_atime;
55 arg1->st_mtime = statbuf->st_mtime;
56 arg1->st_ctime = statbuf->st_ctime;
57 return 0;
58 }
59
60 void MakeDummyStatbuf(struct stat* statbuf) {
61 memset(&statbuf[0], 0, sizeof(struct stat));
62 statbuf->st_dev = 1;
63 statbuf->st_ino = 2;
64 statbuf->st_mode = 3;
65 statbuf->st_nlink = 4;
66 statbuf->st_uid = 5;
67 statbuf->st_gid = 6;
68 statbuf->st_rdev = 7;
69 statbuf->st_size = 8;
70 statbuf->st_atime = 9;
71 statbuf->st_mtime = 10;
72 statbuf->st_ctime = 11;
73 }
74
75 } // namespace
76
77 TEST(KernelWrap, access) {
78 KernelProxyMock mock;
79 ki_init(&mock);
80 EXPECT_CALL(mock, access(StrEq("access"), 12)).Times(1);
81 access("access", 12);
82 }
83
84 TEST(KernelWrap, chdir) {
85 KernelProxyMock mock;
86 ki_init(&mock);
87 EXPECT_CALL(mock, chdir(StrEq("chdir"))).Times(1);
88 chdir("chdir");
89 }
90
91 TEST(KernelWrap, chmod) {
92 KernelProxyMock mock;
93 ki_init(&mock);
94 EXPECT_CALL(mock, chmod(StrEq("chmod"), 23)).Times(1);
95 chmod("chmod", 23);
96 }
97
98 TEST(KernelWrap, close) {
99 KernelProxyMock mock;
100 ki_init(&mock);
101 EXPECT_CALL(mock, close(34)).Times(1);
102 close(34);
103 }
104
105 TEST(KernelWrap, dup) {
106 KernelProxyMock mock;
107 ki_init(&mock);
108 EXPECT_CALL(mock, dup(123)).Times(1);
109 dup(123);
110 }
111
112 TEST(KernelWrap, fstat) {
113 KernelProxyMock mock;
114 ki_init(&mock);
115 struct stat in_statbuf;
116 MakeDummyStatbuf(&in_statbuf);
117 EXPECT_CALL(mock, fstat(234, _))
118 .Times(1)
119 .WillOnce(SetStat(&in_statbuf));
120 struct stat out_statbuf;
121 fstat(234, &out_statbuf);
122 EXPECT_THAT(&in_statbuf, IsEqualToStatbuf(&out_statbuf));
123 }
124
125 TEST(KernelWrap, fsync) {
126 KernelProxyMock mock;
127 ki_init(&mock);
128 EXPECT_CALL(mock, fsync(345)).Times(1);
129 fsync(345);
130 }
131
132 TEST(KernelWrap, getcwd) {
133 KernelProxyMock mock;
134 ki_init(&mock);
135 EXPECT_CALL(mock, getcwd(StrEq("getcwd"), 1)).Times(1);
136 char buffer[] = "getcwd";
137 getcwd(buffer, 1);
138 }
139
140 TEST(KernelWrap, getdents) {
141 KernelProxyMock mock;
142 ki_init(&mock);
143 EXPECT_CALL(mock, getdents(456, NULL, 567)).Times(1);
144 getdents(456, NULL, 567);
145 }
146
147 // gcc gives error: getwd is deprecated.
148 #if defined(__GNUC__)
149 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
150 #endif
151 TEST(KernelWrap, getwd) {
152 KernelProxyMock mock;
153 ki_init(&mock);
154 EXPECT_CALL(mock, getwd(StrEq("getwd"))).Times(1);
155 char buffer[] = "getwd";
156 getwd(buffer);
157 }
158 #if defined(__GNUC__)
159 #pragma GCC diagnostic warning "-Wdeprecated-declarations"
160 #endif
161
162 TEST(KernelWrap, isatty) {
163 KernelProxyMock mock;
164 ki_init(&mock);
165 EXPECT_CALL(mock, isatty(678)).Times(1);
166 isatty(678);
167 }
168
169 TEST(KernelWrap, lseek) {
170 KernelProxyMock mock;
171 ki_init(&mock);
172 EXPECT_CALL(mock, lseek(789, 891, 912)).Times(1);
173 lseek(789, 891, 912);
174 }
175
176 TEST(KernelWrap, mkdir) {
177 KernelProxyMock mock;
178 ki_init(&mock);
179 #if defined(WIN32)
180 EXPECT_CALL(mock, mkdir(StrEq("mkdir"), 0777)).Times(1);
181 mkdir("mkdir");
182 #else
183 EXPECT_CALL(mock, mkdir(StrEq("mkdir"), 1234)).Times(1);
184 mkdir("mkdir", 1234);
185 #endif
186 }
187
188 TEST(KernelWrap, mount) {
189 KernelProxyMock mock;
190 ki_init(&mock);
191 EXPECT_CALL(mock,
192 mount(StrEq("mount1"), StrEq("mount2"), StrEq("mount3"), 2345, NULL))
193 .Times(1);
194 mount("mount1", "mount2", "mount3", 2345, NULL);
195 }
196
197 TEST(KernelWrap, open) {
198 KernelProxyMock mock;
199 ki_init(&mock);
200 EXPECT_CALL(mock, open(StrEq("open"), 3456)).Times(1);
201 open("open", 3456);
202 }
203
204 TEST(KernelWrap, read) {
205 KernelProxyMock mock;
206 ki_init(&mock);
207 EXPECT_CALL(mock, read(4567, NULL, 5678)).Times(1);
208 read(4567, NULL, 5678);
209 }
210
211 TEST(KernelWrap, remove) {
212 KernelProxyMock mock;
213 ki_init(&mock);
214 EXPECT_CALL(mock, remove(StrEq("remove"))).Times(1);
215 remove("remove");
216 }
217
218 TEST(KernelWrap, rmdir) {
219 KernelProxyMock mock;
220 ki_init(&mock);
221 EXPECT_CALL(mock, rmdir(StrEq("rmdir"))).Times(1);
222 rmdir("rmdir");
223 }
224
225 TEST(KernelWrap, stat) {
226 KernelProxyMock mock;
227 ki_init(&mock);
228 struct stat in_statbuf;
229 MakeDummyStatbuf(&in_statbuf);
230 EXPECT_CALL(mock, stat(StrEq("stat"), _))
231 .Times(1)
232 .WillOnce(SetStat(&in_statbuf));
233 struct stat out_statbuf;
234 stat("stat", &out_statbuf);
235 EXPECT_THAT(&in_statbuf, IsEqualToStatbuf(&out_statbuf));
236 }
237
238 TEST(KernelWrap, umount) {
239 KernelProxyMock mock;
240 ki_init(&mock);
241 EXPECT_CALL(mock, umount(StrEq("umount"))).Times(1);
242 umount("umount");
243 }
244
245 TEST(KernelWrap, unlink) {
246 KernelProxyMock mock;
247 ki_init(&mock);
248 EXPECT_CALL(mock, unlink(StrEq("unlink"))).Times(1);
249 unlink("unlink");
250 }
251
252 TEST(KernelWrap, write) {
253 KernelProxyMock mock;
254 ki_init(&mock);
255 EXPECT_CALL(mock, write(6789, NULL, 7891)).Times(1);
256 write(6789, NULL, 7891);
257 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698