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

Side by Side Diff: native_client_sdk/src/tests/nacl_io_test/kernel_proxy_test.cc

Issue 99203014: [NaCl SDK] Map active fds to absolute paths. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Map active fds to absolute paths. Created 6 years, 11 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 #include <errno.h> 5 #include <errno.h>
6 #include <fcntl.h> 6 #include <fcntl.h>
7 #include <pthread.h> 7 #include <pthread.h>
8 #include <stdio.h> 8 #include <stdio.h>
9 #include <sys/stat.h> 9 #include <sys/stat.h>
10 10
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 275
276 memset(text, 0, sizeof(text)); 276 memset(text, 0, sizeof(text));
277 EXPECT_EQ(-1, ki_chdir("foo")); 277 EXPECT_EQ(-1, ki_chdir("foo"));
278 EXPECT_EQ(ENOENT, errno); 278 EXPECT_EQ(ENOENT, errno);
279 EXPECT_EQ(0, ki_chdir("..")); 279 EXPECT_EQ(0, ki_chdir(".."));
280 EXPECT_EQ(0, ki_chdir("/foo")); 280 EXPECT_EQ(0, ki_chdir("/foo"));
281 EXPECT_EQ(text, ki_getcwd(text, sizeof(text))); 281 EXPECT_EQ(text, ki_getcwd(text, sizeof(text)));
282 EXPECT_STREQ("/foo", text); 282 EXPECT_STREQ("/foo", text);
283 } 283 }
284 284
285 TEST_F(KernelProxyTest, FDPathMapping) {
286 char text[1024];
287
288 int fd1, fd2, fd3, fd4;
289
290 EXPECT_EQ(0, ki_mkdir("/foo", S_IREAD | S_IWRITE));
291 EXPECT_EQ(0, ki_mkdir("/foo/bar", S_IREAD | S_IWRITE));
292 EXPECT_EQ(0, ki_mkdir("/example", S_IREAD | S_IWRITE));
293 ki_chdir("/foo");
294
295 fd1 = ki_open("/example", O_RDONLY);
296 EXPECT_NE(-1, fd1);
297 EXPECT_EQ(ki_fchdir(fd1), 0);
298 EXPECT_EQ(text, ki_getcwd(text, sizeof(text)));
299 EXPECT_STREQ("/example", text);
300
301 EXPECT_EQ(0, ki_chdir("/foo"));
302 fd2 = ki_open("../example", O_RDONLY);
303 EXPECT_NE(-1, fd2);
304 EXPECT_EQ(0, ki_fchdir(fd2));
305 EXPECT_EQ(text, ki_getcwd(text, sizeof(text)));
306 EXPECT_STREQ("/example", text);
307
308 EXPECT_EQ(0, ki_chdir("/foo"));
309 fd3 = ki_open("../test", O_CREAT | O_RDWR);
310 EXPECT_NE(-1, fd3);
311 EXPECT_EQ(-1, ki_fchdir(fd3));
312 EXPECT_EQ(ENOTDIR, errno);
313
314 EXPECT_EQ(0, ki_chdir("/foo"));
315 fd4 = ki_open("bar", O_RDONLY);
316 EXPECT_EQ(0, ki_fchdir(fd4));
317 EXPECT_EQ(text, ki_getcwd(text, sizeof(text)));
318 EXPECT_STREQ("/foo/bar", text);
binji 2014/01/07 21:40:29 can you add tests for using fchdir on a fd that wa
319 }
320
285 TEST_F(KernelProxyTest, MemMountIO) { 321 TEST_F(KernelProxyTest, MemMountIO) {
286 char text[1024]; 322 char text[1024];
287 int fd1, fd2, fd3; 323 int fd1, fd2, fd3;
288 int len; 324 int len;
289 325
290 // Fail to delete non existant "/foo" 326 // Fail to delete non existant "/foo"
291 EXPECT_EQ(-1, ki_rmdir("/foo")); 327 EXPECT_EQ(-1, ki_rmdir("/foo"));
292 EXPECT_EQ(ENOENT, errno); 328 EXPECT_EQ(ENOENT, errno);
293 329
294 // Create "/foo" 330 // Create "/foo"
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 703
668 int fd = ki_open("/dummy", O_RDONLY); 704 int fd = ki_open("/dummy", O_RDONLY);
669 EXPECT_NE(0, fd); 705 EXPECT_NE(0, fd);
670 706
671 char buf[20]; 707 char buf[20];
672 EXPECT_EQ(-1, ki_read(fd, &buf[0], 20)); 708 EXPECT_EQ(-1, ki_read(fd, &buf[0], 20));
673 // The Filesystem should be able to return whatever error it wants and have it 709 // The Filesystem should be able to return whatever error it wants and have it
674 // propagate through. 710 // propagate through.
675 EXPECT_EQ(1234, errno); 711 EXPECT_EQ(1234, errno);
676 } 712 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698