blob: 4f9f34a2fc4747b568fd073eaafb395670005132 [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
8find_package(Git)
9
10execute_process(COMMAND "${GIT_EXECUTABLE}" status
11 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
12 RESULT_VARIABLE RET_VALUE
13 ERROR_QUIET OUTPUT_QUIET)
14if(NOT RET_VALUE EQUAL 0)
15 return()
16endif()
17
Tomi Fontanillesed49ce72024-05-15 12:26:50 +030018if(NOT DEFINED RECOMMENDED_TFM_TESTS_VERSION)
David Huea7f7ac2023-11-07 19:17:21 +080019 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.")
22endif()
23
24# Fetch the full HEAD commit ID
25execute_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.
32if(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()
37endif()
38
Tomi Fontanillesed49ce72024-05-15 12:26:50 +030039# Try to fetch the full commit ID of RECOMMENDED_TFM_TESTS_VERSION
David Huea7f7ac2023-11-07 19:17:21 +080040# If the recommended tf-m-test version is a tag, it outputs the corresponding commit ID
41# for comparison.
Tomi Fontanillesed49ce72024-05-15 12:26:50 +030042execute_process(COMMAND "${GIT_EXECUTABLE}" rev-parse ${RECOMMENDED_TFM_TESTS_VERSION}
David Huea7f7ac2023-11-07 19:17:21 +080043 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 Fontanillesed49ce72024-05-15 12:26:50 +030048# 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 Huea7f7ac2023-11-07 19:17:21 +080050if(RET_VALUE)
51 message(FATAL_ERROR
Tomi Fontanillesed49ce72024-05-15 12:26:50 +030052 " 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 Huea7f7ac2023-11-07 19:17:21 +080054 " Otherwise, tf-m-tests and TF-M can be incompatible.")
55endif()
56
57# Check if tf-m-tests HEAD == commit ID recommended by TF-M
58if("${HEAD_FULL_COMMIT}" STREQUAL "${RECOMMENDED_FULL_COMMIT}")
59 message(VERBOSE "tf-m-tests HEAD matches the version recommended by TF-M")
60 return()
61endif()
62
63# 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 +030064execute_process(COMMAND "${GIT_EXECUTABLE}" merge-base --is-ancestor "${RECOMMENDED_TFM_TESTS_VERSION}" HEAD
David Huea7f7ac2023-11-07 19:17:21 +080065 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
69if(VERSION_FROM_TFM_IS_OLDER EQUAL 0)
70 message(WARNING
Tomi Fontanillesed49ce72024-05-15 12:26:50 +030071 " 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 +080072 " - 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 Fontanillesed49ce72024-05-15 12:26:50 +030075 " version *${RECOMMENDED_TFM_TESTS_VERSION}*.\n"
David Huea7f7ac2023-11-07 19:17:21 +080076 " Build or tests might fail due to incompatiable configurations.\n")
77 return()
78endif()
79
80# 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 +030081execute_process(COMMAND "${GIT_EXECUTABLE}" merge-base --is-ancestor HEAD "${RECOMMENDED_TFM_TESTS_VERSION}"
David Huea7f7ac2023-11-07 19:17:21 +080082 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.
87if(VERSION_FROM_TFM_IS_NEWER EQUAL 0)
88 message(FATAL_ERROR
Tomi Fontanillesed49ce72024-05-15 12:26:50 +030089 " 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 +080090 " 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 +030091 " Please update tf-m-tests to version *${RECOMMENDED_TFM_TESTS_VERSION}* before verification.")
David Huea7f7ac2023-11-07 19:17:21 +080092endif()
93
94# The sequence of those 2 commits are unknown.
95# Not sure what has happened. Throw a warning to notify users.
96message(WARNING
Tomi Fontanillesed49ce72024-05-15 12:26:50 +030097 " 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 +080098 " 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")