Skip to content

Commit 56cb158

Browse files
committed
ticker test: add test for set interrupt with timestamp in the past
2 test cases added, one for event in the past, one for event in future but very close to the current time, thus once is set, it is already in the past, and we fire interrupt immediately.
1 parent 4ff4329 commit 56cb158

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

TESTS/mbed_hal/ticker/main.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,6 +1986,58 @@ static void test_irq_handler_insert_non_immediate_in_irq()
19861986
TEST_ASSERT_EQUAL(0, interface_stub.disable_interrupt_call);
19871987
}
19881988

1989+
static uint32_t ticker_interface_stub_read_interrupt_time()
1990+
{
1991+
++interface_stub.read_call;
1992+
// only if set interrupt call, to test the condition afterwards
1993+
if (interface_stub.set_interrupt_call) {
1994+
return interface_stub.interrupt_timestamp;
1995+
} else {
1996+
return interface_stub.timestamp;
1997+
}
1998+
}
1999+
2000+
/**
2001+
* Test to insert an event that is already in the past, the fire_interrupt should
2002+
* be invoked, instead of set_interrupt
2003+
*/
2004+
static void test_set_interrupt_past_time()
2005+
{
2006+
interface_stub.set_interrupt_call = 0;
2007+
interface_stub.fire_interrupt_call = 0;
2008+
interface_stub.timestamp = 0xFF;
2009+
2010+
2011+
// This tests fire now functinality when next_event_timestamp <= present
2012+
ticker_event_t event = { 0 };
2013+
const timestamp_t event_timestamp = interface_stub.timestamp;
2014+
const uint32_t id_last_event = 0xDEADDEAF;
2015+
2016+
ticker_insert_event(&ticker_stub, &event, event_timestamp, id_last_event);
2017+
TEST_ASSERT_EQUAL(0, interface_stub.set_interrupt_call);
2018+
TEST_ASSERT_EQUAL(1, interface_stub.fire_interrupt_call);
2019+
}
2020+
/**
2021+
* Test to insert an event that is being delayed, set_interrupt is set
2022+
* but then event is already in the past, thus fire_interrupt should be invoked right-away
2023+
*/
2024+
static void test_set_interrupt_past_time_with_delay()
2025+
{
2026+
interface_stub.set_interrupt_call = 0;
2027+
interface_stub.fire_interrupt_call = 0;
2028+
interface_stub.timestamp = 0xFF;
2029+
2030+
// This tests fire now functionality when present time >= new_match_time
2031+
interface_stub.interface.read = ticker_interface_stub_read_interrupt_time;
2032+
ticker_event_t event = { 0 };
2033+
const timestamp_t event_timestamp = interface_stub.timestamp + 5;
2034+
const uint32_t id_last_event = 0xDEADDEAF;
2035+
2036+
ticker_insert_event(&ticker_stub, &event, event_timestamp, id_last_event);
2037+
TEST_ASSERT_EQUAL(1, interface_stub.set_interrupt_call);
2038+
TEST_ASSERT_EQUAL(1, interface_stub.fire_interrupt_call);
2039+
}
2040+
19892041
static const case_t cases[] = {
19902042
MAKE_TEST_CASE("ticker initialization", test_ticker_initialization),
19912043
MAKE_TEST_CASE(
@@ -2070,6 +2122,14 @@ static const case_t cases[] = {
20702122
MAKE_TEST_CASE(
20712123
"test_irq_handler_insert_non_immediate_in_irq",
20722124
test_irq_handler_insert_non_immediate_in_irq
2125+
),
2126+
MAKE_TEST_CASE(
2127+
"test_set_interrupt_past_time",
2128+
test_set_interrupt_past_time
2129+
),
2130+
MAKE_TEST_CASE(
2131+
"test_set_interrupt_past_time_with_delay",
2132+
test_set_interrupt_past_time_with_delay
20732133
)
20742134
};
20752135

0 commit comments

Comments
 (0)