Merge branch 'release/2.0.x' into main

Accommodate changes made during release v2.0.0

Signed-off-by: David Hu <david.hu@arm.com>
Change-Id: Ic667b23d91f7ae3c6fdd5e2ee16f37701cae577e
diff --git a/.gitreview b/.gitreview
new file mode 100644
index 0000000..226af35
--- /dev/null
+++ b/.gitreview
@@ -0,0 +1,5 @@
+[gerrit]
+host=review.trustedfirmware.org
+port=29418
+project=TF-M/tf-m-tests
+defaultbranch=main
diff --git a/cmake/check_version.cmake b/cmake/check_version.cmake
new file mode 100644
index 0000000..e3164e2
--- /dev/null
+++ b/cmake/check_version.cmake
@@ -0,0 +1,100 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2023, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+find_package(Git)
+
+execute_process(COMMAND "${GIT_EXECUTABLE}" status
+                WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
+                RESULT_VARIABLE RET_VALUE
+                ERROR_QUIET OUTPUT_QUIET)
+if(NOT RET_VALUE EQUAL 0)
+    return()
+endif()
+
+if(NOT DEFINED RECOMMEND_TFM_TESTS_VERSION)
+    message(FATAL_ERROR
+        " Recommended tf-m-tests version of TF-M is unknown.\n"
+        " Please select tf-m-tests version specified in trusted-firmware-m/lib/ext/tf-m-tests/version.txt.")
+endif()
+
+# Fetch the full HEAD commit ID
+execute_process(COMMAND "${GIT_EXECUTABLE}" rev-parse HEAD
+                WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
+                OUTPUT_VARIABLE HEAD_FULL_COMMIT
+                RESULT_VARIABLE RET_VALUE
+                OUTPUT_STRIP_TRAILING_WHITESPACE
+                ERROR_QUIET)
+# Fail to fetch the current tf-m-tests HEAD commit ID.
+if(RET_VALUE)
+    message(FATAL_ERROR
+        " Failed to fetch the current tf-m-tests HEAD.\n"
+        " Unable to check compatibility with TF-M.")
+    return()
+endif()
+
+# Try to fetch the full commit ID of RECOMMEND_TFM_TESTS_VERSION
+# If the recommended tf-m-test version is a tag, it outputs the corresponding commit ID
+# for comparison.
+execute_process(COMMAND "${GIT_EXECUTABLE}" rev-parse ${RECOMMEND_TFM_TESTS_VERSION}
+                WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
+                OUTPUT_VARIABLE RECOMMENDED_FULL_COMMIT
+                RESULT_VARIABLE RET_VALUE
+                OUTPUT_STRIP_TRAILING_WHITESPACE
+                ERROR_QUIET)
+# Fail to fetch the whole commit ID of RECOMMEND_TFM_TESTS_VERSION.
+# tf-m-tests is not updated yet and therefore behind of RECOMMEND_TFM_TESTS_VERSION
+if(RET_VALUE)
+    message(FATAL_ERROR
+        " Unknown recommended tf-m-tests version: ${RECOMMEND_TFM_TESTS_VERSION}.\n"
+        " Please update local tf-m-tests repo and checkout version *${RECOMMEND_TFM_TESTS_VERSION}*.\n"
+        " Otherwise, tf-m-tests and TF-M can be incompatible.")
+endif()
+
+# Check if tf-m-tests HEAD == commit ID recommended by TF-M
+if("${HEAD_FULL_COMMIT}" STREQUAL "${RECOMMENDED_FULL_COMMIT}")
+    message(VERBOSE "tf-m-tests HEAD matches the version recommended by TF-M")
+    return()
+endif()
+
+# Check whether tf-m-tests commit ID recommended by TF-M is behind current tf-m-tests HEAD
+execute_process(COMMAND "${GIT_EXECUTABLE}" merge-base --is-ancestor "${RECOMMEND_TFM_TESTS_VERSION}" HEAD
+                WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
+                RESULT_VARIABLE VERSION_FROM_TFM_IS_OLDER
+                ERROR_QUIET OUTPUT_QUIET)
+# Users are using a newer version of tf-m-tests to verify TF-M
+if(VERSION_FROM_TFM_IS_OLDER EQUAL 0)
+    message(WARNING
+        " Current tf-m-tests HEAD is ahead of the version *${RECOMMEND_TFM_TESTS_VERSION}* recommended by TF-M.\n"
+        " - If you are developing in tf-m-tests, please update tf-m-tests commit ID in\n"
+        "   trusted-firmware-m/lib/ext/version.txt and upload that change to trusted-firmware-m.\n"
+        " - If you are testing an older version of TF-M, please switch tf-m-tests to\n"
+        "   version *${RECOMMEND_TFM_TESTS_VERSION}*.\n"
+        "   Build or tests might fail due to incompatiable configurations.\n")
+    return()
+endif()
+
+# Check whether tf-m-tests commit ID recommended by TF-M is ahead of current tf-m-tests HEAD
+execute_process(COMMAND "${GIT_EXECUTABLE}" merge-base --is-ancestor HEAD "${RECOMMEND_TFM_TESTS_VERSION}"
+                WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
+                RESULT_VARIABLE VERSION_FROM_TFM_IS_NEWER
+                ERROR_QUIET OUTPUT_QUIET)
+# Users are using an out-of-date version of tf-m-tests to verify TF-M.
+# Test coverage cannot be guaranteed. Block building in case that failures/defects are not detected.
+if(VERSION_FROM_TFM_IS_NEWER EQUAL 0)
+    message(FATAL_ERROR
+        " Current tf-m-tests HEAD is behind the version *${RECOMMEND_TFM_TESTS_VERSION}* recommended by TF-M.\n"
+        " TF-M features might be not properly tested or covered by an older version of tf-m-tests.\n"
+        " Please update tf-m-tests to version *${RECOMMEND_TFM_TESTS_VERSION}* before verification.")
+endif()
+
+# The sequence of those 2 commits are unknown.
+# Not sure what has happened. Throw a warning to notify users.
+message(WARNING
+    " Current tf-m-tests HEAD is different from the version *${RECOMMEND_TFM_TESTS_VERSION}* recommended by TF-M.\n"
+    " You might be working on a development branch diverged from the main branch.\n"
+    " Build or tests might fail due to incompatiable configurations.\n"
+    " Suggest to rebase your commits on tf-m-tests main branch.\n")
diff --git a/tests_reg/CMakeLists.txt b/tests_reg/CMakeLists.txt
index 39bb5f2..3df3034 100644
--- a/tests_reg/CMakeLists.txt
+++ b/tests_reg/CMakeLists.txt
@@ -33,6 +33,9 @@
 # Platform abilities for example IRQ test support status
 include(${CONFIG_SPE_PATH}/platform/config.cmake OPTIONAL)
 
