From b8f5f92fec6c073d8e35405a07e864b799869739 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 Reviewed-by: Etienne Carriere --- host/xtest/regression_1000.c | 72 +++++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 2 deletions(-) diff --git a/host/xtest/regression_1000.c b/host/xtest/regression_1000.c index 8e338e59d..7b487b67e 100644 --- a/host/xtest/regression_1000.c +++ b/host/xtest/regression_1000.c @@ -3270,7 +3270,75 @@ 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 loop_count = 100; + size_t n = 0; + + if (level == 0) + loop_count /= 2; + + while (n < loop_count) { + 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) { + if (res) + a->res = res; + else + a->res = TEEC_ERROR_GENERIC; + return NULL; + } + n++; + } + a->res = TEEC_SUCCESS; + 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");