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