Ana Krulec | afb4584 | 2019-02-13 13:33:03 -0800 | [diff] [blame] | 1 | /* |
| 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 Abraham | 0f4a1b1 | 2019-06-04 16:04:04 -0700 | [diff] [blame] | 20 | #include <gui/ISurfaceComposer.h> |
Ana Krulec | afb4584 | 2019-02-13 13:33:03 -0800 | [diff] [blame] | 21 | |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 22 | #include "Scheduler/DispSync.h" |
Ana Krulec | afb4584 | 2019-02-13 13:33:03 -0800 | [diff] [blame] | 23 | #include "Scheduler/EventThread.h" |
| 24 | #include "Scheduler/Scheduler.h" |
| 25 | |
| 26 | namespace android { |
| 27 | |
| 28 | class TestableScheduler : public Scheduler { |
| 29 | public: |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 30 | explicit TestableScheduler(const scheduler::RefreshRateConfigs& configs) |
| 31 | : Scheduler([](bool) {}, configs) {} |
| 32 | |
Dominik Laskowski | 7c9dbf9 | 2019-08-01 17:57:31 -0700 | [diff] [blame] | 33 | 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 Krulec | afb4584 | 2019-02-13 13:33:03 -0800 | [diff] [blame] | 37 | |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 38 | // Used to inject mock event thread. |
| 39 | ConnectionHandle createConnection(std::unique_ptr<EventThread> eventThread) { |
Steven Thomas | 2bbaabe | 2019-08-28 16:08:35 -0700 | [diff] [blame^] | 40 | return Scheduler::createConnection(std::move(eventThread)); |
Ana Krulec | afb4584 | 2019-02-13 13:33:03 -0800 | [diff] [blame] | 41 | } |
| 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 Laskowski | 7c9dbf9 | 2019-08-01 17:57:31 -0700 | [diff] [blame] | 60 | } |
Ana Krulec | afb4584 | 2019-02-13 13:33:03 -0800 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | } // namespace android |