From 02c78b78259a62e65f6b3fd25f342cf6d8ce2c03 Mon Sep 17 00:00:00 2001 From: Ronald Cron Date: Wed, 27 May 2020 09:22:32 +0200 Subject: [PATCH] tests: Create an include folder Create an include folder dedicated to include files for tests. With the upcoming work on tests for PSA crypto drivers the number of includes specific to tests is going to increase significantly thus create a dedicated folder. Don't put the include files in the include folder but in include/test folder. This way test headers can be included using a test/* path pattern as mbedtls and psa headers are included using an mbedtls/* and psa/* path pattern. This makes explicit the scope of the test headers. Move the existing includes for tests into include/test and update the code and build systems (make and cmake) accordingly. Signed-off-by: Ronald Cron --- tests/.gitignore | 2 +- tests/CMakeLists.txt | 2 +- tests/Makefile | 14 +++++++------- tests/{ => include/test}/psa_crypto_helpers.h | 2 +- tests/{ => include/test}/psa_helpers.h | 0 tests/suites/test_suite_cipher.function | 2 +- tests/suites/test_suite_pk.function | 2 +- tests/suites/test_suite_psa_crypto.function | 2 +- .../suites/test_suite_psa_crypto_entropy.function | 2 +- tests/suites/test_suite_psa_crypto_hash.function | 2 +- tests/suites/test_suite_psa_crypto_init.function | 2 +- .../test_suite_psa_crypto_persistent_key.function | 2 +- .../test_suite_psa_crypto_se_driver_hal.function | 2 +- ...t_suite_psa_crypto_se_driver_hal_mocks.function | 2 +- .../test_suite_psa_crypto_slot_management.function | 2 +- tests/suites/test_suite_psa_its.function | 2 +- 16 files changed, 21 insertions(+), 21 deletions(-) rename tests/{ => include/test}/psa_crypto_helpers.h (99%) rename tests/{ => include/test}/psa_helpers.h (100%) diff --git a/tests/.gitignore b/tests/.gitignore index fbbd0dfe2..805287eb2 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -8,4 +8,4 @@ data_files/hmac_drbg_seed data_files/ctr_drbg_seed data_files/entropy_seed -/instrument_record_status.h +include/test/instrument_record_status.h diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index bd5ed8328..cc5a9c67d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -46,7 +46,7 @@ function(add_test_suite suite_name) DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/scripts/generate_test_code.py mbedtls ${CMAKE_CURRENT_SOURCE_DIR}/suites/helpers.function ${CMAKE_CURRENT_SOURCE_DIR}/suites/main_test.function ${CMAKE_CURRENT_SOURCE_DIR}/suites/host_test.function ${CMAKE_CURRENT_SOURCE_DIR}/suites/test_suite_${suite_name}.function ${CMAKE_CURRENT_SOURCE_DIR}/suites/test_suite_${data_name}.data ) - include_directories(${CMAKE_CURRENT_SOURCE_DIR}) + include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) add_executable(test_suite_${data_name} test_suite_${data_name}.c) target_link_libraries(test_suite_${data_name} ${libs}) if(${data_name} MATCHES ${SKIP_TEST_SUITES_REGEX}) diff --git a/tests/Makefile b/tests/Makefile index e74bf9548..e027e127c 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -6,7 +6,7 @@ CFLAGS ?= -O2 WARNING_CFLAGS ?= -Wall -Wextra LDFLAGS ?= -LOCAL_CFLAGS = $(WARNING_CFLAGS) -I../include -I../library -D_FILE_OFFSET_BITS=64 +LOCAL_CFLAGS = $(WARNING_CFLAGS) -I./include -I../include -I../library -D_FILE_OFFSET_BITS=64 LOCAL_LDFLAGS = -L../library \ -lmbedtls$(SHARED_SUFFIX) \ -lmbedx509$(SHARED_SUFFIX) \ @@ -110,9 +110,9 @@ $(BINARIES): %$(EXEXT): %.c $(DEP) $(CC) $(LOCAL_CFLAGS) $(CFLAGS) $< $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ # Some test suites require additional header files. -$(filter test_suite_psa_crypto%, $(BINARIES)): psa_crypto_helpers.h +$(filter test_suite_psa_crypto%, $(BINARIES)): include/test/psa_crypto_helpers.h $(addprefix embedded_,$(filter test_suite_psa_crypto%, $(APPS))): embedded_%: TESTS/mbedtls/%/psa_crypto_helpers.h -$(filter test_suite_psa_%, $(BINARIES)): psa_helpers.h +$(filter test_suite_psa_%, $(BINARIES)): include/test/psa_helpers.h $(addprefix embedded_,$(filter test_suite_psa_%, $(APPS))): embedded_%: TESTS/mbedtls/%/psa_helpers.h clean: @@ -152,7 +152,7 @@ $(EMBEDDED_TESTS): embedded_%: suites/$$(firstword $$(subst ., ,$$*)).function s generate-target-tests: $(EMBEDDED_TESTS) define copy_header_to_target -TESTS/mbedtls/$(1)/$(2): $(2) +TESTS/mbedtls/$(1)/$(2): include/test/$(2) echo " Copy ./$$@" ifndef WINDOWS mkdir -p $$(@D) @@ -163,11 +163,11 @@ else endif endef -$(foreach app, $(APPS), $(foreach file, $(wildcard *.h), \ +$(foreach app, $(APPS), $(foreach file, $(notdir $(wildcard include/test/*.h)), \ $(eval $(call copy_header_to_target,$(app),$(file))))) ifdef RECORD_PSA_STATUS_COVERAGE_LOG -$(BINARIES): instrument_record_status.h -instrument_record_status.h: ../include/psa/crypto.h Makefile +$(BINARIES): include/test/instrument_record_status.h +include/test/instrument_record_status.h: ../include/psa/crypto.h Makefile sed <../include/psa/crypto.h >$@ -n 's/^psa_status_t \([A-Za-z0-9_]*\)(.*/#define \1(...) RECORD_STATUS("\1", \1(__VA_ARGS__))/p' endif diff --git a/tests/psa_crypto_helpers.h b/tests/include/test/psa_crypto_helpers.h similarity index 99% rename from tests/psa_crypto_helpers.h rename to tests/include/test/psa_crypto_helpers.h index 19303de57..1dd608433 100644 --- a/tests/psa_crypto_helpers.h +++ b/tests/include/test/psa_crypto_helpers.h @@ -22,7 +22,7 @@ #ifndef PSA_CRYPTO_HELPERS_H #define PSA_CRYPTO_HELPERS_H -#include "psa_helpers.h" +#include "test/psa_helpers.h" #include diff --git a/tests/psa_helpers.h b/tests/include/test/psa_helpers.h similarity index 100% rename from tests/psa_helpers.h rename to tests/include/test/psa_helpers.h diff --git a/tests/suites/test_suite_cipher.function b/tests/suites/test_suite_cipher.function index 8405f69c7..783407314 100644 --- a/tests/suites/test_suite_cipher.function +++ b/tests/suites/test_suite_cipher.function @@ -10,7 +10,7 @@ #endif #if defined(MBEDTLS_USE_PSA_CRYPTO) -#include "psa_crypto_helpers.h" +#include "test/psa_crypto_helpers.h" #endif /* END_HEADER */ diff --git a/tests/suites/test_suite_pk.function b/tests/suites/test_suite_pk.function index d88ca5454..a67cb4564 100644 --- a/tests/suites/test_suite_pk.function +++ b/tests/suites/test_suite_pk.function @@ -17,7 +17,7 @@ #if defined(MBEDTLS_USE_PSA_CRYPTO) #include "mbedtls/psa_util.h" -#include "psa_crypto_helpers.h" +#include "test/psa_crypto_helpers.h" #define PSA_INIT( ) PSA_ASSERT( psa_crypto_init( ) ) #else /* Define empty macros so that we can use them in the preamble and teardown diff --git a/tests/suites/test_suite_psa_crypto.function b/tests/suites/test_suite_psa_crypto.function index bc95f6fb0..ae4045c74 100644 --- a/tests/suites/test_suite_psa_crypto.function +++ b/tests/suites/test_suite_psa_crypto.function @@ -9,7 +9,7 @@ * uses mbedtls_ctr_drbg internally. */ #include "mbedtls/ctr_drbg.h" -#include "psa_crypto_helpers.h" +#include "test/psa_crypto_helpers.h" /* Tests that require more than 128kB of RAM plus change have this symbol * as a dependency. Currently we always define this symbol, so the tests diff --git a/tests/suites/test_suite_psa_crypto_entropy.function b/tests/suites/test_suite_psa_crypto_entropy.function index 8538d6d8d..66c241e5e 100644 --- a/tests/suites/test_suite_psa_crypto_entropy.function +++ b/tests/suites/test_suite_psa_crypto_entropy.function @@ -4,7 +4,7 @@ #include "mbedtls/entropy.h" #include "mbedtls/entropy_poll.h" -#include "psa_crypto_helpers.h" +#include "test/psa_crypto_helpers.h" #if defined(MBEDTLS_PSA_ITS_FILE_C) #include #else diff --git a/tests/suites/test_suite_psa_crypto_hash.function b/tests/suites/test_suite_psa_crypto_hash.function index d50ff5ad2..6c577c06a 100644 --- a/tests/suites/test_suite_psa_crypto_hash.function +++ b/tests/suites/test_suite_psa_crypto_hash.function @@ -2,7 +2,7 @@ #include -#include "psa_crypto_helpers.h" +#include "test/psa_crypto_helpers.h" /* END_HEADER */ diff --git a/tests/suites/test_suite_psa_crypto_init.function b/tests/suites/test_suite_psa_crypto_init.function index 3283ac9f6..fd4ff21fc 100644 --- a/tests/suites/test_suite_psa_crypto_init.function +++ b/tests/suites/test_suite_psa_crypto_init.function @@ -1,7 +1,7 @@ /* BEGIN_HEADER */ #include -#include "psa_crypto_helpers.h" +#include "test/psa_crypto_helpers.h" /* Some tests in this module configure entropy sources. */ #include "psa_crypto_invasive.h" diff --git a/tests/suites/test_suite_psa_crypto_persistent_key.function b/tests/suites/test_suite_psa_crypto_persistent_key.function index e2d87efd8..49ce964fb 100644 --- a/tests/suites/test_suite_psa_crypto_persistent_key.function +++ b/tests/suites/test_suite_psa_crypto_persistent_key.function @@ -9,7 +9,7 @@ #include -#include "psa_crypto_helpers.h" +#include "test/psa_crypto_helpers.h" #include "psa_crypto_storage.h" #include "mbedtls/md.h" diff --git a/tests/suites/test_suite_psa_crypto_se_driver_hal.function b/tests/suites/test_suite_psa_crypto_se_driver_hal.function index f95f7e526..9f44b884b 100644 --- a/tests/suites/test_suite_psa_crypto_se_driver_hal.function +++ b/tests/suites/test_suite_psa_crypto_se_driver_hal.function @@ -1,5 +1,5 @@ /* BEGIN_HEADER */ -#include "psa_crypto_helpers.h" +#include "test/psa_crypto_helpers.h" #include "psa/crypto_se_driver.h" #include "psa_crypto_se.h" diff --git a/tests/suites/test_suite_psa_crypto_se_driver_hal_mocks.function b/tests/suites/test_suite_psa_crypto_se_driver_hal_mocks.function index f6acb0727..ef50a6814 100644 --- a/tests/suites/test_suite_psa_crypto_se_driver_hal_mocks.function +++ b/tests/suites/test_suite_psa_crypto_se_driver_hal_mocks.function @@ -1,5 +1,5 @@ /* BEGIN_HEADER */ -#include "psa_crypto_helpers.h" +#include "test/psa_crypto_helpers.h" #include "psa/crypto_se_driver.h" #include "psa_crypto_se.h" diff --git a/tests/suites/test_suite_psa_crypto_slot_management.function b/tests/suites/test_suite_psa_crypto_slot_management.function index 4c824f7de..a9c7f0459 100644 --- a/tests/suites/test_suite_psa_crypto_slot_management.function +++ b/tests/suites/test_suite_psa_crypto_slot_management.function @@ -1,7 +1,7 @@ /* BEGIN_HEADER */ #include -#include "psa_crypto_helpers.h" +#include "test/psa_crypto_helpers.h" #include "psa_crypto_storage.h" typedef enum diff --git a/tests/suites/test_suite_psa_its.function b/tests/suites/test_suite_psa_its.function index 04a735a29..b6cc488a6 100644 --- a/tests/suites/test_suite_psa_its.function +++ b/tests/suites/test_suite_psa_its.function @@ -7,7 +7,7 @@ #include "../library/psa_crypto_its.h" -#include "psa_helpers.h" +#include "test/psa_helpers.h" /* Internal definitions of the implementation, copied for the sake of * some of the tests and of the cleanup code. */