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

Unified Diff: third_party/WebKit/Source/core/css/threaded/MultiThreadedTestUtil.h

Issue 2912523002: Test util to allow MultiThreaded tests on TSan (Closed)
Patch Set: x Created 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/css/threaded/MultiThreadedTestUtil.h
diff --git a/third_party/WebKit/Source/core/css/threaded/MultiThreadedTestUtil.h b/third_party/WebKit/Source/core/css/threaded/MultiThreadedTestUtil.h
new file mode 100644
index 0000000000000000000000000000000000000000..22564300bf5069c3752801b49c043747b6e2aae1
--- /dev/null
+++ b/third_party/WebKit/Source/core/css/threaded/MultiThreadedTestUtil.h
@@ -0,0 +1,56 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+#include "platform/CrossThreadFunctional.h"
+#include "platform/WaitableEvent.h"
+#include "platform/WebTaskRunner.h"
+#include "platform/scheduler/child/web_scheduler.h"
+#include "platform/wtf/Functional.h"
+#include "platform/wtf/RefCounted.h"
+#include "public/platform/Platform.h"
+#include "public/platform/WebThread.h"
+
+namespace blink {
+
+class MultiThreadedTest : public testing::Test {
+ public:
+ // RunOnThreads run a closure num_threads * callbacks_per_thread times.
+ // The default for this is 10*100 = 1000 times.
+
+ template <typename FunctionType, typename... Ps>
+ void RunOnThreads(FunctionType function, Ps&&... parameters) {
+ Vector<std::unique_ptr<WebThread>> threads;
+ Vector<std::unique_ptr<WaitableEvent>> waits;
+
+ for (int i = 0; i < num_threads_; ++i) {
+ threads.push_back(Platform::Current()->CreateThread(""));
+ waits.push_back(WTF::MakeUnique<WaitableEvent>());
+ }
+
+ for (int i = 0; i < num_threads_; ++i) {
+ WebTaskRunner* task_runner = threads[i]->GetWebTaskRunner();
+
+ for (int j = 0; j < callbacks_per_thread_; ++j) {
+ task_runner->PostTask(FROM_HERE,
+ CrossThreadBind(function, parameters...));
+ }
+
+ task_runner->PostTask(
+ FROM_HERE, CrossThreadBind([](WaitableEvent* w) { w->Signal(); },
+ CrossThreadUnretained(waits[i].get())));
+ }
+
+ for (int i = 0; i < num_threads_; ++i) {
+ waits[i]->Wait();
+ }
+ }
+
+ protected:
+ int num_threads_ = 10;
+ int callbacks_per_thread_ = 100;
+};
+
+} // namespace blink
« 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