summaryrefslogtreecommitdiffstats
path: root/tests/hardware/struct-size.cpp
blob: 4207ea80fd9f47ef3db0e2d3a438bf443437a934 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
 * Copyright (C) 2012 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


#include <system/window.h>
#include <hardware/hardware.h>
#include <hardware/sensors.h>
#include <hardware/fb.h>
#include <hardware/hwcomposer.h>
#include <hardware/gralloc.h>
#include <hardware/consumerir.h>
#include <hardware/camera_common.h>
#include <hardware/camera3.h>

template<size_t> static constexpr size_t CheckSizeHelper(size_t, size_t);

template<> constexpr size_t CheckSizeHelper<4>(size_t size32, size_t size64) {
    return size32;
}

template<> constexpr size_t CheckSizeHelper<8>(size_t size32, size_t size64) {
    return size64;
}

template<typename T, size_t size32, size_t size64> static void CheckTypeSize() {
    const size_t mySize = CheckSizeHelper<sizeof(void *)>(size32, size64);

    static_assert(sizeof(T) == mySize, "struct is the wrong size");
}

void CheckSizes(void) {
    //Types defined in hardware.h
    CheckTypeSize<hw_module_t, 128, 248>();
    CheckTypeSize<hw_device_t, 64, 120>();

    //Types defined in sensors.h
    CheckTypeSize<sensors_vec_t, 16, 16>();
    CheckTypeSize<sensors_event_t, 104, 104>();
    CheckTypeSize<struct sensor_t, 68, 104>();
    CheckTypeSize<sensors_poll_device_1_t, 116, 224>();

    //Types defined in fb.h
    CheckTypeSize<framebuffer_device_t, 184, 288>();

    //Types defined in hwcomposer.h
    CheckTypeSize<hwc_layer_1_t, 96, 120>();
    CheckTypeSize<hwc_composer_device_1_t, 116, 224>();

    //Types defined in gralloc.h
    CheckTypeSize<gralloc_module_t, 176, 344>();
    CheckTypeSize<alloc_device_t, 104, 200>();

    //Types defined in consumerir.h
    CheckTypeSize<consumerir_device_t, 96, 184>();

    //Types defined in camera_common.h
    CheckTypeSize<vendor_tag_ops_t, 52, 104>();
    CheckTypeSize<camera_module_t, 176, 344>();

    //Types defined in camera3.h
    CheckTypeSize<camera3_device_ops_t, 64, 128>();
}