From 4c2aa4c223963d4f5cbb3605974fbc11ca2a7a6e Mon Sep 17 00:00:00 2001 From: Rom Lemarchand Date: Thu, 21 Nov 2013 10:24:52 -0800 Subject: 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 --- tests/hardware/Android.mk | 12 +++++++ tests/hardware/struct-size.cpp | 76 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 tests/hardware/Android.mk create mode 100644 tests/hardware/struct-size.cpp (limited to 'tests') 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 +#include +#include +#include +#include +#include +#include +#include +#include + +template 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 static void CheckTypeSize() { + const size_t mySize = CheckSizeHelper(size32, size64); + + static_assert(sizeof(T) == mySize, "struct is the wrong size"); +} + +void CheckSizes(void) { + //Types defined in hardware.h + CheckTypeSize(); + CheckTypeSize(); + + //Types defined in sensors.h + CheckTypeSize(); + CheckTypeSize(); + CheckTypeSize(); + CheckTypeSize(); + + //Types defined in fb.h + CheckTypeSize(); + + //Types defined in hwcomposer.h + CheckTypeSize(); + CheckTypeSize(); + + //Types defined in gralloc.h + CheckTypeSize(); + CheckTypeSize(); + + //Types defined in consumerir.h + CheckTypeSize(); + + //Types defined in camera_common.h + CheckTypeSize(); + CheckTypeSize(); + + //Types defined in camera3.h + CheckTypeSize(); +} + -- cgit v1.1