@@ -2268,6 +2268,82 @@ static void test_match_interval_passed_table()
2268
2268
}
2269
2269
}
2270
2270
2271
+ /* *
2272
+ * Check that suspend and resume work as expected
2273
+ *
2274
+ * Check the following
2275
+ * -time does not change while suspended
2276
+ * -restricted interface functions are not called
2277
+ * -scheduling resumes correctly
2278
+ */
2279
+ static void test_suspend_resume ()
2280
+ {
2281
+ ticker_set_handler (&ticker_stub, NULL );
2282
+
2283
+ interface_stub.timestamp = 1000 ;
2284
+ us_timestamp_t start = ticker_read_us (&ticker_stub);
2285
+ TEST_ASSERT_EQUAL (1000 , start);
2286
+
2287
+ /* Reset call count */
2288
+ interface_stub.init_call = 0 ;
2289
+ interface_stub.read_call = 0 ;
2290
+ interface_stub.set_interrupt_call = 0 ;
2291
+
2292
+ /* Suspend the ticker */
2293
+ ticker_suspend (&ticker_stub);
2294
+ const timestamp_t suspend_time = queue_stub.present_time ;
2295
+
2296
+
2297
+ /* Simulate time passing */
2298
+ interface_stub.timestamp = 1500 ;
2299
+ us_timestamp_t next = ticker_read_us (&ticker_stub);
2300
+
2301
+ /* Time should not have passed and no calls to interface should have been made */
2302
+ TEST_ASSERT_EQUAL (start, next);
2303
+ TEST_ASSERT_EQUAL (0 , interface_stub.init_call );
2304
+ TEST_ASSERT_EQUAL (0 , interface_stub.read_call );
2305
+ TEST_ASSERT_EQUAL (0 , interface_stub.disable_interrupt_call );
2306
+ TEST_ASSERT_EQUAL (0 , interface_stub.clear_interrupt_call );
2307
+ TEST_ASSERT_EQUAL (0 , interface_stub.set_interrupt_call );
2308
+ TEST_ASSERT_EQUAL (0 , interface_stub.fire_interrupt_call );
2309
+
2310
+
2311
+ /* Simulate a reinit (time reset to 0) */
2312
+ interface_stub.timestamp = 0 ;
2313
+ next = ticker_read_us (&ticker_stub);
2314
+
2315
+ /* Time should not have passed and no calls to interface should have been made */
2316
+ TEST_ASSERT_EQUAL (start, next);
2317
+ TEST_ASSERT_EQUAL (0 , interface_stub.init_call );
2318
+ TEST_ASSERT_EQUAL (0 , interface_stub.read_call );
2319
+ TEST_ASSERT_EQUAL (0 , interface_stub.disable_interrupt_call );
2320
+ TEST_ASSERT_EQUAL (0 , interface_stub.clear_interrupt_call );
2321
+ TEST_ASSERT_EQUAL (0 , interface_stub.set_interrupt_call );
2322
+ TEST_ASSERT_EQUAL (0 , interface_stub.fire_interrupt_call );
2323
+
2324
+
2325
+ /* Insert an event in the past and future */
2326
+ ticker_event_t event_past = { 0 };
2327
+ const timestamp_t event_past_timestamp = suspend_time - 10 ;
2328
+ ticker_insert_event_us (&ticker_stub, &event_past, event_past_timestamp, 0 );
2329
+
2330
+ ticker_event_t event_future = { 0 };
2331
+ const timestamp_t event_future_timestamp = suspend_time + 10 ;
2332
+ ticker_insert_event_us (&ticker_stub, &event_future, event_future_timestamp, 0 );
2333
+
2334
+ TEST_ASSERT_EQUAL (0 , interface_stub.init_call );
2335
+ TEST_ASSERT_EQUAL (0 , interface_stub.read_call );
2336
+ TEST_ASSERT_EQUAL (0 , interface_stub.disable_interrupt_call );
2337
+ TEST_ASSERT_EQUAL (0 , interface_stub.clear_interrupt_call );
2338
+ TEST_ASSERT_EQUAL (0 , interface_stub.set_interrupt_call );
2339
+ TEST_ASSERT_EQUAL (0 , interface_stub.fire_interrupt_call );
2340
+
2341
+ /* Resume and verify everything starts again */
2342
+ ticker_resume (&ticker_stub);
2343
+ TEST_ASSERT_EQUAL (suspend_time, queue_stub.present_time );
2344
+ TEST_ASSERT_EQUAL (1 , interface_stub.fire_interrupt_call );
2345
+ }
2346
+
2271
2347
static const case_t cases[] = {
2272
2348
MAKE_TEST_CASE (" ticker initialization" , test_ticker_initialization),
2273
2349
MAKE_TEST_CASE (
@@ -2376,6 +2452,10 @@ static const case_t cases[] = {
2376
2452
MAKE_TEST_CASE (
2377
2453
" test_match_interval_passed_table" ,
2378
2454
test_match_interval_passed_table
2455
+ ),
2456
+ MAKE_TEST_CASE (
2457
+ " test_suspend_resume" ,
2458
+ test_suspend_resume
2379
2459
)
2380
2460
};
2381
2461
0 commit comments