aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJamie Fox <jamie.fox@arm.com>2020-06-12 17:03:23 +0100
committerJamie Fox <jamie.fox@arm.com>2020-06-23 15:22:25 +0100
commit4d0a6285a3da9a87e6ab17fd26d45c7b5c283d97 (patch)
tree6225b5da0d7bbe7ad1eceb3979f39f17298e155b
parent9cfcd7a64a13322fc1f606abb4b7080a0fd2f86a (diff)
downloadtrusted-firmware-m-4d0a6285a3da9a87e6ab17fd26d45c7b5c283d97.tar.gz
Test: Warn when a write-once UID already exists
Changes the storage tests to print a warning, but not fail the test, when the UID that is created with the PSA_STORAGE_FLAG_WRITE_ONCE flag already exists in storage. This makes it possible to run the storage tests multiple times with persistent storage without having failing tests. This is more desirable than automatically wiping the storage before every test run, as it provides proper test coverage for initialisation with an existing filesystem. Change-Id: Ia25384b6a1bb7fc0c718752b9a1ce409f1969507 Signed-off-by: Jamie Fox <jamie.fox@arm.com>
-rw-r--r--test/suites/its/its_tests_common.c36
-rw-r--r--test/suites/ps/non_secure/psa_ps_ns_interface_testsuite.c34
-rw-r--r--test/suites/ps/secure/psa_ps_s_interface_testsuite.c34
3 files changed, 64 insertions, 40 deletions
diff --git a/test/suites/its/its_tests_common.c b/test/suites/its/its_tests_common.c
index 9921952cb0..eb4e21c912 100644
--- a/test/suites/its/its_tests_common.c
+++ b/test/suites/its/its_tests_common.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, Arm Limited. All rights reserved.
+ * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
@@ -68,23 +68,31 @@ void tfm_its_test_common_002(struct test_result_t *ret)
/* Set with no flags */
status = psa_its_set(WRITE_ONCE_UID, data_len, write_data, flags);
- if (status != PSA_SUCCESS) {
+ if (status == PSA_SUCCESS) {
+ /* Set with valid flag: PSA_STORAGE_FLAG_WRITE_ONCE (with previously
+ * created UID)
+ * Note: Once created, WRITE_ONCE_UID cannot be deleted. It is reused
+ * across multiple tests.
+ */
+ status = psa_its_set(WRITE_ONCE_UID, WRITE_ONCE_DATA_SIZE,
+ WRITE_ONCE_DATA, PSA_STORAGE_FLAG_WRITE_ONCE);
+ if (status != PSA_SUCCESS) {
+ TEST_FAIL("Set should not fail with valid flags (existing UID)");
+ return;
+ }
+ } else if (status == PSA_ERROR_NOT_PERMITTED) {
+ /* The UID has already been created with the PSA_STORAGE_FLAG_WRITE_ONCE
+ * flag in a previous test run, so skip creating it again and emit a
+ * warning.
+ */
+ TEST_LOG("Note: The UID in this test has already been created with\r\n"
+ "the PSA_STORAGE_FLAG_WRITE_ONCE flag in a previous test\r\n"
+ "run. Wipe the storage area to run the full test.\r\n");
+ } else {
TEST_FAIL("Set should not fail with no flags");
return;
}
- /* Set with valid flag: PSA_STORAGE_FLAG_WRITE_ONCE (with previously created
- * UID)
- * Note: Once created, WRITE_ONCE_UID cannot be deleted. It is reused across
- * multiple tests.
- */
- status = psa_its_set(WRITE_ONCE_UID, WRITE_ONCE_DATA_SIZE, WRITE_ONCE_DATA,
- PSA_STORAGE_FLAG_WRITE_ONCE);
- if (status != PSA_SUCCESS) {
- TEST_FAIL("Set should not fail with valid flags (and existing UID)");
- return;
- }
-
/* Set with invalid flags */
status = psa_its_set(uid, data_len, write_data, INVALID_FLAG);
if (status != PSA_ERROR_NOT_SUPPORTED) {
diff --git a/test/suites/ps/non_secure/psa_ps_ns_interface_testsuite.c b/test/suites/ps/non_secure/psa_ps_ns_interface_testsuite.c
index e7b767cf72..73b2e2a6aa 100644
--- a/test/suites/ps/non_secure/psa_ps_ns_interface_testsuite.c
+++ b/test/suites/ps/non_secure/psa_ps_ns_interface_testsuite.c
@@ -209,23 +209,31 @@ TFM_PS_NS_TEST(1002, "Thread_A")
/* Set with no flags */
status = psa_ps_set(WRITE_ONCE_UID, data_len, write_data, flags);
- if (status != PSA_SUCCESS) {
+ if (status == PSA_SUCCESS) {
+ /* Set with valid flag: PSA_STORAGE_FLAG_WRITE_ONCE (with previously
+ * created UID)
+ * Note: Once created, WRITE_ONCE_UID cannot be deleted. It is reused
+ * across multiple tests.
+ */
+ status = psa_ps_set(WRITE_ONCE_UID, WRITE_ONCE_DATA_SIZE,
+ WRITE_ONCE_DATA, PSA_STORAGE_FLAG_WRITE_ONCE);
+ if (status != PSA_SUCCESS) {
+ TEST_FAIL("Set should not fail with valid flags (existing UID)");
+ return;
+ }
+ } else if (status == PSA_ERROR_NOT_PERMITTED) {
+ /* The UID has already been created with the PSA_STORAGE_FLAG_WRITE_ONCE
+ * flag in a previous test run, so skip creating it again and emit a
+ * warning.
+ */
+ TEST_LOG("Note: The UID in this test has already been created with\r\n"
+ "the PSA_STORAGE_FLAG_WRITE_ONCE flag in a previous test\r\n"
+ "run. Wipe the storage area to run the full test.\r\n");
+ } else {
TEST_FAIL("Set should not fail with no flags");
return;
}
- /* Set with valid flag: PSA_STORAGE_FLAG_WRITE_ONCE
- * (with previously created UID)
- * Note: Once created, WRITE_ONCE_UID cannot be deleted. It is reused across
- * multiple tests.
- */
- status = psa_ps_set(WRITE_ONCE_UID, WRITE_ONCE_DATA_SIZE, WRITE_ONCE_DATA,
- PSA_STORAGE_FLAG_WRITE_ONCE);
- if (status != PSA_SUCCESS) {
- TEST_FAIL("Set should not fail with valid flags (and existing UID)");
- return;
- }
-
/* Set with invalid flags */
status = psa_ps_set(uid, data_len, write_data, INVALID_FLAG);
if (status != PSA_ERROR_NOT_SUPPORTED) {
diff --git a/test/suites/ps/secure/psa_ps_s_interface_testsuite.c b/test/suites/ps/secure/psa_ps_s_interface_testsuite.c
index 7db5b3421c..c8d651669d 100644
--- a/test/suites/ps/secure/psa_ps_s_interface_testsuite.c
+++ b/test/suites/ps/secure/psa_ps_s_interface_testsuite.c
@@ -195,23 +195,31 @@ static void tfm_ps_test_2002(struct test_result_t *ret)
/* Set with no flags */
status = psa_ps_set(WRITE_ONCE_UID, data_len, write_data, flags);
- if (status != PSA_SUCCESS) {
+ if (status == PSA_SUCCESS) {
+ /* Set with valid flag: PSA_STORAGE_FLAG_WRITE_ONCE (with previously
+ * created UID)
+ * Note: Once created, WRITE_ONCE_UID cannot be deleted. It is reused
+ * across multiple tests.
+ */
+ status = psa_ps_set(WRITE_ONCE_UID, WRITE_ONCE_DATA_SIZE,
+ WRITE_ONCE_DATA, PSA_STORAGE_FLAG_WRITE_ONCE);
+ if (status != PSA_SUCCESS) {
+ TEST_FAIL("Set should not fail with valid flags (existing UID)");
+ return;
+ }
+ } else if (status == PSA_ERROR_NOT_PERMITTED) {
+ /* The UID has already been created with the PSA_STORAGE_FLAG_WRITE_ONCE
+ * flag in a previous test run, so skip creating it again and emit a
+ * warning.
+ */
+ TEST_LOG("Note: The UID in this test has already been created with\r\n"
+ "the PSA_STORAGE_FLAG_WRITE_ONCE flag in a previous test\r\n"
+ "run. Wipe the storage area to run the full test.\r\n");
+ } else {
TEST_FAIL("Set should not fail with no flags");
return;
}
- /* Set with valid flag: PSA_STORAGE_FLAG_WRITE_ONCE
- * (with previously created UID)
- * Note: Once created, WRITE_ONCE_UID cannot be deleted. It is reused across
- * multiple tests.
- */
- status = psa_ps_set(WRITE_ONCE_UID, WRITE_ONCE_DATA_SIZE, WRITE_ONCE_DATA,
- PSA_STORAGE_FLAG_WRITE_ONCE);
- if (status != PSA_SUCCESS) {
- TEST_FAIL("Set should not fail with valid flags (and existing UID)");
- return;
- }
-
/* Set with invalid flags */
status = psa_ps_set(uid, data_len, write_data, INVALID_FLAG);
if (status != PSA_ERROR_NOT_SUPPORTED) {