OLD | NEW |
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 Loading... |
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, fd5; |
| 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); |
| 319 EXPECT_EQ(0, ki_chdir("/example")); |
| 320 EXPECT_EQ(0, ki_fchdir(fd4)); |
| 321 EXPECT_EQ(text, ki_getcwd(text, sizeof(text))); |
| 322 EXPECT_STREQ("/foo/bar", text); |
| 323 |
| 324 EXPECT_EQ(0, ki_chdir("/example")); |
| 325 fd5 = ki_dup(fd4); |
| 326 ASSERT_GT(fd5, -1); |
| 327 ASSERT_NE(fd4, fd5); |
| 328 EXPECT_EQ(0, ki_fchdir(fd5)); |
| 329 EXPECT_EQ(text, ki_getcwd(text, sizeof(text))); |
| 330 EXPECT_STREQ("/foo/bar", text); |
| 331 |
| 332 fd5 = 123; |
| 333 |
| 334 EXPECT_EQ(0, ki_chdir("/example")); |
| 335 EXPECT_EQ(fd5, ki_dup2(fd4, fd5)); |
| 336 EXPECT_EQ(0, ki_fchdir(fd5)); |
| 337 EXPECT_EQ(text, ki_getcwd(text, sizeof(text))); |
| 338 EXPECT_STREQ("/foo/bar", text); |
| 339 } |
| 340 |
285 TEST_F(KernelProxyTest, MemMountIO) { | 341 TEST_F(KernelProxyTest, MemMountIO) { |
286 char text[1024]; | 342 char text[1024]; |
287 int fd1, fd2, fd3; | 343 int fd1, fd2, fd3; |
288 int len; | 344 int len; |
289 | 345 |
290 // Fail to delete non existant "/foo" | 346 // Fail to delete non existant "/foo" |
291 EXPECT_EQ(-1, ki_rmdir("/foo")); | 347 EXPECT_EQ(-1, ki_rmdir("/foo")); |
292 EXPECT_EQ(ENOENT, errno); | 348 EXPECT_EQ(ENOENT, errno); |
293 | 349 |
294 // Create "/foo" | 350 // Create "/foo" |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 | 723 |
668 int fd = ki_open("/dummy", O_RDONLY); | 724 int fd = ki_open("/dummy", O_RDONLY); |
669 EXPECT_NE(0, fd); | 725 EXPECT_NE(0, fd); |
670 | 726 |
671 char buf[20]; | 727 char buf[20]; |
672 EXPECT_EQ(-1, ki_read(fd, &buf[0], 20)); | 728 EXPECT_EQ(-1, ki_read(fd, &buf[0], 20)); |
673 // The Filesystem should be able to return whatever error it wants and have it | 729 // The Filesystem should be able to return whatever error it wants and have it |
674 // propagate through. | 730 // propagate through. |
675 EXPECT_EQ(1234, errno); | 731 EXPECT_EQ(1234, errno); |
676 } | 732 } |
OLD | NEW |