blob: e3164e257c16f456a226ea52bfd5435f6a0daf2f [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
18if(NOT DEFINED RECOMMEND_TFM_TESTS_VERSION)
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.")
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
39# Try to fetch the full commit ID of RECOMMEND_TFM_TESTS_VERSION
40# If the recommended tf-m-test version is a tag, it outputs the corresponding commit ID
41# for comparison.
42execute_process(COMMAND "${GIT_EXECUTABLE}" rev-parse ${RECOMMEND_TFM_TESTS_VERSION}
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)
48# Fail to fetch the whole commit ID of RECOMMEND_TFM_TESTS_VERSION.
49# tf-m-tests is not updated yet and therefore behind of RECOMMEND_TFM_TESTS_VERSION
50if(RET_VALUE)
51 message(FATAL_ERROR
52 " Unknown recommended tf-m-tests version: ${RECOMMEND_TFM_TESTS_VERSION}.\n"
53 " Please update local tf-m-tests repo and checkout version *${RECOMMEND_TFM_TESTS_VERSION}*.\n"
54 " 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
64execute_process(COMMAND "${GIT_EXECUTABLE}" merge-base --is-ancestor "${RECOMMEND_TFM_TESTS_VERSION}" HEAD
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
69if(VERSION_FROM_TFM_IS_OLDER EQUAL 0)
70 message(WARNING
71 " Current tf-m-tests HEAD is ahead of the version *${RECOMMEND_TFM_TESTS_VERSION}* recommended by TF-M.\n"
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"
75 " version *${RECOMMEND_TFM_TESTS_VERSION}*.\n"
76 " 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
81execute_process(COMMAND "${GIT_EXECUTABLE}" merge-base --is-ancestor HEAD "${RECOMMEND_TFM_TESTS_VERSION}"
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.
87if(VERSION_FROM_TFM_IS_NEWER EQUAL 0)
88 message(FATAL_ERROR
89 " Current tf-m-tests HEAD is behind the version *${RECOMMEND_TFM_TESTS_VERSION}* recommended by TF-M.\n"
90 " TF-M features might be not properly tested or covered by an older version of tf-m-tests.\n"
91 " Please update tf-m-tests to version *${RECOMMEND_TFM_TESTS_VERSION}* before verification.")
92endif()
93
94# The sequence of those 2 commits are unknown.
95# Not sure what has happened. Throw a warning to notify users.
96message(WARNING
97 " Current tf-m-tests HEAD is different from the version *${RECOMMEND_TFM_TESTS_VERSION}* recommended by TF-M.\n"
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")