summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRom Lemarchand <romlem@google.com>2013-11-21 10:24:52 -0800
committerRom Lemarchand <romlem@google.com>2013-11-21 15:52:05 -0800
commit4c2aa4c223963d4f5cbb3605974fbc11ca2a7a6e (patch)
treea6a1480446b90a271520f703055d0664c41b58fb /tests
parent22bf9724a177548cc439231bfde4a2fda636f4e2 (diff)
downloadhardware_libhardware-4c2aa4c223963d4f5cbb3605974fbc11ca2a7a6e.zip
hardware_libhardware-4c2aa4c223963d4f5cbb3605974fbc11ca2a7a6e.tar.gz
hardware_libhardware-4c2aa4c223963d4f5cbb3605974fbc11ca2a7a6e.tar.bz2
HAL test: statically test the size of HAL structs
Ensure none of the HAL structs change size over time. Issues might arise when making changes without taking the different pointer sizes for specific architectures into account. Change-Id: I63f00004a23f09b2f46df01e7c69296766a5d03f
Diffstat (limited to 'tests')
-rw-r--r--tests/hardware/Android.mk12
-rw-r--r--tests/hardware/struct-size.cpp76
2 files changed, 88 insertions, 0 deletions
diff --git a/tests/hardware/Android.mk b/tests/hardware/Android.mk
new file mode 100644
index 0000000..90cae87
--- /dev/null
+++ b/tests/hardware/Android.mk
@@ -0,0 +1,12 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := struct-size
+LOCAL_SRC_FILES := struct-size.cpp
+LOCAL_SHARED_LIBRARIES := libhardware
+LOCAL_CFLAGS := -std=gnu++11 -O0
+
+LOCAL_C_INCLUDES += \
+ system/media/camera/include
+
+include $(BUILD_STATIC_LIBRARY)
diff --git a/tests/hardware/struct-size.cpp b/tests/hardware/struct-size.cpp
new file mode 100644
index 0000000..4207ea8
--- /dev/null
+++ b/tests/hardware/struct-size.cpp
@@ -0,0 +1,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>();
+}
+