blob: ae7246780a86f84b1af1b8aa7e4db2fdde8d5c6c [file] [log] [blame]
Ana Krulecafb45842019-02-13 13:33:03 -08001/*
2 * Copyright 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <gmock/gmock.h>
Ady Abraham0f4a1b12019-06-04 16:04:04 -070020#include <gui/ISurfaceComposer.h>
Ana Krulecafb45842019-02-13 13:33:03 -080021
Dominik Laskowski98041832019-08-01 18:35:59 -070022#include "Scheduler/DispSync.h"
Ana Krulecafb45842019-02-13 13:33:03 -080023#include "Scheduler/EventThread.h"
24#include "Scheduler/Scheduler.h"
25
26namespace android {
27
28class TestableScheduler : public Scheduler {
29public:
Dominik Laskowski98041832019-08-01 18:35:59 -070030 explicit TestableScheduler(const scheduler::RefreshRateConfigs& configs)
31 : Scheduler([](bool) {}, configs) {}
32
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -070033 TestableScheduler(std::unique_ptr<DispSync> primaryDispSync,
34 std::unique_ptr<EventControlThread> eventControlThread,
35 const scheduler::RefreshRateConfigs& configs)
36 : Scheduler(std::move(primaryDispSync), std::move(eventControlThread), configs) {}
Ana Krulecafb45842019-02-13 13:33:03 -080037
Dominik Laskowski98041832019-08-01 18:35:59 -070038 // Used to inject mock event thread.
39 ConnectionHandle createConnection(std::unique_ptr<EventThread> eventThread) {
Steven Thomas2bbaabe2019-08-28 16:08:35 -070040 return Scheduler::createConnection(std::move(eventThread));
Ana Krulecafb45842019-02-13 13:33:03 -080041 }
42
43 /* ------------------------------------------------------------------------
44 * Read-write access to private data to set up preconditions and assert
45 * post-conditions.
46 */
47 auto& mutablePrimaryHWVsyncEnabled() { return mPrimaryHWVsyncEnabled; }
48 auto& mutableEventControlThread() { return mEventControlThread; }
49 auto& mutablePrimaryDispSync() { return mPrimaryDispSync; }
50 auto& mutableHWVsyncAvailable() { return mHWVsyncAvailable; }
51
52 ~TestableScheduler() {
53 // All these pointer and container clears help ensure that GMock does
54 // not report a leaked object, since the Scheduler instance may
55 // still be referenced by something despite our best efforts to destroy
56 // it after each test is done.
57 mutableEventControlThread().reset();
58 mutablePrimaryDispSync().reset();
59 mConnections.clear();
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -070060 }
Ana Krulecafb45842019-02-13 13:33:03 -080061};
62
63} // namespace android