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

Unified Diff: sandbox/linux/services/broker_process_unittest.cc

Issue 229893002: Add unit test to check for broker FD leak (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: sandbox/linux/services/broker_process_unittest.cc
diff --git a/sandbox/linux/services/broker_process_unittest.cc b/sandbox/linux/services/broker_process_unittest.cc
index 7f1a685fe11cbac269e0157e7a0c6825756d3f44..8d3068d87ada2700daf6b95e4a7fe99393a00352 100644
--- a/sandbox/linux/services/broker_process_unittest.cc
+++ b/sandbox/linux/services/broker_process_unittest.cc
@@ -21,6 +21,7 @@
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/posix/eintr_wrapper.h"
+#include "base/posix/unix_domain_socket_linux.h"
#include "sandbox/linux/tests/test_utils.h"
#include "sandbox/linux/tests/unit_tests.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -434,4 +435,37 @@ TEST(BrokerProcess, OpenComplexFlagsNoClientCheck) {
// expected.
}
+SANDBOX_DEATH_TEST(BrokerProcess, RecvMsgDescriptorLeak, DEATH_EXIT_CODE(0)) {
+ // Find the lowest available file descriptor currently.
+ const int min_fd = dup(STDIN_FILENO);
+ SANDBOX_ASSERT(min_fd >= 0);
+ SANDBOX_ASSERT(0 == IGNORE_EINTR(close(min_fd)));
+
+ // Lower our file descriptor limit to just above the current limit so we can
+ // test for descriptor leaks easier.
+ const unsigned kExtraFiles = 8;
+ const struct rlimit new_rlim = {min_fd + kExtraFiles, min_fd + kExtraFiles};
+ SANDBOX_ASSERT(0 == setrlimit(RLIMIT_NOFILE, &new_rlim));
+
+ const char kCpuInfo[] = "/proc/cpuinfo";
+ std::vector<std::string> read_whitelist;
+ read_whitelist.push_back(kCpuInfo);
+
+ BrokerProcess open_broker(EPERM, read_whitelist, std::vector<std::string>());
+ SANDBOX_ASSERT(open_broker.Init(base::Bind(&NoOpCallback)));
+
+ static const char kBogus[] = "not a pickle";
+ const std::vector<int> fds(1, STDIN_FILENO);
+
+ for (unsigned i = 0; i < kExtraFiles; ++i) {
+ SANDBOX_ASSERT(UnixDomainSocket::SendMsg(
+ open_broker.ipc_socketpair(), kBogus, sizeof(kBogus), fds));
+ }
+
+ const int fd = open_broker.Open(kCpuInfo, O_RDONLY);
+ SANDBOX_ASSERT(fd >= 0);
+ SANDBOX_ASSERT(0 == IGNORE_EINTR(close(fd)));
+ _exit(0);
+}
+
} // namespace sandbox
« sandbox/linux/services/broker_process.h ('K') | « sandbox/linux/services/broker_process.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698