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

Side by Side Diff: native_client_sdk/src/tests/nacl_io_test/kernel_object_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 <sys/stat.h> 8 #include <sys/stat.h>
9 9
10 #include <map> 10 #include <map>
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 // There should be two references to the KernelHandle, the filesystem and node 88 // There should be two references to the KernelHandle, the filesystem and node
89 // should be unchanged. 89 // should be unchanged.
90 EXPECT_EQ(2, handle_a->RefCount()); 90 EXPECT_EQ(2, handle_a->RefCount());
91 EXPECT_EQ(2, handle_b->RefCount()); 91 EXPECT_EQ(2, handle_b->RefCount());
92 EXPECT_EQ(handle_a.get(), handle_b.get()); 92 EXPECT_EQ(handle_a.get(), handle_b.get());
93 EXPECT_EQ(2, fs->RefCount()); 93 EXPECT_EQ(2, fs->RefCount());
94 EXPECT_EQ(2, node->RefCount()); 94 EXPECT_EQ(2, node->RefCount());
95 95
96 // Allocating an FD should cause the KernelProxy to ref the handle and 96 // Allocating an FD should cause the KernelProxy to ref the handle and
97 // the node and filesystem should be unchanged. 97 // the node and filesystem should be unchanged.
98 int fd1 = proxy.AllocateFD(handle_a); 98 int fd1 = proxy.AllocateFD(handle_a, "/example");
99 EXPECT_EQ(3, handle_a->RefCount()); 99 EXPECT_EQ(3, handle_a->RefCount());
100 EXPECT_EQ(2, fs->RefCount()); 100 EXPECT_EQ(2, fs->RefCount());
101 EXPECT_EQ(2, node->RefCount()); 101 EXPECT_EQ(2, node->RefCount());
102 EXPECT_EQ("/example", proxy.GetFDPath(fd1));
102 103
103 // If we "dup" the handle, we should bump the ref count on the handle 104 // If we "dup" the handle, we should bump the ref count on the handle
104 int fd2 = proxy.AllocateFD(handle_b); 105 int fd2 = proxy.AllocateFD(handle_b, "");
105 EXPECT_EQ(4, handle_a->RefCount()); 106 EXPECT_EQ(4, handle_a->RefCount());
106 EXPECT_EQ(2, fs->RefCount()); 107 EXPECT_EQ(2, fs->RefCount());
107 EXPECT_EQ(2, node->RefCount()); 108 EXPECT_EQ(2, node->RefCount());
109 EXPECT_EQ("", proxy.GetFDPath(fd2));
108 110
109 // Handles are expected to come out in order 111 // Handles are expected to come out in order
110 EXPECT_EQ(0, fd1); 112 EXPECT_EQ(0, fd1);
111 EXPECT_EQ(1, fd2); 113 EXPECT_EQ(1, fd2);
112 114
113 // Now we "free" the handles, since the proxy should hold them. 115 // Now we "free" the handles, since the proxy should hold them.
114 handle_a.reset(NULL); 116 handle_a.reset(NULL);
115 handle_b.reset(NULL); 117 handle_b.reset(NULL);
116 EXPECT_EQ(2, fs->RefCount()); 118 EXPECT_EQ(2, fs->RefCount());
117 EXPECT_EQ(2, node->RefCount()); 119 EXPECT_EQ(2, node->RefCount());
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 EXPECT_EQ(1, fs->RefCount()); 160 EXPECT_EQ(1, fs->RefCount());
159 EXPECT_EQ(1, node->RefCount()); 161 EXPECT_EQ(1, node->RefCount());
160 162
161 KernelHandle* raw_handle = new KernelHandleForTesting(fs, node); 163 KernelHandle* raw_handle = new KernelHandleForTesting(fs, node);
162 ScopedKernelHandle handle(raw_handle); 164 ScopedKernelHandle handle(raw_handle);
163 165
164 EXPECT_EQ(2, fs->RefCount()); 166 EXPECT_EQ(2, fs->RefCount());
165 EXPECT_EQ(2, node->RefCount()); 167 EXPECT_EQ(2, node->RefCount());
166 EXPECT_EQ(1, raw_handle->RefCount()); 168 EXPECT_EQ(1, raw_handle->RefCount());
167 169
168 proxy.AllocateFD(handle); 170 int fd1 = proxy.AllocateFD(handle, "/example");
169 EXPECT_EQ(2, fs->RefCount()); 171 EXPECT_EQ(2, fs->RefCount());
170 EXPECT_EQ(2, node->RefCount()); 172 EXPECT_EQ(2, node->RefCount());
171 EXPECT_EQ(2, raw_handle->RefCount()); 173 EXPECT_EQ(2, raw_handle->RefCount());
174 EXPECT_EQ("/example", proxy.GetFDPath(fd1));
172 175
173 proxy.FreeAndReassignFD(5, handle); 176 proxy.FreeAndReassignFD(5, handle);
174 EXPECT_EQ(2, fs->RefCount()); 177 EXPECT_EQ(2, fs->RefCount());
175 EXPECT_EQ(2, node->RefCount()); 178 EXPECT_EQ(2, node->RefCount());
176 EXPECT_EQ(3, raw_handle->RefCount()); 179 EXPECT_EQ(3, raw_handle->RefCount());
180 EXPECT_EQ("/example", proxy.GetFDPath(fd1));
181
177 182
178 handle.reset(); 183 handle.reset();
179 EXPECT_EQ(2, raw_handle->RefCount()); 184 EXPECT_EQ(2, raw_handle->RefCount());
180 185
181 proxy.AcquireHandle(5, &handle); 186 proxy.AcquireHandle(5, &handle);
182 EXPECT_EQ(3, raw_handle->RefCount()); 187 EXPECT_EQ(3, raw_handle->RefCount());
183 EXPECT_EQ(raw_handle, handle.get()); 188 EXPECT_EQ(raw_handle, handle.get());
184 } 189 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698