blob: 66a4499ef03316bd2603714fd976b45aeb0b10e5 [file] [log] [blame]
Brad Bishopbec4ebc2022-08-03 09:55:16 -04001From 22120b4bd64da232e5a4e04a9a15376f34a933a3 Mon Sep 17 00:00:00 2001
2From: Julian Hall <julian.hall@arm.com>
3Date: Mon, 6 Dec 2021 15:20:12 +0000
4Subject: [PATCH] Add uefi-test deployment
5
6Adds a new deployment for building and running service level tests
7for UEFI SMM services. Tests may be run against StMM, smm-gateway
8or any other similar secure-world uefi service provider.
9
10Signed-off-by: Julian Hall <julian.hall@arm.com>
11Change-Id: Ic0e16dff51ef76ddd1f4dea37a4a55b029edd696
12
13Upstream-Status: Pending [Not submitted to upstream yet]
14Signed-off-by: Vishnu Banavath <vishnu.banavath@arm.com>
15
16
17---
18 .../ts-service-test/arm-linux/CMakeLists.txt | 3 -
19 .../uefi-test/arm-linux/CMakeLists.txt | 43 +++++++++++
20 deployments/uefi-test/linux-pc/CMakeLists.txt | 76 +++++++++++++++++++
21 deployments/uefi-test/uefi-test.cmake | 52 +++++++++++++
22 tools/b-test/test_data.yaml | 10 +++
23 5 files changed, 181 insertions(+), 3 deletions(-)
24 create mode 100644 deployments/uefi-test/arm-linux/CMakeLists.txt
25 create mode 100644 deployments/uefi-test/linux-pc/CMakeLists.txt
26 create mode 100644 deployments/uefi-test/uefi-test.cmake
27
28diff --git a/deployments/ts-service-test/arm-linux/CMakeLists.txt b/deployments/ts-service-test/arm-linux/CMakeLists.txt
29index 6a01d38a..e902cd2f 100644
30--- a/deployments/ts-service-test/arm-linux/CMakeLists.txt
31+++ b/deployments/ts-service-test/arm-linux/CMakeLists.txt
32@@ -23,9 +23,6 @@ add_components(
33 BASE_DIR ${TS_ROOT}
34 COMPONENTS
35 "components/app/test-runner"
36-# Running smm_variable tests currently requires kernel built with CONFIG_STRICT_DEVMEM=n
37-# "components/service/smm_variable/client/cpp"
38-# "components/service/smm_variable/test/service"
39 )
40
41 include(${TS_ROOT}/external/CppUTest/CppUTest.cmake)
42diff --git a/deployments/uefi-test/arm-linux/CMakeLists.txt b/deployments/uefi-test/arm-linux/CMakeLists.txt
43new file mode 100644
44index 00000000..053041ad
45--- /dev/null
46+++ b/deployments/uefi-test/arm-linux/CMakeLists.txt
47@@ -0,0 +1,43 @@
48+#-------------------------------------------------------------------------------
49+# Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
50+#
51+# SPDX-License-Identifier: BSD-3-Clause
52+#
53+#-------------------------------------------------------------------------------
54+cmake_minimum_required(VERSION 3.16)
55+include(../../deployment.cmake REQUIRED)
56+
57+#-------------------------------------------------------------------------------
58+# The CMakeLists.txt for building the uefi-test deployment for arm-linux
59+#
60+# Used for building and running service level tests from Linux user-space
61+# on an Arm platform with real deployments of UEFI SMM services
62+#-------------------------------------------------------------------------------
63+include(${TS_ROOT}/environments/arm-linux/env.cmake)
64+project(trusted-services LANGUAGES CXX C)
65+add_executable(uefi-test)
66+target_include_directories(uefi-test PRIVATE "${TOP_LEVEL_INCLUDE_DIRS}")
67+
68+add_components(
69+ TARGET "uefi-test"
70+ BASE_DIR ${TS_ROOT}
71+ COMPONENTS
72+ "components/app/test-runner"
73+ )
74+
75+include(${TS_ROOT}/external/CppUTest/CppUTest.cmake)
76+target_link_libraries(uefi-test PRIVATE CppUTest)
77+
78+#-------------------------------------------------------------------------------
79+# Extend with components that are common across all deployments of
80+# uefi-test
81+#
82+#-------------------------------------------------------------------------------
83+include(../uefi-test.cmake REQUIRED)
84+
85+#-------------------------------------------------------------------------------
86+# Define library options and dependencies.
87+#
88+#-------------------------------------------------------------------------------
89+env_set_link_options(TGT uefi-test)
90+target_link_libraries(uefi-test PRIVATE stdc++ gcc m)
91diff --git a/deployments/uefi-test/linux-pc/CMakeLists.txt b/deployments/uefi-test/linux-pc/CMakeLists.txt
92new file mode 100644
93index 00000000..be6e9840
94--- /dev/null
95+++ b/deployments/uefi-test/linux-pc/CMakeLists.txt
96@@ -0,0 +1,76 @@
97+#-------------------------------------------------------------------------------
98+# Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
99+#
100+# SPDX-License-Identifier: BSD-3-Clause
101+#
102+#-------------------------------------------------------------------------------
103+cmake_minimum_required(VERSION 3.16)
104+include(../../deployment.cmake REQUIRED)
105+
106+#-------------------------------------------------------------------------------
107+# The CMakeLists.txt for building the uefi-test deployment for linux-pc
108+#
109+# Used for building and running service level tests in a native PC enviroment.
110+# Tests can be run by running the built executable called "uefi-test"
111+#-------------------------------------------------------------------------------
112+include(${TS_ROOT}/environments/linux-pc/env.cmake)
113+project(trusted-services LANGUAGES CXX C)
114+
115+# Prevents symbols in the uefi-test executable overriding symbols with
116+# with same name in libts during dynamic linking performed by the program
117+# loader.
118+set(CMAKE_C_VISIBILITY_PRESET hidden)
119+
120+# Preparing firmware-test-build by including it
121+include(${TS_ROOT}/external/firmware_test_builder/FirmwareTestBuilder.cmake)
122+
123+include(CTest)
124+include(UnitTest)
125+
126+set(COVERAGE FALSE CACHE BOOL "Enable code coverage measurement")
127+set(UNIT_TEST_PROJECT_PATH ${TS_ROOT} CACHE PATH "Path of the project directory")
128+set(CMAKE_CXX_STANDARD 11)
129+
130+unit_test_init_cpputest()
131+
132+if (COVERAGE)
133+ include(Coverage)
134+
135+ set(COVERAGE_FILE "coverage.info")
136+ set(TS_SERVICE_TEST_COVERAGE_FILE "uefi-test-coverage.info" CACHE PATH "Path of coverage info file")
137+ set(TS_SERVICE_TEST_COVERAGE_REPORT_DIR "${CMAKE_CURRENT_BINARY_DIR}/ts-service-coverage-report" CACHE PATH "Directory of coverage report")
138+
139+ # Collecting coverage
140+ coverage_generate(
141+ NAME "ts-service test"
142+ SOURCE_DIR ${TS_ROOT}
143+ BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}
144+ OUTPUT_FILE ${COVERAGE_FILE}
145+ )
146+
147+ # Filtering project file coverage
148+ coverage_filter(
149+ INPUT_FILE ${COVERAGE_FILE}
150+ OUTPUT_FILE ${TS_SERVICE_TEST_COVERAGE_FILE}
151+ INCLUDE_DIRECTORY ${UNIT_TEST_PROJECT_PATH}/components
152+ )
153+
154+ # Coverage report
155+ coverage_generate_report(
156+ INPUT_FILE ${TS_SERVICE_TEST_COVERAGE_FILE}
157+ OUTPUT_DIRECTORY ${TS_SERVICE_TEST_COVERAGE_REPORT_DIR}
158+ )
159+endif()
160+
161+unit_test_add_suite(
162+ NAME uefi-test
163+)
164+
165+target_include_directories(uefi-test PRIVATE "${TOP_LEVEL_INCLUDE_DIRS}")
166+
167+#-------------------------------------------------------------------------------
168+# Extend with components that are common across all deployments of
169+# uefi-test
170+#
171+#-------------------------------------------------------------------------------
172+include(../uefi-test.cmake REQUIRED)
173diff --git a/deployments/uefi-test/uefi-test.cmake b/deployments/uefi-test/uefi-test.cmake
174new file mode 100644
175index 00000000..ea678d0e
176--- /dev/null
177+++ b/deployments/uefi-test/uefi-test.cmake
178@@ -0,0 +1,52 @@
179+#-------------------------------------------------------------------------------
180+# Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
181+#
182+# SPDX-License-Identifier: BSD-3-Clause
183+#
184+#-------------------------------------------------------------------------------
185+
186+#-------------------------------------------------------------------------------
187+# The base build file shared between deployments of 'uefi-test' for
188+# different environments. Used for running end-to-end service-level tests
189+# against SMM service providers that implement UEFI services such as smm
190+# variable.
191+#-------------------------------------------------------------------------------
192+
193+#-------------------------------------------------------------------------------
194+# Use libts for locating and accessing services. An appropriate version of
195+# libts will be imported for the enviroment in which service tests are
196+# deployed.
197+#-------------------------------------------------------------------------------
198+include(${TS_ROOT}/deployments/libts/libts-import.cmake)
199+target_link_libraries(uefi-test PRIVATE libts)
200+
201+#-------------------------------------------------------------------------------
202+# Components that are common accross all deployments
203+#
204+#-------------------------------------------------------------------------------
205+add_components(
206+ TARGET "uefi-test"
207+ BASE_DIR ${TS_ROOT}
208+ COMPONENTS
209+ "components/service/smm_variable/client/cpp"
210+ "components/service/smm_variable/test/service"
211+)
212+
213+#-------------------------------------------------------------------------------
214+# Components used from external projects
215+#
216+#-------------------------------------------------------------------------------
217+
218+# Nanopb
219+include(${TS_ROOT}/external/nanopb/nanopb.cmake)
220+target_link_libraries(uefi-test PRIVATE nanopb::protobuf-nanopb-static)
221+protobuf_generate_all(TGT "uefi-test" NAMESPACE "protobuf" BASE_DIR "${TS_ROOT}/protocols")
222+
223+#-------------------------------------------------------------------------------
224+# Define install content.
225+#
226+#-------------------------------------------------------------------------------
227+if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
228+ set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/install CACHE PATH "location to install build output to." FORCE)
229+endif()
230+install(TARGETS uefi-test RUNTIME DESTINATION ${TS_ENV}/bin)
231diff --git a/tools/b-test/test_data.yaml b/tools/b-test/test_data.yaml
232index 11f8f633..33a85b12 100644
233--- a/tools/b-test/test_data.yaml
234+++ b/tools/b-test/test_data.yaml
235@@ -163,3 +163,13 @@ data:
236 os_id : "GNU/Linux"
237 params:
238 - "-GUnix Makefiles"
239+ - name: "uefi-test-pc-linux"
240+ src: "$TS_ROOT/deployments/uefi-test/linux-pc"
241+ os_id : "GNU/Linux"
242+ params:
243+ - "-GUnix Makefiles"
244+ - name: "uefi-test-arm-linux"
245+ src: "$TS_ROOT/deployments/uefi-test/arm-linux"
246+ os_id : "GNU/Linux"
247+ params:
248+ - "-GUnix Makefiles"