tests: edac: Ensure vars are not changed in assert evaluation
Coverity analysis reported following cases with side effect in assertion (ASSERT_SIDE_EFFECT): CID: 219574 CID: 219644 CID: 219659 Avoid issue by loading volatiles to local variables before assertion. Fixes: #33079 Fixes: #33042 Fixes: #33030 Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
This commit is contained in:
parent
d2a2b7cb56
commit
c1cd44cab4
1 changed files with 16 additions and 8 deletions
|
@ -135,7 +135,7 @@ static void test_inject(uint64_t addr, uint64_t mask, uint8_t type)
|
||||||
|
|
||||||
uint64_t test_addr;
|
uint64_t test_addr;
|
||||||
uint32_t test_value;
|
uint32_t test_value;
|
||||||
int ret;
|
int ret, num_int;
|
||||||
|
|
||||||
interrupt = 0;
|
interrupt = 0;
|
||||||
|
|
||||||
|
@ -173,12 +173,15 @@ static void test_inject(uint64_t addr, uint64_t mask, uint8_t type)
|
||||||
/* Wait for interrupt if needed */
|
/* Wait for interrupt if needed */
|
||||||
k_busy_wait(USEC_PER_MSEC * DURATION);
|
k_busy_wait(USEC_PER_MSEC * DURATION);
|
||||||
|
|
||||||
zassert_not_equal(interrupt, 0, "Interrupt handler did not execute");
|
/* Load to local variable to avoid using volatile in assert */
|
||||||
zassert_equal(interrupt, 1,
|
num_int = interrupt;
|
||||||
"Interrupt handler executed more than once! (%d)\n",
|
|
||||||
interrupt);
|
|
||||||
|
|
||||||
TC_PRINT("Interrupt %d\n", interrupt);
|
zassert_not_equal(num_int, 0, "Interrupt handler did not execute");
|
||||||
|
zassert_equal(num_int, 1,
|
||||||
|
"Interrupt handler executed more than once! (%d)\n",
|
||||||
|
num_int);
|
||||||
|
|
||||||
|
TC_PRINT("Interrupt %d\n", num_int);
|
||||||
TC_PRINT("ECC Error Log 0x%llx\n", edac_ecc_error_log_get(dev));
|
TC_PRINT("ECC Error Log 0x%llx\n", edac_ecc_error_log_get(dev));
|
||||||
TC_PRINT("Error: type %u, address 0x%llx, syndrome %u\n",
|
TC_PRINT("Error: type %u, address 0x%llx, syndrome %u\n",
|
||||||
error_type, error_address, error_syndrome);
|
error_type, error_address, error_syndrome);
|
||||||
|
@ -188,15 +191,20 @@ static int check_values(void *p1, void *p2, void *p3)
|
||||||
{
|
{
|
||||||
intptr_t address = (intptr_t)p1;
|
intptr_t address = (intptr_t)p1;
|
||||||
intptr_t type = (intptr_t)p2;
|
intptr_t type = (intptr_t)p2;
|
||||||
|
intptr_t addr, errtype;
|
||||||
|
|
||||||
#if defined(CONFIG_USERSPACE)
|
#if defined(CONFIG_USERSPACE)
|
||||||
TC_PRINT("Test communication in user mode thread\n");
|
TC_PRINT("Test communication in user mode thread\n");
|
||||||
zassert_true(_is_user_context(), "thread left in kernel mode");
|
zassert_true(_is_user_context(), "thread left in kernel mode");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Load to local variables to avoid using volatile in assert */
|
||||||
|
addr = error_address;
|
||||||
|
errtype = error_type;
|
||||||
|
|
||||||
/* Verify page address and error type */
|
/* Verify page address and error type */
|
||||||
zassert_equal(error_address, address, "Error address wrong");
|
zassert_equal(addr, address, "Error address wrong");
|
||||||
zassert_equal(error_type, type, "Error type wrong");
|
zassert_equal(errtype, type, "Error type wrong");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue