blob: 13d5b8b55449475fdb93285e834a4fbb188459cf [file] [log] [blame]
David Huea7f7ac2023-11-07 19:17:21 +08001#-------------------------------------------------------------------------------
2# Copyright (c) 2023, Arm Limited. All rights reserved.
3#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6#-------------------------------------------------------------------------------
7
Tomi Fontanillesd438e9b2024-05-15 12:36:50 +03008if(NOT CHECK_TFM_TESTS_VERSION)
9 return()
10endif()
11
David Huea7f7ac2023-11-07 19:17:21 +080012find_package(Git)
13
14execute_process(COMMAND "${GIT_EXECUTABLE}" status
15 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
16 RESULT_VARIABLE RET_VALUE
17 ERROR_QUIET OUTPUT_QUIET)
18if(NOT RET_VALUE EQUAL 0)
19 return()
20endif()
21
Tomi Fontanillesed49ce72024-05-15 12:26:50 +030022if(NOT DEFINED RECOMMENDED_TFM_TESTS_VERSION)
David Huea7f7ac2023-11-07 19:17:21 +080023 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.")
26endif()
27
28# Fetch the full HEAD commit ID
29execute_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.
36if(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()
41endif()
42
Tomi Fontanillesed49ce72024-05-15 12:26:50 +030043# Try to fetch the full commit ID of RECOMMENDED_TFM_TESTS_VERSION
David Huea7f7ac2023-11-07 19:17:21 +080044# If the recommended tf-m-test version is a tag, it outputs the corresponding commit ID
45# for comparison.
Tomi Fontanillesed49ce72024-05-15 12:26:50 +030046execute_process(COMMAND "${GIT_EXECUTABLE}" rev-parse ${RECOMMENDED_TFM_TESTS_VERSION}
David Huea7f7ac2023-11-07 19:17:21 +080047 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 Fontanillesed49ce72024-05-15 12:26:50 +030052# 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 Huea7f7ac2023-11-07 19:17:21 +080054if(RET_VALUE)
55 message(FATAL_ERROR
Tomi Fontanillesed49ce72024-05-15 12:26:50 +030056 " 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 Huea7f7ac2023-11-07 19:17:21 +080058 " Otherwise, tf-m-tests and TF-M can be incompatible.")
59endif()
60
61# Check if tf-m-tests HEAD == commit ID recommended by TF-M
62if("${HEAD_FULL_COMMIT}" STREQUAL "${RECOMMENDED_FULL_COMMIT}")
63 message(VERBOSE "tf-m-tests HEAD matches the version recommended by TF-M")
64 return()
65endif()
66
67# Check whether tf-m-tests commit ID recommended by TF-M is behind current tf-m-tests HEAD
Tomi Fontanillesed49ce72024-05-15 12:26:50 +030068execute_process(COMMAND "${GIT_EXECUTABLE}" merge-base --is-ancestor "${RECOMMENDED_TFM_TESTS_VERSION}" HEAD
David Huea7f7ac2023-11-07 19:17:21 +080069 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
73if(VERSION_FROM_TFM_IS_OLDER EQUAL 0)
74 message(WARNING
Tomi Fontanillesed49ce72024-05-15 12:26:50 +030075 " Current tf-m-tests HEAD is ahead of the version *${RECOMMENDED_TFM_TESTS_VERSION}* recommended by TF-M.\n"
David Huea7f7ac2023-11-07 19:17:21 +080076 " - 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 Fontanillesed49ce72024-05-15 12:26:50 +030079 " version *${RECOMMENDED_TFM_TESTS_VERSION}*.\n"
Nicola Mazzucatoa2282cb2025-02-07 14:52:43 +000080 " Build or tests might fail due to incompatible configurations.\n")
David Huea7f7ac2023-11-07 19:17:21 +080081 return()
82endif()
83
84# Check whether tf-m-tests commit ID recommended by TF-M is ahead of current tf-m-tests HEAD
Tomi Fontanillesed49ce72024-05-15 12:26:50 +030085execute_process(COMMAND "${GIT_EXECUTABLE}" merge-base --is-ancestor HEAD "${RECOMMENDED_TFM_TESTS_VERSION}"
David Huea7f7ac2023-11-07 19:17:21 +080086 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.
91if(VERSION_FROM_TFM_IS_NEWER EQUAL 0)
92 message(FATAL_ERROR
Tomi Fontanillesed49ce72024-05-15 12:26:50 +030093 " Current tf-m-tests HEAD is behind the version *${RECOMMENDED_TFM_TESTS_VERSION}* recommended by TF-M.\n"
David Huea7f7ac2023-11-07 19:17:21 +080094 " TF-M features might be not properly tested or covered by an older version of tf-m-tests.\n"
Tomi Fontanillesed49ce72024-05-15 12:26:50 +030095 " Please update tf-m-tests to version *${RECOMMENDED_TFM_TESTS_VERSION}* before verification.")
David Huea7f7ac2023-11-07 19:17:21 +080096endif()
97
98# The sequence of those 2 commits are unknown.
99# Not sure what has happened. Throw a warning to notify users.
100message(WARNING
Tomi Fontanillesed49ce72024-05-15 12:26:50 +0300101 " Current tf-m-tests HEAD is different from the version *${RECOMMENDED_TFM_TESTS_VERSION}* recommended by TF-M.\n"
David Huea7f7ac2023-11-07 19:17:21 +0800102 " You might be working on a development branch diverged from the main branch.\n"
Nicola Mazzucatoa2282cb2025-02-07 14:52:43 +0000103 " Build or tests might fail due to incompatible configurations.\n"
David Huea7f7ac2023-11-07 19:17:21 +0800104 " Suggest to rebase your commits on tf-m-tests main branch.\n")