Skip to content

Commit

Permalink
[review] core: pta: test: invoke pta command to test interrupt notif
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
etienne-lms committed Jan 30, 2023
1 parent a360a00 commit c37d1b1
Showing 1 changed file with 70 additions and 70 deletions.
140 changes: 70 additions & 70 deletions core/pta/tests/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,77 +26,70 @@
#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;
}

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;
}
}
}
Expand All @@ -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;
}
Expand All @@ -132,19 +125,20 @@ 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;
}
}
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;
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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;
}

Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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();
Expand Down

0 comments on commit c37d1b1

Please sign in to comment.