blob: 5157cc4e2c1c6776a21958d05d1d757fbbc0f562 [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
22#include "Scheduler/EventThread.h"
23#include "Scheduler/Scheduler.h"
24
25namespace android {
26
27class TestableScheduler : public Scheduler {
28public:
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -070029 TestableScheduler(std::unique_ptr<DispSync> primaryDispSync,
30 std::unique_ptr<EventControlThread> eventControlThread,
31 const scheduler::RefreshRateConfigs& configs)
32 : Scheduler(std::move(primaryDispSync), std::move(eventControlThread), configs) {}
Ana Krulecafb45842019-02-13 13:33:03 -080033
34 // Creates EventThreadConnection with the given eventThread. Creates Scheduler::Connection
35 // and adds it to the list of connectins. Returns the ConnectionHandle for the
36 // Scheduler::Connection. This allows plugging in mock::EventThread.
37 sp<Scheduler::ConnectionHandle> addConnection(std::unique_ptr<EventThread> eventThread) {
38 sp<EventThreadConnection> eventThreadConnection =
Ady Abraham0f4a1b12019-06-04 16:04:04 -070039 new EventThreadConnection(eventThread.get(), ResyncCallback(),
40 ISurfaceComposer::eConfigChangedSuppress);
Ana Krulecafb45842019-02-13 13:33:03 -080041 const int64_t id = sNextId++;
42 mConnections.emplace(id,
43 std::make_unique<Scheduler::Connection>(new ConnectionHandle(id),
44 eventThreadConnection,
45 std::move(eventThread)));
46 return mConnections[id]->handle;
47 }
48
49 /* ------------------------------------------------------------------------
50 * Read-write access to private data to set up preconditions and assert
51 * post-conditions.
52 */
53 auto& mutablePrimaryHWVsyncEnabled() { return mPrimaryHWVsyncEnabled; }
54 auto& mutableEventControlThread() { return mEventControlThread; }
55 auto& mutablePrimaryDispSync() { return mPrimaryDispSync; }
56 auto& mutableHWVsyncAvailable() { return mHWVsyncAvailable; }
57
58 ~TestableScheduler() {
59 // All these pointer and container clears help ensure that GMock does
60 // not report a leaked object, since the Scheduler instance may
61 // still be referenced by something despite our best efforts to destroy
62 // it after each test is done.
63 mutableEventControlThread().reset();
64 mutablePrimaryDispSync().reset();
65 mConnections.clear();
Dominik Laskowski7c9dbf92019-08-01 17:57:31 -070066 }
Ana Krulecafb45842019-02-13 13:33:03 -080067};
68
69} // namespace android