test(sdei): add test for attempting to bind too many events
The test makes sure that if you attempt to bind more events than are
available, it will return an error code instead of crashing.
Change-Id: Ib74589a04ed7cbd0d1a9de355a9bf3c99f945ae5
Signed-off-by: Charlie Bareham <charlie.bareham@arm.com>
diff --git a/tftf/tests/runtime_services/standard_service/sdei/system_tests/test_sdei_bind_failure.c b/tftf/tests/runtime_services/standard_service/sdei/system_tests/test_sdei_bind_failure.c
new file mode 100644
index 0000000..a553adf
--- /dev/null
+++ b/tftf/tests/runtime_services/standard_service/sdei/system_tests/test_sdei_bind_failure.c
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2024, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <debug.h>
+#include <tftf_lib.h>
+#include <sdei.h>
+#include <drivers/arm/arm_gic.h>
+
+/*
+ * Only this many events can be bound in the PPI range. If you attempt to bind
+ * more, an error code should be returned.
+ */
+#define MAX_EVENTS_IN_PPI_RANGE U(3)
+
+/*
+ * Test that it doesn't crash when you attempt to bind more events in the PPI
+ * range than are available.
+ */
+test_result_t test_sdei_bind_failure(void)
+{
+ int64_t ret, ev;
+ struct sdei_intr_ctx intr_ctx;
+ int intr, num_bound;
+ bool bind_failed, bind_should_fail;
+
+ ret = sdei_version();
+ if (ret != MAKE_SDEI_VERSION(1, 0, 0)) {
+ printf("%d: Unexpected SDEI version: 0x%llx\n",
+ __LINE__, (unsigned long long) ret);
+ return TEST_RESULT_SKIPPED;
+ }
+
+ num_bound = 0;
+ for (intr = MIN_PPI_ID; intr < MAX_PPI_ID; intr++) {
+ printf("Binding to interrupt %d.\n", intr);
+
+ bind_should_fail = num_bound >= MAX_EVENTS_IN_PPI_RANGE;
+
+ ev = sdei_interrupt_bind(intr, &intr_ctx);
+
+ if (ev == -SMC_EDENY) {
+ /*
+ * This isn't a non-secure interrupt number, so we can't
+ * use it.
+ */
+ continue;
+ }
+
+ num_bound++;
+
+ /*
+ * Every bind should succeed except the last one, which should
+ * fail.
+ */
+ bind_failed = ev < 0;
+ if (bind_failed != bind_should_fail) {
+ printf("%d: SDEI interrupt bind; ret=%lld; Bind should "
+ "have %s\n",
+ __LINE__,
+ ev,
+ bind_should_fail ? "failed" : "succeeded");
+ return TEST_RESULT_FAIL;
+ }
+ }
+
+ return TEST_RESULT_SUCCESS;
+}
diff --git a/tftf/tests/tests-sdei.mk b/tftf/tests/tests-sdei.mk
index e73bfb7..6aca291 100644
--- a/tftf/tests/tests-sdei.mk
+++ b/tftf/tests/tests-sdei.mk
@@ -1,5 +1,5 @@
#
-# Copyright (c) 2020-2021, Arm Limited. All rights reserved.
+# Copyright (c) 2020-2024, Arm Limited. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
@@ -11,4 +11,5 @@
test_sdei_state.c \
test_sdei_rm_any.c \
test_sdei_pstate.c \
+ test_sdei_bind_failure.c \
)
diff --git a/tftf/tests/tests-sdei.xml b/tftf/tests/tests-sdei.xml
index 38c7c0d..45411f3 100644
--- a/tftf/tests/tests-sdei.xml
+++ b/tftf/tests/tests-sdei.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
- Copyright (c) 2020-2021, Arm Limited. All rights reserved.
+ Copyright (c) 2020-2024, Arm Limited. All rights reserved.
SPDX-License-Identifier: BSD-3-Clause
-->
@@ -16,6 +16,7 @@
<testcase name="SDEI event signaling: one core signals all others" function="test_sdei_event_signal_all" />
<testcase name="SDEI event routing all: SPI events routed to all CPUs" function="test_sdei_routing_any" />
<testcase name="SDEI event handler pstate testing" function="test_sdei_event_check_pstate" />
+ <testcase name="Test binding more events than are available in the PPI range" function="test_sdei_bind_failure" />
</testsuite>
</testsuites>