From f135dd7bb8e8eff7b0cb98f9e24305108d7c3006 Mon Sep 17 00:00:00 2001 From: Jens Wiklander Date: Fri, 1 Sep 2023 20:21:16 +0200 Subject: [PATCH] xtest: regression: add case 1040 Adds regression case 1040 to test panic in concurrent open/invoke/close session. Signed-off-by: Jens Wiklander --- host/xtest/regression_1000.c | 66 ++++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 2 deletions(-) diff --git a/host/xtest/regression_1000.c b/host/xtest/regression_1000.c index 272ab9332..c550d9dbe 100644 --- a/host/xtest/regression_1000.c +++ b/host/xtest/regression_1000.c @@ -3270,7 +3270,69 @@ static void xtest_tee_test_1039(ADBG_Case_t *c) Do_ADBG_EndSubCase(c, "Load TA with identity subkey"); } - - ADBG_CASE_DEFINE(regression, 1039, xtest_tee_test_1039, "Test subkey verification"); + +struct test_1040_thread_arg { + TEEC_Result res; + pthread_t thr; +}; + +static void *test_1040_thread(void *arg) +{ + TEEC_Operation op = TEEC_OPERATION_INITIALIZER; + struct test_1040_thread_arg *a = arg; + TEEC_Result res = TEEC_SUCCESS; + uint32_t err_orig = 0; + TEEC_Session session = { }; + size_t n = 0; + + while (n < 100) { + res = xtest_teec_open_session(&session, &sims_test_ta_uuid, + NULL, &err_orig); + if (res) { + if (res == TEEC_ERROR_TARGET_DEAD) + continue; + a->res = res; + return NULL; + } + + memset(&op, 0, sizeof(op)); + op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, + TEEC_NONE, TEEC_NONE, + TEEC_NONE); + res = TEEC_InvokeCommand(&session, TA_SIMS_CMD_PANIC, &op, + &err_orig); + TEEC_CloseSession(&session); + if (res != TEEC_ERROR_TARGET_DEAD) { + a->res = res; + return NULL; + } + n++; + } + return NULL; +} + +static void xtest_tee_test_1040(ADBG_Case_t *c) +{ + struct test_1040_thread_arg arg[NUM_THREADS] = { }; + size_t nt = NUM_THREADS; + size_t n = 0; + + Do_ADBG_BeginSubCase(c, "Concurent invoke with panic in TA"); + for (n = 0; n < nt; n++) { + if (!ADBG_EXPECT(c, 0, pthread_create(&arg[n].thr, NULL, + test_1040_thread, + arg + n))) + nt = n; /* break loop and start cleanup */ + } + for (n = 0; n < nt; n++) { + ADBG_EXPECT(c, 0, pthread_join(arg[n].thr, NULL)); + ADBG_EXPECT_TEEC_SUCCESS(c, arg[n].res); + } + Do_ADBG_EndSubCase(c, "Concurent invoke with panic in TA"); + +} +ADBG_CASE_DEFINE(regression, 1040, xtest_tee_test_1040, + "Test panic in concurrent open/invoke/close session"); +