1 //
2 // Copyright 2016 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // WorkerThread_unittest:
7 // Simple tests for the worker thread class.
8
9 #include <gtest/gtest.h>
10 #include <array>
11
12 #include "libANGLE/WorkerThread.h"
13
14 using namespace angle;
15
16 namespace
17 {
18
19 // Tests simple worker pool application.
TEST(WorkerPoolTest,SimpleTask)20 TEST(WorkerPoolTest, SimpleTask)
21 {
22 class TestTask : public Closure
23 {
24 public:
25 void operator()() override { fired = true; }
26
27 bool fired = false;
28 };
29
30 std::array<std::shared_ptr<WorkerThreadPool>, 2> pools = {
31 {WorkerThreadPool::Create(false), WorkerThreadPool::Create(true)}};
32 for (auto &pool : pools)
33 {
34 std::array<std::shared_ptr<TestTask>, 4> tasks = {
35 {std::make_shared<TestTask>(), std::make_shared<TestTask>(),
36 std::make_shared<TestTask>(), std::make_shared<TestTask>()}};
37 std::array<std::shared_ptr<WaitableEvent>, 4> waitables = {
38 {WorkerThreadPool::PostWorkerTask(pool, tasks[0]),
39 WorkerThreadPool::PostWorkerTask(pool, tasks[1]),
40 WorkerThreadPool::PostWorkerTask(pool, tasks[2]),
41 WorkerThreadPool::PostWorkerTask(pool, tasks[3])}};
42
43 WaitableEvent::WaitMany(&waitables);
44
45 for (const auto &task : tasks)
46 {
47 EXPECT_TRUE(task->fired);
48 }
49 }
50 }
51
52 } // anonymous namespace
53