109109# means that components can assume that the working directory is in a
110110# cleaned-up state, and don't need to perform the cleanup themselves.
111111# * Run `make clean`.
112- # * Restore `include/mbedtls/mbedtls_config.h` from a backup made before running
113- # the component.
114- # * Check out `Makefile`, `library/Makefile`, `programs/Makefile`,
115- # `tests/Makefile` and `programs/fuzz/Makefile` from git.
116- # This cleans up after an in-tree use of CMake.
112+ # * Restore the various config files (potentially modified by config.py) from
113+ # a backup made when starting the script.
114+ # * If in Mbed TLS, restore the various `Makefile`s (potentially modified by
115+ # in-tree use of CMake) from a backup made when starting the script. (Note:
116+ # if the files look generated when starting the script, they will be
117+ # restored from the git index before making the backup.)
117118
118119
119120# ###############################################################
@@ -156,15 +157,16 @@ pre_check_environment () {
156157# Must be called before pre_initialize_variables which sets ALL_COMPONENTS.
157158pre_load_components () {
158159 # Include the components from components.sh
159- test_script_dir= " ${0 %/* } "
160- for file in " $test_script_dir " /components-* .sh; do
160+ # Use a path relative to the current directory, aka project's root.
161+ for file in tests/scripts /components-* .sh; do
161162 source $file
162163 done
163164}
164165
165166pre_initialize_variables () {
166167 if in_mbedtls_repo; then
167168 CONFIG_H=' include/mbedtls/mbedtls_config.h'
169+ CONFIG_TEST_DRIVER_H=' tests/include/test/drivers/config_test_driver.h'
168170 if [ -d tf-psa-crypto ]; then
169171 CRYPTO_CONFIG_H=' tf-psa-crypto/include/psa/crypto_config.h'
170172 PSA_CORE_PATH=' tf-psa-crypto/core'
@@ -176,20 +178,21 @@ pre_initialize_variables () {
176178 PSA_CORE_PATH=' '
177179 BUILTIN_SRC_PATH=' '
178180 fi
181+ config_files=" $CONFIG_H $CRYPTO_CONFIG_H $CONFIG_TEST_DRIVER_H "
179182 else
180- CONFIG_H=' drivers/builtin/include/mbedtls/mbedtls_config.h'
181183 CRYPTO_CONFIG_H=' include/psa/crypto_config.h'
182184 PSA_CORE_PATH=' core'
183185 BUILTIN_SRC_PATH=' drivers/builtin/src'
186+
187+ config_files=" $CRYPTO_CONFIG_H "
184188 fi
185- CONFIG_TEST_DRIVER_H=' tests/include/test/drivers/config_test_driver.h'
186189
187190 # Files that are clobbered by some jobs will be backed up. Use a different
188191 # suffix from auxiliary scripts so that all.sh and auxiliary scripts can
189192 # independently decide when to remove the backup file.
190193 backup_suffix=' .all.bak'
191194 # Files clobbered by config.py
192- files_to_back_up=" $CONFIG_H $CRYPTO_CONFIG_H $CONFIG_TEST_DRIVER_H "
195+ files_to_back_up=" $config_files "
193196 if in_mbedtls_repo; then
194197 # Files clobbered by in-tree cmake
195198 files_to_back_up=" $files_to_back_up Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile"
@@ -623,7 +626,7 @@ pre_parse_command_line () {
623626pre_check_git () {
624627 if [ $FORCE -eq 1 ]; then
625628 rm -rf " $OUT_OF_SOURCE_DIR "
626- git checkout-index -f -q $CONFIG_H
629+ git checkout-index -f -q $config_files
627630 cleanup
628631 else
629632
@@ -634,12 +637,14 @@ pre_check_git () {
634637 exit 1
635638 fi
636639
637- if ! git diff --quiet " $CONFIG_H " ; then
638- err_msg " Warning - the configuration file '$CONFIG_H ' has been edited. "
639- echo " You can either delete or preserve your work, or force the test by rerunning the"
640- echo " script as: $0 --force"
641- exit 1
642- fi
640+ for config in $config_files ; do
641+ if ! git diff --quiet " $config " ; then
642+ err_msg " Warning - the configuration file '$config ' has been edited. "
643+ echo " You can either delete or preserve your work, or force the test by rerunning the"
644+ echo " script as: $0 --force"
645+ exit 1
646+ fi
647+ done
643648 fi
644649}
645650
@@ -866,7 +871,8 @@ pre_check_tools () {
866871 set " $@ " ARMC6_CC=" $ARMC6_CC " RUN_ARMCC=1;;
867872 * ) set " $@ " RUN_ARMCC=0;;
868873 esac
869- " $@ " scripts/output_env.sh
874+ # Use a path relative to the currently-sourced file.
875+ " $@ " " ${BASH_SOURCE%/* } " /../../scripts/output_env.sh
870876}
871877
872878pre_generate_files () {
@@ -881,8 +887,8 @@ pre_generate_files() {
881887}
882888
883889pre_load_helpers () {
884- # The path is going to change when this is moved to the framework
885- test_script_dir=" ${0 %/* } "
890+ # Use a path relative to the currently-sourced file.
891+ test_script_dir=" ${BASH_SOURCE %/* } "
886892 source " $test_script_dir " /all-helpers.sh
887893}
888894
0 commit comments