blob: 0df7e2fafacbfefc6a5f24265856a954486ff203 [file] [log] [blame]
Rachel Leeef2e21f2022-02-01 14:51:34 -08001/*
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
20namespace android {
21
22class DisplayEventReceiverTest : public ::testing::Test {
23public:
24 void SetUp() override { EXPECT_EQ(NO_ERROR, mDisplayEventReceiver.initCheck()); }
25
26 DisplayEventReceiver mDisplayEventReceiver;
27};
28
29TEST_F(DisplayEventReceiverTest, getLatestVsyncEventData) {
30 const nsecs_t now = systemTime();
Rachel Leeb9c5a772022-02-04 21:17:37 -080031 ParcelableVsyncEventData parcelableVsyncEventData;
32 EXPECT_EQ(NO_ERROR, mDisplayEventReceiver.getLatestVsyncEventData(&parcelableVsyncEventData));
Rachel Leeef2e21f2022-02-01 14:51:34 -080033
Rachel Leeb9c5a772022-02-04 21:17:37 -080034 const VsyncEventData& vsyncEventData = parcelableVsyncEventData.vsync;
Rachel Leeef2e21f2022-02-01 14:51:34 -080035 EXPECT_NE(std::numeric_limits<size_t>::max(), vsyncEventData.preferredFrameTimelineIndex);
36 EXPECT_GT(vsyncEventData.frameTimelines[0].deadlineTimestamp, now)
37 << "Deadline timestamp should be greater than frame time";
Rachel Leeb9c5a772022-02-04 21:17:37 -080038 for (size_t i = 0; i < VsyncEventData::kFrameTimelinesLength; i++) {
Huihong Luo1b0c49f2022-03-15 19:18:21 -070039 EXPECT_NE(gui::FrameTimelineInfo::INVALID_VSYNC_ID,
40 vsyncEventData.frameTimelines[i].vsyncId);
Rachel Leeb9c5a772022-02-04 21:17:37 -080041 EXPECT_GT(vsyncEventData.frameTimelines[i].expectedPresentationTime,
Rachel Leeef2e21f2022-02-01 14:51:34 -080042 vsyncEventData.frameTimelines[i].deadlineTimestamp)
43 << "Expected vsync timestamp should be greater than deadline";
44 if (i > 0) {
45 EXPECT_GT(vsyncEventData.frameTimelines[i].deadlineTimestamp,
46 vsyncEventData.frameTimelines[i - 1].deadlineTimestamp)
47 << "Deadline timestamp out of order for frame timeline " << i;
Rachel Leeb9c5a772022-02-04 21:17:37 -080048 EXPECT_GT(vsyncEventData.frameTimelines[i].expectedPresentationTime,
49 vsyncEventData.frameTimelines[i - 1].expectedPresentationTime)
Rachel Leeef2e21f2022-02-01 14:51:34 -080050 << "Expected vsync timestamp out of order for frame timeline " << i;
51 }
52 }
53}
54
Huihong Luo1b0c49f2022-03-15 19:18:21 -070055} // namespace android