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

Side by Side Diff: util/thread/thread_test.cc

Issue 1134943003: Move thread from test/ to util/thread/. (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 5 years, 7 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
(Empty)
1 // Copyright 2015 The Crashpad Authors. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "util/thread/thread.h"
16
17 #include "base/basictypes.h"
18 #include "gtest/gtest.h"
19 #include "util/synchronization/semaphore.h"
20
21 namespace crashpad {
22 namespace test {
23 namespace {
24
25 class NoopThread : public Thread {
26 public:
27 NoopThread() {}
28 ~NoopThread() override {}
29
30 private:
31 void ThreadMain() override {}
32
33 DISALLOW_COPY_AND_ASSIGN(NoopThread);
34 };
35
36 class WaitThread : public Thread {
37 public:
38 explicit WaitThread(Semaphore* semaphore) : semaphore_(semaphore) {}
39 ~WaitThread() override {}
40
41 private:
42 void ThreadMain() override { semaphore_->Wait(); }
43
44 Semaphore* semaphore_;
45
46 DISALLOW_COPY_AND_ASSIGN(WaitThread);
47 };
48
49 class JoinAndSignalThread : public Thread {
50 public:
51 JoinAndSignalThread(Thread* thread, Semaphore* semaphore)
52 : thread_(thread), semaphore_(semaphore) {}
53 ~JoinAndSignalThread() override {}
54
55 private:
56 void ThreadMain() override {
57 thread_->Join();
58 semaphore_->Signal();
59 }
60
61 Thread* thread_;
62 Semaphore* semaphore_;
63
64 DISALLOW_COPY_AND_ASSIGN(JoinAndSignalThread);
65 };
66
67 TEST(ThreadTest, NoStart) {
68 NoopThread thread;
69 }
70
71 TEST(ThreadTest, Start) {
72 NoopThread thread;
73 thread.Start();
74 thread.Join();
75 }
76
77 TEST(ThreadTest, JoinBlocks) {
78 Semaphore unblock_wait_thread(0);
scottmg 2015/05/11 21:52:00 `unblock_wait_thread` makes it sound like a thread
erikwright (departed) 2015/05/13 15:27:49 Done.
79 Semaphore join_completed(0);
80 WaitThread wait_thread(&unblock_wait_thread);
81 wait_thread.Start();
82 JoinAndSignalThread join_and_signal_thread(&wait_thread, &join_completed);
83 join_and_signal_thread.Start();
84 // Wait 100ms to give a broken Join implementation a chance to complete.
85 ASSERT_FALSE(join_completed.TimedWait(.1));
scottmg 2015/05/11 21:52:00 I don't like this timeout too much. I think just w
Robert Sesek 2015/05/11 22:10:51 +1. This will be flaky.
erikwright (departed) 2015/05/13 15:27:49 I think you misunderstood the purpose of this time
scottmg 2015/05/13 17:31:49 I guess we would need a WFMO version to avoid the
86 unblock_wait_thread.Signal();
87 join_completed.Wait();
88 join_and_signal_thread.Join();
89 }
90
91 } // namespace
92 } // namespace test
93 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698