AuditLog: Test infrastructure update
-- Modify the test infrastructure to add two more test
suites to provide functional testing of the Audit
Logging interface from S and NS world.
-- Modify the build system for the test framework to
accomodate the new source files added.
Change-Id: I979cd840834c5d71ef31fca56581866f4d4c04c6
Signed-off-by: Antonio de Angelis <antonio.deangelis@arm.com>
diff --git a/test/CMakeLists.inc b/test/CMakeLists.inc
index 694ab75..61fb94c 100644
--- a/test/CMakeLists.inc
+++ b/test/CMakeLists.inc
@@ -1,5 +1,5 @@
#-------------------------------------------------------------------------------
-# Copyright (c) 2017, Arm Limited. All rights reserved.
+# Copyright (c) 2017-2018, Arm Limited. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
@@ -30,4 +30,5 @@
include(${CMAKE_CURRENT_LIST_DIR}/suites/core/CMakeLists.inc)
include(${CMAKE_CURRENT_LIST_DIR}/suites/invert/CMakeLists.inc)
include(${CMAKE_CURRENT_LIST_DIR}/suites/sst/CMakeLists.inc)
+include(${CMAKE_CURRENT_LIST_DIR}/suites/log/CMakeLists.inc)
include(${CMAKE_CURRENT_LIST_DIR}/test_services/CMakeLists.inc)
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 4166f35..546b758 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -45,6 +45,7 @@
endif()
set(ENABLE_SECURE_STORAGE_SERVICE_TESTS TRUE)
+set(ENABLE_AUDIT_LOGGING_SERVICE_TESTS TRUE)
set(ENABLE_INVERT_SERVICE_TESTS TRUE)
include(${CMAKE_CURRENT_LIST_DIR}/CMakeLists.inc)
diff --git a/test/framework/non_secure_suites.c b/test/framework/non_secure_suites.c
index e691bcf..7cfbde2 100644
--- a/test/framework/non_secure_suites.c
+++ b/test/framework/non_secure_suites.c
@@ -11,6 +11,7 @@
/* Service specific includes */
#include "test/suites/sst/non_secure/sst_ns_tests.h"
+#include "test/suites/log/non_secure/log_ns_tests.h"
#include "test/suites/invert/non_secure/invert_ns_tests.h"
#include "test/suites/core/non_secure/core_ns_tests.h"
@@ -25,6 +26,9 @@
{®ister_testsuite_ns_sst_ref_access, 0, 0, 0},
#endif
+ /* Non-secure LOG test cases */
+ {®ister_testsuite_ns_log_interface, 0, 0, 0},
+
#ifdef TFM_PARTITION_TEST_CORE
/* Non-secure invert test cases */
/* Note: since this is sample code, only run if test services are enabled */
diff --git a/test/framework/secure_suites.c b/test/framework/secure_suites.c
index 8287226..144cfef 100644
--- a/test/framework/secure_suites.c
+++ b/test/framework/secure_suites.c
@@ -11,6 +11,7 @@
/* Service specific includes */
#include "test/suites/sst/secure/sst_tests.h"
+#include "test/suites/log/secure/log_s_tests.h"
#include "test/suites/invert/secure/invert_s_tests.h"
#include "secure_fw/services/secure_storage/sst_core_interface.h"
@@ -20,6 +21,9 @@
{®ister_testsuite_s_sst_sec_interface, 0, 0, 0},
{®ister_testsuite_s_sst_reliability, 0, 0, 0},
+ /* Secure LOG test cases */
+ {®ister_testsuite_s_log_interface, 0, 0, 0},
+
#ifdef TFM_PARTITION_TEST_CORE
/* Secure invert test cases */
/* Note: since this is sample code, only run if test services are enabled */
diff --git a/test/suites/log/CMakeLists.inc b/test/suites/log/CMakeLists.inc
new file mode 100644
index 0000000..52b39c1
--- /dev/null
+++ b/test/suites/log/CMakeLists.inc
@@ -0,0 +1,36 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2018, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+#Definitions to compile the "audit logging test" module.
+#This file assumes it will be included from a project specific cmakefile, and
+#will not create a library or executable.
+#Inputs:
+# TFM_ROOT_DIR - root directory of the TF-M repo.
+#
+#Outputs:
+# Will modify include directories to make the source compile.
+# ALL_SRC_C: C source files to be compiled will be added to this list. This shall be added to your add_executable or add_library command.
+# ALL_SRC_CXX: C++ source files to be compiled will be added to this list. This shall be added to your add_executable or add_library command.
+# ALL_SRC_ASM: assembly source files to be compiled will be added to this list. This shall be added to your add_executable or add_library command.
+# Include directories will be modified by using the include_directories() commands as needed.
+
+#Get the current directory where this file is located.
+set(AUDIT_LOGGING_TEST_DIR ${CMAKE_CURRENT_LIST_DIR})
+if(NOT DEFINED TFM_ROOT_DIR)
+ message(FATAL_ERROR "Please set TFM_ROOT_DIR before including this file.")
+endif()
+
+if (NOT DEFINED ENABLE_AUDIT_LOGGING_SERVICE_TESTS)
+ message(FATAL_ERROR "Incomplete build configuration: ENABLE_AUDIT_LOGGING_SERVICE_TESTS is undefined. ")
+elseif(ENABLE_AUDIT_LOGGING_SERVICE_TESTS)
+ list(APPEND ALL_SRC_C_S "${AUDIT_LOGGING_TEST_DIR}/secure/log_s_interface_testsuite.c")
+ list(APPEND ALL_SRC_C_NS "${AUDIT_LOGGING_TEST_DIR}/non_secure/log_ns_interface_testsuite.c")
+
+ #Setting include directories
+ embedded_include_directories(PATH ${TFM_ROOT_DIR} ABSOLUTE)
+ embedded_include_directories(PATH ${TFM_ROOT_DIR}/interface/include ABSOLUTE)
+endif()
diff --git a/test/suites/log/non_secure/log_ns_interface_testsuite.c b/test/suites/log/non_secure/log_ns_interface_testsuite.c
new file mode 100644
index 0000000..35b564e
--- /dev/null
+++ b/test/suites/log/non_secure/log_ns_interface_testsuite.c
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2018, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#include "test/framework/helpers.h"
+#include "tfm_log_api.h"
+#include "log_ns_tests.h"
+#include "tfm_api.h"
+
+/* List of tests */
+static void tfm_log_test_1001(struct test_result_t *ret);
+
+static struct test_t log_veneers_tests[] = {
+ {&tfm_log_test_1001, "TFM_LOG_TEST_1001",
+ "Retrieve log", {0} },
+};
+
+void register_testsuite_ns_log_interface(struct test_suite_t *p_test_suite)
+{
+ uint32_t list_size;
+
+ list_size = (sizeof(log_veneers_tests) /
+ sizeof(log_veneers_tests[0]));
+
+ set_testsuite("Audit Logging non-secure interface test (TFM_LOG_TEST_1XXX)",
+ log_veneers_tests, list_size, p_test_suite);
+}
+
+/**
+ * \brief Use the NS API to retrieve the log
+ */
+static void tfm_log_test_1001(struct test_result_t *ret)
+{
+ enum tfm_log_err err;
+
+ uint8_t local_buffer[4];
+ uint32_t size, log_size;
+
+ /* Retrieve 4 bytes at most */
+ size = 4;
+
+ err = tfm_log_retrieve(size, &local_buffer[0], &log_size);
+
+ if (err != TFM_LOG_ERR_SUCCESS) {
+ TEST_FAIL("Log retrieval has returned an error");
+ return;
+ }
+
+ ret->val = TEST_PASSED;
+}
diff --git a/test/suites/log/non_secure/log_ns_tests.h b/test/suites/log/non_secure/log_ns_tests.h
new file mode 100644
index 0000000..110008b
--- /dev/null
+++ b/test/suites/log/non_secure/log_ns_tests.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2018, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#ifndef __LOG_NS_TESTS_H__
+#define __LOG_NS_TESTS_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "test/framework/test_framework.h"
+
+/**
+ * \brief Register testsuite for audit logging non-secure interface.
+ *
+ * \param[in] p_test_suite The test suite to be executed.
+ */
+void register_testsuite_ns_log_interface(struct test_suite_t *p_test_suite);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __LOG_NS_TESTS_H__ */
diff --git a/test/suites/log/secure/log_s_interface_testsuite.c b/test/suites/log/secure/log_s_interface_testsuite.c
new file mode 100644
index 0000000..f36a68b
--- /dev/null
+++ b/test/suites/log/secure/log_s_interface_testsuite.c
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2018, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#include "test/framework/helpers.h"
+#include "tfm_log_api.h"
+#include "log_s_tests.h"
+#include "tfm_api.h"
+#include "tfm_log_veneers.h"
+
+/* List of tests */
+static void tfm_log_test_1001(struct test_result_t *ret);
+
+static struct test_t log_veneers_tests[] = {
+ {&tfm_log_test_1001, "TFM_LOG_TEST_1001",
+ "Add an entry to the log", {0} },
+};
+
+void register_testsuite_s_log_interface(struct test_suite_t *p_test_suite)
+{
+ uint32_t list_size;
+
+ list_size = (sizeof(log_veneers_tests) /
+ sizeof(log_veneers_tests[0]));
+
+ set_testsuite("Audit Logging secure interface test (TFM_LOG_TEST_1XXX)",
+ log_veneers_tests, list_size, p_test_suite);
+}
+
+/**
+ * \brief Use the secure only API to add an entry to the log
+ */
+static void tfm_log_test_1001(struct test_result_t *ret)
+{
+ enum tfm_log_err err;
+ uint8_t local_buffer[24];
+ struct tfm_log_line *line = (struct tfm_log_line *)
+ &local_buffer[0];
+
+ /* Fill the log_line with random values */
+ line->size = 20;
+ line->function_id = 0xABCDABCD;
+ line->arg[0] = 0x0;
+ line->arg[1] = 0x1;
+ line->arg[2] = 0x2;
+ line->arg[3] = 0x3;
+
+ /* The line doesn't contain any payload */
+ err = tfm_log_veneer_add_line(line);
+ if (err != TFM_LOG_ERR_SUCCESS) {
+ TEST_FAIL("Log line addition has returned an error");
+ return;
+ }
+
+ ret->val = TEST_PASSED;
+}
diff --git a/test/suites/log/secure/log_s_tests.h b/test/suites/log/secure/log_s_tests.h
new file mode 100644
index 0000000..0ef77dd
--- /dev/null
+++ b/test/suites/log/secure/log_s_tests.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2018, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#ifndef __LOG_S_TESTS_H__
+#define __LOG_S_TESTS_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "test/framework/test_framework.h"
+
+/**
+ * \brief Register testsuite for audit logging secure interface.
+ *
+ * \param[in] p_test_suite The test suite to be executed.
+ */
+void register_testsuite_s_log_interface(struct test_suite_t *p_test_suite);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __LOG_S_TESTS_H__ */