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

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

Issue 795213003: Fix handling of free descriptors when calling dup2. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixes Created 6 years 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
« no previous file with comments | « native_client_sdk/src/libraries/nacl_io/kernel_object.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include <sys/types.h> 10 #include <sys/types.h>
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 ASSERT_EQ(4, ki_write(dup_fd, "more", 4)); 520 ASSERT_EQ(4, ki_write(dup_fd, "more", 4));
521 521
522 ASSERT_EQ(0, ki_close(dup2_fd)); 522 ASSERT_EQ(0, ki_close(dup2_fd));
523 // fd, new_fd -> "/bar" 523 // fd, new_fd -> "/bar"
524 // dup_fd -> "/foo" 524 // dup_fd -> "/foo"
525 525
526 ASSERT_EQ(dup_fd, ki_dup2(fd, dup_fd)); 526 ASSERT_EQ(dup_fd, ki_dup2(fd, dup_fd));
527 // fd, new_fd, dup_fd -> "/bar" 527 // fd, new_fd, dup_fd -> "/bar"
528 } 528 }
529 529
530 TEST_F(KernelProxyTest, DescriptorAllocationConsistency) {
531 // Check that the descriptor free list returns the expected ones,
532 // as the order is mandated by POSIX.
533
534 // Open a file to a get a descriptor to copy for this test.
535 // The test makes the assumption at all descriptors
536 // open by default are contiguous starting from zero.
537 int fd = ki_open("/foo", O_CREAT | O_RDWR, 0777);
538 ASSERT_GT(fd, -1);
539
540 // The next descriptor allocated should follow the first.
541 int dup_fd = ki_dup(fd);
542 ASSERT_EQ(fd + 1, dup_fd);
543
544 // Allocate a high descriptor number.
545 ASSERT_EQ(100, ki_dup2(fd, 100));
546
547 // The next descriptor allocate should still come 2 places
548 // after the first.
549 int dup_fd2 = ki_dup(fd);
550 ASSERT_EQ(fd + 2, dup_fd2);
551 }
552
530 TEST_F(KernelProxyTest, Lstat) { 553 TEST_F(KernelProxyTest, Lstat) {
531 int fd = ki_open("/foo", O_CREAT | O_RDWR, 0777); 554 int fd = ki_open("/foo", O_CREAT | O_RDWR, 0777);
532 ASSERT_GT(fd, -1); 555 ASSERT_GT(fd, -1);
533 ASSERT_EQ(0, ki_mkdir("/bar", S_IREAD | S_IWRITE)); 556 ASSERT_EQ(0, ki_mkdir("/bar", S_IREAD | S_IWRITE));
534 557
535 struct stat buf; 558 struct stat buf;
536 EXPECT_EQ(0, ki_lstat("/foo", &buf)); 559 EXPECT_EQ(0, ki_lstat("/foo", &buf));
537 EXPECT_EQ(0, buf.st_size); 560 EXPECT_EQ(0, buf.st_size);
538 EXPECT_TRUE(S_ISREG(buf.st_mode)); 561 EXPECT_TRUE(S_ISREG(buf.st_mode));
539 562
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
1005 1028
1006 int fd = ki_open("/dummy", O_RDONLY, 0); 1029 int fd = ki_open("/dummy", O_RDONLY, 0);
1007 EXPECT_NE(0, fd); 1030 EXPECT_NE(0, fd);
1008 1031
1009 char buf[20]; 1032 char buf[20];
1010 EXPECT_EQ(-1, ki_read(fd, &buf[0], 20)); 1033 EXPECT_EQ(-1, ki_read(fd, &buf[0], 20));
1011 // The Filesystem should be able to return whatever error it wants and have it 1034 // The Filesystem should be able to return whatever error it wants and have it
1012 // propagate through. 1035 // propagate through.
1013 EXPECT_EQ(1234, errno); 1036 EXPECT_EQ(1234, errno);
1014 } 1037 }
OLDNEW
« no previous file with comments | « native_client_sdk/src/libraries/nacl_io/kernel_object.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698