test(smc_fuzzing): add tsp testing
Adding TSP based SMC instructions to fuzzing infrastructure.
Change-Id: Ic47879dd6294be5afe44a37da9a630cf635f920a
Signed-off-by: mardyk01 <mark.dykes@arm.com>
diff --git a/smc_fuzz/dts/top.dts b/smc_fuzz/dts/top.dts
index 201b2a3..bda77d6 100644
--- a/smc_fuzz/dts/top.dts
+++ b/smc_fuzz/dts/top.dts
@@ -47,4 +47,23 @@
functionname = "sdei_shared_reset";
};
};
+ tsp {
+ bias = <30>;
+ tsp_add_op {
+ bias = <30>;
+ functionname = "tsp_add_op";
+ };
+ tsp_sub_op {
+ bias = <30>;
+ functionname = "tsp_sub_op";
+ };
+ tsp_mul_op {
+ bias = <30>;
+ functionname = "tsp_mul_op";
+ };
+ tsp_div_op {
+ bias = <30>;
+ functionname = "tsp_div_op";
+ };
+ };
};
diff --git a/smc_fuzz/include/fuzz_helper.h b/smc_fuzz/include/fuzz_helper.h
new file mode 100644
index 0000000..defa0a5
--- /dev/null
+++ b/smc_fuzz/include/fuzz_helper.h
@@ -0,0 +1,7 @@
+/*
+ * Copyright (c) 2023, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#define CMP_SUCCESS 0
diff --git a/smc_fuzz/include/sdei_fuzz_helper.h b/smc_fuzz/include/sdei_fuzz_helper.h
new file mode 100644
index 0000000..71d462d
--- /dev/null
+++ b/smc_fuzz/include/sdei_fuzz_helper.h
@@ -0,0 +1,16 @@
+/*
+ * Copyright (c) 2023, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <fuzz_helper.h>
+#include <power_management.h>
+#include <sdei.h>
+#include <test_helpers.h>
+#include <tftf_lib.h>
+#include <timer.h>
+
+void tftf_test_sdei_noarg(int64_t (*sdei_func)(void), char *);
+void tftf_test_sdei_singlearg(int64_t (*sdei_func)(uint64_t), char *funcstr);
+void run_sdei_fuzz(char *);
diff --git a/smc_fuzz/include/tsp_fuzz_helper.h b/smc_fuzz/include/tsp_fuzz_helper.h
new file mode 100644
index 0000000..444d54b
--- /dev/null
+++ b/smc_fuzz/include/tsp_fuzz_helper.h
@@ -0,0 +1,15 @@
+/*
+ * Copyright (c) 2023, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <fuzz_helper.h>
+#include <power_management.h>
+#include <sdei.h>
+#include <test_helpers.h>
+#include <tftf_lib.h>
+#include <timer.h>
+
+void tftf_test_tsp_smc(uint64_t tsp_id, char *);
+void run_tsp_fuzz(char *);
diff --git a/smc_fuzz/src/randsmcmod.c b/smc_fuzz/src/randsmcmod.c
index 6f27105..7bedf81 100644
--- a/smc_fuzz/src/randsmcmod.c
+++ b/smc_fuzz/src/randsmcmod.c
@@ -582,6 +582,7 @@
test_result_t smc_fuzzing_top(void)
{
test_result_t result = TEST_RESULT_SUCCESS;
+
init_smc_fuzzing();
#ifdef MULTI_CPU_SMC_FUZZER
u_register_t lead_mpid, target_mpid;
diff --git a/smc_fuzz/src/runtestfunction_helpers.c b/smc_fuzz/src/runtestfunction_helpers.c
index f932a68..b9fa794 100644
--- a/smc_fuzz/src/runtestfunction_helpers.c
+++ b/smc_fuzz/src/runtestfunction_helpers.c
@@ -4,79 +4,15 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
- #include <power_management.h>
- #include <sdei.h>
- #include <test_helpers.h>
- #include <tftf_lib.h>
- #include <timer.h>
+#include <sdei_fuzz_helper.h>
+#include <tsp_fuzz_helper.h>
-#define CMP_SUCCESS 0
/*
* Invoke the SMC call based on the function name specified.
*/
void runtestfunction(char *funcstr)
{
- if (strcmp(funcstr, "sdei_version") == CMP_SUCCESS) {
- long long ret = sdei_version();
-
- if (ret != MAKE_SDEI_VERSION(1, 0, 0)) {
- tftf_testcase_printf("Unexpected SDEI version: 0x%llx\n",
- ret);
- }
- printf("running %s\n", funcstr);
- }
- if (strcmp(funcstr, "sdei_pe_unmask") == CMP_SUCCESS) {
- long long ret = sdei_pe_unmask();
-
- if (ret < 0) {
- tftf_testcase_printf("SDEI pe unmask failed: 0x%llx\n",
- ret);
- }
- printf("running %s\n", funcstr);
- }
- if (strcmp(funcstr, "sdei_pe_mask") == CMP_SUCCESS) {
- int64_t ret = sdei_pe_mask();
-
- if (ret < 0) {
- tftf_testcase_printf("SDEI pe mask failed: 0x%llx\n", ret);
- }
- printf("running %s\n", funcstr);
- }
- if (strcmp(funcstr, "sdei_event_status") == CMP_SUCCESS) {
- int64_t ret = sdei_event_status(0);
-
- if (ret < 0) {
- tftf_testcase_printf("SDEI event status failed: 0x%llx\n",
- ret);
- }
- printf("running %s\n", funcstr);
- }
- if (strcmp(funcstr, "sdei_event_signal") == CMP_SUCCESS) {
- int64_t ret = sdei_event_signal(0);
-
- if (ret < 0) {
- tftf_testcase_printf("SDEI event signal failed: 0x%llx\n",
- ret);
- }
- printf("running %s\n", funcstr);
- }
- if (strcmp(funcstr, "sdei_private_reset") == CMP_SUCCESS) {
- int64_t ret = sdei_private_reset();
-
- if (ret < 0) {
- tftf_testcase_printf("SDEI private reset failed: 0x%llx\n",
- ret);
- }
- printf("running %s\n", funcstr);
- }
- if (strcmp(funcstr, "sdei_shared_reset") == CMP_SUCCESS) {
- int64_t ret = sdei_shared_reset();
-
- if (ret < 0) {
- tftf_testcase_printf("SDEI shared reset failed: 0x%llx\n",
- ret);
- }
- printf("running %s\n", funcstr);
- }
+ run_sdei_fuzz(funcstr);
+ run_tsp_fuzz(funcstr);
}
diff --git a/smc_fuzz/src/sdei_fuzz_helper.c b/smc_fuzz/src/sdei_fuzz_helper.c
new file mode 100644
index 0000000..cb634dc
--- /dev/null
+++ b/smc_fuzz/src/sdei_fuzz_helper.c
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2023, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <sdei_fuzz_helper.h>
+
+void tftf_test_sdei_noarg(int64_t (*sdei_func)(void), char *funcstr)
+{
+ int64_t ret = (*sdei_func)();
+
+ if (ret < 0) {
+ tftf_testcase_printf("%s failed: 0x%llx\n", funcstr, ret);
+ }
+}
+
+void tftf_test_sdei_singlearg(int64_t (*sdei_func)(uint64_t), char *funcstr)
+{
+ int64_t ret = (*sdei_func)(0);
+
+ if (ret < 0) {
+ tftf_testcase_printf("%s failed: 0x%llx\n", funcstr, ret);
+ }
+}
+
+
+void run_sdei_fuzz(char *funcstr)
+{
+ if (strcmp(funcstr, "sdei_version") == CMP_SUCCESS) {
+ long long ret = sdei_version();
+
+ if (ret != MAKE_SDEI_VERSION(1, 0, 0)) {
+ tftf_testcase_printf("Unexpected SDEI version: 0x%llx\n",
+ ret);
+ }
+ } else if (strcmp(funcstr, "sdei_pe_unmask") == CMP_SUCCESS) {
+ tftf_test_sdei_noarg(sdei_pe_unmask, "sdei_pe_unmask");
+ } else if (strcmp(funcstr, "sdei_pe_mask") == CMP_SUCCESS) {
+ tftf_test_sdei_noarg(sdei_pe_mask, "sdei_pe_mask");
+ } else if (strcmp(funcstr, "sdei_event_status") == CMP_SUCCESS) {
+ tftf_test_sdei_singlearg((int64_t (*)(uint64_t))sdei_event_status,
+ "sdei_event_status");
+ } else if (strcmp(funcstr, "sdei_event_signal") == CMP_SUCCESS) {
+ tftf_test_sdei_singlearg(sdei_event_signal, "sdei_event_signal");
+ } else if (strcmp(funcstr, "sdei_private_reset") == CMP_SUCCESS) {
+ tftf_test_sdei_noarg(sdei_private_reset, "sdei_private_reset");
+ } else if (strcmp(funcstr, "sdei_shared_reset") == CMP_SUCCESS) {
+ tftf_test_sdei_noarg(sdei_shared_reset, "sdei_shared_reset");
+ }
+}
diff --git a/smc_fuzz/src/tsp_fuzz_helper.c b/smc_fuzz/src/tsp_fuzz_helper.c
new file mode 100644
index 0000000..c6ed219
--- /dev/null
+++ b/smc_fuzz/src/tsp_fuzz_helper.c
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2023, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+#include <tsp_fuzz_helper.h>
+
+void tftf_test_tsp_smc(uint64_t tsp_id, char *funcstr)
+{
+ uint64_t fn_identifier = TSP_FAST_FID(tsp_id);
+ uint64_t arg1 = 4;
+ uint64_t arg2 = 6;
+ smc_args tsp_svc_params = {fn_identifier, arg1, arg2};
+ smc_ret_values tsp_result;
+
+ tsp_result = tftf_smc(&tsp_svc_params);
+
+ if (tsp_result.ret0) {
+ tftf_testcase_printf("TSP operation 0x%x failed, error:0x%x\n",
+ (unsigned int) fn_identifier,
+ (unsigned int) tsp_result.ret0);
+ }
+}
+
+void run_tsp_fuzz(char *funcstr)
+{
+ if (strcmp(funcstr, "tsp_add_op") == CMP_SUCCESS) {
+ tftf_test_tsp_smc(TSP_ADD, "tsp_add_op");
+ } else if (strcmp(funcstr, "tsp_sub_op") == CMP_SUCCESS) {
+ tftf_test_tsp_smc(TSP_SUB, "tsp_sub_op");
+ } else if (strcmp(funcstr, "tsp_mul_op") == CMP_SUCCESS) {
+ tftf_test_tsp_smc(TSP_MUL, "tsp_mul_op");
+ } else if (strcmp(funcstr, "tsp_div_op") == CMP_SUCCESS) {
+ tftf_test_tsp_smc(TSP_DIV, "tsp_div_op");
+ }
+}
diff --git a/tftf/tests/tests-smcfuzzing.mk b/tftf/tests/tests-smcfuzzing.mk
index c3d4522..738e1d6 100644
--- a/tftf/tests/tests-smcfuzzing.mk
+++ b/tftf/tests/tests-smcfuzzing.mk
@@ -44,4 +44,6 @@
smcmalloc.c \
fifo3d.c \
runtestfunction_helpers.c \
+ sdei_fuzz_helper.c \
+ tsp_fuzz_helper.c \
)