From c37d1b1b93ef0531d1a441e06ed4036d27672fba Mon Sep 17 00:00:00 2001 From: Etienne Carriere Date: Mon, 30 Jan 2023 11:51:33 +0100 Subject: [PATCH] [review] core: pta: test: invoke pta command to test interrupt notif Remove use of test_index in itr notif test for invoke test PTA to not confuse the local test itr notif index and the notif itr number. Signed-off-by: Etienne Carriere --- core/pta/tests/misc.c | 140 +++++++++++++++++++++--------------------- 1 file changed, 70 insertions(+), 70 deletions(-) diff --git a/core/pta/tests/misc.c b/core/pta/tests/misc.c index 633581dc996..666a2aef047 100644 --- a/core/pta/tests/misc.c +++ b/core/pta/tests/misc.c @@ -26,60 +26,49 @@ #define LOG(...) #ifdef CFG_ITR_NOTIF_TEST +/* + * Register TEST_ITR_NOTIF_CNT interrupt notifiers with interrupt number IDs + * starting from CFG_CORE_ITR_NOTIF_MAX + 1. + */ static struct notif_itr test_itr_notif[TEST_ITR_NOTIF_CNT]; -/* Helper to release registered resource in case of error */ +/* Helper to release only registered resources in case of error */ static bool test_itr_notif_registered[TEST_ITR_NOTIF_CNT]; -static unsigned int idx2id(unsigned int test_idx) -{ - assert(test_idx < TEST_ITR_NOTIF_CNT); - - return test_idx + CFG_CORE_ITR_NOTIF_MAX + 1; -} - -static bool test_itr_is_pending(unsigned int test_idx) -{ - return notif_itr_is_pending(idx2id(test_idx)); -} - -static bool test_itr_is_masked(unsigned int test_idx) -{ - return notif_itr_is_masked(idx2id(test_idx)); -} - -static TEE_Result register_test_itr_notif(unsigned int test_idx, +static TEE_Result register_test_itr_notif(unsigned int test_itr_index, const struct notif_itr_ops *ops) { - struct notif_itr *notif = test_itr_notif + test_idx; + struct notif_itr *notif = test_itr_notif + test_itr_index; TEE_Result res = TEE_SUCCESS; + unsigned int itr_num = 0; - assert(test_idx < TEST_ITR_NOTIF_CNT); + assert(test_itr_index < TEST_ITR_NOTIF_CNT); + itr_num = CFG_CORE_ITR_NOTIF_MAX + 1 + test_itr_index; - if (test_itr_notif_registered[test_idx]) + if (test_itr_notif_registered[test_itr_index]) return TEE_ERROR_GENERIC; - notif->itr_num = idx2id(test_idx); + notif->itr_num = itr_num; notif->ops = ops; res = notif_itr_register(notif); if (res) { - EMSG("Registering itr notif %u failed %#"PRIx32, test_idx, res); + EMSG("Registering itr notif %u failed %#"PRIx32, itr_num, res); return res; } - if (test_itr_is_pending(test_idx)) { - EMSG("Unexpected itr #%u notifier state: event pending", test_idx); + if (notif_itr_is_pending(itr_num)) { + EMSG("Bad itr notifier #%u state: event pending", itr_num); res = TEE_ERROR_GENERIC; } - if (test_itr_is_pending(test_idx)) { - EMSG("Unexpected itr #%u notifier state: event pending", test_idx); + if (!notif_itr_is_masked(itr_num)) { + EMSG("Bad itr notifier #%u state: not masked", itr_num); res = TEE_ERROR_GENERIC; } if (res) notif_itr_unregister(notif); else - test_itr_notif_registered[test_idx] = true; + test_itr_notif_registered[test_itr_index] = true; return res; } @@ -87,16 +76,20 @@ static TEE_Result register_test_itr_notif(unsigned int test_idx, static void unregister_test_all_notif(void) { TEE_Result res = TEE_SUCCESS; - size_t n = 0; + size_t test_index = 0; - for (n = 0; n < TEST_ITR_NOTIF_CNT; n++) { - if (test_itr_notif_registered[n]) { - res = notif_itr_unregister(test_itr_notif + n); - if (res) - DMSG("Unregistering itr notif %u failed %#"PRIx32, - n, res); + for (test_index = 0; test_index < TEST_ITR_NOTIF_CNT; test_index++) { + struct notif_itr *notif = test_itr_notif + test_index; + + if (test_itr_notif_registered[test_index]) { + res = notif_itr_unregister(notif); + if (res) { + EMSG("Can't unregister itr notif %u: %#"PRIx32, + notif->itr_num, res); + panic(); + } - test_itr_notif_registered[n] = false; + test_itr_notif_registered[test_index] = false; } } } @@ -107,10 +100,10 @@ static void unregister_test_all_notif(void) static TEE_Result register_test1_itr_notif(void) { TEE_Result res = TEE_SUCCESS; - size_t n = 0; + size_t test_index = 0; - for (n = 0; n < TEST_ITR_NOTIF_CNT; n++) { - res = register_test_itr_notif(n, NULL); + for (test_index = 0; test_index < TEST_ITR_NOTIF_CNT; test_index++) { + res = register_test_itr_notif(test_index, NULL); if (res) return res; } @@ -132,7 +125,7 @@ static TEE_Result test1_itr_notif_do(void) IMSG("Itr-notif: check all test interrupt notifs are masked"); for (n = 0; n < TEST_ITR_NOTIF_CNT; n++) { - if (!notif_itr_is_masked(idx2id(n))) { + if (!notif_itr_is_masked(test_itr_notif[n].itr_num)) { DMSG("ITR notifier %u is not default masked", n); res = TEE_ERROR_GENERIC; } @@ -140,11 +133,12 @@ static TEE_Result test1_itr_notif_do(void) if (res) goto out; - /* Unmask irq 2, raise itr and check it's been masked */ - IMSG("Itr-notif: test single interrupt "); + /* Unmask test itr number 2, raise itr and check it's been retrieved */ + IMSG("Itr-notif: test single interrupt on itr notif %u", + test_itr_notif[2].itr_num); - notif_itr_set_mask(idx2id(2), 0); - if (test_itr_is_masked(2)) { + notif_itr_set_mask(test_itr_notif[2].itr_num, 0); + if (notif_itr_is_masked(test_itr_notif[2].itr_num)) { DMSG("Unmasking notification has no effect"); res = TEE_ERROR_GENERIC; goto out; @@ -153,12 +147,12 @@ static TEE_Result test1_itr_notif_do(void) notif_itr_raise_event(test_itr_notif + 2); mdelay(10); - if (test_itr_is_pending(2)) { + if (notif_itr_is_pending(test_itr_notif[2].itr_num)) { EMSG("Test Itr notif 2 still pending"); res = TEE_ERROR_GENERIC; goto out; } - notif_itr_set_mask(idx2id(2), 1); + notif_itr_set_mask(test_itr_notif[2].itr_num, 1); /* * Unmask test interrupt 1 to 6, raise test interrupts 0 to 6 in 1 shot @@ -168,21 +162,25 @@ static TEE_Result test1_itr_notif_do(void) /* Unmask test interrupts 1 to 6 */ for (n = 1; n <= 6; n++) - notif_itr_set_mask(idx2id(n), 0); + notif_itr_set_mask(test_itr_notif[n].itr_num, 0); - /* Check 0 and 7 are nmasked, 1 to 6 are unmasked */ - if (test_itr_is_pending(0) || !test_itr_is_masked(0)) { - EMSG("Itr notif 0 in bad state"); + /* Test itr 0 and 7 should be masked, and 1 to 6 unmasked */ + if (notif_itr_is_pending(test_itr_notif[0].itr_num) || + !notif_itr_is_masked(test_itr_notif[0].itr_num)) { + EMSG("Test itr notif %u bad state", test_itr_notif[0].itr_num); res = TEE_ERROR_GENERIC; } for (n = 1; n <= 6; n++) { - if (test_itr_is_pending(n) || test_itr_is_masked(n)) { - EMSG("Test Itr notif %u in bad state", n); + if (notif_itr_is_pending(test_itr_notif[n].itr_num) || + notif_itr_is_masked(test_itr_notif[n].itr_num)) { + EMSG("Test itr notif %u bad state", + test_itr_notif[n].itr_num); res = TEE_ERROR_GENERIC; } } - if (test_itr_is_pending(7) || !test_itr_is_masked(7)) { - EMSG("Itr notif 0 in bad state"); + if (notif_itr_is_pending(test_itr_notif[7].itr_num) || + !notif_itr_is_masked(test_itr_notif[7].itr_num)) { + EMSG("Test itr notif %u bad state", test_itr_notif[7].itr_num); res = TEE_ERROR_GENERIC; } if (res) @@ -196,36 +194,38 @@ static TEE_Result test1_itr_notif_do(void) mdelay(10); /* Check 0 is pending/masked, 1 to 7 are not pending, 7 is masked */ - if (!test_itr_is_pending(0) || !test_itr_is_masked(0)) { - EMSG("Test Itr notif 0 in bad state (%u/%u)", - !!test_itr_is_pending(0), !!test_itr_is_masked(0)); + if (!notif_itr_is_pending(test_itr_notif[0].itr_num) || + !notif_itr_is_masked(test_itr_notif[0].itr_num)) { + EMSG("Test itr notif %u bad state", test_itr_notif[0].itr_num); res = TEE_ERROR_GENERIC; goto out; } for (n = 1; n <= 6; n++) { - if (test_itr_is_pending(n)) { - EMSG("Test Itr notif %u still pending", n); + if (notif_itr_is_pending(test_itr_notif[n].itr_num)) { + EMSG("Test itr notif %u bad state", + test_itr_notif[n].itr_num); res = TEE_ERROR_GENERIC; } } - if (test_itr_is_pending(7) || !test_itr_is_masked(7)) { - EMSG("Test Itr notif %u in bad state (%u/%u)", 7, - !!test_itr_is_pending(7), !!test_itr_is_masked(7)); + if (notif_itr_is_pending(test_itr_notif[7].itr_num) || + !notif_itr_is_masked(test_itr_notif[7].itr_num)) { + EMSG("Test itr notif %u bad state", test_itr_notif[7].itr_num); res = TEE_ERROR_GENERIC; goto out; } if (res) goto out; - IMSG("Itr-notif: test unmasking pending test interrupt #7 delivers it"); + IMSG("Itr-notif: test unmasking pending itr notif #%u delivers it", + test_itr_notif[0].itr_num); /* Unmake test interrupt 0 to get it delivered */ - notif_itr_set_mask(idx2id(0), 0); + notif_itr_set_mask(test_itr_notif[0].itr_num, 0); mdelay(10); /* Check 0 is no more pending */ - if (test_itr_is_pending(0)) { - EMSG("Test Itr notif 0 is still pending"); + if (notif_itr_is_pending(test_itr_notif[0].itr_num)) { + EMSG("Test itr notif %u bad state", test_itr_notif[0].itr_num); res = TEE_ERROR_GENERIC; } @@ -283,7 +283,7 @@ static TEE_Result test2_itr_notif_do(void) IMSG("Itr-notif: test interrupt during interrupt "); for (n = 0; n <= 3; n++) - notif_itr_set_mask(idx2id(n), 0); + notif_itr_set_mask(test_itr_notif[n].itr_num, 0); /* * This test simulates cases where an interrupt is notified and @@ -303,7 +303,7 @@ static TEE_Result test2_itr_notif_do(void) mdelay(10); for (n = 0; n <= 3; n++) - if (test_itr_is_pending(n)) + if (notif_itr_is_pending(test_itr_notif[n].itr_num)) break; if (n < 4) { @@ -313,7 +313,7 @@ static TEE_Result test2_itr_notif_do(void) } for (n = 0; n <= 3; n++) - notif_itr_set_mask(idx2id(n), 1); + notif_itr_set_mask(test_itr_notif[n].itr_num, 1); out: unregister_test_all_notif();