blob: 0e54664f771a3365023d7945de155f43d210e481 [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++) {
39 EXPECT_NE(FrameTimelineInfo::INVALID_VSYNC_ID, vsyncEventData.frameTimelines[i].vsyncId);
40 EXPECT_GT(vsyncEventData.frameTimelines[i].expectedPresentationTime,
Rachel Leeef2e21f2022-02-01 14:51:34 -080041 vsyncEventData.frameTimelines[i].deadlineTimestamp)
42 << "Expected vsync timestamp should be greater than deadline";
43 if (i > 0) {
44 EXPECT_GT(vsyncEventData.frameTimelines[i].deadlineTimestamp,
45 vsyncEventData.frameTimelines[i - 1].deadlineTimestamp)
46 << "Deadline timestamp out of order for frame timeline " << i;
Rachel Leeb9c5a772022-02-04 21:17:37 -080047 EXPECT_GT(vsyncEventData.frameTimelines[i].expectedPresentationTime,
48 vsyncEventData.frameTimelines[i - 1].expectedPresentationTime)
Rachel Leeef2e21f2022-02-01 14:51:34 -080049 << "Expected vsync timestamp out of order for frame timeline " << i;
50 }
51 }
52}
53
54} // namespace android