Yahan Zhou | 3cbda59 | 2020-08-03 15:53:27 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 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::test { |
| 21 | |
| 22 | #define CHECK_OFFSET(type, member, expected_offset) \ |
Rachel Lee | b9c5a77 | 2022-02-04 21:17:37 -0800 | [diff] [blame] | 23 | static_assert((offsetof(type, member) == (expected_offset))) |
Yahan Zhou | 3cbda59 | 2020-08-03 15:53:27 -0700 | [diff] [blame] | 24 | |
| 25 | TEST(DisplayEventStructLayoutTest, TestEventAlignment) { |
Rachel Lee | b9c5a77 | 2022-02-04 21:17:37 -0800 | [diff] [blame] | 26 | static_assert(std::is_pod<DisplayEventReceiver::Event::VSync>::value); |
Yahan Zhou | 3cbda59 | 2020-08-03 15:53:27 -0700 | [diff] [blame] | 27 | CHECK_OFFSET(DisplayEventReceiver::Event, vsync, 24); |
| 28 | CHECK_OFFSET(DisplayEventReceiver::Event, hotplug, 24); |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 29 | CHECK_OFFSET(DisplayEventReceiver::Event, modeChange, 24); |
Yahan Zhou | 3cbda59 | 2020-08-03 15:53:27 -0700 | [diff] [blame] | 30 | |
| 31 | CHECK_OFFSET(DisplayEventReceiver::Event::Header, type, 0); |
| 32 | CHECK_OFFSET(DisplayEventReceiver::Event::Header, displayId, 8); |
| 33 | CHECK_OFFSET(DisplayEventReceiver::Event::Header, timestamp, 16); |
| 34 | |
| 35 | CHECK_OFFSET(DisplayEventReceiver::Event::VSync, count, 0); |
Rachel Lee | b9c5a77 | 2022-02-04 21:17:37 -0800 | [diff] [blame] | 36 | CHECK_OFFSET(DisplayEventReceiver::Event::VSync, vsyncData.frameInterval, 8); |
| 37 | CHECK_OFFSET(DisplayEventReceiver::Event::VSync, vsyncData.preferredFrameTimelineIndex, 16); |
Rachel Lee | 0655a91 | 2023-04-20 19:54:18 -0700 | [diff] [blame] | 38 | CHECK_OFFSET(DisplayEventReceiver::Event::VSync, vsyncData.frameTimelinesLength, 20); |
Rachel Lee | b9c5a77 | 2022-02-04 21:17:37 -0800 | [diff] [blame] | 39 | CHECK_OFFSET(DisplayEventReceiver::Event::VSync, vsyncData.frameTimelines, 24); |
| 40 | CHECK_OFFSET(DisplayEventReceiver::Event::VSync, vsyncData.frameTimelines[0].vsyncId, 24); |
| 41 | CHECK_OFFSET(DisplayEventReceiver::Event::VSync, vsyncData.frameTimelines[0].deadlineTimestamp, |
| 42 | 32); |
| 43 | CHECK_OFFSET(DisplayEventReceiver::Event::VSync, |
| 44 | vsyncData.frameTimelines[0].expectedPresentationTime, 40); |
| 45 | // Also test the offsets of the last frame timeline. A loop is not used because the non-const |
| 46 | // index cannot be used in static_assert. |
| 47 | const int lastFrameTimelineOffset = /* Start of array */ 24 + |
Rachel Lee | 40aef42 | 2023-04-25 14:35:47 -0700 | [diff] [blame] | 48 | (VsyncEventData::kFrameTimelinesCapacity - 1) * /* Size of FrameTimeline */ 24; |
Rachel Lee | b9c5a77 | 2022-02-04 21:17:37 -0800 | [diff] [blame] | 49 | CHECK_OFFSET(DisplayEventReceiver::Event::VSync, |
Rachel Lee | 40aef42 | 2023-04-25 14:35:47 -0700 | [diff] [blame] | 50 | vsyncData.frameTimelines[VsyncEventData::kFrameTimelinesCapacity - 1].vsyncId, |
Rachel Lee | b9c5a77 | 2022-02-04 21:17:37 -0800 | [diff] [blame] | 51 | lastFrameTimelineOffset); |
| 52 | CHECK_OFFSET(DisplayEventReceiver::Event::VSync, |
Rachel Lee | 40aef42 | 2023-04-25 14:35:47 -0700 | [diff] [blame] | 53 | vsyncData.frameTimelines[VsyncEventData::kFrameTimelinesCapacity - 1] |
Rachel Lee | b9c5a77 | 2022-02-04 21:17:37 -0800 | [diff] [blame] | 54 | .deadlineTimestamp, |
| 55 | lastFrameTimelineOffset + 8); |
| 56 | CHECK_OFFSET(DisplayEventReceiver::Event::VSync, |
Rachel Lee | 40aef42 | 2023-04-25 14:35:47 -0700 | [diff] [blame] | 57 | vsyncData.frameTimelines[VsyncEventData::kFrameTimelinesCapacity - 1] |
Rachel Lee | b9c5a77 | 2022-02-04 21:17:37 -0800 | [diff] [blame] | 58 | .expectedPresentationTime, |
| 59 | lastFrameTimelineOffset + 16); |
Yahan Zhou | 3cbda59 | 2020-08-03 15:53:27 -0700 | [diff] [blame] | 60 | |
| 61 | CHECK_OFFSET(DisplayEventReceiver::Event::Hotplug, connected, 0); |
Brian Johnson | 5dcd75d | 2023-08-15 09:36:37 -0700 | [diff] [blame] | 62 | CHECK_OFFSET(DisplayEventReceiver::Event::Hotplug, connectionError, 4); |
Yahan Zhou | 3cbda59 | 2020-08-03 15:53:27 -0700 | [diff] [blame] | 63 | |
Marin Shalamanov | a7fe304 | 2021-01-29 21:02:08 +0100 | [diff] [blame] | 64 | CHECK_OFFSET(DisplayEventReceiver::Event::ModeChange, modeId, 0); |
| 65 | CHECK_OFFSET(DisplayEventReceiver::Event::ModeChange, vsyncPeriod, 8); |
Ady Abraham | 62f216c | 2020-10-13 19:07:23 -0700 | [diff] [blame] | 66 | |
| 67 | CHECK_OFFSET(DisplayEventReceiver::Event::FrameRateOverride, uid, 0); |
| 68 | CHECK_OFFSET(DisplayEventReceiver::Event::FrameRateOverride, frameRateHz, 8); |
Yahan Zhou | 3cbda59 | 2020-08-03 15:53:27 -0700 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | } // namespace android::test |