1515
1616#define TEST_ANIMATION_TIME 10
1717
18- PROCESS_NAME (pbio_light_animation_process );
19-
2018static uint8_t test_animation_set_hsv_call_count ;
2119
2220static uint32_t test_animation_next (pbio_light_animation_t * animation ) {
2321 test_animation_set_hsv_call_count ++ ;
2422 return TEST_ANIMATION_TIME ;
2523}
2624
27- static PT_THREAD (test_light_animation (struct pt * pt )) {
28- PT_BEGIN (pt );
25+ #define YIELD (state ) \
26+ do { \
27+ do_yield_now = 1; \
28+ PBIO_OS_ASYNC_SET_CHECKPOINT(state); \
29+ if (do_yield_now) { \
30+ return PBIO_ERROR_AGAIN; \
31+ } \
32+ } while (0)
33+
34+ static pbio_error_t test_light_animation (pbio_os_state_t * state , void * context ) {
35+ PBIO_OS_ASYNC_BEGIN (state );
2936
3037 static pbio_light_animation_t test_animation ;
3138 pbio_light_animation_init (& test_animation , test_animation_next );
3239
33- // process should not be running yet
34- tt_want (!process_is_running (& pbio_light_animation_process ));
40+ // animation should not be started yet
3541 tt_want (!pbio_light_animation_is_started (& test_animation ));
3642
37- // starting animation should start process and set a timer at 0ms to call
43+ // starting animation should set a timer at 0ms to call
3844 // next() after handling pending events
3945 pbio_light_animation_start (& test_animation );
4046 tt_want (pbio_light_animation_is_started (& test_animation ));
41- tt_want (process_is_running (& pbio_light_animation_process ));
42- pbio_handle_pending_events ();
47+ YIELD (state );
4348 tt_want_uint_op (test_animation_set_hsv_call_count , = = , 1 );
4449
4550 // next() should not be called again until after a delay
46- pbio_test_clock_tick (TEST_ANIMATION_TIME - 1 );
47- PT_YIELD ( pt );
51+ pbio_test_clock_tick (TEST_ANIMATION_TIME - 2 );
52+ YIELD ( state );
4853 tt_want_uint_op (test_animation_set_hsv_call_count , = = , 1 );
4954 pbio_test_clock_tick (1 );
50- PT_YIELD ( pt );
55+ YIELD ( state );
5156 tt_want_uint_op (test_animation_set_hsv_call_count , = = , 2 );
5257
53- // stopping the animation stops the process
58+ // stopping the animation stops the animation
5459 pbio_light_animation_stop (& test_animation );
5560 tt_want (!pbio_light_animation_is_started (& test_animation ));
56- tt_want (!process_is_running (& pbio_light_animation_process ));
5761
5862 // exercise multiple animations for code coverage
5963 static pbio_light_animation_t test_animation2 ;
@@ -65,27 +69,23 @@ static PT_THREAD(test_light_animation(struct pt *pt)) {
6569 pbio_light_animation_stop (& test_animation );
6670 tt_want (!pbio_light_animation_is_started (& test_animation ));
6771 tt_want (pbio_light_animation_is_started (& test_animation2 ));
68- tt_want (process_is_running (& pbio_light_animation_process ));
6972 pbio_light_animation_stop (& test_animation2 );
7073 tt_want (!pbio_light_animation_is_started (& test_animation ));
7174 tt_want (!pbio_light_animation_is_started (& test_animation2 ));
72- tt_want (!process_is_running (& pbio_light_animation_process ));
7375
7476 // stopping all animations stops the process
7577 pbio_light_animation_start (& test_animation );
7678 pbio_light_animation_start (& test_animation2 );
7779 tt_want (pbio_light_animation_is_started (& test_animation ));
7880 tt_want (pbio_light_animation_is_started (& test_animation2 ));
79- tt_want (process_is_running (& pbio_light_animation_process ));
8081 pbio_light_animation_stop_all ();
8182 tt_want (!pbio_light_animation_is_started (& test_animation ));
8283 tt_want (!pbio_light_animation_is_started (& test_animation2 ));
83- tt_want (!process_is_running (& pbio_light_animation_process ));
8484
85- PT_END ( pt );
85+ PBIO_OS_ASYNC_END ( PBIO_SUCCESS );
8686}
8787
8888struct testcase_t pbio_light_animation_tests [] = {
89- PBIO_PT_THREAD_TEST (test_light_animation ),
89+ PBIO_PT_THREAD_TEST_WITH_PBIO_OS (test_light_animation ),
9090 END_OF_TESTCASES
9191};
0 commit comments