mirror of
https://github.com/Mbed-TLS/mbedtls-framework.git
synced 2026-06-06 05:25:18 +00:00
Include <test/test_common.h> first in test code
This lets us define things that we want to have everywhere in test code. In particular, this lets us define platform-specific symbols that influence what system headers declare. This also takes care of including the library configuration. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
#ifndef TEST_ARGUMENTS_H
|
||||
#define TEST_ARGUMENTS_H
|
||||
|
||||
#include "mbedtls/build_info.h"
|
||||
#include "test_common.h"
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#ifndef ASN1_HELPERS_H
|
||||
#define ASN1_HELPERS_H
|
||||
|
||||
#include "test_common.h"
|
||||
#include "test/helpers.h"
|
||||
|
||||
/** Skip past an INTEGER in an ASN.1 buffer.
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
#ifndef BIGNUM_CODEPATH_CHECK_H
|
||||
#define BIGNUM_CODEPATH_CHECK_H
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
#include "bignum_core.h"
|
||||
|
||||
#if defined(MBEDTLS_TEST_HOOKS) && !defined(MBEDTLS_THREADING_C)
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#ifndef TEST_BIGNUM_HELPERS_H
|
||||
#define TEST_BIGNUM_HELPERS_H
|
||||
|
||||
#include <mbedtls/build_info.h>
|
||||
#include "test_common.h"
|
||||
|
||||
#if defined(MBEDTLS_BIGNUM_C)
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#ifndef TEST_CONSTANT_FLOW_H
|
||||
#define TEST_CONSTANT_FLOW_H
|
||||
|
||||
#include "mbedtls/build_info.h"
|
||||
#include "test_common.h"
|
||||
|
||||
/*
|
||||
* This file defines the two macros
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#ifndef FAKE_EXTERNAL_RNG_FOR_TEST_H
|
||||
#define FAKE_EXTERNAL_RNG_FOR_TEST_H
|
||||
|
||||
#include "mbedtls/build_info.h"
|
||||
#include "test_common.h"
|
||||
|
||||
#if defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
|
||||
/** Enable the insecure implementation of mbedtls_psa_external_get_random().
|
||||
|
||||
@@ -13,12 +13,7 @@
|
||||
#ifndef TEST_HELPERS_H
|
||||
#define TEST_HELPERS_H
|
||||
|
||||
/* Most fields of publicly available structs are private and are wrapped with
|
||||
* MBEDTLS_PRIVATE macro. This define allows tests to access the private fields
|
||||
* directly (without using the MBEDTLS_PRIVATE wrapper). */
|
||||
#define MBEDTLS_ALLOW_PRIVATE_ACCESS
|
||||
|
||||
#include "mbedtls/build_info.h"
|
||||
#include "test_common.h"
|
||||
|
||||
#if defined(__SANITIZE_ADDRESS__) /* gcc -fsanitize=address */
|
||||
# define MBEDTLS_TEST_HAVE_ASAN
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#ifndef TEST_MACROS_H
|
||||
#define TEST_MACROS_H
|
||||
|
||||
#include "mbedtls/build_info.h"
|
||||
#include "test_common.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
#ifndef TEST_MEMORY_H
|
||||
#define TEST_MEMORY_H
|
||||
|
||||
#include "mbedtls/build_info.h"
|
||||
#include "test_common.h"
|
||||
|
||||
#include "mbedtls/platform.h"
|
||||
#include "test/helpers.h"
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#ifndef PK_HELPERS_H
|
||||
#define PK_HELPERS_H
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
#if defined(MBEDTLS_PK_C)
|
||||
|
||||
#include <psa/crypto.h>
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#ifndef PSA_CRYPTO_HELPERS_H
|
||||
#define PSA_CRYPTO_HELPERS_H
|
||||
|
||||
#include "test_common.h"
|
||||
#include "test/helpers.h"
|
||||
|
||||
#if (MBEDTLS_VERSION_MAJOR < 4 && defined(MBEDTLS_PSA_CRYPTO_C)) || \
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#ifndef PSA_EXERCISE_KEY_H
|
||||
#define PSA_EXERCISE_KEY_H
|
||||
|
||||
#include "test_common.h"
|
||||
#include "test/helpers.h"
|
||||
#include "test/psa_crypto_helpers.h"
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#ifndef PSA_HELPERS_H
|
||||
#define PSA_HELPERS_H
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
#if defined(MBEDTLS_PSA_CRYPTO_SPM)
|
||||
#include "spm/psa_defs.h"
|
||||
#endif
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
#ifndef PSA_MEMORY_POISONING_WRAPPERS_H
|
||||
#define PSA_MEMORY_POISONING_WRAPPERS_H
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
#include "psa/crypto.h"
|
||||
|
||||
#include "test/memory.h"
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#ifndef TEST_RANDOM_H
|
||||
#define TEST_RANDOM_H
|
||||
|
||||
#include "mbedtls/build_info.h"
|
||||
#include "test_common.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* \file test_common.h
|
||||
*
|
||||
* \brief Common things for all Mbed TLS and TF-PSA-Crypto test code.
|
||||
*
|
||||
* Include this header first in all headers in `include/test/`.
|
||||
* Include this or another header from `include/test/` in all test C files.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright The Mbed TLS Contributors
|
||||
* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#ifndef TEST_TEST_COMMON_H
|
||||
#define TEST_TEST_COMMON_H
|
||||
|
||||
/* On Mingw-w64, force the use of a C99-compliant printf() and friends.
|
||||
* This is necessary on older versions of Mingw and/or Windows runtimes
|
||||
* where snprintf does not always zero-terminate the buffer, and does
|
||||
* not support formats such as "%zu" for size_t and "%lld" for long long.
|
||||
*/
|
||||
#if !defined(__USE_MINGW_ANSI_STDIO)
|
||||
#define __USE_MINGW_ANSI_STDIO 1
|
||||
#endif
|
||||
|
||||
#include <mbedtls/build_info.h>
|
||||
|
||||
/* Most fields of publicly available structs are private and are wrapped with
|
||||
* MBEDTLS_PRIVATE macro. This define allows tests to access the private fields
|
||||
* directly (without using the MBEDTLS_PRIVATE wrapper). */
|
||||
#define MBEDTLS_ALLOW_PRIVATE_ACCESS
|
||||
|
||||
#endif /* TEST_TEST_COMMON_H */
|
||||
@@ -13,18 +13,12 @@
|
||||
#ifndef THREADING_HELPERS_H
|
||||
#define THREADING_HELPERS_H
|
||||
|
||||
#include "mbedtls/private_access.h"
|
||||
#include "mbedtls/build_info.h"
|
||||
#include "test_common.h"
|
||||
|
||||
#if defined MBEDTLS_THREADING_C
|
||||
|
||||
#include <mbedtls/threading.h>
|
||||
|
||||
/* Most fields of publicly available structs are private and are wrapped with
|
||||
* MBEDTLS_PRIVATE macro. This define allows tests to access the private fields
|
||||
* directly (without using the MBEDTLS_PRIVATE wrapper). */
|
||||
#define MBEDTLS_ALLOW_PRIVATE_ACCESS
|
||||
|
||||
/* Error in thread management */
|
||||
#define MBEDTLS_ERR_THREADING_THREAD_ERROR -0x001F
|
||||
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#include <mbedtls/pk.h>
|
||||
#include <test/macros.h>
|
||||
#include <test/helpers.h>
|
||||
#include <test/pk_helpers.h>
|
||||
#include <test/psa_helpers.h>
|
||||
#include <test/test_keys.h>
|
||||
#include <mbedtls/pk.h>
|
||||
#include "psa_util_internal.h"
|
||||
|
||||
/* Functions like mbedtls_pk_wrap_psa() are only available in tf-psa-crypto and
|
||||
|
||||
Reference in New Issue
Block a user