xref: /aosp_15_r20/frameworks/native/services/surfaceflinger/tests/DisplayEventReceiver_test.cpp (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
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:
SetUp()24     void SetUp() override { EXPECT_EQ(NO_ERROR, mDisplayEventReceiver.initCheck()); }
25 
26     DisplayEventReceiver mDisplayEventReceiver;
27 };
28 
TEST_F(DisplayEventReceiverTest,getLatestVsyncEventData)29 TEST_F(DisplayEventReceiverTest, getLatestVsyncEventData) {
30     const nsecs_t now = systemTime();
31     ParcelableVsyncEventData parcelableVsyncEventData;
32     EXPECT_EQ(NO_ERROR, mDisplayEventReceiver.getLatestVsyncEventData(&parcelableVsyncEventData));
33 
34     const VsyncEventData& vsyncEventData = parcelableVsyncEventData.vsync;
35     EXPECT_NE(std::numeric_limits<size_t>::max(), vsyncEventData.preferredFrameTimelineIndex);
36     EXPECT_GT(static_cast<int64_t>(vsyncEventData.frameTimelinesLength), 0)
37             << "Frame timelines length should be greater than 0";
38     EXPECT_LE(static_cast<int64_t>(vsyncEventData.frameTimelinesLength),
39               VsyncEventData::kFrameTimelinesCapacity)
40             << "Frame timelines length should not exceed max capacity";
41     EXPECT_GT(vsyncEventData.frameTimelines[0].deadlineTimestamp, now)
42             << "Deadline timestamp should be greater than frame time";
43     for (size_t i = 0; i < vsyncEventData.frameTimelinesLength; i++) {
44         EXPECT_NE(gui::FrameTimelineInfo::INVALID_VSYNC_ID,
45                   vsyncEventData.frameTimelines[i].vsyncId);
46         EXPECT_GT(vsyncEventData.frameTimelines[i].expectedPresentationTime,
47                   vsyncEventData.frameTimelines[i].deadlineTimestamp)
48                 << "Expected vsync timestamp should be greater than deadline";
49         if (i > 0) {
50             EXPECT_GT(vsyncEventData.frameTimelines[i].deadlineTimestamp,
51                       vsyncEventData.frameTimelines[i - 1].deadlineTimestamp)
52                     << "Deadline timestamp out of order for frame timeline " << i;
53             EXPECT_GT(vsyncEventData.frameTimelines[i].expectedPresentationTime,
54                       vsyncEventData.frameTimelines[i - 1].expectedPresentationTime)
55                     << "Expected vsync timestamp out of order for frame timeline " << i;
56         }
57     }
58 }
59 
60 } // namespace android
61