From 5df77c63fba92d58c76161c959aa1db337db57c6 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Tue, 13 Jul 2021 17:22:58 +0200 Subject: [PATCH] Fix race condition when running generate_psa_tests.py Fix a race condition in parallel builds: when generating *.data files with generate_psa_tests.py, make instantiated the recipe once per output file, potentially resulting in multiple instances of generate_psa_tests.py running in parallel. This not only was inefficient, but occasionally caused the output to be corrupted (https://github.com/ARMmbed/mbedtls/issues/4773). Fix this by ensuring the recipe only runs once. Signed-off-by: Gilles Peskine --- tests/Makefile | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/tests/Makefile b/tests/Makefile index c1620d6e7..6695437bf 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -63,18 +63,25 @@ GENERATED_DATA_FILES := $(patsubst tests/%,%,$(shell $(PYTHON) scripts/generate_ GENERATED_FILES := $(GENERATED_DATA_FILES) generated_files: $(GENERATED_FILES) -$(GENERATED_DATA_FILES): scripts/generate_psa_tests.py +# generate_psa_tests.py spends more time analyzing inputs than generating +# outputs. Its inputs are the same no matter which files are being generated. +# It's rare not to want all the outputs. So always generate all of its outputs. +# Use an intermediate phony dependency so that parallel builds don't run +# a separate instance of the recipe for each output file. +.SECONDARY: generated_psa_test_data +$(GENERATED_DATA_FILES): generated_psa_test_data +generated_psa_test_data: scripts/generate_psa_tests.py ## The generated file only depends on the options that are present in ## crypto_config.h, not on which options are set. To avoid regenerating this ## file all the time when switching between configurations, don't declare ## crypto_config.h as a dependency. Remove this file from your working tree ## if you've just added or removed an option in crypto_config.h. -#$(GENERATED_DATA_FILES): ../include/psa/crypto_config.h -$(GENERATED_DATA_FILES): ../include/psa/crypto_values.h -$(GENERATED_DATA_FILES): ../include/psa/crypto_extra.h -$(GENERATED_DATA_FILES): suites/test_suite_psa_crypto_metadata.data -$(GENERATED_DATA_FILES): - echo " Gen $@ ..." +#generated_psa_test_data: ../include/psa/crypto_config.h +generated_psa_test_data: ../include/psa/crypto_values.h +generated_psa_test_data: ../include/psa/crypto_extra.h +generated_psa_test_data: suites/test_suite_psa_crypto_metadata.data +generated_psa_test_data: + echo " Gen $(GENERATED_DATA_FILES) ..." $(PYTHON) scripts/generate_psa_tests.py # A test application is built for each suites/test_suite_*.data file.