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

Side by Side Diff: base/threading/thread_unittest.cc

Issue 2395303002: Scale Stack Limits in ThreadTest.StartWithOptions_StackSize with Bitness (Closed)
Patch Set: Created 4 years, 2 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/threading/thread.h" 5 #include "base/threading/thread.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h>
8 9
9 #include <vector> 10 #include <vector>
10 11
11 #include "base/bind.h" 12 #include "base/bind.h"
12 #include "base/debug/leak_annotations.h" 13 #include "base/debug/leak_annotations.h"
13 #include "base/macros.h" 14 #include "base/macros.h"
14 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
15 #include "base/run_loop.h" 16 #include "base/run_loop.h"
16 #include "base/single_thread_task_runner.h" 17 #include "base/single_thread_task_runner.h"
17 #include "base/synchronization/waitable_event.h" 18 #include "base/synchronization/waitable_event.h"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 base::WaitableEvent* event) { 130 base::WaitableEvent* event) {
130 *id = thread->GetThreadId(); 131 *id = thread->GetThreadId();
131 event->Signal(); 132 event->Signal();
132 } 133 }
133 134
134 } // namespace 135 } // namespace
135 136
136 TEST_F(ThreadTest, StartWithOptions_StackSize) { 137 TEST_F(ThreadTest, StartWithOptions_StackSize) {
137 Thread a("StartWithStackSize"); 138 Thread a("StartWithStackSize");
138 // Ensure that the thread can work with only 12 kb and still process a 139 // Ensure that the thread can work with only 12 kb and still process a
139 // message. 140 // message. At the same time, we should scale with the bitness of the system
141 // where 12 kb is definitely not enough.
142 // 12 kb = 3072 Slots on a 32-bit system, so we'll scale based off of that.
140 Thread::Options options; 143 Thread::Options options;
141 #if defined(ADDRESS_SANITIZER) || !defined(NDEBUG) 144 #if defined(ADDRESS_SANITIZER) || !defined(NDEBUG)
142 // ASan bloats the stack variables and overflows the 12 kb stack. Some debug 145 // ASan bloats the stack variables and overflows the 3072 slot stack. Some
143 // builds also grow the stack too much. 146 // debug builds also grow the stack too much.
144 options.stack_size = 24*1024; 147 options.stack_size = 2 * 3072 * sizeof(uintptr_t);
145 #else 148 #else
146 options.stack_size = 12*1024; 149 options.stack_size = 3072 * sizeof(uintptr_t);
147 #endif 150 #endif
148 EXPECT_TRUE(a.StartWithOptions(options)); 151 EXPECT_TRUE(a.StartWithOptions(options));
149 EXPECT_TRUE(a.message_loop()); 152 EXPECT_TRUE(a.message_loop());
150 EXPECT_TRUE(a.IsRunning()); 153 EXPECT_TRUE(a.IsRunning());
151 154
152 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::AUTOMATIC, 155 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::AUTOMATIC,
153 base::WaitableEvent::InitialState::NOT_SIGNALED); 156 base::WaitableEvent::InitialState::NOT_SIGNALED);
154 a.task_runner()->PostTask(FROM_HERE, base::Bind(&base::WaitableEvent::Signal, 157 a.task_runner()->PostTask(FROM_HERE, base::Bind(&base::WaitableEvent::Signal,
155 base::Unretained(&event))); 158 base::Unretained(&event)));
156 event.Wait(); 159 event.Wait();
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 511
509 a.Stop(); 512 a.Stop();
510 EXPECT_FALSE(a.message_loop()); 513 EXPECT_FALSE(a.message_loop());
511 EXPECT_FALSE(a.IsRunning()); 514 EXPECT_FALSE(a.IsRunning());
512 515
513 // Confirm that running any remaining tasks posted from Stop() goes smoothly 516 // Confirm that running any remaining tasks posted from Stop() goes smoothly
514 // (e.g. https://codereview.chromium.org/2135413003/#ps300001 crashed if 517 // (e.g. https://codereview.chromium.org/2135413003/#ps300001 crashed if
515 // StopSoon() posted Thread::ThreadQuitHelper() while |run_loop_| was null). 518 // StopSoon() posted Thread::ThreadQuitHelper() while |run_loop_| was null).
516 base::RunLoop().RunUntilIdle(); 519 base::RunLoop().RunUntilIdle();
517 } 520 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698