summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRom Lemarchand <romlem@google.com>2013-11-22 15:26:48 -0800
committerRom Lemarchand <romlem@google.com>2013-11-22 17:47:53 -0800
commitca10795491ce576a66d49103e3270acb3bf9ddfa (patch)
tree576045a4fc26866a564d70c35e9ab1995eb08e6f /tests
parent1b22d0759458a0735bc3f4be783a8887d08b5d14 (diff)
downloadhardware_libhardware-ca10795491ce576a66d49103e3270acb3bf9ddfa.zip
hardware_libhardware-ca10795491ce576a66d49103e3270acb3bf9ddfa.tar.gz
hardware_libhardware-ca10795491ce576a66d49103e3270acb3bf9ddfa.tar.bz2
HAL test: statically test the last member of structs
Ensure the last member of structs is actually the one we expect Change-Id: Ib623f1a5e09fd9b8d464456528a94742b0ccd00b
Diffstat (limited to 'tests')
-rw-r--r--tests/hardware/Android.mk2
-rw-r--r--tests/hardware/struct-last.cpp69
2 files changed, 70 insertions, 1 deletions
diff --git a/tests/hardware/Android.mk b/tests/hardware/Android.mk
index 3df02f6..02540c9 100644
--- a/tests/hardware/Android.mk
+++ b/tests/hardware/Android.mk
@@ -2,7 +2,7 @@ LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := static-hal-check
-LOCAL_SRC_FILES := struct-size.cpp struct-offset.cpp
+LOCAL_SRC_FILES := struct-size.cpp struct-offset.cpp struct-last.cpp
LOCAL_SHARED_LIBRARIES := libhardware
LOCAL_CFLAGS := -std=gnu++11 -O0
diff --git a/tests/hardware/struct-last.cpp b/tests/hardware/struct-last.cpp
new file mode 100644
index 0000000..44a7b2d
--- /dev/null
+++ b/tests/hardware/struct-last.cpp
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2013 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 <cstddef>
+#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>
+
+#define GET_PADDING(align, size) (((align) - ((size) % (align))) % (align))
+
+#define CHECK_LAST_MEMBER(type, member) \
+do { \
+static constexpr size_t calc_size = offsetof(type, member) + sizeof(((type *)0)->member); \
+static_assert(sizeof(type) == calc_size + GET_PADDING(alignof(type), calc_size), \
+"" #member " is not the last element of " #type); \
+} while (0)
+
+void CheckSizes(void) {
+ //Types defined in hardware.h
+ CHECK_LAST_MEMBER(hw_module_t, reserved);
+ CHECK_LAST_MEMBER(hw_device_t, close);
+
+ //Types defined in sensors.h
+ CHECK_LAST_MEMBER(sensors_vec_t, reserved);
+ CHECK_LAST_MEMBER(sensors_event_t, reserved1);
+ CHECK_LAST_MEMBER(struct sensor_t, reserved);
+ CHECK_LAST_MEMBER(sensors_poll_device_1_t, reserved_procs);
+
+ //Types defined in fb.h
+ CHECK_LAST_MEMBER(framebuffer_device_t, reserved_proc);
+
+ //Types defined in hwcomposer.h
+ CHECK_LAST_MEMBER(hwc_layer_1_t, reserved);
+ CHECK_LAST_MEMBER(hwc_composer_device_1_t, reserved_proc);
+
+ //Types defined in gralloc.h
+ CHECK_LAST_MEMBER(gralloc_module_t, reserved_proc);
+ CHECK_LAST_MEMBER(alloc_device_t, reserved_proc);
+
+ //Types defined in consumerir.h
+ CHECK_LAST_MEMBER(consumerir_device_t, reserved);
+
+ //Types defined in camera_common.h
+ CHECK_LAST_MEMBER(vendor_tag_ops_t, reserved);
+ CHECK_LAST_MEMBER(camera_module_t, reserved);
+
+ //Types defined in camera3.h
+ CHECK_LAST_MEMBER(camera3_device_ops_t, reserved);
+}
+