tests: static_idt: convert legacy test to ztest

Migrate testcase to ztest and use ztest macros

Signed-off-by: Punit Vara <punit.vara@intel.com>
This commit is contained in:
Punit Vara 2017-11-03 15:08:04 +05:30 committed by Anas Nashif
parent 283a0cdafb
commit d8f85d736d
3 changed files with 32 additions and 45 deletions

View file

@ -1,2 +1,3 @@
CONFIG_EXCEPTION_DEBUG=n
CONFIG_MAIN_THREAD_PRIORITY=6
CONFIG_ZTEST=y

View file

@ -1,3 +1,3 @@
ccflags-y += -I${ZEPHYR_BASE}/tests/include
include $(ZEPHYR_BASE)/tests/Makefile.test
obj-y = static_idt.o test_stubs.o

View file

@ -12,6 +12,7 @@
*/
#include <zephyr.h>
#include <ztest.h>
#include <tc_util.h>
#include <arch/x86/segmentation.h>
@ -109,8 +110,8 @@ int idt_stub_test(void)
(_idt_base_address + (TEST_SOFT_INT << 3));
offset = (u32_t)(&int_stub);
if (DTE_OFFSET(p_idt_entry) != offset) {
TC_ERROR("Failed to find offset of int_stub (0x%x) at vector %d\n",
offset, TEST_SOFT_INT);
TC_ERROR("Failed to find offset of int_stub (0x%x)"
" at vector %d\n", offset, TEST_SOFT_INT);
return TC_FAIL;
}
@ -119,14 +120,15 @@ int idt_stub_test(void)
(_idt_base_address + (IV_DIVIDE_ERROR << 3));
offset = (u32_t)(&_EXCEPTION_STUB_NAME(exc_divide_error_handler, 0));
if (DTE_OFFSET(p_idt_entry) != offset) {
TC_ERROR("Failed to find offset of exc stub (0x%x) at vector %d\n",
offset, IV_DIVIDE_ERROR);
TC_ERROR("Failed to find offset of exc stub (0x%x)"
" at vector %d\n", offset, IV_DIVIDE_ERROR);
return TC_FAIL;
}
/*
* If the other fields are wrong, the system will crash when the exception
* and software interrupt are triggered so we don't check them.
* If the other fields are wrong, the system will crash when the
* exception and software interrupt are triggered so we don't check
* them.
*/
return TC_PASS;
}
@ -156,53 +158,38 @@ void idt_spur_task(void *arg1, void *arg2, void *arg3)
* @return N/A
*/
void main(void)
void testing_static_idt(void)
{
int rv; /* return value from tests */
volatile int error; /* used to create a divide by zero error */
TC_START("Starting static IDT tests");
TC_PRINT("Testing to see if IDT has address of test stubs()\n");
rv = idt_stub_test();
if (rv != TC_PASS) {
goto done_tests;
}
zassert_equal(rv, TC_PASS, "idt stub test");
TC_PRINT("Testing to see interrupt handler executes properly\n");
_trigger_isr_handler();
if (int_handler_executed == 0) {
TC_ERROR("Interrupt handler did not execute\n");
rv = TC_FAIL;
goto done_tests;
} else if (int_handler_executed != 1) {
TC_ERROR("Interrupt handler executed more than once! (%d)\n",
int_handler_executed);
rv = TC_FAIL;
goto done_tests;
}
zassert_not_equal(int_handler_executed, 0,
"Interrupt handler did not execute\n");
zassert_equal(int_handler_executed, 1,
"Interrupt handler executed more than once! (%d)\n",
int_handler_executed);
TC_PRINT("Testing to see exception handler executes properly\n");
/*
* Use exc_handler_executed instead of 0 to prevent the compiler issuing a
* 'divide by zero' warning.
* Use exc_handler_executed instead of 0 to prevent the compiler
* issuing a 'divide by zero' warning.
*/
error = 32; /* avoid static checker uninitialized warnings */
error = error / exc_handler_executed;
if (exc_handler_executed == 0) {
TC_ERROR("Exception handler did not execute\n");
rv = TC_FAIL;
goto done_tests;
} else if (exc_handler_executed != 1) {
TC_ERROR("Exception handler executed more than once! (%d)\n",
exc_handler_executed);
rv = TC_FAIL;
goto done_tests;
}
zassert_not_equal(exc_handler_executed, 0,
"Exception handler did not execute\n");
zassert_equal(exc_handler_executed, 1,
"Exception handler executed more than once! (%d)\n",
exc_handler_executed);
/*
* Start task to trigger the spurious interrupt handler
*/
@ -215,13 +202,12 @@ void main(void)
* The thread should not run past where the spurious interrupt is
* generated. Therefore spur_handler_aborted_thread should remain at 1.
*/
if (spur_handler_aborted_thread == 0) {
TC_ERROR("Spurious handler did not execute as expected\n");
rv = TC_FAIL;
goto done_tests;
}
done_tests:
TC_END(rv, "%s - %s.\n", rv == TC_PASS ? PASS : FAIL, __func__);
TC_END_REPORT(rv);
zassert_not_equal(spur_handler_aborted_thread, 0,
"Spurious handler did not execute as expected\n");
}
void test_main(void)
{
ztest_test_suite(test_static_idt, ztest_unit_test(testing_static_idt));
ztest_run_test_suite(test_static_idt);
}