David Hu | ea7f7ac | 2023-11-07 19:17:21 +0800 | [diff] [blame] | 1 | #------------------------------------------------------------------------------- |
| 2 | # Copyright (c) 2023, Arm Limited. All rights reserved. |
| 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
| 5 | # |
| 6 | #------------------------------------------------------------------------------- |
| 7 | |
| 8 | find_package(Git) |
| 9 | |
| 10 | execute_process(COMMAND "${GIT_EXECUTABLE}" status |
| 11 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} |
| 12 | RESULT_VARIABLE RET_VALUE |
| 13 | ERROR_QUIET OUTPUT_QUIET) |
| 14 | if(NOT RET_VALUE EQUAL 0) |
| 15 | return() |
| 16 | endif() |
| 17 | |
Tomi Fontanilles | ed49ce7 | 2024-05-15 12:26:50 +0300 | [diff] [blame^] | 18 | if(NOT DEFINED RECOMMENDED_TFM_TESTS_VERSION) |
David Hu | ea7f7ac | 2023-11-07 19:17:21 +0800 | [diff] [blame] | 19 | message(FATAL_ERROR |
| 20 | " Recommended tf-m-tests version of TF-M is unknown.\n" |
| 21 | " Please select tf-m-tests version specified in trusted-firmware-m/lib/ext/tf-m-tests/version.txt.") |
| 22 | endif() |
| 23 | |
| 24 | # Fetch the full HEAD commit ID |
| 25 | execute_process(COMMAND "${GIT_EXECUTABLE}" rev-parse HEAD |
| 26 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} |
| 27 | OUTPUT_VARIABLE HEAD_FULL_COMMIT |
| 28 | RESULT_VARIABLE RET_VALUE |
| 29 | OUTPUT_STRIP_TRAILING_WHITESPACE |
| 30 | ERROR_QUIET) |
| 31 | # Fail to fetch the current tf-m-tests HEAD commit ID. |
| 32 | if(RET_VALUE) |
| 33 | message(FATAL_ERROR |
| 34 | " Failed to fetch the current tf-m-tests HEAD.\n" |
| 35 | " Unable to check compatibility with TF-M.") |
| 36 | return() |
| 37 | endif() |
| 38 | |
Tomi Fontanilles | ed49ce7 | 2024-05-15 12:26:50 +0300 | [diff] [blame^] | 39 | # Try to fetch the full commit ID of RECOMMENDED_TFM_TESTS_VERSION |
David Hu | ea7f7ac | 2023-11-07 19:17:21 +0800 | [diff] [blame] | 40 | # If the recommended tf-m-test version is a tag, it outputs the corresponding commit ID |
| 41 | # for comparison. |
Tomi Fontanilles | ed49ce7 | 2024-05-15 12:26:50 +0300 | [diff] [blame^] | 42 | execute_process(COMMAND "${GIT_EXECUTABLE}" rev-parse ${RECOMMENDED_TFM_TESTS_VERSION} |
David Hu | ea7f7ac | 2023-11-07 19:17:21 +0800 | [diff] [blame] | 43 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} |
| 44 | OUTPUT_VARIABLE RECOMMENDED_FULL_COMMIT |
| 45 | RESULT_VARIABLE RET_VALUE |
| 46 | OUTPUT_STRIP_TRAILING_WHITESPACE |
| 47 | ERROR_QUIET) |
Tomi Fontanilles | ed49ce7 | 2024-05-15 12:26:50 +0300 | [diff] [blame^] | 48 | # Fail to fetch the whole commit ID of RECOMMENDED_TFM_TESTS_VERSION. |
| 49 | # tf-m-tests is not updated yet and therefore behind of RECOMMENDED_TFM_TESTS_VERSION |
David Hu | ea7f7ac | 2023-11-07 19:17:21 +0800 | [diff] [blame] | 50 | if(RET_VALUE) |
| 51 | message(FATAL_ERROR |
Tomi Fontanilles | ed49ce7 | 2024-05-15 12:26:50 +0300 | [diff] [blame^] | 52 | " Unknown recommended tf-m-tests version: ${RECOMMENDED_TFM_TESTS_VERSION}.\n" |
| 53 | " Please update local tf-m-tests repo and checkout version *${RECOMMENDED_TFM_TESTS_VERSION}*.\n" |
David Hu | ea7f7ac | 2023-11-07 19:17:21 +0800 | [diff] [blame] | 54 | " Otherwise, tf-m-tests and TF-M can be incompatible.") |
| 55 | endif() |
| 56 | |
| 57 | # Check if tf-m-tests HEAD == commit ID recommended by TF-M |
| 58 | if("${HEAD_FULL_COMMIT}" STREQUAL "${RECOMMENDED_FULL_COMMIT}") |
| 59 | message(VERBOSE "tf-m-tests HEAD matches the version recommended by TF-M") |
| 60 | return() |
| 61 | endif() |
| 62 | |
| 63 | # Check whether tf-m-tests commit ID recommended by TF-M is behind current tf-m-tests HEAD |
Tomi Fontanilles | ed49ce7 | 2024-05-15 12:26:50 +0300 | [diff] [blame^] | 64 | execute_process(COMMAND "${GIT_EXECUTABLE}" merge-base --is-ancestor "${RECOMMENDED_TFM_TESTS_VERSION}" HEAD |
David Hu | ea7f7ac | 2023-11-07 19:17:21 +0800 | [diff] [blame] | 65 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} |
| 66 | RESULT_VARIABLE VERSION_FROM_TFM_IS_OLDER |
| 67 | ERROR_QUIET OUTPUT_QUIET) |
| 68 | # Users are using a newer version of tf-m-tests to verify TF-M |
| 69 | if(VERSION_FROM_TFM_IS_OLDER EQUAL 0) |
| 70 | message(WARNING |
Tomi Fontanilles | ed49ce7 | 2024-05-15 12:26:50 +0300 | [diff] [blame^] | 71 | " Current tf-m-tests HEAD is ahead of the version *${RECOMMENDED_TFM_TESTS_VERSION}* recommended by TF-M.\n" |
David Hu | ea7f7ac | 2023-11-07 19:17:21 +0800 | [diff] [blame] | 72 | " - If you are developing in tf-m-tests, please update tf-m-tests commit ID in\n" |
| 73 | " trusted-firmware-m/lib/ext/version.txt and upload that change to trusted-firmware-m.\n" |
| 74 | " - If you are testing an older version of TF-M, please switch tf-m-tests to\n" |
Tomi Fontanilles | ed49ce7 | 2024-05-15 12:26:50 +0300 | [diff] [blame^] | 75 | " version *${RECOMMENDED_TFM_TESTS_VERSION}*.\n" |
David Hu | ea7f7ac | 2023-11-07 19:17:21 +0800 | [diff] [blame] | 76 | " Build or tests might fail due to incompatiable configurations.\n") |
| 77 | return() |
| 78 | endif() |
| 79 | |
| 80 | # Check whether tf-m-tests commit ID recommended by TF-M is ahead of current tf-m-tests HEAD |
Tomi Fontanilles | ed49ce7 | 2024-05-15 12:26:50 +0300 | [diff] [blame^] | 81 | execute_process(COMMAND "${GIT_EXECUTABLE}" merge-base --is-ancestor HEAD "${RECOMMENDED_TFM_TESTS_VERSION}" |
David Hu | ea7f7ac | 2023-11-07 19:17:21 +0800 | [diff] [blame] | 82 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} |
| 83 | RESULT_VARIABLE VERSION_FROM_TFM_IS_NEWER |
| 84 | ERROR_QUIET OUTPUT_QUIET) |
| 85 | # Users are using an out-of-date version of tf-m-tests to verify TF-M. |
| 86 | # Test coverage cannot be guaranteed. Block building in case that failures/defects are not detected. |
| 87 | if(VERSION_FROM_TFM_IS_NEWER EQUAL 0) |
| 88 | message(FATAL_ERROR |
Tomi Fontanilles | ed49ce7 | 2024-05-15 12:26:50 +0300 | [diff] [blame^] | 89 | " Current tf-m-tests HEAD is behind the version *${RECOMMENDED_TFM_TESTS_VERSION}* recommended by TF-M.\n" |
David Hu | ea7f7ac | 2023-11-07 19:17:21 +0800 | [diff] [blame] | 90 | " TF-M features might be not properly tested or covered by an older version of tf-m-tests.\n" |
Tomi Fontanilles | ed49ce7 | 2024-05-15 12:26:50 +0300 | [diff] [blame^] | 91 | " Please update tf-m-tests to version *${RECOMMENDED_TFM_TESTS_VERSION}* before verification.") |
David Hu | ea7f7ac | 2023-11-07 19:17:21 +0800 | [diff] [blame] | 92 | endif() |
| 93 | |
| 94 | # The sequence of those 2 commits are unknown. |
| 95 | # Not sure what has happened. Throw a warning to notify users. |
| 96 | message(WARNING |
Tomi Fontanilles | ed49ce7 | 2024-05-15 12:26:50 +0300 | [diff] [blame^] | 97 | " Current tf-m-tests HEAD is different from the version *${RECOMMENDED_TFM_TESTS_VERSION}* recommended by TF-M.\n" |
David Hu | ea7f7ac | 2023-11-07 19:17:21 +0800 | [diff] [blame] | 98 | " You might be working on a development branch diverged from the main branch.\n" |
| 99 | " Build or tests might fail due to incompatiable configurations.\n" |
| 100 | " Suggest to rebase your commits on tf-m-tests main branch.\n") |