+# Check current tf-m-tests is compatible to TF-M under verfication
+include(check_version)
+
 include(${TFM_TOOLCHAIN_FILE})
 project(tfm_ns LANGUAGES C ASM)
 tfm_toolchain_reload_compiler()
diff --git a/tests_reg/test/ns_regression/CMakeLists.txt b/tests_reg/test/ns_regression/CMakeLists.txt
index f780357..122db8d 100644
--- a/tests_reg/test/ns_regression/CMakeLists.txt
+++ b/tests_reg/test/ns_regression/CMakeLists.txt
@@ -32,7 +32,7 @@
     )
 
 # Common regression test framework
-add_subdirectory(${CMAKE_SOURCE_DIR}/test/framework ${CMAKE_CURRENT_BINARY_DIR}/framework)
+add_subdirectory(../framework ${CMAKE_CURRENT_BINARY_DIR}/framework)
 
 add_library(tfm_ns_tests INTERFACE)
 add_library(tfm_test_framework_ns INTERFACE)
@@ -65,6 +65,6 @@
         $<$<BOOL:${TFM_FUZZER_TOOL_TESTS}>:TFM_FUZZER_TOOL_TESTS>
 )
 
-add_subdirectory(${CMAKE_SOURCE_DIR}/test/secure_fw/non_secure
+add_subdirectory(../secure_fw/non_secure
                  ${CMAKE_CURRENT_BINARY_DIR}/secure_fw/suites
 )
diff --git a/tests_reg/test/secure_fw/suites/attestation/non_secure/CMakeLists.txt b/tests_reg/test/secure_fw/suites/attestation/non_secure/CMakeLists.txt
index a3182b7..d036b9d 100644
--- a/tests_reg/test/secure_fw/suites/attestation/non_secure/CMakeLists.txt
+++ b/tests_reg/test/secure_fw/suites/attestation/non_secure/CMakeLists.txt
@@ -48,7 +48,6 @@
         tfm_qcbor_ns
         tfm_t_cose_ns
         tfm_test_framework_ns
-        platform_ns
 )
 
 target_link_libraries(tfm_ns_tests
diff --git a/tests_reg/test/secure_fw/suites/spm/irq/non_secure/CMakeLists.txt b/tests_reg/test/secure_fw/suites/spm/irq/non_secure/CMakeLists.txt
index 9c30baa..0826b9b 100644
--- a/tests_reg/test/secure_fw/suites/spm/irq/non_secure/CMakeLists.txt
+++ b/tests_reg/test/secure_fw/suites/spm/irq/non_secure/CMakeLists.txt
@@ -39,7 +39,6 @@
 target_link_libraries(tfm_test_suite_irq
     PRIVATE
         tfm_test_framework_ns
-        platform_ns
         spm_test_common
 )