diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/camera2/CameraBurstTests.cpp | 25 | ||||
-rw-r--r-- | tests/camera2/CameraFrameTests.cpp | 4 | ||||
-rw-r--r-- | tests/camera2/CameraMultiStreamTests.cpp | 25 | ||||
-rw-r--r-- | tests/camera2/CameraStreamFixture.h | 8 | ||||
-rw-r--r-- | tests/camera2/camera2.cpp | 31 | ||||
-rw-r--r-- | tests/fingerprint/Android.mk | 19 | ||||
-rw-r--r-- | tests/fingerprint/fingerprint_test_fixtures.h | 75 | ||||
-rw-r--r-- | tests/fingerprint/fingerprint_tests.cpp | 37 | ||||
-rw-r--r-- | tests/hardware/Android.mk | 12 | ||||
-rw-r--r-- | tests/hardware/struct-last.cpp | 69 | ||||
-rw-r--r-- | tests/hardware/struct-offset.cpp | 224 | ||||
-rw-r--r-- | tests/hardware/struct-size.cpp | 76 |
12 files changed, 562 insertions, 43 deletions
diff --git a/tests/camera2/CameraBurstTests.cpp b/tests/camera2/CameraBurstTests.cpp index 7301fce..65ff460 100644 --- a/tests/camera2/CameraBurstTests.cpp +++ b/tests/camera2/CameraBurstTests.cpp @@ -15,6 +15,7 @@ */ #include <gtest/gtest.h> +#include <inttypes.h> #define LOG_TAG "CameraBurstTest" //#define LOG_NDEBUG 0 @@ -218,7 +219,7 @@ TEST_F(CameraBurstTest, ManualExposureControl) { CameraMetadata tmpRequest = previewRequest; ASSERT_EQ(OK, tmpRequest.update(ANDROID_SENSOR_EXPOSURE_TIME, &exposures[i], 1)); - ALOGV("Submitting capture request %d with exposure %lld", i, + ALOGV("Submitting capture request %d with exposure %"PRId64, i, exposures[i]); dout << "Capture request " << i << " exposure is " << (exposures[i]/1e6f) << std::endl; @@ -230,11 +231,11 @@ TEST_F(CameraBurstTest, ManualExposureControl) { float brightnesses[CAMERA_FRAME_BURST_COUNT]; // Get each frame (metadata) and then the buffer. Calculate brightness. for (int i = 0; i < CAMERA_FRAME_BURST_COUNT; ++i) { - ALOGV("Reading capture request %d with exposure %lld", i, exposures[i]); + ALOGV("Reading capture request %d with exposure %"PRId64, i, exposures[i]); ASSERT_EQ(OK, mDevice->waitForNextFrame(CAMERA_FRAME_TIMEOUT)); ALOGV("Reading capture request-1 %d", i); - CameraMetadata frameMetadata; - ASSERT_EQ(OK, mDevice->getNextFrame(&frameMetadata)); + CaptureResult result; + ASSERT_EQ(OK, mDevice->getNextResult(&result)); ALOGV("Reading capture request-2 %d", i); ASSERT_EQ(OK, mFrameListener->waitForFrame(CAMERA_FRAME_TIMEOUT)); @@ -613,7 +614,7 @@ TEST_F(CameraBurstTest, VariableBurst) { &durationList[i], 1)); ASSERT_EQ(OK, tmpRequest.update(ANDROID_SENSOR_SENSITIVITY, &sensitivityList[i], 1)); - ALOGV("Submitting capture %d with exposure %lld, frame duration %lld, sensitivity %d", + ALOGV("Submitting capture %zu with exposure %"PRId64", frame duration %"PRId64", sensitivity %d", i, expList[i], durationList[i], sensitivityList[i]); dout << "Capture request " << i << ": exposure is " << (expList[i]/1e6f) << " ms" << @@ -631,7 +632,7 @@ TEST_F(CameraBurstTest, VariableBurst) { // Get each frame (metadata) and then the buffer. Calculate brightness. for (size_t i = 0; i < expList.size(); ++i) { - ALOGV("Reading request %d", i); + ALOGV("Reading request %zu", i); dout << "Waiting for capture " << i << ": " << " exposure " << (expList[i]/1e6f) << " ms," << " frame duration " << (durationList[i]/1e6f) << " ms," << @@ -644,10 +645,10 @@ TEST_F(CameraBurstTest, VariableBurst) { if (durationList[i] * 2 > waitLimit) waitLimit = durationList[i] * 2; ASSERT_EQ(OK, mDevice->waitForNextFrame(waitLimit)); - ALOGV("Reading capture request-1 %d", i); - CameraMetadata frameMetadata; - ASSERT_EQ(OK, mDevice->getNextFrame(&frameMetadata)); - ALOGV("Reading capture request-2 %d", i); + ALOGV("Reading capture request-1 %zu", i); + CaptureResult result; + ASSERT_EQ(OK, mDevice->getNextResult(&result)); + ALOGV("Reading capture request-2 %zu", i); ASSERT_EQ(OK, mFrameListener->waitForFrame(CAMERA_FRAME_TIMEOUT)); ALOGV("We got the frame now"); @@ -668,7 +669,7 @@ TEST_F(CameraBurstTest, VariableBurst) { avgBrightness = 255; } - ALOGV("Total brightness for frame %d was %lld (underexposed %d, " + ALOGV("Total brightness for frame %zu was %lld (underexposed %d, " "overexposed %d), avg %f", i, brightness, underexposed, overexposed, avgBrightness); dout << "Average brightness (frame " << i << ") was " << avgBrightness @@ -711,7 +712,7 @@ TEST_F(CameraBurstTest, VariableBurst) { if (dumpFrames) { String8 dumpName = - String8::format("/data/local/tmp/camera2_test_variable_burst_frame_%03d.yuv", i); + String8::format("/data/local/tmp/camera2_test_variable_burst_frame_%03zu.yuv", i); dout << " Writing YUV dump to " << dumpName << std::endl; DumpYuvToFile(dumpName, imgBuffer); } diff --git a/tests/camera2/CameraFrameTests.cpp b/tests/camera2/CameraFrameTests.cpp index e78a862..3c5abf7 100644 --- a/tests/camera2/CameraFrameTests.cpp +++ b/tests/camera2/CameraFrameTests.cpp @@ -115,8 +115,8 @@ TEST_P(CameraFrameTest, GetFrame) { ALOGV("Reading capture request %d", i); ASSERT_EQ(OK, mDevice->waitForNextFrame(CAMERA_FRAME_TIMEOUT)); - CameraMetadata frameMetadata; - ASSERT_EQ(OK, mDevice->getNextFrame(&frameMetadata)); + CaptureResult result; + ASSERT_EQ(OK, mDevice->getNextResult(&result)); // wait for buffer to be available ASSERT_EQ(OK, mFrameListener->waitForFrame(CAMERA_FRAME_TIMEOUT)); diff --git a/tests/camera2/CameraMultiStreamTests.cpp b/tests/camera2/CameraMultiStreamTests.cpp index a78950c..536b656 100644 --- a/tests/camera2/CameraMultiStreamTests.cpp +++ b/tests/camera2/CameraMultiStreamTests.cpp @@ -14,6 +14,7 @@ * limitations under the License. */ +#include <inttypes.h> #define LOG_TAG "CameraMultiStreamTest" //#define LOG_NDEBUG 0 #include "CameraStreamFixture.h" @@ -181,11 +182,13 @@ public: mHeight(height) { mFormat = param.mFormat; if (useCpuConsumer) { - sp<BufferQueue> bq = new BufferQueue(); - mCpuConsumer = new CpuConsumer(bq, param.mHeapCount); + sp<IGraphicBufferProducer> producer; + sp<IGraphicBufferConsumer> consumer; + BufferQueue::createBufferQueue(&producer, &consumer); + mCpuConsumer = new CpuConsumer(consumer, param.mHeapCount); mCpuConsumer->setName(String8( "CameraMultiStreamTest::mCpuConsumer")); - mNativeWindow = new Surface(bq); + mNativeWindow = new Surface(producer); } else { // Render the stream to screen. mCpuConsumer = NULL; @@ -353,7 +356,7 @@ public: ASSERT_EQ(OK, request.update(ANDROID_SENSOR_EXPOSURE_TIME, &exposures[i], 1)); ASSERT_EQ(OK, request.update(ANDROID_SENSOR_SENSITIVITY, &sensitivities[i], 1)); ASSERT_EQ(OK, mDevice->capture(request)); - ALOGV("Submitting request with: id %d with exposure %lld, sensitivity %d", + ALOGV("Submitting request with: id %d with exposure %"PRId64", sensitivity %d", *requestIdStart, exposures[i], sensitivities[i]); if (CAMERA_MULTI_STREAM_DEBUGGING) { request.dump(STDOUT_FILENO); @@ -368,7 +371,7 @@ public: // Set wait limit based on expected frame duration. int64_t waitLimit = CAMERA_FRAME_TIMEOUT; for (size_t i = 0; i < requestCount; i++) { - ALOGV("Reading request result %d", i); + ALOGV("Reading request result %zu", i); /** * Raise the timeout to be at least twice as long as the exposure @@ -378,11 +381,13 @@ public: waitLimit = exposures[i] * EXP_WAIT_MULTIPLIER; } + CaptureResult result; CameraMetadata frameMetadata; int32_t resultRequestId; do { ASSERT_EQ(OK, mDevice->waitForNextFrame(waitLimit)); - ASSERT_EQ(OK, mDevice->getNextFrame(&frameMetadata)); + ASSERT_EQ(OK, mDevice->getNextResult(&result)); + frameMetadata = result.mMetadata; camera_metadata_entry_t resultEntry = frameMetadata.find(ANDROID_REQUEST_ID); ASSERT_EQ(1u, resultEntry.count); @@ -392,7 +397,7 @@ public: } } while (resultRequestId != targetRequestId); targetRequestId++; - ALOGV("Got capture burst result for request %d", i); + ALOGV("Got capture burst result for request %zu", i); // Validate capture result if (CAMERA_MULTI_STREAM_DEBUGGING) { @@ -411,7 +416,7 @@ public: captureBurstTimes.push_back(systemTime()); CpuConsumer::LockedBuffer imgBuffer; ASSERT_EQ(OK, consumer->lockNextBuffer(&imgBuffer)); - ALOGV("Got capture buffer for request %d", i); + ALOGV("Got capture buffer for request %zu", i); /** * TODO: Validate capture buffer. Current brightness calculation @@ -523,7 +528,7 @@ TEST_F(CameraMultiStreamTest, MultiBurst) { minFrameDuration = DEFAULT_FRAME_DURATION; } - ALOGV("targeted minimal frame duration is: %lldns", minFrameDuration); + ALOGV("targeted minimal frame duration is: %"PRId64"ns", minFrameDuration); data = &(availableJpegSizes.data.i32[0]); count = availableJpegSizes.count; @@ -643,7 +648,7 @@ TEST_F(CameraMultiStreamTest, MultiBurst) { ASSERT_EQ(OK, previewRequest.update( ANDROID_SENSOR_EXPOSURE_TIME, &exposures[i], 1)); - ALOGV("Submitting preview request %d with exposure %lld", + ALOGV("Submitting preview request %zu with exposure %"PRId64, i, exposures[i]); ASSERT_EQ(OK, mDevice->setStreamingRequest(previewRequest)); diff --git a/tests/camera2/CameraStreamFixture.h b/tests/camera2/CameraStreamFixture.h index a1f3aae..12b1971 100644 --- a/tests/camera2/CameraStreamFixture.h +++ b/tests/camera2/CameraStreamFixture.h @@ -161,11 +161,13 @@ protected: sp<CameraDeviceBase> device = mDevice; CameraStreamParams p = mParam; - sp<BufferQueue> bq = new BufferQueue(); - mCpuConsumer = new CpuConsumer(bq, p.mHeapCount); + sp<IGraphicBufferProducer> producer; + sp<IGraphicBufferConsumer> consumer; + BufferQueue::createBufferQueue(&producer, &consumer); + mCpuConsumer = new CpuConsumer(consumer, p.mHeapCount); mCpuConsumer->setName(String8("CameraStreamTest::mCpuConsumer")); - mNativeWindow = new Surface(bq); + mNativeWindow = new Surface(producer); int format = MapAutoFormat(p.mFormat); diff --git a/tests/camera2/camera2.cpp b/tests/camera2/camera2.cpp index 600d440..e3e7d9a 100644 --- a/tests/camera2/camera2.cpp +++ b/tests/camera2/camera2.cpp @@ -172,13 +172,6 @@ class Camera2Test: public testing::Test { err = listener.getNotificationsFrom(dev); if (err != OK) return err; - vendor_tag_query_ops_t *vendor_metadata_tag_ops; - err = dev->ops->get_metadata_vendor_tag_ops(dev, &vendor_metadata_tag_ops); - if (err != OK) return err; - - err = set_camera_metadata_vendor_tag_ops(vendor_metadata_tag_ops); - if (err != OK) return err; - return OK; } @@ -388,8 +381,10 @@ TEST_F(Camera2Test, Capture1Raw) { ASSERT_NO_FATAL_FAILURE(setUpCamera(id)); - sp<BufferQueue> bq = new BufferQueue(); - sp<CpuConsumer> rawConsumer = new CpuConsumer(bq, 1); + sp<IGraphicBufferProducer> bqProducer; + sp<IGraphicBufferConsumer> bqConsumer; + BufferQueue::createBufferQueue(&bqProducer, &bqConsumer); + sp<CpuConsumer> rawConsumer = new CpuConsumer(bqConsumer, 1); sp<FrameWaiter> rawWaiter = new FrameWaiter(); rawConsumer->setFrameAvailableListener(rawWaiter); @@ -420,7 +415,7 @@ TEST_F(Camera2Test, Capture1Raw) { int streamId; ASSERT_NO_FATAL_FAILURE( - setUpStream(bq, width, height, format, &streamId) ); + setUpStream(bqProducer, width, height, format, &streamId) ); camera_metadata_t *request; request = allocate_camera_metadata(20, 2000); @@ -522,8 +517,10 @@ TEST_F(Camera2Test, CaptureBurstRaw) { ASSERT_NO_FATAL_FAILURE(setUpCamera(id)); - sp<BufferQueue> bq = new BufferQueue(); - sp<CpuConsumer> rawConsumer = new CpuConsumer(bq, 1); + sp<IGraphicBufferProducer> bqProducer; + sp<IGraphicBufferConsumer> bqConsumer; + BufferQueue::createBufferQueue(&bqProducer, &bqConsumer); + sp<CpuConsumer> rawConsumer = new CpuConsumer(bqConsumer, 1); sp<FrameWaiter> rawWaiter = new FrameWaiter(); rawConsumer->setFrameAvailableListener(rawWaiter); @@ -554,7 +551,7 @@ TEST_F(Camera2Test, CaptureBurstRaw) { int streamId; ASSERT_NO_FATAL_FAILURE( - setUpStream(bq, width, height, format, &streamId) ); + setUpStream(bqProducer, width, height, format, &streamId) ); camera_metadata_t *request; request = allocate_camera_metadata(20, 2000); @@ -703,8 +700,10 @@ TEST_F(Camera2Test, Capture1Jpeg) { ASSERT_NO_FATAL_FAILURE(setUpCamera(id)); - sp<BufferQueue> bq = new BufferQueue(); - sp<CpuConsumer> jpegConsumer = new CpuConsumer(bq, 1); + sp<IGraphicBufferProducer> bqProducer; + sp<IGraphicBufferConsumer> bqConsumer; + BufferQueue::createBufferQueue(&bqProducer, &bqConsumer); + sp<CpuConsumer> jpegConsumer = new CpuConsumer(bqConsumer, 1); sp<FrameWaiter> jpegWaiter = new FrameWaiter(); jpegConsumer->setFrameAvailableListener(jpegWaiter); @@ -723,7 +722,7 @@ TEST_F(Camera2Test, Capture1Jpeg) { int streamId; ASSERT_NO_FATAL_FAILURE( - setUpStream(bq, width, height, format, &streamId) ); + setUpStream(bqProducer, width, height, format, &streamId) ); camera_metadata_t *request; request = allocate_camera_metadata(20, 2000); diff --git a/tests/fingerprint/Android.mk b/tests/fingerprint/Android.mk new file mode 100644 index 0000000..4f03c39 --- /dev/null +++ b/tests/fingerprint/Android.mk @@ -0,0 +1,19 @@ +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_SRC_FILES:= \ + fingerprint_tests.cpp \ + +LOCAL_SHARED_LIBRARIES := \ + liblog \ + libhardware \ + +#LOCAL_C_INCLUDES += \ +# system/media/camera/include \ + +LOCAL_CFLAGS += -Wall -Wextra + +LOCAL_MODULE:= fingerprint_tests +LOCAL_MODULE_TAGS := tests + +include $(BUILD_NATIVE_TEST) diff --git a/tests/fingerprint/fingerprint_test_fixtures.h b/tests/fingerprint/fingerprint_test_fixtures.h new file mode 100644 index 0000000..a526203 --- /dev/null +++ b/tests/fingerprint/fingerprint_test_fixtures.h @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2014 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. + */ + +#ifndef __ANDROID_HAL_FINGERPRINT_TEST_COMMON__ +#define __ANDROID_HAL_FINGERPRINT_TEST_COMMON__ + +#include <gtest/gtest.h> +#include <hardware/hardware.h> +#include <hardware/fingerprint.h> + +namespace tests { + +static const uint16_t kVersion = HARDWARE_MODULE_API_VERSION(1, 0); + +class FingerprintModule : public testing::Test { + public: + FingerprintModule() : + fp_module_(NULL) {} + ~FingerprintModule() {} + protected: + virtual void SetUp() { + const hw_module_t *hw_module = NULL; + ASSERT_EQ(0, hw_get_module(FINGERPRINT_HARDWARE_MODULE_ID, &hw_module)) + << "Can't get fingerprint module"; + ASSERT_TRUE(NULL != hw_module) + << "hw_get_module didn't return a valid fingerprint module"; + + fp_module_ = reinterpret_cast<const fingerprint_module_t*>(hw_module); + } + const fingerprint_module_t* fp_module() { return fp_module_; } + private: + const fingerprint_module_t *fp_module_; +}; + +class FingerprintDevice : public FingerprintModule { + public: + FingerprintDevice() : + fp_device_(NULL) {} + ~FingerprintDevice() {} + protected: + virtual void SetUp() { + FingerprintModule::SetUp(); + hw_device_t *device = NULL; + ASSERT_TRUE(NULL != fp_module()->common.methods->open) + << "Fingerprint open() is unimplemented"; + ASSERT_EQ(0, fp_module()->common.methods->open( + (const hw_module_t*)fp_module(), NULL, &device)) + << "Can't open fingerprint device"; + ASSERT_TRUE(NULL != device) + << "Fingerprint open() returned a NULL device"; + ASSERT_EQ(kVersion, device->version) + << "Unsupported version"; + fp_device_ = reinterpret_cast<fingerprint_device_t*>(device); + } + fingerprint_device_t* fp_device() { return fp_device_; } + private: + fingerprint_device_t *fp_device_; +}; + +} // namespace tests + +#endif // __ANDROID_HAL_FINGERPRINT_TEST_COMMON__ diff --git a/tests/fingerprint/fingerprint_tests.cpp b/tests/fingerprint/fingerprint_tests.cpp new file mode 100644 index 0000000..4463751 --- /dev/null +++ b/tests/fingerprint/fingerprint_tests.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2014 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 <gtest/gtest.h> +#include "fingerprint_test_fixtures.h" + +namespace tests { + +TEST_F(FingerprintDevice, isThereEnroll) { + ASSERT_TRUE(NULL != fp_device()->enroll) + << "enroll() function is not implemented"; +} + +TEST_F(FingerprintDevice, isThereRemove) { + ASSERT_TRUE(NULL != fp_device()->remove) + << "remove() function is not implemented"; +} + +TEST_F(FingerprintDevice, isThereSetNotify) { + ASSERT_TRUE(NULL != fp_device()->set_notify) + << "set_notify() function is not implemented"; +} + +} // namespace tests diff --git a/tests/hardware/Android.mk b/tests/hardware/Android.mk new file mode 100644 index 0000000..02540c9 --- /dev/null +++ b/tests/hardware/Android.mk @@ -0,0 +1,12 @@ +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_MODULE := static-hal-check +LOCAL_SRC_FILES := struct-size.cpp struct-offset.cpp struct-last.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-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); +} + diff --git a/tests/hardware/struct-offset.cpp b/tests/hardware/struct-offset.cpp new file mode 100644 index 0000000..6abe360 --- /dev/null +++ b/tests/hardware/struct-offset.cpp @@ -0,0 +1,224 @@ +/* + * 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 <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> + +//Ideally this would print type.member instead we need to rely on the line number from the output +template <size_t actual, size_t expected> void check_member(void) { + static_assert(actual == expected, ""); +} + +#ifdef __LP64__ +#define CHECK_MEMBER_AT(type, member, off32, off64) \ + check_member<offsetof(type, member), off64>() +#else +#define CHECK_MEMBER_AT(type, member, off32, off64) \ + check_member<offsetof(type, member), off32>() +#endif + +void CheckOffsets(void) { + //Types defined in hardware.h + CHECK_MEMBER_AT(hw_module_t, tag, 0, 0); + CHECK_MEMBER_AT(hw_module_t, module_api_version, 4, 4); + CHECK_MEMBER_AT(hw_module_t, hal_api_version, 6, 6); + CHECK_MEMBER_AT(hw_module_t, id, 8, 8); + CHECK_MEMBER_AT(hw_module_t, name, 12, 16); + CHECK_MEMBER_AT(hw_module_t, author, 16, 24); + CHECK_MEMBER_AT(hw_module_t, methods, 20, 32); + CHECK_MEMBER_AT(hw_module_t, dso, 24, 40); + CHECK_MEMBER_AT(hw_module_t, reserved, 28, 48); + + CHECK_MEMBER_AT(hw_device_t, tag, 0, 0); + CHECK_MEMBER_AT(hw_device_t, version, 4, 4); + CHECK_MEMBER_AT(hw_device_t, module, 8, 8); + CHECK_MEMBER_AT(hw_device_t, reserved, 12, 16); + CHECK_MEMBER_AT(hw_device_t, close, 60, 112); + + //Types defined in sensors.h + CHECK_MEMBER_AT(sensors_vec_t, v, 0, 0); + CHECK_MEMBER_AT(sensors_vec_t, x, 0, 0); + CHECK_MEMBER_AT(sensors_vec_t, y, 4, 4); + CHECK_MEMBER_AT(sensors_vec_t, z, 8, 8); + CHECK_MEMBER_AT(sensors_vec_t, azimuth, 0, 0); + CHECK_MEMBER_AT(sensors_vec_t, pitch, 4, 4); + CHECK_MEMBER_AT(sensors_vec_t, roll, 8, 8); + CHECK_MEMBER_AT(sensors_vec_t, status, 12, 12); + CHECK_MEMBER_AT(sensors_vec_t, reserved, 13, 13); + + CHECK_MEMBER_AT(sensors_event_t, version, 0, 0); + CHECK_MEMBER_AT(sensors_event_t, sensor, 4, 4); + CHECK_MEMBER_AT(sensors_event_t, type, 8, 8); + CHECK_MEMBER_AT(sensors_event_t, reserved0, 12, 12); + CHECK_MEMBER_AT(sensors_event_t, timestamp, 16, 16); + CHECK_MEMBER_AT(sensors_event_t, data, 24, 24); + CHECK_MEMBER_AT(sensors_event_t, acceleration, 24, 24); + CHECK_MEMBER_AT(sensors_event_t, magnetic, 24, 24); + CHECK_MEMBER_AT(sensors_event_t, orientation, 24, 24); + CHECK_MEMBER_AT(sensors_event_t, gyro, 24, 24); + CHECK_MEMBER_AT(sensors_event_t, temperature, 24, 24); + CHECK_MEMBER_AT(sensors_event_t, distance, 24, 24); + CHECK_MEMBER_AT(sensors_event_t, light, 24, 24); + CHECK_MEMBER_AT(sensors_event_t, pressure, 24, 24); + CHECK_MEMBER_AT(sensors_event_t, relative_humidity, 24, 24); + CHECK_MEMBER_AT(sensors_event_t, uncalibrated_gyro, 24, 24); + CHECK_MEMBER_AT(sensors_event_t, uncalibrated_magnetic, 24, 24); + CHECK_MEMBER_AT(sensors_event_t, meta_data, 24, 24); + CHECK_MEMBER_AT(sensors_event_t, u64, 24, 24); + CHECK_MEMBER_AT(sensors_event_t, u64.data, 24, 24); + CHECK_MEMBER_AT(sensors_event_t, u64.step_counter, 24, 24); + CHECK_MEMBER_AT(sensors_event_t, flags, 88, 88); + CHECK_MEMBER_AT(sensors_event_t, reserved1, 92, 92); + + CHECK_MEMBER_AT(struct sensor_t, name, 0, 0); + CHECK_MEMBER_AT(struct sensor_t, vendor, 4, 8); + CHECK_MEMBER_AT(struct sensor_t, version, 8, 16); + CHECK_MEMBER_AT(struct sensor_t, handle, 12, 20); + CHECK_MEMBER_AT(struct sensor_t, type, 16, 24); + CHECK_MEMBER_AT(struct sensor_t, maxRange, 20, 28); + CHECK_MEMBER_AT(struct sensor_t, resolution, 24, 32); + CHECK_MEMBER_AT(struct sensor_t, power, 28, 36); + CHECK_MEMBER_AT(struct sensor_t, minDelay, 32, 40); + CHECK_MEMBER_AT(struct sensor_t, fifoReservedEventCount, 36, 44); + CHECK_MEMBER_AT(struct sensor_t, fifoMaxEventCount, 40, 48); + CHECK_MEMBER_AT(struct sensor_t, stringType, 44, 56); + CHECK_MEMBER_AT(struct sensor_t, requiredPermission, 48, 64); + CHECK_MEMBER_AT(struct sensor_t, maxDelay, 52, 72); + CHECK_MEMBER_AT(struct sensor_t, flags, 56, 80); + CHECK_MEMBER_AT(struct sensor_t, reserved, 60, 88); + + CHECK_MEMBER_AT(sensors_poll_device_1_t, v0, 0, 0); + CHECK_MEMBER_AT(sensors_poll_device_1_t, common, 0, 0); + CHECK_MEMBER_AT(sensors_poll_device_1_t, activate, 64, 120); + CHECK_MEMBER_AT(sensors_poll_device_1_t, setDelay, 68, 128); + CHECK_MEMBER_AT(sensors_poll_device_1_t, poll, 72, 136); + CHECK_MEMBER_AT(sensors_poll_device_1_t, batch, 76, 144); + CHECK_MEMBER_AT(sensors_poll_device_1_t, flush, 80, 152); + CHECK_MEMBER_AT(sensors_poll_device_1_t, reserved_procs, 84, 160); + + //Types defined in fb.h + CHECK_MEMBER_AT(framebuffer_device_t, common, 0, 0); + CHECK_MEMBER_AT(framebuffer_device_t, flags, 64, 120); + CHECK_MEMBER_AT(framebuffer_device_t, width, 68, 124); + CHECK_MEMBER_AT(framebuffer_device_t, height, 72, 128); + CHECK_MEMBER_AT(framebuffer_device_t, stride, 76, 132); + CHECK_MEMBER_AT(framebuffer_device_t, format, 80, 136); + CHECK_MEMBER_AT(framebuffer_device_t, xdpi, 84, 140); + CHECK_MEMBER_AT(framebuffer_device_t, ydpi, 88, 144); + CHECK_MEMBER_AT(framebuffer_device_t, fps, 92, 148); + CHECK_MEMBER_AT(framebuffer_device_t, minSwapInterval, 96, 152); + CHECK_MEMBER_AT(framebuffer_device_t, maxSwapInterval, 100, 156); + CHECK_MEMBER_AT(framebuffer_device_t, numFramebuffers, 104, 160); + CHECK_MEMBER_AT(framebuffer_device_t, reserved, 108, 164); + CHECK_MEMBER_AT(framebuffer_device_t, setSwapInterval, 136, 192); + CHECK_MEMBER_AT(framebuffer_device_t, setUpdateRect, 140, 200); + CHECK_MEMBER_AT(framebuffer_device_t, post, 144, 208); + CHECK_MEMBER_AT(framebuffer_device_t, compositionComplete, 148, 216); + CHECK_MEMBER_AT(framebuffer_device_t, dump, 152, 224); + CHECK_MEMBER_AT(framebuffer_device_t, enableScreen, 156, 232); + CHECK_MEMBER_AT(framebuffer_device_t, reserved_proc, 160, 240); + + //Types defined in hwcomposer.h + CHECK_MEMBER_AT(hwc_layer_1_t, compositionType, 0, 0); + CHECK_MEMBER_AT(hwc_layer_1_t, hints, 4, 4); + CHECK_MEMBER_AT(hwc_layer_1_t, flags, 8, 8); + CHECK_MEMBER_AT(hwc_layer_1_t, backgroundColor, 12, 16); + CHECK_MEMBER_AT(hwc_layer_1_t, handle, 12, 16); + CHECK_MEMBER_AT(hwc_layer_1_t, transform, 16, 24); + CHECK_MEMBER_AT(hwc_layer_1_t, blending, 20, 28); + CHECK_MEMBER_AT(hwc_layer_1_t, sourceCropi, 24, 32); + CHECK_MEMBER_AT(hwc_layer_1_t, sourceCrop, 24, 32); + CHECK_MEMBER_AT(hwc_layer_1_t, sourceCropf, 24, 32); + CHECK_MEMBER_AT(hwc_layer_1_t, displayFrame, 40, 48); + CHECK_MEMBER_AT(hwc_layer_1_t, visibleRegionScreen, 56, 64); + CHECK_MEMBER_AT(hwc_layer_1_t, acquireFenceFd, 64, 80); + CHECK_MEMBER_AT(hwc_layer_1_t, releaseFenceFd, 68, 84); + CHECK_MEMBER_AT(hwc_layer_1_t, planeAlpha, 72, 88); + CHECK_MEMBER_AT(hwc_layer_1_t, _pad, 73, 89); + + CHECK_MEMBER_AT(hwc_composer_device_1_t, common, 0, 0); + CHECK_MEMBER_AT(hwc_composer_device_1_t, prepare, 64, 120); + CHECK_MEMBER_AT(hwc_composer_device_1_t, set, 68, 128); + CHECK_MEMBER_AT(hwc_composer_device_1_t, eventControl, 72, 136); + CHECK_MEMBER_AT(hwc_composer_device_1_t, blank, 76, 144); + CHECK_MEMBER_AT(hwc_composer_device_1_t, query, 80, 152); + CHECK_MEMBER_AT(hwc_composer_device_1_t, registerProcs, 84, 160); + CHECK_MEMBER_AT(hwc_composer_device_1_t, dump, 88, 168); + CHECK_MEMBER_AT(hwc_composer_device_1_t, getDisplayConfigs, 92, 176); + CHECK_MEMBER_AT(hwc_composer_device_1_t, getDisplayAttributes, 96, 184); + CHECK_MEMBER_AT(hwc_composer_device_1_t, reserved_proc, 100, 192); + + //Types defined in gralloc.h + CHECK_MEMBER_AT(gralloc_module_t, common, 0, 0); + CHECK_MEMBER_AT(gralloc_module_t, registerBuffer, 128, 248); + CHECK_MEMBER_AT(gralloc_module_t, unregisterBuffer, 132, 256); + CHECK_MEMBER_AT(gralloc_module_t, lock, 136, 264); + CHECK_MEMBER_AT(gralloc_module_t, unlock, 140, 272); + CHECK_MEMBER_AT(gralloc_module_t, perform, 144, 280); + CHECK_MEMBER_AT(gralloc_module_t, lock_ycbcr, 148, 288); + CHECK_MEMBER_AT(gralloc_module_t, lockAsync, 152, 296); + CHECK_MEMBER_AT(gralloc_module_t, unlockAsync, 156, 304); + CHECK_MEMBER_AT(gralloc_module_t, lockAsync_ycbcr, 160, 312); + CHECK_MEMBER_AT(gralloc_module_t, reserved_proc, 164, 320); + + CHECK_MEMBER_AT(alloc_device_t, common, 0, 0); + CHECK_MEMBER_AT(alloc_device_t, alloc, 64, 120); + CHECK_MEMBER_AT(alloc_device_t, free, 68, 128); + CHECK_MEMBER_AT(alloc_device_t, dump, 72, 136); + CHECK_MEMBER_AT(alloc_device_t, reserved_proc, 76, 144); + + //Types defined in consumerir.h + CHECK_MEMBER_AT(consumerir_device_t, common, 0, 0); + CHECK_MEMBER_AT(consumerir_device_t, transmit, 64, 120); + CHECK_MEMBER_AT(consumerir_device_t, get_num_carrier_freqs, 68, 128); + CHECK_MEMBER_AT(consumerir_device_t, get_carrier_freqs, 72, 136); + CHECK_MEMBER_AT(consumerir_device_t, reserved, 76, 144); + + //Types defined in camera_common.h + CHECK_MEMBER_AT(vendor_tag_ops_t, get_tag_count, 0, 0); + CHECK_MEMBER_AT(vendor_tag_ops_t, get_all_tags, 4, 8); + CHECK_MEMBER_AT(vendor_tag_ops_t, get_section_name, 8, 16); + CHECK_MEMBER_AT(vendor_tag_ops_t, get_tag_name, 12, 24); + CHECK_MEMBER_AT(vendor_tag_ops_t, get_tag_type, 16, 32); + CHECK_MEMBER_AT(vendor_tag_ops_t, reserved, 20, 40); + + CHECK_MEMBER_AT(camera_module_t, common, 0, 0); + CHECK_MEMBER_AT(camera_module_t, get_number_of_cameras, 128, 248); + CHECK_MEMBER_AT(camera_module_t, get_camera_info, 132, 256); + CHECK_MEMBER_AT(camera_module_t, set_callbacks, 136, 264); + CHECK_MEMBER_AT(camera_module_t, get_vendor_tag_ops, 140, 272); + CHECK_MEMBER_AT(camera_module_t, reserved, 144, 280); + + //Types defined in camera3.h + CHECK_MEMBER_AT(camera3_device_ops_t, initialize, 0, 0); + CHECK_MEMBER_AT(camera3_device_ops_t, configure_streams, 4, 8); + CHECK_MEMBER_AT(camera3_device_ops_t, register_stream_buffers, 8, 16); + CHECK_MEMBER_AT(camera3_device_ops_t, construct_default_request_settings, 12, 24); + CHECK_MEMBER_AT(camera3_device_ops_t, process_capture_request, 16, 32); + CHECK_MEMBER_AT(camera3_device_ops_t, get_metadata_vendor_tag_ops, 20, 40); + CHECK_MEMBER_AT(camera3_device_ops_t, dump, 24, 48); + CHECK_MEMBER_AT(camera3_device_ops_t, flush, 28, 56); + CHECK_MEMBER_AT(camera3_device_ops_t, reserved, 32, 64); +} + 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>(); +} + |