@@ -1986,6 +1986,58 @@ static void test_irq_handler_insert_non_immediate_in_irq()
1986
1986
TEST_ASSERT_EQUAL (0 , interface_stub.disable_interrupt_call );
1987
1987
}
1988
1988
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
+
1989
2041
static const case_t cases[] = {
1990
2042
MAKE_TEST_CASE (" ticker initialization" , test_ticker_initialization),
1991
2043
MAKE_TEST_CASE (
@@ -2070,6 +2122,14 @@ static const case_t cases[] = {
2070
2122
MAKE_TEST_CASE (
2071
2123
" test_irq_handler_insert_non_immediate_in_irq" ,
2072
2124
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
2073
2133
)
2074
2134
};
2075
2135
0 commit comments