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

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

Issue 938223004: Linux sandbox: better APIs with /proc/ arguments (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix invalid proc_fd_ usage. Created 5 years, 10 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
« no previous file with comments | « sandbox/linux/services/thread_helpers.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sandbox/linux/services/thread_helpers_unittests.cc
diff --git a/sandbox/linux/services/thread_helpers_unittests.cc b/sandbox/linux/services/thread_helpers_unittests.cc
index 7f99aaf2a16898ad198b33633974bcfde5d8a6e0..888651671d55f2cc17d457b362f22f8f715c4dda 100644
--- a/sandbox/linux/services/thread_helpers_unittests.cc
+++ b/sandbox/linux/services/thread_helpers_unittests.cc
@@ -38,71 +38,71 @@ int GetRaceTestIterations() {
}
}
-class ScopedProcSelfTask {
+class ScopedProc {
public:
- ScopedProcSelfTask() : fd_(-1) {
- fd_ = open("/proc/self/task/", O_RDONLY | O_DIRECTORY);
+ ScopedProc() : fd_(-1) {
+ fd_ = open("/proc/", O_RDONLY | O_DIRECTORY);
CHECK_LE(0, fd_);
}
- ~ScopedProcSelfTask() { PCHECK(0 == IGNORE_EINTR(close(fd_))); }
+ ~ScopedProc() { PCHECK(0 == IGNORE_EINTR(close(fd_))); }
int fd() { return fd_; }
private:
int fd_;
- DISALLOW_COPY_AND_ASSIGN(ScopedProcSelfTask);
+ DISALLOW_COPY_AND_ASSIGN(ScopedProc);
};
TEST(ThreadHelpers, IsSingleThreadedBasic) {
- ScopedProcSelfTask task;
- ASSERT_TRUE(ThreadHelpers::IsSingleThreaded(task.fd()));
+ ScopedProc proc_fd;
+ ASSERT_TRUE(ThreadHelpers::IsSingleThreaded(proc_fd.fd()));
ASSERT_TRUE(ThreadHelpers::IsSingleThreaded());
base::Thread thread("sandbox_tests");
ASSERT_TRUE(thread.Start());
- ASSERT_FALSE(ThreadHelpers::IsSingleThreaded(task.fd()));
+ ASSERT_FALSE(ThreadHelpers::IsSingleThreaded(proc_fd.fd()));
ASSERT_FALSE(ThreadHelpers::IsSingleThreaded());
// Explicitly stop the thread here to not pollute the next test.
- ASSERT_TRUE(ThreadHelpers::StopThreadAndWatchProcFS(task.fd(), &thread));
+ ASSERT_TRUE(ThreadHelpers::StopThreadAndWatchProcFS(proc_fd.fd(), &thread));
}
SANDBOX_TEST(ThreadHelpers, AssertSingleThreaded) {
- ScopedProcSelfTask task;
- SANDBOX_ASSERT(ThreadHelpers::IsSingleThreaded(task.fd()));
+ ScopedProc proc_fd;
+ SANDBOX_ASSERT(ThreadHelpers::IsSingleThreaded(proc_fd.fd()));
SANDBOX_ASSERT(ThreadHelpers::IsSingleThreaded());
- ThreadHelpers::AssertSingleThreaded(task.fd());
+ ThreadHelpers::AssertSingleThreaded(proc_fd.fd());
ThreadHelpers::AssertSingleThreaded();
}
TEST(ThreadHelpers, IsSingleThreadedIterated) {
- ScopedProcSelfTask task;
- ASSERT_TRUE(ThreadHelpers::IsSingleThreaded(task.fd()));
+ ScopedProc proc_fd;
+ ASSERT_TRUE(ThreadHelpers::IsSingleThreaded(proc_fd.fd()));
// Iterate to check for race conditions.
for (int i = 0; i < GetRaceTestIterations(); ++i) {
base::Thread thread("sandbox_tests");
ASSERT_TRUE(thread.Start());
- ASSERT_FALSE(ThreadHelpers::IsSingleThreaded(task.fd()));
+ ASSERT_FALSE(ThreadHelpers::IsSingleThreaded(proc_fd.fd()));
// Explicitly stop the thread here to not pollute the next test.
- ASSERT_TRUE(ThreadHelpers::StopThreadAndWatchProcFS(task.fd(), &thread));
+ ASSERT_TRUE(ThreadHelpers::StopThreadAndWatchProcFS(proc_fd.fd(), &thread));
}
}
TEST(ThreadHelpers, IsSingleThreadedStartAndStop) {
- ScopedProcSelfTask task;
- ASSERT_TRUE(ThreadHelpers::IsSingleThreaded(task.fd()));
+ ScopedProc proc_fd;
+ ASSERT_TRUE(ThreadHelpers::IsSingleThreaded(proc_fd.fd()));
base::Thread thread("sandbox_tests");
// This is testing for a race condition, so iterate.
// Manually, this has been tested with more that 1M iterations.
for (int i = 0; i < GetRaceTestIterations(); ++i) {
ASSERT_TRUE(thread.Start());
- ASSERT_FALSE(ThreadHelpers::IsSingleThreaded(task.fd()));
+ ASSERT_FALSE(ThreadHelpers::IsSingleThreaded(proc_fd.fd()));
- ASSERT_TRUE(ThreadHelpers::StopThreadAndWatchProcFS(task.fd(), &thread));
- ASSERT_TRUE(ThreadHelpers::IsSingleThreaded(task.fd()));
+ ASSERT_TRUE(ThreadHelpers::StopThreadAndWatchProcFS(proc_fd.fd(), &thread));
+ ASSERT_TRUE(ThreadHelpers::IsSingleThreaded(proc_fd.fd()));
ASSERT_EQ(1, base::GetNumberOfThreads(base::GetCurrentProcessHandle()));
}
}
« no previous file with comments | « sandbox/linux/services/thread_helpers.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698