Add uefi-test deployment

Adds a new deployment for building and running service level tests
for UEFI SMM services. Tests may be run against StMM, smm-gateway
or any other similar secure-world uefi service provider.

Signed-off-by: Julian Hall <julian.hall@arm.com>
Change-Id: Ic0e16dff51ef76ddd1f4dea37a4a55b029edd696
diff --git a/deployments/ts-service-test/arm-linux/CMakeLists.txt b/deployments/ts-service-test/arm-linux/CMakeLists.txt
index 6a01d38..e902cd2 100644
--- a/deployments/ts-service-test/arm-linux/CMakeLists.txt
+++ b/deployments/ts-service-test/arm-linux/CMakeLists.txt
@@ -23,9 +23,6 @@
 	BASE_DIR ${TS_ROOT}
 	COMPONENTS
 		"components/app/test-runner"
-# Running smm_variable tests currently requires kernel built with CONFIG_STRICT_DEVMEM=n
-#		"components/service/smm_variable/client/cpp"
-#		"components/service/smm_variable/test/service"
  )
 
 include(${TS_ROOT}/external/CppUTest/CppUTest.cmake)
diff --git a/deployments/uefi-test/arm-linux/CMakeLists.txt b/deployments/uefi-test/arm-linux/CMakeLists.txt
new file mode 100644
index 0000000..053041a
--- /dev/null
+++ b/deployments/uefi-test/arm-linux/CMakeLists.txt
@@ -0,0 +1,43 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+cmake_minimum_required(VERSION 3.16)
+include(../../deployment.cmake REQUIRED)
+
+#-------------------------------------------------------------------------------
+#  The CMakeLists.txt for building the uefi-test deployment for arm-linux
+#
+#  Used for building and running service level tests from Linux user-space
+#  on an Arm platform with real deployments of UEFI SMM services
+#-------------------------------------------------------------------------------
+include(${TS_ROOT}/environments/arm-linux/env.cmake)
+project(trusted-services LANGUAGES CXX C)
+add_executable(uefi-test)
+target_include_directories(uefi-test PRIVATE "${TOP_LEVEL_INCLUDE_DIRS}")
+
+add_components(
+	TARGET "uefi-test"
+	BASE_DIR ${TS_ROOT}
+	COMPONENTS
+		"components/app/test-runner"
+ )
+
+include(${TS_ROOT}/external/CppUTest/CppUTest.cmake)
+target_link_libraries(uefi-test PRIVATE CppUTest)
+
+#-------------------------------------------------------------------------------
+#  Extend with components that are common across all deployments of
+#  uefi-test
+#
+#-------------------------------------------------------------------------------
+include(../uefi-test.cmake REQUIRED)
+
+#-------------------------------------------------------------------------------
+#  Define library options and dependencies.
+#
+#-------------------------------------------------------------------------------
+env_set_link_options(TGT uefi-test)
+target_link_libraries(uefi-test PRIVATE stdc++ gcc m)
diff --git a/deployments/uefi-test/linux-pc/CMakeLists.txt b/deployments/uefi-test/linux-pc/CMakeLists.txt
new file mode 100644
index 0000000..be6e984
--- /dev/null
+++ b/deployments/uefi-test/linux-pc/CMakeLists.txt
@@ -0,0 +1,76 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+cmake_minimum_required(VERSION 3.16)
+include(../../deployment.cmake REQUIRED)
+
+#-------------------------------------------------------------------------------
+#  The CMakeLists.txt for building the uefi-test deployment for linux-pc
+#
+#  Used for building and running service level tests in a native PC enviroment.
+#  Tests can be run by running the built executable called "uefi-test"
+#-------------------------------------------------------------------------------
+include(${TS_ROOT}/environments/linux-pc/env.cmake)
+project(trusted-services LANGUAGES CXX C)
+
+# Prevents symbols in the uefi-test executable overriding symbols with
+# with same name in libts during dynamic linking performed by the program
+# loader.
+set(CMAKE_C_VISIBILITY_PRESET hidden)
+
+# Preparing firmware-test-build by including it
+include(${TS_ROOT}/external/firmware_test_builder/FirmwareTestBuilder.cmake)
+
+include(CTest)
+include(UnitTest)
+
+set(COVERAGE FALSE CACHE BOOL "Enable code coverage measurement")
+set(UNIT_TEST_PROJECT_PATH ${TS_ROOT} CACHE PATH "Path of the project directory")
+set(CMAKE_CXX_STANDARD 11)
+
+unit_test_init_cpputest()
+
+if (COVERAGE)
+	include(Coverage)
+
+	set(COVERAGE_FILE "coverage.info")
+	set(TS_SERVICE_TEST_COVERAGE_FILE "uefi-test-coverage.info" CACHE PATH "Path of coverage info file")
+	set(TS_SERVICE_TEST_COVERAGE_REPORT_DIR "${CMAKE_CURRENT_BINARY_DIR}/ts-service-coverage-report" CACHE PATH "Directory of coverage report")
+
+	# Collecting coverage
+	coverage_generate(
+		NAME "ts-service test"
+		SOURCE_DIR ${TS_ROOT}
+		BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}
+		OUTPUT_FILE ${COVERAGE_FILE}
+	)
+
+	# Filtering project file coverage
+	coverage_filter(
+		INPUT_FILE ${COVERAGE_FILE}
+		OUTPUT_FILE ${TS_SERVICE_TEST_COVERAGE_FILE}
+		INCLUDE_DIRECTORY ${UNIT_TEST_PROJECT_PATH}/components
+	)
+
+	# Coverage report
+	coverage_generate_report(
+		INPUT_FILE ${TS_SERVICE_TEST_COVERAGE_FILE}
+		OUTPUT_DIRECTORY ${TS_SERVICE_TEST_COVERAGE_REPORT_DIR}
+	)
+endif()
+
+unit_test_add_suite(
+	NAME uefi-test
+)
+
+target_include_directories(uefi-test PRIVATE "${TOP_LEVEL_INCLUDE_DIRS}")
+
+#-------------------------------------------------------------------------------
+#  Extend with components that are common across all deployments of
+#  uefi-test
+#
+#-------------------------------------------------------------------------------
+include(../uefi-test.cmake REQUIRED)
diff --git a/deployments/uefi-test/uefi-test.cmake b/deployments/uefi-test/uefi-test.cmake
new file mode 100644
index 0000000..ea678d0
--- /dev/null
+++ b/deployments/uefi-test/uefi-test.cmake
@@ -0,0 +1,52 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+#-------------------------------------------------------------------------------
+#  The base build file shared between deployments of 'uefi-test' for
+#  different environments.  Used for running end-to-end service-level tests
+#  against SMM service providers that implement UEFI services such as smm
+#  variable.
+#-------------------------------------------------------------------------------
+
+#-------------------------------------------------------------------------------
+#  Use libts for locating and accessing services. An appropriate version of
+#  libts will be imported for the enviroment in which service tests are
+#  deployed.
+#-------------------------------------------------------------------------------
+include(${TS_ROOT}/deployments/libts/libts-import.cmake)
+target_link_libraries(uefi-test PRIVATE libts)
+
+#-------------------------------------------------------------------------------
+#  Components that are common accross all deployments
+#
+#-------------------------------------------------------------------------------
+add_components(
+	TARGET "uefi-test"
+	BASE_DIR ${TS_ROOT}
+	COMPONENTS
+		"components/service/smm_variable/client/cpp"
+		"components/service/smm_variable/test/service"
+)
+
+#-------------------------------------------------------------------------------
+#  Components used from external projects
+#
+#-------------------------------------------------------------------------------
+
+# Nanopb
+include(${TS_ROOT}/external/nanopb/nanopb.cmake)
+target_link_libraries(uefi-test PRIVATE nanopb::protobuf-nanopb-static)
+protobuf_generate_all(TGT "uefi-test" NAMESPACE "protobuf" BASE_DIR "${TS_ROOT}/protocols")
+
+#-------------------------------------------------------------------------------
+#  Define install content.
+#
+#-------------------------------------------------------------------------------
+if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
+	set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/install CACHE PATH "location to install build output to." FORCE)
+endif()
+install(TARGETS uefi-test RUNTIME DESTINATION ${TS_ENV}/bin)
diff --git a/tools/b-test/test_data.yaml b/tools/b-test/test_data.yaml
index 9f11888..0731d48 100644
--- a/tools/b-test/test_data.yaml
+++ b/tools/b-test/test_data.yaml
@@ -154,3 +154,13 @@
       os_id : "GNU/Linux"
       params:
           - "-GUnix Makefiles"
+    - name: "uefi-test-pc-linux"
+      src: "$TS_ROOT/deployments/uefi-test/linux-pc"
+      os_id : "GNU/Linux"
+      params:
+          - "-GUnix Makefiles"
+    - name: "uefi-test-arm-linux"
+      src: "$TS_ROOT/deployments/uefi-test/arm-linux"
+      os_id : "GNU/Linux"
+      params:
+          - "-GUnix Makefiles"