diff options
author | dmichael@google.com <dmichael@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-13 20:04:31 +0000 |
---|---|---|
committer | dmichael@google.com <dmichael@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-13 20:04:31 +0000 |
commit | 1ad2a1dbcde42412bb92c83fe5e0d6999ed00311 (patch) | |
tree | bec94376d42b1943e2830e695956252232283b4d /ppapi/tests | |
parent | f68fbd1b300401c79df8df9773bbe7aa36ff6062 (diff) | |
download | chromium_src-1ad2a1dbcde42412bb92c83fe5e0d6999ed00311.zip chromium_src-1ad2a1dbcde42412bb92c83fe5e0d6999ed00311.tar.gz chromium_src-1ad2a1dbcde42412bb92c83fe5e0d6999ed00311.tar.bz2 |
Add compile assertions to enforce the sizes of all structs and enums in the C API. Adjust some structs to make their sizes consistent across architectures. Note that some structs contain pointers, so are difficult to make consistent between 32-bit and 64-bit. Those types are in test_struct_sizes.c. Other types have a compile assertion immediately after their definition.
This was broken off from a bigger CL:
http://codereview.chromium.org/5340003/
BUG=61004,92983
TEST=test_struct_sizes.c, compile assertions throughout
See this CL for the code that helped generate the static assertions and find affected interfaces:
http://codereview.chromium.org/5730003
Review URL: http://codereview.chromium.org/5674004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@69038 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/tests')
-rw-r--r-- | ppapi/tests/all_c_includes.h | 79 | ||||
-rw-r--r-- | ppapi/tests/all_cpp_includes.h (renamed from ppapi/tests/test_cc_includes.cc) | 6 | ||||
-rw-r--r-- | ppapi/tests/arch_dependent_sizes_32.h | 31 | ||||
-rw-r--r-- | ppapi/tests/arch_dependent_sizes_64.h | 31 | ||||
-rw-r--r-- | ppapi/tests/test_c_includes.c | 73 | ||||
-rw-r--r-- | ppapi/tests/test_cpp_includes.cc | 10 | ||||
-rw-r--r-- | ppapi/tests/test_struct_sizes.c | 28 |
7 files changed, 188 insertions, 70 deletions
diff --git a/ppapi/tests/all_c_includes.h b/ppapi/tests/all_c_includes.h new file mode 100644 index 0000000..5f337db --- /dev/null +++ b/ppapi/tests/all_c_includes.h @@ -0,0 +1,79 @@ +/* Copyright (c) 2010 The Chromium Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + * + * This test simply includes all the C headers to ensure they compile with a C + * compiler. If it compiles, it passes. + */ +#ifndef PPAPI_TESTS_ALL_C_INCLUDES_H_ +#define PPAPI_TESTS_ALL_C_INCLUDES_H_ + +#include "ppapi/c/dev/deprecated_bool.h" +#include "ppapi/c/dev/pp_cursor_type_dev.h" +#include "ppapi/c/dev/pp_file_info_dev.h" +#include "ppapi/c/dev/pp_video_dev.h" +#include "ppapi/c/dev/ppb_audio_config_dev.h" +#include "ppapi/c/dev/ppb_audio_dev.h" +#include "ppapi/c/dev/ppb_audio_trusted_dev.h" +#include "ppapi/c/dev/ppb_buffer_dev.h" +#include "ppapi/c/dev/ppb_char_set_dev.h" +#include "ppapi/c/dev/ppb_cursor_control_dev.h" +#include "ppapi/c/dev/ppb_directory_reader_dev.h" +#include "ppapi/c/dev/ppb_file_chooser_dev.h" +#include "ppapi/c/dev/ppb_file_io_dev.h" +#include "ppapi/c/dev/ppb_file_io_trusted_dev.h" +#include "ppapi/c/dev/ppb_file_ref_dev.h" +#include "ppapi/c/dev/ppb_file_system_dev.h" +#include "ppapi/c/dev/ppb_find_dev.h" +#include "ppapi/c/dev/ppb_font_dev.h" +#include "ppapi/c/dev/ppb_fullscreen_dev.h" +#include "ppapi/c/dev/ppb_graphics_3d_dev.h" +#include "ppapi/c/dev/ppb_opengles_dev.h" +#include "ppapi/c/dev/ppb_scrollbar_dev.h" +#include "ppapi/c/dev/ppb_testing_dev.h" +#include "ppapi/c/dev/ppb_transport_dev.h" +#include "ppapi/c/dev/ppb_url_util_dev.h" +#include "ppapi/c/dev/ppb_var_deprecated.h" +#include "ppapi/c/dev/ppb_video_decoder_dev.h" +#include "ppapi/c/dev/ppb_widget_dev.h" +#include "ppapi/c/dev/ppb_zoom_dev.h" +#include "ppapi/c/dev/ppp_class_deprecated.h" +#include "ppapi/c/dev/ppp_cursor_control_dev.h" +#include "ppapi/c/dev/ppp_find_dev.h" +#include "ppapi/c/dev/ppp_graphics_3d_dev.h" +#include "ppapi/c/dev/ppp_printing_dev.h" +#include "ppapi/c/dev/ppp_scrollbar_dev.h" +#include "ppapi/c/dev/ppp_selection_dev.h" +#include "ppapi/c/dev/ppp_widget_dev.h" +#include "ppapi/c/dev/ppp_zoom_dev.h" +#include "ppapi/c/pp_bool.h" +#include "ppapi/c/pp_completion_callback.h" +#include "ppapi/c/pp_errors.h" +#include "ppapi/c/pp_input_event.h" +#include "ppapi/c/pp_instance.h" +#include "ppapi/c/pp_macros.h" +#include "ppapi/c/pp_module.h" +#include "ppapi/c/pp_point.h" +#include "ppapi/c/pp_rect.h" +#include "ppapi/c/pp_resource.h" +#include "ppapi/c/pp_size.h" +#include "ppapi/c/pp_stdint.h" +#include "ppapi/c/pp_time.h" +#include "ppapi/c/pp_var.h" +#include "ppapi/c/ppb.h" +#include "ppapi/c/ppb_class.h" +#include "ppapi/c/ppb_core.h" +#include "ppapi/c/ppb_graphics_2d.h" +#include "ppapi/c/ppb_image_data.h" +#include "ppapi/c/ppb_instance.h" +#include "ppapi/c/ppb_url_loader.h" +#include "ppapi/c/ppb_url_request_info.h" +#include "ppapi/c/ppb_url_response_info.h" +#include "ppapi/c/ppb_var.h" +#include "ppapi/c/ppp.h" +#include "ppapi/c/ppp_instance.h" +#include "ppapi/c/trusted/ppb_image_data_trusted.h" +#include "ppapi/c/trusted/ppb_url_loader_trusted.h" + +#endif /* PPAPI_TESTS_ALL_C_INCLUDES_H_ */ + diff --git a/ppapi/tests/test_cc_includes.cc b/ppapi/tests/all_cpp_includes.h index 1e76230..b9e634a 100644 --- a/ppapi/tests/test_cc_includes.cc +++ b/ppapi/tests/all_cpp_includes.h @@ -1,4 +1,3 @@ - // Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -6,6 +5,9 @@ // This test simply includes all the C++ headers to ensure they compile with a // C++ compiler. If it compiles, it passes. // +#ifndef PPAPI_TESTS_ALL_CPP_INCLUDES_H_ +#define PPAPI_TESTS_ALL_CPP_INCLUDES_H_ + #include "ppapi/cpp/common.h" #include "ppapi/cpp/completion_callback.h" #include "ppapi/cpp/core.h" @@ -51,3 +53,5 @@ #include "ppapi/cpp/url_response_info.h" #include "ppapi/cpp/var.h" +#endif // PPAPI_TESTS_ALL_CPP_INCLUDES_H_ + diff --git a/ppapi/tests/arch_dependent_sizes_32.h b/ppapi/tests/arch_dependent_sizes_32.h new file mode 100644 index 0000000..971279c --- /dev/null +++ b/ppapi/tests/arch_dependent_sizes_32.h @@ -0,0 +1,31 @@ +/* Copyright (c) 2010 The Chromium Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + * + * This file has compile assertions for the sizes of types that are dependent + * on the architecture for which they are compiled (i.e., 32-bit vs 64-bit). + */ + +#ifndef PPAPI_TESTS_ARCH_DEPENDENT_SIZES_32_H_ +#define PPAPI_TESTS_ARCH_DEPENDENT_SIZES_32_H_ + +#include "ppapi/tests/test_struct_sizes.c" + +PP_COMPILE_ASSERT_SIZE_IN_BYTES(GLintptr, 4); +PP_COMPILE_ASSERT_SIZE_IN_BYTES(GLsizeiptr, 4); +PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_ClassDestructor, 4); +PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_ClassFunction, 4); +PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_CompletionCallback_Func, 4); +PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_URLLoaderTrusted_StatusCallback, 4); +PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_VideoConfig_Dev, 4); +PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_VideoDecodeEventHandler_Func_Dev, 4); +PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_VideoDecodeInputCallback_Func_Dev, 4); +PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_VideoDecodeOutputCallback_Func_Dev, 4); +PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_ClassProperty, 20); +PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_CompletionCallback, 8); +PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_FileChooserOptions_Dev, 8); +PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_VideoDecoderConfig_Dev, 20); +PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_VideoFrameBuffer_Dev, 112); +PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_VideoUncompressedDataBuffer_Dev, 136); + +#endif /* PPAPI_TESTS_ARCH_DEPENDENT_SIZES_32_H_ */ diff --git a/ppapi/tests/arch_dependent_sizes_64.h b/ppapi/tests/arch_dependent_sizes_64.h new file mode 100644 index 0000000..e70b420 --- /dev/null +++ b/ppapi/tests/arch_dependent_sizes_64.h @@ -0,0 +1,31 @@ +/* Copyright (c) 2010 The Chromium Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + * + * This file has compile assertions for the sizes of types that are dependent + * on the architecture for which they are compiled (i.e., 32-bit vs 64-bit). + */ + +#ifndef PPAPI_TESTS_ARCH_DEPENDENT_SIZES_64_H_ +#define PPAPI_TESTS_ARCH_DEPENDENT_SIZES_64_H_ + +#include "ppapi/tests/test_struct_sizes.c" + +PP_COMPILE_ASSERT_SIZE_IN_BYTES(GLintptr, 8); +PP_COMPILE_ASSERT_SIZE_IN_BYTES(GLsizeiptr, 8); +PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_ClassDestructor, 8); +PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_ClassFunction, 8); +PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_CompletionCallback_Func, 8); +PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_URLLoaderTrusted_StatusCallback, 8); +PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_VideoConfig_Dev, 8); +PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_VideoDecodeEventHandler_Func_Dev, 8); +PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_VideoDecodeInputCallback_Func_Dev, 8); +PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_VideoDecodeOutputCallback_Func_Dev, 8); +PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_ClassProperty, 40); +PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_CompletionCallback, 16); +PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_FileChooserOptions_Dev, 16); +PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_VideoDecoderConfig_Dev, 40); +PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_VideoFrameBuffer_Dev, 120); +PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_VideoUncompressedDataBuffer_Dev, 152); + +#endif /* PPAPI_TESTS_ARCH_DEPENDENT_SIZES_64_H_ */ diff --git a/ppapi/tests/test_c_includes.c b/ppapi/tests/test_c_includes.c index c54b427..dda6ac3 100644 --- a/ppapi/tests/test_c_includes.c +++ b/ppapi/tests/test_c_includes.c @@ -1,75 +1,10 @@ - /* Copyright (c) 2010 The Chromium Authors. All rights reserved. * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. * - * This test simply includes all the C headers to ensure they compile with a C - * compiler. If it compiles, it passes. + * This test simply includes all the C headers to ensure they compile with a + * C compiler. If it compiles, it passes. */ -#include "ppapi/c/dev/deprecated_bool.h" -#include "ppapi/c/dev/pp_cursor_type_dev.h" -#include "ppapi/c/dev/pp_file_info_dev.h" -#include "ppapi/c/dev/pp_video_dev.h" -#include "ppapi/c/dev/ppb_audio_config_dev.h" -#include "ppapi/c/dev/ppb_audio_dev.h" -#include "ppapi/c/dev/ppb_audio_trusted_dev.h" -#include "ppapi/c/dev/ppb_buffer_dev.h" -#include "ppapi/c/dev/ppb_char_set_dev.h" -#include "ppapi/c/dev/ppb_cursor_control_dev.h" -#include "ppapi/c/dev/ppb_directory_reader_dev.h" -#include "ppapi/c/dev/ppb_file_chooser_dev.h" -#include "ppapi/c/dev/ppb_file_io_dev.h" -#include "ppapi/c/dev/ppb_file_io_trusted_dev.h" -#include "ppapi/c/dev/ppb_file_ref_dev.h" -#include "ppapi/c/dev/ppb_file_system_dev.h" -#include "ppapi/c/dev/ppb_find_dev.h" -#include "ppapi/c/dev/ppb_font_dev.h" -#include "ppapi/c/dev/ppb_fullscreen_dev.h" -#include "ppapi/c/dev/ppb_graphics_3d_dev.h" -#include "ppapi/c/dev/ppb_opengles_dev.h" -#include "ppapi/c/dev/ppb_scrollbar_dev.h" -#include "ppapi/c/dev/ppb_testing_dev.h" -#include "ppapi/c/dev/ppb_transport_dev.h" -#include "ppapi/c/dev/ppb_url_util_dev.h" -#include "ppapi/c/dev/ppb_var_deprecated.h" -#include "ppapi/c/dev/ppb_video_decoder_dev.h" -#include "ppapi/c/dev/ppb_widget_dev.h" -#include "ppapi/c/dev/ppb_zoom_dev.h" -#include "ppapi/c/dev/ppp_class_deprecated.h" -#include "ppapi/c/dev/ppp_cursor_control_dev.h" -#include "ppapi/c/dev/ppp_find_dev.h" -#include "ppapi/c/dev/ppp_graphics_3d_dev.h" -#include "ppapi/c/dev/ppp_printing_dev.h" -#include "ppapi/c/dev/ppp_scrollbar_dev.h" -#include "ppapi/c/dev/ppp_selection_dev.h" -#include "ppapi/c/dev/ppp_widget_dev.h" -#include "ppapi/c/dev/ppp_zoom_dev.h" -#include "ppapi/c/pp_bool.h" -#include "ppapi/c/pp_completion_callback.h" -#include "ppapi/c/pp_errors.h" -#include "ppapi/c/pp_input_event.h" -#include "ppapi/c/pp_instance.h" -#include "ppapi/c/pp_macros.h" -#include "ppapi/c/pp_module.h" -#include "ppapi/c/pp_point.h" -#include "ppapi/c/pp_rect.h" -#include "ppapi/c/pp_resource.h" -#include "ppapi/c/pp_size.h" -#include "ppapi/c/pp_stdint.h" -#include "ppapi/c/pp_time.h" -#include "ppapi/c/pp_var.h" -#include "ppapi/c/ppb.h" -#include "ppapi/c/ppb_class.h" -#include "ppapi/c/ppb_core.h" -#include "ppapi/c/ppb_graphics_2d.h" -#include "ppapi/c/ppb_image_data.h" -#include "ppapi/c/ppb_instance.h" -#include "ppapi/c/ppb_url_loader.h" -#include "ppapi/c/ppb_url_request_info.h" -#include "ppapi/c/ppb_url_response_info.h" -#include "ppapi/c/ppb_var.h" -#include "ppapi/c/ppp.h" -#include "ppapi/c/ppp_instance.h" -#include "ppapi/c/trusted/ppb_image_data_trusted.h" -#include "ppapi/c/trusted/ppb_url_loader_trusted.h" + +#include "ppapi/tests/all_c_includes.h" diff --git a/ppapi/tests/test_cpp_includes.cc b/ppapi/tests/test_cpp_includes.cc new file mode 100644 index 0000000..080a152 --- /dev/null +++ b/ppapi/tests/test_cpp_includes.cc @@ -0,0 +1,10 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// +// This test simply includes all the C++ headers to ensure they compile with a +// C++ compiler. If it compiles, it passes. +// + +#include "ppapi/tests/all_cpp_includes.h" + diff --git a/ppapi/tests/test_struct_sizes.c b/ppapi/tests/test_struct_sizes.c new file mode 100644 index 0000000..238a269f --- /dev/null +++ b/ppapi/tests/test_struct_sizes.c @@ -0,0 +1,28 @@ +/* Copyright (c) 2010 The Chromium Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + * + * This test ensures (at compile time) that some types have the expected size in + * C. The purpose is to ensure that the ABI of PPAPI is known, consistent, and + * stable. Only structs that have architecture-dependent size are checked by + * this test. These structs use at least one type which differs in size between + * 64-bit and 32-bit (e.g. pointers or long). By convention, we require other + * types to be of consistent size on 32-bit and 64-bit architectures. + */ + +#include "ppapi/tests/all_c_includes.h" + +#if !defined(__native_client__) && (defined(_M_X64) || defined(__x86_64__)) +/* This section is for 64-bit compilation on Windows, Mac, and Linux. Native + client follows ILP32 even if -m64 is used, so NaCl code is explicitly treated + as 32-bit. This means pointers are always 4 bytes in native client, and it + matches Win32 (see below). + */ +#include "ppapi/tests/arch_dependent_sizes_64.h" +#else +/* This section is for compilation on 32-bit targets plus native client (in both + 32-bit and 64-bit mode, since native client always conforms to ILP32). + */ +#include "ppapi/tests/arch_dependent_sizes_32.h" +#endif + |