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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: native_client_sdk/src/tests/nacl_io_test/kernel_proxy_test.cc
diff --git a/native_client_sdk/src/tests/nacl_io_test/kernel_proxy_test.cc b/native_client_sdk/src/tests/nacl_io_test/kernel_proxy_test.cc
index a93d0305034a3992050c3e3bbd1a626db6bbd8ef..acc1921998e28b6fd4a1be7d4365077951a1c7bf 100644
--- a/native_client_sdk/src/tests/nacl_io_test/kernel_proxy_test.cc
+++ b/native_client_sdk/src/tests/nacl_io_test/kernel_proxy_test.cc
@@ -527,6 +527,29 @@ TEST_F(KernelProxyTest, MemMountDup) {
// fd, new_fd, dup_fd -> "/bar"
}
+TEST_F(KernelProxyTest, DescriptorAllocationConsistency) {
+ // Check that the descriptor free list returns the expected ones,
+ // as the order is mandated by POSIX.
+
+ // Open a file to a get a descriptor to copy for this test.
+ // The test makes the assumption at all descriptors
+ // open by default are contiguous starting from zero.
+ int fd = ki_open("/foo", O_CREAT | O_RDWR, 0777);
+ ASSERT_GT(fd, -1);
+
+ // The next descriptor allocated should follow the first.
+ int dup_fd = ki_dup(fd);
+ ASSERT_EQ(fd + 1, dup_fd);
+
+ // Allocate a high descriptor number.
+ ASSERT_EQ(100, ki_dup2(fd, 100));
+
+ // The next descriptor allocate should still come 2 places
+ // after the first.
+ int dup_fd2 = ki_dup(fd);
+ ASSERT_EQ(fd + 2, dup_fd2);
+}
+
TEST_F(KernelProxyTest, Lstat) {
int fd = ki_open("/foo", O_CREAT | O_RDWR, 0777);
ASSERT_GT(fd, -1);
« 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