AuditLog: Align the implementation to the PSA header
This change modifies the AuditLog service implementation
to reflect the changes introduced by the PSA compliant API
interface. The symbol name patterns for functions, variables,
folders and source files are also changed to be audit_* /
tfm_audit*.
Change-Id: I674060979961f568912870f49a72ed571499f059
Signed-off-by: Antonio de Angelis <antonio.deangelis@arm.com>
diff --git a/test/CMakeLists.inc b/test/CMakeLists.inc
index 61fb94c..fdc59bf 100644
--- a/test/CMakeLists.inc
+++ b/test/CMakeLists.inc
@@ -30,5 +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}/suites/audit/CMakeLists.inc)
include(${CMAKE_CURRENT_LIST_DIR}/test_services/CMakeLists.inc)
diff --git a/test/framework/non_secure_suites.c b/test/framework/non_secure_suites.c
index da74723..51ed186 100644
--- a/test/framework/non_secure_suites.c
+++ b/test/framework/non_secure_suites.c
@@ -11,7 +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/audit/non_secure/audit_ns_tests.h"
#include "test/suites/invert/non_secure/invert_ns_tests.h"
#include "test/suites/core/non_secure/core_ns_tests.h"
@@ -26,8 +26,8 @@
{®ister_testsuite_ns_sst_ref_access, 0, 0, 0},
#endif
- /* Non-secure LOG test cases */
- {®ister_testsuite_ns_log_interface, 0, 0, 0},
+ /* Non-secure Audit Logging test cases */
+ {®ister_testsuite_ns_audit_interface, 0, 0, 0},
#ifdef TFM_PARTITION_TEST_CORE
/* Non-secure invert test cases */
diff --git a/test/framework/secure_suites.c b/test/framework/secure_suites.c
index f002cd7..63f0e96 100644
--- a/test/framework/secure_suites.c
+++ b/test/framework/secure_suites.c
@@ -11,7 +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/audit/secure/audit_s_tests.h"
#include "test/suites/invert/secure/invert_s_tests.h"
#include "secure_fw/services/secure_storage/sst_object_system.h"
@@ -21,8 +21,8 @@
{®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},
+ /* Secure Audit Logging test cases */
+ {®ister_testsuite_s_audit_interface, 0, 0, 0},
#ifdef TFM_PARTITION_TEST_CORE
/* Secure invert test cases */
diff --git a/test/suites/log/CMakeLists.inc b/test/suites/audit/CMakeLists.inc
similarity index 93%
rename from test/suites/log/CMakeLists.inc
rename to test/suites/audit/CMakeLists.inc
index 52b39c1..5231381 100644
--- a/test/suites/log/CMakeLists.inc
+++ b/test/suites/audit/CMakeLists.inc
@@ -27,8 +27,8 @@
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")
+ list(APPEND ALL_SRC_C_S "${AUDIT_LOGGING_TEST_DIR}/secure/audit_s_interface_testsuite.c")
+ list(APPEND ALL_SRC_C_NS "${AUDIT_LOGGING_TEST_DIR}/non_secure/audit_ns_interface_testsuite.c")
#Setting include directories
embedded_include_directories(PATH ${TFM_ROOT_DIR} ABSOLUTE)
diff --git a/test/suites/log/log_tests_common.h b/test/suites/audit/audit_tests_common.h
similarity index 70%
rename from test/suites/log/log_tests_common.h
rename to test/suites/audit/audit_tests_common.h
index 0b10293..c23efff 100644
--- a/test/suites/log/log_tests_common.h
+++ b/test/suites/audit/audit_tests_common.h
@@ -5,8 +5,8 @@
*
*/
-#ifndef __LOG_TESTS_COMMON_H__
-#define __LOG_TESTS_COMMON_H__
+#ifndef __AUDIT_TESTS_COMMON_H__
+#define __AUDIT_TESTS_COMMON_H__
#include <stddef.h>
@@ -28,7 +28,7 @@
* \brief Size in bytes of the local buffer. Size accomodates two standard size
* (no payload) log items, at maximum
*/
-#define LOCAL_BUFFER_SIZE (100)
+#define LOCAL_BUFFER_SIZE (80)
/*!
* \def LOCAL_BUFFER_ITEMS
@@ -42,24 +42,24 @@
* \def STANDARD_LOG_ENTRY_SIZE
*
* \brief A log item with no payload (standard size) has the following size.
- * More details can be found observing \ref tfm_log_line
+ * More details can be found observing \ref psa_audit_record
* \ref tfm_log_tlr and \ref tfm_log_hdr
*/
-#define STANDARD_LOG_ENTRY_SIZE (44)
+#define STANDARD_LOG_ENTRY_SIZE (28)
/*!
* \def INITIAL_LOGGING_REQUESTS
*
* \brief Number of initial consecutive logging requests to perform
*/
-#define INITIAL_LOGGING_REQUESTS (23)
+#define INITIAL_LOGGING_REQUESTS (36)
/*!
* \def INITIAL_LOGGING_SIZE
*
* \brief Size of the initial consecutive logging requests
*/
-#define INITIAL_LOGGING_SIZE (1012)
+#define INITIAL_LOGGING_SIZE (1008)
/*!
* \def FINAL_LOGGING_REQUESTS
@@ -79,17 +79,24 @@
* \note This defines the state of the log when secure interface tests are
* terminated
*/
-#define FINAL_LOGGING_SIZE (88)
+#define FINAL_LOGGING_SIZE (56)
+
+/*!
+ * \def DUMMY_TEST_ID_BASE
+ *
+ * \brief The log record is initialized with a dummy ID which uses this value as
+ * base value
+ */
+#define DUMMY_TEST_RECORD_ID_BASE (0xABCD0000)
/*!
* \def SECOND_ELEMENT_EXPECTED_CONTENT
*
- * \brief Content of the log line in the second log item in the final request.
- * In particular this is the value of the first argument which has been
- * stored in the last addition from the secure test suite
+ * \brief Content of the log record in the second log item in the final request
+ *
*/
-#define SECOND_ELEMENT_EXPECTED_CONTENT ( 1 + \
- (INITIAL_LOGGING_REQUESTS+1+FINAL_LOGGING_REQUESTS)*10 )
+#define SECOND_ELEMENT_EXPECTED_CONTENT ( (DUMMY_TEST_RECORD_ID_BASE) + \
+ (INITIAL_LOGGING_REQUESTS+1+FINAL_LOGGING_REQUESTS) )
/*!
* \def MAX_LOG_SIZE
*
@@ -101,14 +108,14 @@
#define MAX_LOG_SIZE (1024)
/*!
- * \def MAX_LOG_LINE_SIZE
+ * \def MAX_LOG_RECORD_SIZE
*
* \brief The maximum possible log line size to fill a MAX_LOG_SIZE bytes log
*
* \note This takes into account additional fields that are concatenated to the
- * log line in the header and trailer
+ * record in the header and trailer
*/
-#define MAX_LOG_LINE_SIZE (1000)
+#define MAX_LOG_RECORD_SIZE (1000)
/*!
* \def INITIAL_LOG_SIZE
@@ -120,16 +127,16 @@
#define INITIAL_LOG_SIZE (FINAL_LOGGING_SIZE)
/*!
- * \def INITIAL_LOG_ITEMS
+ * \def INITIAL_LOG_RECORDS
*
- * \brief Initial state of the log number of items
+ * \brief Initial state of the log number of records
*
* \note This defines the state of the log when non-secure interface tests start
*/
-#define INITIAL_LOG_ITEMS (FINAL_LOGGING_REQUESTS)
+#define INITIAL_LOG_RECORDS (FINAL_LOGGING_REQUESTS)
#ifdef __cplusplus
}
#endif
-#endif /* __LOG_TESTS_COMMON_H__ */
+#endif /* __AUDIT_TESTS_COMMON_H__ */
diff --git a/test/suites/audit/non_secure/audit_ns_interface_testsuite.c b/test/suites/audit/non_secure/audit_ns_interface_testsuite.c
new file mode 100644
index 0000000..2391f18
--- /dev/null
+++ b/test/suites/audit/non_secure/audit_ns_interface_testsuite.c
@@ -0,0 +1,256 @@
+/*
+ * Copyright (c) 2018, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#include "test/framework/helpers.h"
+#include "psa_audit_api.h"
+#include "audit_ns_tests.h"
+#include "tfm_api.h"
+#include "secure_fw/services/audit_logging/audit_core.h"
+
+#include "../audit_tests_common.h"
+
+/*!
+ * \def EMPTY_RETRIEVED_LOG_SIZE
+ *
+ * \brief Log size when the retrieved buffer is empty
+ */
+#define EMPTY_RETRIEVED_LOG_SIZE (0)
+
+/*!
+ * \def EMPTY_RETRIEVED_LOG_ITEMS
+ *
+ * \brief Number of log items when retrieved buffer is empty
+ */
+#define EMPTY_RETRIEVED_LOG_ITEMS (0)
+
+/*!
+ * \def SINGLE_RETRIEVED_LOG_SIZE
+ *
+ * \brief Log size when the retrieved buffer has 1 item
+ * of standard size (no payload)
+ */
+#define SINGLE_RETRIEVED_LOG_SIZE (STANDARD_LOG_ENTRY_SIZE)
+
+/*!
+ * \def SINGLE_RETRIEVED_LOG_ITEMS
+ *
+ * \brief Number of log items when retrieved buffer has 1 item
+ */
+#define SINGLE_RETRIEVED_LOG_ITEMS (1)
+
+/*!
+ * \def SECOND_ELEMENT_START_INDEX
+ *
+ * \brief Index of the second item in the log
+ */
+#define SECOND_ELEMENT_START_INDEX (1)
+
+/* List of tests */
+static void tfm_audit_test_1001(struct test_result_t *ret);
+
+static struct test_t audit_veneers_tests[] = {
+ {&tfm_audit_test_1001, "TFM_AUDIT_TEST_1001",
+ "Non Secure functional", {0} },
+};
+
+void register_testsuite_ns_audit_interface(struct test_suite_t *p_test_suite)
+{
+ uint32_t list_size;
+
+ list_size = (sizeof(audit_veneers_tests) /
+ sizeof(audit_veneers_tests[0]));
+
+ set_testsuite("AuditLog non-secure interface test (TFM_AUDIT_TEST_1XXX)",
+ audit_veneers_tests, list_size, p_test_suite);
+}
+
+/**
+ * \brief Functional test of NS API
+ *
+ * \note This is a functional test only and doesn't
+ * mean to test all possible combinations of
+ * input parameters and return values.
+ * This tests the current status of the log as
+ * it's been left from the Secure tests. In case
+ * other tests are added in the Secure test suite,
+ * the status of the log will change and these
+ * tests may start failing.
+ */
+static void tfm_audit_test_1001(struct test_result_t *ret)
+{
+ enum psa_audit_err err;
+
+ uint8_t local_buffer[LOCAL_BUFFER_SIZE];
+ uint32_t idx, stored_size, num_records, retrieved_size;
+
+ struct psa_audit_record *retrieved_buffer;
+
+ /* Get the log size (current state) */
+ err = psa_audit_get_info(&num_records, &stored_size);
+ if (err != PSA_AUDIT_ERR_SUCCESS) {
+ TEST_FAIL("Getting log info has returned error");
+ return;
+ }
+
+ if (stored_size != INITIAL_LOG_SIZE) {
+ TEST_FAIL("Stored size different from " STR(INITIAL_LOG_SIZE));
+ return;
+ }
+
+ if (num_records != INITIAL_LOG_RECORDS) {
+ TEST_FAIL("Stored records different from " STR(INITIAL_LOG_RECORDS));
+ return;
+ }
+
+ /* Check the length of each record individually */
+ for (idx=0; idx<num_records; idx++) {
+ err = psa_audit_get_record_info(idx, &stored_size);
+ if (err != PSA_AUDIT_ERR_SUCCESS) {
+ TEST_FAIL("Getting record size individually has returned error");
+ return;
+ }
+
+ if (stored_size != STANDARD_LOG_ENTRY_SIZE) {
+ TEST_FAIL("Unexpected record size for a single standard record");
+ return;
+ }
+ }
+
+ /* Check that if requesting length of a record which is not there fails */
+ err = psa_audit_get_record_info(num_records, &stored_size);
+ if (err != PSA_AUDIT_ERR_FAILURE) {
+ TEST_FAIL("Getting record size for non-existent record has not failed");
+ return;
+ }
+
+ /* Log contains 2 items. Retrieve into buffer which is able to contain the
+ * the full contents of the log, one record at a time
+ */
+ for (idx=0; idx<INITIAL_LOG_RECORDS; idx++) {
+ err = psa_audit_retrieve_record(
+ idx,
+ LOCAL_BUFFER_SIZE,
+ NULL,
+ 0,
+ &local_buffer[idx*STANDARD_LOG_ENTRY_SIZE],
+ &retrieved_size);
+
+ if (err != PSA_AUDIT_ERR_SUCCESS) {
+ TEST_FAIL("Log retrieval from NS returned error");
+ return;
+ }
+
+ if (retrieved_size != STANDARD_LOG_ENTRY_SIZE) {
+ TEST_FAIL("Expected retrieve size: " STR(STANDARD_LOG_ENTRY_SIZE));
+ return;
+ }
+ }
+
+ /* Retrieve into a small buffer. It's not enough to store a single
+ * item so the provided buffer must be empty after retrieval. We
+ * check the info structure to count how many items and bytes have
+ * been returned, and if they're zeros items / zero bytes, there is
+ * no point in checking the contents of the local_buffer.
+ */
+ err = psa_audit_retrieve_record(0,
+ LOCAL_BUFFER_SIZE/4,
+ NULL,
+ 0,
+ &local_buffer[0],
+ &retrieved_size);
+
+ if (err != PSA_AUDIT_ERR_FAILURE) {
+ TEST_FAIL("Log retrieval from NS should fail, buffer too small");
+ return;
+ }
+
+ if (retrieved_size != EMPTY_RETRIEVED_LOG_SIZE) {
+ TEST_FAIL("Expected log size is " STR(EMPTY_RETRIEVED_LOG_SIZE));
+ return;
+ }
+
+ /* Retrieve into a buffer which can hold a single element, but start from
+ * the second element that is stored in the log
+ */
+ err = psa_audit_retrieve_record(1,
+ STANDARD_LOG_ENTRY_SIZE,
+ NULL,
+ 0,
+ &local_buffer[0],
+ &retrieved_size);
+
+ if (err != PSA_AUDIT_ERR_SUCCESS) {
+ TEST_FAIL("Log retrieval from NS returned error");
+ return;
+ }
+
+ if (retrieved_size != SINGLE_RETRIEVED_LOG_SIZE) {
+ TEST_FAIL("Expected log size is " STR(SINGLE_RETRIEVED_LOG_SIZE));
+ return;
+ }
+
+ /* Inspect the contents of the retrieved buffer, i.e. check the
+ * retrieved log record contents
+ */
+ retrieved_buffer = (struct psa_audit_record *)
+ &local_buffer[offsetof(struct log_hdr, size)];
+
+ if (retrieved_buffer->id != SECOND_ELEMENT_EXPECTED_CONTENT) {
+ TEST_FAIL("Unexpected argument in the first entry");
+ return;
+ }
+
+ /* Delete oldest element in the log */
+ err = psa_audit_delete_record(0, NULL, 0);
+ if (err != PSA_AUDIT_ERR_SUCCESS) {
+ TEST_FAIL("Log record deletion from NS returned error");
+ return;
+ }
+
+ /* Get the log size (current state) */
+ err = psa_audit_get_info(&num_records, &stored_size);
+ if (err != PSA_AUDIT_ERR_SUCCESS) {
+ TEST_FAIL("Getting log info has returned error");
+ return;
+ }
+
+ if (num_records != 1) {
+ TEST_FAIL("Unexpected number of records in the log after delete");
+ return;
+ }
+
+ if (stored_size != STANDARD_LOG_ENTRY_SIZE) {
+ TEST_FAIL("Unexpected size in the log after deletion");
+ return;
+ }
+
+ /* Delete oldest element in the log. After this, the log will be empty */
+ err = psa_audit_delete_record(0, NULL, 0);
+ if (err != PSA_AUDIT_ERR_SUCCESS) {
+ TEST_FAIL("Log record deletion from NS returned error");
+ return;
+ }
+
+ /* Get the log size (current state) */
+ err = psa_audit_get_info(&num_records, &stored_size);
+ if (err != PSA_AUDIT_ERR_SUCCESS) {
+ TEST_FAIL("Getting log info has returned error");
+ return;
+ }
+
+ if (num_records != 0) {
+ TEST_FAIL("Unexpected number of records in the log after deletion");
+ return;
+ }
+
+ if (stored_size != 0) {
+ TEST_FAIL("Unexpected size in the log after deletion");
+ return;
+ }
+
+ ret->val = TEST_PASSED;
+}
diff --git a/test/suites/log/non_secure/log_ns_tests.h b/test/suites/audit/non_secure/audit_ns_tests.h
similarity index 67%
rename from test/suites/log/non_secure/log_ns_tests.h
rename to test/suites/audit/non_secure/audit_ns_tests.h
index 110008b..3578bbe 100644
--- a/test/suites/log/non_secure/log_ns_tests.h
+++ b/test/suites/audit/non_secure/audit_ns_tests.h
@@ -5,8 +5,8 @@
*
*/
-#ifndef __LOG_NS_TESTS_H__
-#define __LOG_NS_TESTS_H__
+#ifndef __AUDIT_NS_TESTS_H__
+#define __AUDIT_NS_TESTS_H__
#ifdef __cplusplus
extern "C" {
@@ -19,10 +19,10 @@
*
* \param[in] p_test_suite The test suite to be executed.
*/
-void register_testsuite_ns_log_interface(struct test_suite_t *p_test_suite);
+void register_testsuite_ns_audit_interface(struct test_suite_t *p_test_suite);
#ifdef __cplusplus
}
#endif
-#endif /* __LOG_NS_TESTS_H__ */
+#endif /* __AUDIT_NS_TESTS_H__ */
diff --git a/test/suites/audit/secure/audit_s_interface_testsuite.c b/test/suites/audit/secure/audit_s_interface_testsuite.c
new file mode 100644
index 0000000..847ab9b
--- /dev/null
+++ b/test/suites/audit/secure/audit_s_interface_testsuite.c
@@ -0,0 +1,426 @@
+/*
+ * Copyright (c) 2018, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#include "test/framework/helpers.h"
+#include "psa_audit_api.h"
+#include "audit_s_tests.h"
+#include "tfm_api.h"
+#include "tfm_audit_veneers.h"
+#include "audit_wrappers.h"
+#include "secure_fw/services/audit_logging/audit_core.h"
+
+#include "../audit_tests_common.h"
+
+/*!
+ * \def BASE_RETRIEVAL_LOG_INDEX
+ *
+ * \brief Base index from where to start elements retrieval
+ */
+#define BASE_RETRIEVAL_LOG_INDEX (6)
+
+/*!
+ * \def FIRST_RETRIEVAL_LOG_INDEX
+ *
+ * \brief Index of the first element in the log
+ */
+#define FIRST_RETRIEVAL_LOG_INDEX (0)
+
+/* List of tests */
+static void tfm_audit_test_1001(struct test_result_t *ret);
+
+static struct test_t audit_veneers_tests[] = {
+ {&tfm_audit_test_1001, "TFM_AUDIT_TEST_1001",
+ "Secure functional", {0} },
+};
+
+void register_testsuite_s_audit_interface(struct test_suite_t *p_test_suite)
+{
+ uint32_t list_size;
+
+ list_size = (sizeof(audit_veneers_tests) /
+ sizeof(audit_veneers_tests[0]));
+
+ set_testsuite("Audit Logging secure interface test (TFM_AUDIT_TEST_1XXX)",
+ audit_veneers_tests, list_size, p_test_suite);
+}
+
+/**
+ * \brief Functional test of the Secure interface
+ *
+ * \note This is a functional test only and doesn't
+ * mean to test all possible combinations of
+ * input parameters and return values.
+ * This tests will leave the log in a certain
+ * status which, in turn, will be evaluated by
+ * the Non Secure functional tests. If any tests
+ * are added here that will leave the log in a
+ * different state, Non Secure functional tests
+ * need to be amended accordingly.
+ */
+static void tfm_audit_test_1001(struct test_result_t *ret)
+{
+ enum psa_audit_err err;
+ uint8_t local_buffer[LOCAL_BUFFER_SIZE], idx;
+ struct psa_audit_record *record = (struct psa_audit_record *)
+ &local_buffer[0];
+ uint32_t num_records, stored_size, record_size;
+ struct psa_audit_record *retrieved_buffer;
+
+ struct audit_core_retrieve_output retrieve_output_s;
+
+ /* Fill the log with 36 records, each record is 28 bytes
+ * we end up filling the log without wrapping
+ */
+ for (idx=0; idx<INITIAL_LOGGING_REQUESTS; idx++) {
+ record->size = sizeof(struct psa_audit_record) - 4;
+ record->id = DUMMY_TEST_RECORD_ID_BASE + idx;
+
+ /* The record doesn't contain any payload */
+ err = tfm_audit_veneer_add_record(record);
+ if (err != PSA_AUDIT_ERR_SUCCESS) {
+ TEST_FAIL("Record addition has returned an error");
+ return;
+ }
+ }
+
+ /* Get the log size */
+ err = tfm_audit_veneer_get_info(&num_records, &stored_size);
+ if (err != PSA_AUDIT_ERR_SUCCESS) {
+ TEST_FAIL("Getting log info has returned error");
+ return;
+ }
+
+ if (stored_size != INITIAL_LOGGING_SIZE) {
+ TEST_FAIL("Expected log size is " STR(INITIAL_LOGGING_SIZE));
+ return;
+ }
+
+ if (num_records != INITIAL_LOGGING_REQUESTS) {
+ TEST_FAIL("Expected log records are " STR(INITIAL_LOGGING_REQUESTS));
+ return;
+ }
+
+ /* Retrieve two log records starting from a given index */
+ for (idx=BASE_RETRIEVAL_LOG_INDEX; idx<BASE_RETRIEVAL_LOG_INDEX+2; idx++) {
+
+ struct audit_core_retrieve_input retrieve_input_s =
+ {.record_index = idx,
+ .buffer_size = LOCAL_BUFFER_SIZE,
+ .token = NULL,
+ .token_size = 0};
+ retrieve_output_s.buffer =
+ &local_buffer[(idx-BASE_RETRIEVAL_LOG_INDEX)*STANDARD_LOG_ENTRY_SIZE];
+ retrieve_output_s.record_size = &record_size;
+
+ err = tfm_audit_veneer_retrieve_record(&retrieve_input_s,
+ &retrieve_output_s);
+
+ if (err != PSA_AUDIT_ERR_SUCCESS) {
+ TEST_FAIL("Retrieve indexes 6 or 7 has returned an error");
+ return;
+ }
+
+ if (record_size != STANDARD_LOG_ENTRY_SIZE) {
+ TEST_FAIL("Expected log size is " STR(STANDARD_LOG_ENTRY_SIZE));
+ return;
+ }
+ }
+
+ /* Inspect the content of the second log record retrieved */
+ retrieved_buffer = (struct psa_audit_record *)
+ &local_buffer[offsetof(struct log_hdr,size)+STANDARD_LOG_ENTRY_SIZE];
+
+ if (retrieved_buffer->id != ( DUMMY_TEST_RECORD_ID_BASE +
+ (BASE_RETRIEVAL_LOG_INDEX+1) )) {
+ TEST_FAIL("Unexpected argument in the index 7 entry");
+ return;
+ }
+
+ /* Retrieve the last two log records */
+ for (idx=num_records-2; idx<num_records; idx++) {
+
+ struct audit_core_retrieve_input retrieve_input_s =
+ {.record_index = idx,
+ .buffer_size = LOCAL_BUFFER_SIZE,
+ .token = NULL,
+ .token_size = 0};
+ retrieve_output_s.buffer =
+ &local_buffer[(idx-(num_records-2))*STANDARD_LOG_ENTRY_SIZE];
+ retrieve_output_s.record_size = &record_size;
+
+ err = tfm_audit_veneer_retrieve_record(&retrieve_input_s,
+ &retrieve_output_s);
+
+ if (err != PSA_AUDIT_ERR_SUCCESS) {
+ TEST_FAIL("Retrieve of last two log records has returned error");
+ return;
+ }
+
+ if (record_size != STANDARD_LOG_ENTRY_SIZE) {
+ TEST_FAIL("Expected log size is " STR(STANDARD_LOG_ENTRY_SIZE));
+ return;
+ }
+ }
+
+ /* Inspect the first record retrieved in the local buffer */
+ retrieved_buffer = (struct psa_audit_record *)
+ &local_buffer[offsetof(struct log_hdr,size)];
+
+ if (retrieved_buffer->id != ( DUMMY_TEST_RECORD_ID_BASE +
+ (INITIAL_LOGGING_REQUESTS-2) )) {
+ TEST_FAIL("Unexpected argument in the second last entry");
+ return;
+ }
+
+ /* Retrieve the first log item */
+ struct audit_core_retrieve_input retrieve_input_s_first =
+ {.record_index = 0,
+ .buffer_size = LOCAL_BUFFER_SIZE,
+ .token = NULL,
+ .token_size = 0};
+
+ retrieve_output_s.buffer = &local_buffer[0];
+ retrieve_output_s.record_size = &record_size;
+
+ err = tfm_audit_veneer_retrieve_record(&retrieve_input_s_first,
+ &retrieve_output_s);
+
+ if (err != PSA_AUDIT_ERR_SUCCESS) {
+ TEST_FAIL("Retrieve of the first log entry has returned error");
+ return;
+ }
+
+ if (record_size != STANDARD_LOG_ENTRY_SIZE) {
+ TEST_FAIL("Expected log size is " STR(STANDARD_LOG_ENTRY_SIZE));
+ return;
+ }
+
+ if (retrieved_buffer->id != DUMMY_TEST_RECORD_ID_BASE) {
+ TEST_FAIL("Unexpected argument in the first entry");
+ return;
+ }
+
+ /* Retrieve the last log item */
+ struct audit_core_retrieve_input retrieve_input_s_last =
+ {.record_index = num_records-1,
+ .buffer_size = LOCAL_BUFFER_SIZE,
+ .token = NULL,
+ .token_size = 0};
+
+ retrieve_output_s.buffer = &local_buffer[0];
+ retrieve_output_s.record_size = &record_size;
+
+ err = tfm_audit_veneer_retrieve_record(&retrieve_input_s_last,
+ &retrieve_output_s);
+
+ if (err != PSA_AUDIT_ERR_SUCCESS) {
+ TEST_FAIL("Retrieve of last two log entries has returned error");
+ return;
+ }
+
+ if (record_size != STANDARD_LOG_ENTRY_SIZE) {
+ TEST_FAIL("Expected log size is " STR(STANDARD_LOG_ENTRY_SIZE));
+ return;
+ }
+
+ /* Inspect the item just retrieved */
+ if (retrieved_buffer->id != ( DUMMY_TEST_RECORD_ID_BASE +
+ (INITIAL_LOGGING_REQUESTS-1) )) {
+ TEST_FAIL("Unexpected argument in the second last entry");
+ return;
+ }
+
+ /* Fill one more log record, this will wrap */
+ record->size = sizeof(struct psa_audit_record) - 4;
+ record->id = DUMMY_TEST_RECORD_ID_BASE + INITIAL_LOGGING_REQUESTS;
+
+ /* The addition of this new log item will wrap the log ending */
+ err = tfm_audit_veneer_add_record(record);
+ if (err != PSA_AUDIT_ERR_SUCCESS) {
+ TEST_FAIL("Record addition has returned an error");
+ return;
+ }
+
+ /* Get the log size */
+ err = tfm_audit_veneer_get_info(&num_records, &stored_size);
+ if (err != PSA_AUDIT_ERR_SUCCESS) {
+ TEST_FAIL("Getting log info has returned error");
+ return;
+ }
+
+ /* Check that the log state is the same, the item addition just performed
+ * is resulted into the removal of the oldest entry, so log size and number
+ * of log records is still the same as before
+ */
+ if (stored_size != INITIAL_LOGGING_SIZE) {
+ TEST_FAIL("Expected log size is " STR(INITIAL_LOGGING_SIZE));
+ return;
+ }
+
+ if (num_records != INITIAL_LOGGING_REQUESTS) {
+ TEST_FAIL("Expected log records are " STR(INITIAL_LOGGING_REQUESTS));
+ return;
+ }
+
+ /* Retrieve the last two log records */
+ for (idx=num_records-2; idx<num_records; idx++) {
+
+ struct audit_core_retrieve_input retrieve_input_s =
+ {.record_index = idx,
+ .buffer_size = LOCAL_BUFFER_SIZE,
+ .token = NULL,
+ .token_size = 0};
+
+ retrieve_output_s.buffer =
+ &local_buffer[(idx-(num_records-2))*STANDARD_LOG_ENTRY_SIZE];
+ retrieve_output_s.record_size = &record_size;
+
+ /* Retrieve the last two items */
+ err = tfm_audit_veneer_retrieve_record(&retrieve_input_s,
+ &retrieve_output_s);
+
+ if (err != PSA_AUDIT_ERR_SUCCESS) {
+ TEST_FAIL("Retrieve of last two log records has returned error");
+ return;
+ }
+
+ if (record_size != STANDARD_LOG_ENTRY_SIZE) {
+ TEST_FAIL("Expected record size is " STR(STANDARD_LOG_ENTRY_SIZE));
+ return;
+ }
+ }
+
+ /* Inspect the first record retrieved */
+ if (retrieved_buffer->id != ( DUMMY_TEST_RECORD_ID_BASE +
+ (INITIAL_LOGGING_REQUESTS-1) )) {
+ TEST_FAIL("Unexpected argument in the second last entry");
+ return;
+ }
+
+ /* Inspect the second record retrieved in the local buffer */
+ retrieved_buffer = (struct psa_audit_record *)
+ &local_buffer[offsetof(struct log_hdr,size)+STANDARD_LOG_ENTRY_SIZE];
+
+ if (retrieved_buffer->id != ( DUMMY_TEST_RECORD_ID_BASE +
+ (INITIAL_LOGGING_REQUESTS) )) {
+ TEST_FAIL("Unexpected argument in the last entry");
+ return;
+ }
+
+ /* Fill now one big record that will invalidate all existing records */
+ record->size = MAX_LOG_RECORD_SIZE;
+ record->id = DUMMY_TEST_RECORD_ID_BASE + INITIAL_LOGGING_REQUESTS + 1;
+
+ /* The record has maximum possible payload for log size of 1024 */
+ err = tfm_audit_veneer_add_record(record);
+ if (err != PSA_AUDIT_ERR_SUCCESS) {
+ TEST_FAIL("Record addition has returned an error");
+ return;
+ }
+
+ /* Get the log size */
+ err = tfm_audit_veneer_get_info(&num_records, &stored_size);
+ if (err != PSA_AUDIT_ERR_SUCCESS) {
+ TEST_FAIL("Getting log info has returned error");
+ return;
+ }
+
+ /* Check that the log state has one element with maximum size */
+ if (stored_size != MAX_LOG_SIZE) {
+ TEST_FAIL("Expected log size is " STR(MAX_LOG_SIZE));
+ return;
+ }
+
+ if (num_records != 1) {
+ TEST_FAIL("Expected log records are 1");
+ return;
+ }
+
+ /* Try to retrieve the maximum possible size that fits our buffer.
+ * As there is just one big record filling the whole space, nothing
+ * will be returned and the API will fail
+ */
+ struct audit_core_retrieve_input retrieve_input_s_max =
+ {.record_index = 0,
+ .buffer_size = LOCAL_BUFFER_SIZE,
+ .token = NULL,
+ .token_size = 0};
+
+ retrieve_output_s.buffer = &local_buffer[0];
+ retrieve_output_s.record_size = &record_size;
+
+ err = tfm_audit_veneer_retrieve_record(&retrieve_input_s_max,
+ &retrieve_output_s);
+
+ if (err != PSA_AUDIT_ERR_FAILURE) {
+ TEST_FAIL("Retrieve of index 0 should fail as it's too big");
+ return;
+ }
+
+ if (record_size != 0) {
+ TEST_FAIL("Retrieved log size has unexpected size instead of 0");
+ return;
+ }
+
+ /* Add two standard length records again */
+ for (idx=0; idx<2; idx++) {
+ record->size = sizeof(struct psa_audit_record) - 4;
+ record->id = DUMMY_TEST_RECORD_ID_BASE +
+ INITIAL_LOGGING_REQUESTS + 2 + idx;
+
+ /* The record doesn't contain any payload */
+ err = tfm_audit_veneer_add_record(record);
+ if (err != PSA_AUDIT_ERR_SUCCESS) {
+ TEST_FAIL("Record addition has returned an error");
+ return;
+ }
+ }
+
+ /* Get the log size */
+ err = tfm_audit_veneer_get_info(&num_records, &stored_size);
+ if (err != PSA_AUDIT_ERR_SUCCESS) {
+ TEST_FAIL("Getting log info has returned error");
+ return;
+ }
+
+ /* As the log was full, the addition of the last two log records results
+ * in the resetting of the log completely. The log will contain only
+ * the last two items we have just added.
+ */
+ if (stored_size != FINAL_LOGGING_SIZE) {
+ TEST_FAIL("Expected log size is " STR(FINAL_LOGGING_SIZE));
+ return;
+ }
+
+ if (num_records != FINAL_LOGGING_REQUESTS) {
+ TEST_FAIL("Expected log records are " STR(FINAL_LOGGING_REQUESTS));
+ return;
+ }
+
+ /* Check the length of each record individually */
+ for (idx=0; idx<num_records; idx++) {
+ err = tfm_audit_veneer_get_record_info(idx, &stored_size);
+ if (err != PSA_AUDIT_ERR_SUCCESS) {
+ TEST_FAIL("Getting record size individually has returned error");
+ return;
+ }
+
+ if (stored_size != STANDARD_LOG_ENTRY_SIZE) {
+ TEST_FAIL("Unexpected log record size for a single standard item");
+ return;
+ }
+ }
+
+ /* Check that if requesting length of a record which is not there fails */
+ err = tfm_audit_veneer_get_record_info(num_records, &stored_size);
+ if (err != PSA_AUDIT_ERR_FAILURE) {
+ TEST_FAIL("Getting record size for non-existent record has not failed");
+ return;
+ }
+
+ ret->val = TEST_PASSED;
+}
diff --git a/test/suites/log/secure/log_s_tests.h b/test/suites/audit/secure/audit_s_tests.h
similarity index 68%
rename from test/suites/log/secure/log_s_tests.h
rename to test/suites/audit/secure/audit_s_tests.h
index 0ef77dd..87bc904 100644
--- a/test/suites/log/secure/log_s_tests.h
+++ b/test/suites/audit/secure/audit_s_tests.h
@@ -5,8 +5,8 @@
*
*/
-#ifndef __LOG_S_TESTS_H__
-#define __LOG_S_TESTS_H__
+#ifndef __AUDIT_S_TESTS_H__
+#define __AUDIT_S_TESTS_H__
#ifdef __cplusplus
extern "C" {
@@ -19,10 +19,10 @@
*
* \param[in] p_test_suite The test suite to be executed.
*/
-void register_testsuite_s_log_interface(struct test_suite_t *p_test_suite);
+void register_testsuite_s_audit_interface(struct test_suite_t *p_test_suite);
#ifdef __cplusplus
}
#endif
-#endif /* __LOG_S_TESTS_H__ */
+#endif /* __AUDIT_S_TESTS_H__ */
diff --git a/test/suites/log/non_secure/log_ns_interface_testsuite.c b/test/suites/log/non_secure/log_ns_interface_testsuite.c
deleted file mode 100644
index e1e6c4e..0000000
--- a/test/suites/log/non_secure/log_ns_interface_testsuite.c
+++ /dev/null
@@ -1,249 +0,0 @@
-/*
- * 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"
-#include "secure_fw/services/audit_logging/log_core.h"
-
-#include "../log_tests_common.h"
-
-/*!
- * \def EMPTY_RETRIEVED_LOG_SIZE
- *
- * \brief Log size when the retrieved buffer is empty
- */
-#define EMPTY_RETRIEVED_LOG_SIZE (0)
-
-/*!
- * \def EMPTY_RETRIEVED_LOG_ITEMS
- *
- * \brief Number of log items when retrieved buffer is empty
- */
-#define EMPTY_RETRIEVED_LOG_ITEMS (0)
-
-/*!
- * \def SINGLE_RETRIEVED_LOG_SIZE
- *
- * \brief Log size when the retrieved buffer has 1 item
- * of standard size (no payload)
- */
-#define SINGLE_RETRIEVED_LOG_SIZE (STANDARD_LOG_ENTRY_SIZE)
-
-/*!
- * \def SINGLE_RETRIEVED_LOG_ITEMS
- *
- * \brief Number of log items when retrieved buffer has 1 item
- */
-#define SINGLE_RETRIEVED_LOG_ITEMS (1)
-
-/*!
- * \def SECOND_ELEMENT_START_INDEX
- *
- * \brief Index of the second item in the log
- */
-#define SECOND_ELEMENT_START_INDEX (1)
-
-/* 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",
- "Non Secure functional", {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 Functional test of NS API
- *
- * \note This is a functional test only and doesn't
- * mean to test all possible combinations of
- * input parameters and return values.
- * This tests the current status of the log as
- * it's been left from the Secure tests. In case
- * other tests are added in the Secure test suite,
- * the status of the log will change and these
- * tests may start failing.
- */
-static void tfm_log_test_1001(struct test_result_t *ret)
-{
- enum tfm_log_err err;
-
- uint8_t local_buffer[LOCAL_BUFFER_SIZE];
- uint32_t size, rem_items;
-
- struct tfm_log_info info;
- struct tfm_log_line *retrieved_buffer;
-
- /* Get the log size (current state) */
- err = tfm_log_get_info(&info);
- if (err != TFM_LOG_ERR_SUCCESS) {
- TEST_FAIL("Getting log info has returned error");
- return;
- }
-
- if (info.size != INITIAL_LOG_SIZE) {
- TEST_FAIL("Stored size different from " STR(INITIAL_LOG_SIZE));
- return;
- }
-
- if (info.num_items != INITIAL_LOG_ITEMS) {
- TEST_FAIL("Stored items number different from " STR(INITIAL_LOG_ITEMS));
- return;
- }
-
- /* Log contains 2 items. Retrieve into buffer which is able to contain the
- * the full contents of the log
- */
- size = INITIAL_LOG_SIZE;
-
- err = tfm_log_retrieve(size,
- TFM_LOG_READ_RECENT,
- &local_buffer[0],
- &info);
-
- if (err != TFM_LOG_ERR_SUCCESS) {
- TEST_FAIL("Log retrieval from NS returned error");
- return;
- }
-
- if (info.size != INITIAL_LOG_SIZE) {
- TEST_FAIL("Expected log size to retrieve is " STR(INITIAL_LOG_SIZE));
- return;
- }
-
- if (info.num_items != INITIAL_LOG_ITEMS) {
- TEST_FAIL("Expected number of items read is " STR(INITIAL_LOG_ITEMS));
- return;
- }
-
- /* Retrieve into a 16-byte buffer. It's not enough to store a single
- * item so the provided buffer must be empty after retrieval. We
- * check the info structure to count how many items and bytes have
- * been returned, and if they're zeros items / zero bytes, there is
- * no point in checking the contents of the local_buffer.
- */
- size = 16;
-
- err = tfm_log_retrieve(size,
- TFM_LOG_READ_RECENT,
- &local_buffer[0],
- &info);
-
- if (err != TFM_LOG_ERR_SUCCESS) {
- TEST_FAIL("Log retrieval from NS returned error");
- return;
- }
-
- if (info.size != EMPTY_RETRIEVED_LOG_SIZE) {
- TEST_FAIL("Expected log size is " STR(EMPTY_RETRIEVED_LOG_SIZE));
- return;
- }
-
- if (info.num_items != EMPTY_RETRIEVED_LOG_ITEMS) {
- TEST_FAIL("Expected read items are " STR(EMPTY_RETRIEVED_LOG_ITEMS));
- return;
- }
-
- /* Retrieve into a 70-byte buffer: only last entry fits and is retrieved */
- size = 70;
-
- err = tfm_log_retrieve(size,
- TFM_LOG_READ_RECENT,
- &local_buffer[0],
- &info);
-
- if (err != TFM_LOG_ERR_SUCCESS) {
- TEST_FAIL("Log retrieval from NS returned error");
- return;
- }
-
- if (info.size != SINGLE_RETRIEVED_LOG_SIZE) {
- TEST_FAIL("Expected log size is " STR(SINGLE_RETRIEVED_LOG_SIZE));
- return;
- }
-
- if (info.num_items != SINGLE_RETRIEVED_LOG_ITEMS) {
- TEST_FAIL("Expected read items are " STR(SINGLE_RETRIEVED_LOG_ITEMS));
- return;
- }
-
- /* Retrieve into a buffer which can hold a single element, but start from
- * the second element that is stored in the log
- */
- size = STANDARD_LOG_ENTRY_SIZE;
-
- err = tfm_log_retrieve(size,
- SECOND_ELEMENT_START_INDEX,
- &local_buffer[0],
- &info);
-
- if (err != TFM_LOG_ERR_SUCCESS) {
- TEST_FAIL("Log retrieval from NS returned error");
- return;
- }
-
- if (info.size != SINGLE_RETRIEVED_LOG_SIZE) {
- TEST_FAIL("Expected log size is " STR(SINGLE_RETRIEVED_LOG_SIZE));
- return;
- }
-
- if (info.num_items != SINGLE_RETRIEVED_LOG_ITEMS) {
- TEST_FAIL("Expected read items are " STR(SINGLE_RETRIEVED_LOG_ITEMS));
- return;
- }
-
- /* Inspect the contents of the retrieved buffer, i.e. check the
- * retrieved log line contents
- */
- retrieved_buffer = (struct tfm_log_line *)
- &local_buffer[offsetof(struct log_hdr, size)];
-
- if (retrieved_buffer->arg[0] != SECOND_ELEMENT_EXPECTED_CONTENT) {
- TEST_FAIL("Unexpected argument in the first entry");
- return;
- }
-
- /* Delete one element in the log */
- err = tfm_log_delete_items(1, &rem_items);
- if (err != TFM_LOG_ERR_SUCCESS) {
- TEST_FAIL("Log item deletion from NS returned error");
- return;
- }
-
- if (rem_items != 1) {
- TEST_FAIL("Unexpected number of deleted items different than 1");
- return;
- }
-
- /* Try to delete two elements in the log. The log has just one element, so
- * check that the number of deleted items is less than requested
- */
- err = tfm_log_delete_items(2, &rem_items);
- if (err != TFM_LOG_ERR_SUCCESS) {
- TEST_FAIL("Log item deletion from NS returned error");
- return;
- }
-
- if (rem_items != 1) {
- TEST_FAIL("Unexpected number of deleted items different than 1");
- return;
- }
-
- ret->val = TEST_PASSED;
-}
diff --git a/test/suites/log/secure/log_s_interface_testsuite.c b/test/suites/log/secure/log_s_interface_testsuite.c
deleted file mode 100644
index e1be93a..0000000
--- a/test/suites/log/secure/log_s_interface_testsuite.c
+++ /dev/null
@@ -1,398 +0,0 @@
-/*
- * 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"
-#include "secure_fw/services/audit_logging/log_core.h"
-
-#include "../log_tests_common.h"
-
-/*!
- * \def TEST_FUNCTION_ID
- *
- * \brief The log line is initialized with a function ID
- * which corresponds to the requester function ID, i.e.
- * a dummy test function ID
- */
-#define DUMMY_TEST_FUNCTION_ID (0xABCDABCD)
-
-/*!
- * \def BASE_RETRIEVAL_LOG_INDEX
- *
- * \brief Base index from where to start elements retrieval
- */
-#define BASE_RETRIEVAL_LOG_INDEX (6)
-
-/*!
- * \def FIRST_RETRIEVAL_LOG_INDEX
- *
- * \brief Index of the first element in the log
- */
-#define FIRST_RETRIEVAL_LOG_INDEX (0)
-
-/* 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",
- "Secure functional", {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 Functional test of the Secure interface
- *
- * \note This is a functional test only and doesn't
- * mean to test all possible combinations of
- * input parameters and return values.
- * This tests will leave the log in a certain
- * status which, in turn, will be evaluated by
- * the Non Secure functional tests. If any tests
- * are added here that will leave the log in a
- * different state, Non Secure functional tests
- * need to be amended accordingly.
- */
-static void tfm_log_test_1001(struct test_result_t *ret)
-{
- enum tfm_log_err err;
- uint8_t local_buffer[LOCAL_BUFFER_SIZE], idx = 0;
- struct tfm_log_line *line = (struct tfm_log_line *)
- &local_buffer[0];
- struct tfm_log_info info;
- struct tfm_log_line *retrieved_buffer;
-
- /* Fill the log with 25 lines, each line is 40 bytes
- * we end up filling the log without wrapping
- */
- for (idx=0; idx<INITIAL_LOGGING_REQUESTS; idx++) {
- line->size = sizeof(struct tfm_log_line) - 4;
- line->function_id = DUMMY_TEST_FUNCTION_ID;
- line->arg[0] = 0x1 + idx*10;
- line->arg[1] = 0x2 + idx*10;
- line->arg[2] = 0x3 + idx*10;
- line->arg[3] = 0x4 + idx*10;
-
- /* 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;
- }
- }
-
- /* Get the log size */
- err = tfm_log_veneer_get_info(&info);
- if (err != TFM_LOG_ERR_SUCCESS) {
- TEST_FAIL("Getting log info has returned error");
- return;
- }
-
- if (info.size != INITIAL_LOGGING_SIZE) {
- TEST_FAIL("Expected log size is " STR(INITIAL_LOGGING_SIZE));
- return;
- }
-
- if (info.num_items != INITIAL_LOGGING_REQUESTS) {
- TEST_FAIL("Expected log items are " STR(INITIAL_LOGGING_REQUESTS));
- return;
- }
-
- /* Retrieve two log items starting from a given index */
- err = tfm_log_veneer_retrieve(LOCAL_BUFFER_SIZE,
- BASE_RETRIEVAL_LOG_INDEX,
- &local_buffer[0],
- &info);
-
- if (err != TFM_LOG_ERR_SUCCESS) {
- TEST_FAIL("Retrieve indexes 6 and 7 has returned an error");
- return;
- }
-
- if (info.size != (2*STANDARD_LOG_ENTRY_SIZE)) {
- TEST_FAIL("Expected log size is " STR((2*STANDARD_LOG_ENTRY_SIZE)));
- return;
- }
-
- if (info.num_items != LOCAL_BUFFER_ITEMS) {
- TEST_FAIL("Expected log items are " STR(LOCAL_BUFFER_ITEMS));
- return;
- }
-
- /* Inspect the content of the second log line retrieved */
- retrieved_buffer = (struct tfm_log_line *)
- &local_buffer[offsetof(struct log_hdr,size)+STANDARD_LOG_ENTRY_SIZE];
-
- if (retrieved_buffer->arg[0] != (0x1 + (BASE_RETRIEVAL_LOG_INDEX+1)*10)) {
- TEST_FAIL("Unexpected argument in the index 7 entry");
- return;
- }
-
- /* Retrieve the last two log items */
- err = tfm_log_veneer_retrieve(LOCAL_BUFFER_SIZE,
- TFM_LOG_READ_RECENT,
- &local_buffer[0],
- &info);
-
- if (err != TFM_LOG_ERR_SUCCESS) {
- TEST_FAIL("Retrieve of last two log entries has returned error");
- return;
- }
-
- /* Inspect the first line retrieved in the local buffer */
- retrieved_buffer = (struct tfm_log_line *)
- &local_buffer[offsetof(struct log_hdr,size)];
-
- if (info.size != (2*STANDARD_LOG_ENTRY_SIZE)) {
- TEST_FAIL("Expected log size is " STR((2*STANDARD_LOG_ENTRY_SIZE)));
- return;
- }
-
- if (info.num_items != LOCAL_BUFFER_ITEMS) {
- TEST_FAIL("Expected log items are " STR(LOCAL_BUFFER_ITEMS));
- return;
- }
-
- if (retrieved_buffer->arg[0] != (0x1 + (INITIAL_LOGGING_REQUESTS-2)*10)) {
- TEST_FAIL("Unexpected argument in the second last entry");
- return;
- }
-
- /* Retrieve the first log item */
- err = tfm_log_veneer_retrieve(STANDARD_LOG_ENTRY_SIZE,
- FIRST_RETRIEVAL_LOG_INDEX,
- &local_buffer[0],
- &info);
-
- if (err != TFM_LOG_ERR_SUCCESS) {
- TEST_FAIL("Retrieve of the first log entry has returned error");
- return;
- }
-
- if (info.size != STANDARD_LOG_ENTRY_SIZE) {
- TEST_FAIL("Expected log size is " STR(STANDARD_LOG_ENTRY_SIZE));
- return;
- }
-
- if (info.num_items != 1) {
- TEST_FAIL("Number of items read is different from 1");
- return;
- }
-
- if (retrieved_buffer->arg[0] != (0x1 + FIRST_RETRIEVAL_LOG_INDEX*10)) {
- TEST_FAIL("Unexpected argument in the first entry");
- return;
- }
-
- /* Retrieve the last log item. Provide a buffer size which is slightly
- * bigger than the size of a single log entry
- */
- err = tfm_log_veneer_retrieve(STANDARD_LOG_ENTRY_SIZE+4,
- TFM_LOG_READ_RECENT,
- &local_buffer[0],
- &info);
-
- if (err != TFM_LOG_ERR_SUCCESS) {
- TEST_FAIL("Retrieve of last two log entries has returned error");
- return;
- }
-
- if (info.size != STANDARD_LOG_ENTRY_SIZE) {
- TEST_FAIL("Expected log size is " STR(STANDARD_LOG_ENTRY_SIZE));
- return;
- }
-
- if (info.num_items != 1) {
- TEST_FAIL("Number of items read is different from 1");
- return;
- }
-
- if (retrieved_buffer->arg[0] != (0x1 + (INITIAL_LOGGING_REQUESTS-1)*10)) {
- TEST_FAIL("Unexpected argument in the second last entry");
- return;
- }
-
- /* Fill one more log line, this will wrap */
- line->size = sizeof(struct tfm_log_line) - 4;
- line->function_id = DUMMY_TEST_FUNCTION_ID;
- line->arg[0] = 0x1 + INITIAL_LOGGING_REQUESTS*10;
- line->arg[1] = 0x2 + INITIAL_LOGGING_REQUESTS*10;
- line->arg[2] = 0x3 + INITIAL_LOGGING_REQUESTS*10;
- line->arg[3] = 0x4 + INITIAL_LOGGING_REQUESTS*10;
-
- /* The addition of this new log item will wrap the log ending */
- err = tfm_log_veneer_add_line(line);
- if (err != TFM_LOG_ERR_SUCCESS) {
- TEST_FAIL("Log line addition has returned an error");
- return;
- }
-
- /* Get the log size */
- err = tfm_log_veneer_get_info(&info);
- if (err != TFM_LOG_ERR_SUCCESS) {
- TEST_FAIL("Getting log info has returned error");
- return;
- }
-
- /* Check that the log state is the same, the item addition just performed
- * is resulted into the removal of the oldest entry, so log size and number
- * of log items is still the same as before
- */
- if (info.size != INITIAL_LOGGING_SIZE) {
- TEST_FAIL("Expected log size is " STR(INITIAL_LOGGING_SIZE));
- return;
- }
-
- if (info.num_items != INITIAL_LOGGING_REQUESTS) {
- TEST_FAIL("Expected log items are " STR(INITIAL_LOGGING_REQUESTS));
- return;
- }
-
- /* Retrieve the last two items */
- err = tfm_log_veneer_retrieve(LOCAL_BUFFER_SIZE,
- TFM_LOG_READ_RECENT,
- &local_buffer[0],
- &info);
-
- if (err != TFM_LOG_ERR_SUCCESS) {
- TEST_FAIL("Retrieve of last two log entries has returned error");
- return;
- }
-
- if (info.size != (2*STANDARD_LOG_ENTRY_SIZE)) {
- TEST_FAIL("Expected log size is " STR((2*STANDARD_LOG_ENTRY_SIZE)));
- return;
- }
-
- if (info.num_items != LOCAL_BUFFER_ITEMS) {
- TEST_FAIL("Expected log items are " STR(LOCAL_BUFFER_ITEMS));
- return;
- }
-
- if (retrieved_buffer->arg[0] != (0x1 + (INITIAL_LOGGING_REQUESTS-1)*10)) {
- TEST_FAIL("Unexpected argument in the second last entry");
- return;
- }
-
- /* Inspect the second line retrieved in the local buffer */
- retrieved_buffer = (struct tfm_log_line *)
- &local_buffer[offsetof(struct log_hdr,size)+STANDARD_LOG_ENTRY_SIZE];
-
- if (retrieved_buffer->arg[0] != (0x1 + INITIAL_LOGGING_REQUESTS*10)) {
- TEST_FAIL("Unexpected argument in the last entry");
- return;
- }
-
- /* Fill now one big line that will invalidate all existing lines */
- line->size = MAX_LOG_LINE_SIZE;
- line->function_id = DUMMY_TEST_FUNCTION_ID;
- line->arg[0] = 0x1 + ((INITIAL_LOGGING_REQUESTS+1)*10);
- line->arg[1] = 0x2 + ((INITIAL_LOGGING_REQUESTS+1)*10);
- line->arg[2] = 0x3 + ((INITIAL_LOGGING_REQUESTS+1)*10);
- line->arg[3] = 0x4 + ((INITIAL_LOGGING_REQUESTS+1)*10);
-
- /* The line has maximum possible payload for log size of 1024 */
- err = tfm_log_veneer_add_line(line);
- if (err != TFM_LOG_ERR_SUCCESS) {
- TEST_FAIL("Log line addition has returned an error");
- return;
- }
-
- /* Get the log size */
- err = tfm_log_veneer_get_info(&info);
- if (err != TFM_LOG_ERR_SUCCESS) {
- TEST_FAIL("Getting log info has returned error");
- return;
- }
-
- /* Check that the log state has one element with maximum size */
- if (info.size != MAX_LOG_SIZE) {
- TEST_FAIL("Expected log size is " STR(MAX_LOG_SIZE));
- return;
- }
-
- if (info.num_items != 1) {
- TEST_FAIL("Expected log items are 1");
- return;
- }
-
- /* Try to retrieve the maximum possible size that fits our buffer.
- * As there is just one big line filling the whole space, nothing
- * will be returned
- */
- err = tfm_log_veneer_retrieve(LOCAL_BUFFER_SIZE,
- TFM_LOG_READ_RECENT,
- &local_buffer[0],
- &info);
-
- if (err != TFM_LOG_ERR_SUCCESS) {
- TEST_FAIL("Retrieve of last two log entries has returned error");
- return;
- }
-
- if (info.size != 0) {
- TEST_FAIL("Retrieved log size has unexpected size instead of 0");
- return;
- }
-
- if (info.num_items != 0) {
- TEST_FAIL("Number of items read is different from 0");
- return;
- }
-
- /* Add two standard length lines again */
- for (idx=0; idx<2; idx++) {
- line->size = sizeof(struct tfm_log_line) - 4;
- line->function_id = DUMMY_TEST_FUNCTION_ID;
- line->arg[0] = 0x1 + (INITIAL_LOGGING_REQUESTS+2+idx)*10;
- line->arg[1] = 0x2 + (INITIAL_LOGGING_REQUESTS+2+idx)*10;
- line->arg[2] = 0x3 + (INITIAL_LOGGING_REQUESTS+2+idx)*10;
- line->arg[3] = 0x4 + (INITIAL_LOGGING_REQUESTS+2+idx)*10;
-
- /* 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;
- }
- }
-
- /* Get the log size */
- err = tfm_log_veneer_get_info(&info);
- if (err != TFM_LOG_ERR_SUCCESS) {
- TEST_FAIL("Getting log info has returned error");
- return;
- }
-
- /* As the log was full, the addition of the last two log lines results
- * in the resetting of the log completely. The log will contain only
- * the last two items we have just added.
- */
- if (info.size != FINAL_LOGGING_SIZE) {
- TEST_FAIL("Expected log size is " STR(FINAL_LOGGING_SIZE));
- return;
- }
-
- if (info.num_items != FINAL_LOGGING_REQUESTS) {
- TEST_FAIL("Expected log items are " STR(FINAL_LOGGING_REQUESTS));
- return;
- }
-
- ret->val = TEST_PASSED;
-}