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