Rachel Lee | ef2e21f | 2022-02-01 14:51:34 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2022 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 | #include <gtest/gtest.h> |
| 18 | #include <gui/DisplayEventReceiver.h> |
| 19 | |
| 20 | namespace android { |
| 21 | |
| 22 | class DisplayEventReceiverTest : public ::testing::Test { |
| 23 | public: |
| 24 | void SetUp() override { EXPECT_EQ(NO_ERROR, mDisplayEventReceiver.initCheck()); } |
| 25 | |
| 26 | DisplayEventReceiver mDisplayEventReceiver; |
| 27 | }; |
| 28 | |
| 29 | TEST_F(DisplayEventReceiverTest, getLatestVsyncEventData) { |
| 30 | const nsecs_t now = systemTime(); |
| 31 | VsyncEventData vsyncEventData; |
| 32 | EXPECT_EQ(NO_ERROR, mDisplayEventReceiver.getLatestVsyncEventData(&vsyncEventData)); |
| 33 | |
| 34 | EXPECT_NE(std::numeric_limits<size_t>::max(), vsyncEventData.preferredFrameTimelineIndex); |
| 35 | EXPECT_GT(vsyncEventData.frameTimelines[0].deadlineTimestamp, now) |
| 36 | << "Deadline timestamp should be greater than frame time"; |
| 37 | for (size_t i = 0; i < vsyncEventData.frameTimelines.size(); i++) { |
| 38 | EXPECT_NE(FrameTimelineInfo::INVALID_VSYNC_ID, vsyncEventData.frameTimelines[i].id); |
| 39 | EXPECT_GT(vsyncEventData.frameTimelines[i].expectedPresentTime, |
| 40 | vsyncEventData.frameTimelines[i].deadlineTimestamp) |
| 41 | << "Expected vsync timestamp should be greater than deadline"; |
| 42 | if (i > 0) { |
| 43 | EXPECT_GT(vsyncEventData.frameTimelines[i].deadlineTimestamp, |
| 44 | vsyncEventData.frameTimelines[i - 1].deadlineTimestamp) |
| 45 | << "Deadline timestamp out of order for frame timeline " << i; |
| 46 | EXPECT_GT(vsyncEventData.frameTimelines[i].expectedPresentTime, |
| 47 | vsyncEventData.frameTimelines[i - 1].expectedPresentTime) |
| 48 | << "Expected vsync timestamp out of order for frame timeline " << i; |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | } // namespace android |