Add mock PSA FWU M interface implementation
Implement mock PSA FWU M interface for testing.
Signed-off-by: Imre Kis <imre.kis@arm.com>
Change-Id: Ie4977346bf5948ce61b470ae482dfd9c5683482f
diff --git a/components/service/fwu/psa_fwu_m/interface/mock/component.cmake b/components/service/fwu/psa_fwu_m/interface/mock/component.cmake
new file mode 100644
index 0000000..176a4aa
--- /dev/null
+++ b/components/service/fwu/psa_fwu_m/interface/mock/component.cmake
@@ -0,0 +1,13 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2024, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+if (NOT DEFINED TGT)
+ message(FATAL_ERROR "mandatory parameter TGT is not defined.")
+endif()
+
+target_sources(${TGT} PRIVATE
+ "${CMAKE_CURRENT_LIST_DIR}/mock_psa_fwu_m.cpp"
+)
diff --git a/components/service/fwu/psa_fwu_m/interface/mock/mock_psa_fwu_m.cpp b/components/service/fwu/psa_fwu_m/interface/mock/mock_psa_fwu_m.cpp
new file mode 100644
index 0000000..fd24c55
--- /dev/null
+++ b/components/service/fwu/psa_fwu_m/interface/mock/mock_psa_fwu_m.cpp
@@ -0,0 +1,160 @@
+/*
+ * Copyright (c) 2024, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#include "mock_psa_fwu_m.h"
+#include <CppUTestExt/MockSupport.h>
+
+void expect_mock_psa_fwu_query(psa_fwu_component_t component, const psa_fwu_component_info_t *info,
+ psa_status_t result)
+{
+ mock().
+ expectOneCall("psa_fwu_query").
+ withUnsignedIntParameter("component", component).
+ withOutputParameterReturning("info", info, sizeof(*info)).
+ andReturnValue(result);
+}
+
+psa_status_t psa_fwu_query(psa_fwu_component_t component, psa_fwu_component_info_t *info)
+{
+ return mock().
+ actualCall("psa_fwu_query").
+ withUnsignedIntParameter("component", component).
+ withOutputParameter("info", info).
+ returnIntValue();
+}
+
+void expect_mock_psa_fwu_start(psa_fwu_component_t component, const void *manifest,
+ size_t manifest_size, psa_status_t result)
+{
+ mock().
+ expectOneCall("psa_fwu_start").
+ withUnsignedIntParameter("component", component).
+ withMemoryBufferParameter("manifest", (const uint8_t *)manifest, manifest_size).
+ withUnsignedIntParameter("manifest_size", manifest_size).
+ andReturnValue(result);
+}
+
+psa_status_t psa_fwu_start(psa_fwu_component_t component, const void *manifest,
+ size_t manifest_size)
+{
+ return mock().
+ actualCall("psa_fwu_start").
+ withUnsignedIntParameter("component", component).
+ withMemoryBufferParameter("manifest", (const uint8_t *)manifest, manifest_size).
+ withUnsignedIntParameter("manifest_size", manifest_size).
+ returnIntValue();
+}
+
+void expect_mock_psa_fwu_write(psa_fwu_component_t component, size_t image_offset,
+ void *block, size_t block_size, psa_status_t result)
+{
+ mock().
+ expectOneCall("psa_fwu_write").
+ withUnsignedIntParameter("image_offset", image_offset).
+ withMemoryBufferParameter("block", (const uint8_t *)block, block_size).
+ withUnsignedIntParameter("block_size", block_size).
+ andReturnValue(result);
+}
+
+psa_status_t psa_fwu_write(psa_fwu_component_t component, size_t image_offset, const void *block,
+ size_t block_size)
+{
+ return mock().
+ actualCall("psa_fwu_write").
+ withUnsignedIntParameter("image_offset", image_offset).
+ withMemoryBufferParameter("block", (const uint8_t *)block, block_size).
+ withUnsignedIntParameter("block_size", block_size).
+ returnIntValue();
+}
+
+void expect_mock_psa_fwu_finish(psa_fwu_component_t component, psa_status_t result)
+{
+ mock().
+ expectOneCall("psa_fwu_finish").
+ withUnsignedIntParameter("component", component).
+ andReturnValue(result);
+}
+
+psa_status_t psa_fwu_finish(psa_fwu_component_t component)
+{
+ return mock().
+ actualCall("psa_fwu_finish").
+ withUnsignedIntParameter("component", component).
+ returnIntValue();
+}
+
+void expect_mock_psa_fwu_cancel(psa_fwu_component_t component, psa_status_t result)
+{
+ mock().
+ expectOneCall("psa_fwu_cancel").
+ withUnsignedIntParameter("component", component).
+ andReturnValue(result);
+}
+
+psa_status_t psa_fwu_cancel(psa_fwu_component_t component)
+{
+ return mock().
+ actualCall("psa_fwu_cancel").
+ withUnsignedIntParameter("component", component).
+ returnIntValue();
+}
+
+void expect_mock_psa_fwu_clean(psa_fwu_component_t component, psa_status_t result)
+{
+ mock().
+ expectOneCall("psa_fwu_clean").
+ withUnsignedIntParameter("component", component).
+ andReturnValue(result);
+}
+
+psa_status_t psa_fwu_clean(psa_fwu_component_t component)
+{
+ return mock().
+ actualCall("psa_fwu_clean").
+ withUnsignedIntParameter("component", component).
+ returnIntValue();
+}
+
+void expect_mock_psa_fwu_install(psa_status_t result)
+{
+ mock().expectOneCall("psa_fwu_install").andReturnValue(result);
+}
+
+psa_status_t psa_fwu_install(void)
+{
+ return mock().actualCall("psa_fwu_install").returnIntValue();
+}
+
+void expect_mock_psa_fwu_request_reboot(psa_status_t result)
+{
+ mock().expectOneCall("psa_fwu_request_reboot").andReturnValue(result);
+}
+
+psa_status_t psa_fwu_request_reboot(void)
+{
+ return mock().actualCall("psa_fwu_request_reboot").returnIntValue();
+}
+
+void expect_mock_psa_fwu_reject(psa_status_t error, psa_status_t result)
+{
+ mock().expectOneCall("psa_fwu_reject").withIntParameter("error", error).andReturnValue(result);
+}
+
+psa_status_t psa_fwu_reject(psa_status_t error)
+{
+ return mock().actualCall("psa_fwu_reject").withIntParameter("error", error).returnIntValue();
+}
+
+void expect_mock_psa_fwu_accept(psa_status_t result)
+{
+ mock().expectOneCall("psa_fwu_accept").andReturnValue(result);
+}
+
+psa_status_t psa_fwu_accept(void)
+{
+ return mock().actualCall("psa_fwu_accept").returnIntValue();
+}
\ No newline at end of file
diff --git a/components/service/fwu/psa_fwu_m/interface/mock/mock_psa_fwu_m.h b/components/service/fwu/psa_fwu_m/interface/mock/mock_psa_fwu_m.h
new file mode 100644
index 0000000..954f07c
--- /dev/null
+++ b/components/service/fwu/psa_fwu_m/interface/mock/mock_psa_fwu_m.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2024, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#include "../update.h"
+
+void expect_mock_psa_fwu_query(psa_fwu_component_t component, const psa_fwu_component_info_t *info,
+ psa_status_t result);
+
+void expect_mock_psa_fwu_start(psa_fwu_component_t component, const void *manifest,
+ size_t manifest_size, psa_status_t result);
+
+void expect_mock_psa_fwu_write(psa_fwu_component_t component, size_t image_offset,
+ void *block, size_t block_size, psa_status_t result);
+
+void expect_mock_psa_fwu_finish(psa_fwu_component_t component, psa_status_t result);
+
+void expect_mock_psa_fwu_cancel(psa_fwu_component_t component, psa_status_t result);
+
+void expect_mock_psa_fwu_clean(psa_fwu_component_t component, psa_status_t result);
+
+void expect_mock_psa_fwu_install(psa_status_t result);
+
+void expect_mock_psa_fwu_request_reboot(psa_status_t result);
+
+void expect_mock_psa_fwu_reject(psa_status_t error, psa_status_t result);
+
+void expect_mock_psa_fwu_accept(psa_status_t result);
diff --git a/components/service/fwu/psa_fwu_m/interface/mock/test/component.cmake b/components/service/fwu/psa_fwu_m/interface/mock/test/component.cmake
new file mode 100644
index 0000000..8846b40
--- /dev/null
+++ b/components/service/fwu/psa_fwu_m/interface/mock/test/component.cmake
@@ -0,0 +1,13 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2024, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+if (NOT DEFINED TGT)
+ message(FATAL_ERROR "mandatory parameter TGT is not defined.")
+endif()
+
+target_sources(${TGT} PRIVATE
+ "${CMAKE_CURRENT_LIST_DIR}/test_mock_psa_fwu_m.cpp"
+)
diff --git a/components/service/fwu/psa_fwu_m/interface/mock/test/test_mock_psa_fwu_m.cpp b/components/service/fwu/psa_fwu_m/interface/mock/test/test_mock_psa_fwu_m.cpp
new file mode 100644
index 0000000..b3287f2
--- /dev/null
+++ b/components/service/fwu/psa_fwu_m/interface/mock/test/test_mock_psa_fwu_m.cpp
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2024, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#include "../mock_psa_fwu_m.h"
+#include <string.h>
+#include <CppUTest/TestHarness.h>
+#include <CppUTestExt/MockSupport.h>
+
+TEST_GROUP(mock_psa_fwu_m) {
+ TEST_TEARDOWN() {
+ mock().checkExpectations();
+ mock().clear();
+ }
+
+ const psa_fwu_component_t component = 0x5a;
+ const psa_status_t result = PSA_ERROR_GENERIC_ERROR;
+};
+
+TEST(mock_psa_fwu_m, query)
+{
+ psa_fwu_component_info_t expected_info = { 0 };
+ psa_fwu_component_info_t info = { 0 };
+
+ memset(&expected_info, 0x5a, sizeof(expected_info));
+
+ expect_mock_psa_fwu_query(component, &expected_info, result);
+ LONGS_EQUAL(result, psa_fwu_query(component, &info));
+ MEMCMP_EQUAL(&info, &expected_info, sizeof(info));
+}
+
+TEST(mock_psa_fwu_m, start)
+{
+ uint8_t manifest[8];
+
+ memset(manifest, 0x5a, sizeof(manifest));
+
+ expect_mock_psa_fwu_start(component, manifest, sizeof(manifest), result);
+ LONGS_EQUAL(result, psa_fwu_start(component, manifest, sizeof(manifest)));
+}
+
+TEST(mock_psa_fwu_m, start_null_manifest)
+{
+ expect_mock_psa_fwu_start(component, NULL, 0, result);
+ LONGS_EQUAL(result, psa_fwu_start(component, NULL, 0));
+}
+
+TEST(mock_psa_fwu_m, write)
+{
+ const size_t image_offset = 0x1000;
+ uint8_t block[8];
+
+ memset(block, 0x5a, sizeof(block));
+
+ expect_mock_psa_fwu_write(component, image_offset, block, sizeof(block), result);
+ LONGS_EQUAL(result, psa_fwu_write(component, image_offset, block, sizeof(block)));
+}
+
+TEST(mock_psa_fwu_m, finish)
+{
+ expect_mock_psa_fwu_finish(component, result);
+ LONGS_EQUAL(result, psa_fwu_finish(component));
+}
+
+TEST(mock_psa_fwu_m, cancel)
+{
+ expect_mock_psa_fwu_cancel(component, result);
+ LONGS_EQUAL(result, psa_fwu_cancel(component));
+}
+
+TEST(mock_psa_fwu_m, clean)
+{
+ expect_mock_psa_fwu_clean(component, result);
+ LONGS_EQUAL(result, psa_fwu_clean(component));
+}
+
+TEST(mock_psa_fwu_m, install)
+{
+ expect_mock_psa_fwu_install(result);
+ LONGS_EQUAL(result, psa_fwu_install());
+}
+
+TEST(mock_psa_fwu_m, request_reboot)
+{
+ expect_mock_psa_fwu_request_reboot(result);
+ LONGS_EQUAL(result, psa_fwu_request_reboot());
+}
+
+TEST(mock_psa_fwu_m, reject)
+{
+ psa_status_t error = PSA_ERROR_STORAGE_FAILURE;
+
+ expect_mock_psa_fwu_reject(error, result);
+ LONGS_EQUAL(result, psa_fwu_reject(error));
+}
+
+TEST(mock_psa_fwu_m, accept)
+{
+ expect_mock_psa_fwu_accept(result);
+ LONGS_EQUAL(result, psa_fwu_accept());
+}
diff --git a/components/service/fwu/psa_fwu_m/interface/update.h b/components/service/fwu/psa_fwu_m/interface/update.h
index 3c8037a..c11c07f 100644
--- a/components/service/fwu/psa_fwu_m/interface/update.h
+++ b/components/service/fwu/psa_fwu_m/interface/update.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021-2022, Arm Limited. All rights reserved.
+ * Copyright (c) 2021-2024, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
@@ -14,13 +14,12 @@
#include <stdint.h>
#include "psa/error.h"
-#ifdef FWU_DEVICE_CONFIG_FILE
-#include FWU_DEVICE_CONFIG_FILE
-#else
-#include "psa/fwu_config.h"
-#endif
#include "tfm_fwu_defs.h"
+#ifndef TFM_FWU_MAX_DIGEST_SIZE
+#define TFM_FWU_MAX_DIGEST_SIZE 32
+#endif /* TFM_FWU_MAX_DIGEST_SIZE */
+
#ifdef __cplusplus
extern "C" {
#endif
diff --git a/deployments/component-test/component-test.cmake b/deployments/component-test/component-test.cmake
index 9cb5fe0..625d348 100644
--- a/deployments/component-test/component-test.cmake
+++ b/deployments/component-test/component-test.cmake
@@ -122,6 +122,8 @@
"components/service/fwu/inspector/direct"
"components/service/fwu/provider"
"components/service/fwu/provider/serializer"
+ "components/service/fwu/psa_fwu_m/interface/mock"
+ "components/service/fwu/psa_fwu_m/interface/mock/test"
"components/service/fwu/test/fwu_client/direct"
"components/service/fwu/test/fwu_dut"
"components/service/fwu/test/fwu_dut/sim"