77#include <stdio.h>
88#include <assert.h>
99
10+ /* Defines */
11+
12+ #define set_current_time_ms (ms ) current_time_ms = *local_current_time_ms = ms;
13+
1014/* Gobals */
1115
12- __thread pa_time_t pa_current_time_ms ;
16+ pa_time_t current_time_ms = 0 ;
1317
1418/* Helpers */
1519
@@ -77,7 +81,7 @@ pa_activity (TestAwait, pa_ctx(pa_co_res(4); int value; int actual; int expected
7781
7882/* Delay Tests */
7983
80- pa_activity (TestDelaySpec , pa_ctx (), int * value , int * expected ) {
84+ pa_activity (TestDelaySpec , pa_ctx (), int * value , int * expected , pa_time_t * local_current_time_ms ) {
8185 * expected = 1 ;
8286 pa_pause ;
8387 * expected = 2 ;
@@ -88,25 +92,25 @@ pa_activity (TestDelaySpec, pa_ctx(), int* value, int* expected) {
8892 * expected = 5 ;
8993 pa_pause ;
9094
91- pa_current_time_ms = 0 ;
95+ set_current_time_ms ( 0 ) ;
9296 * expected = 6 ;
9397 pa_pause ;
94- pa_current_time_ms = 9 ;
98+ set_current_time_ms ( 9 ) ;
9599 pa_pause ;
96- pa_current_time_ms = 10 ;
100+ set_current_time_ms ( 10 ) ;
97101 * expected = 7 ;
98102 pa_pause ;
99- pa_current_time_ms = 11 ;
103+ set_current_time_ms ( 11 ) ;
100104 * expected = 9 ;
101105 pa_pause ;
102106
103107 * expected = 10 ;
104- pa_current_time_ms = -3 ;
108+ set_current_time_ms ( -3 ) ;
105109 pa_pause ;
106- pa_current_time_ms = 0 ;
110+ set_current_time_ms ( 0 ) ;
107111 pa_pause ;
108112 * expected = 11 ;
109- pa_current_time_ms = 2 ;
113+ set_current_time_ms ( 2 ) ;
110114 pa_pause ;
111115} pa_end ;
112116
@@ -149,7 +153,7 @@ pa_activity (TestDelayCheck, pa_ctx(), int actual, int expected) {
149153pa_activity (TestDelay , pa_ctx (pa_co_res (4 ); int value ; int actual ; int expected ;
150154 pa_use (TestDelaySpec ); pa_use (TestDelayTest ); pa_use (TestDelayCheck ))) {
151155 pa_co (3 ) {
152- pa_with_weak (TestDelaySpec , & pa_self .value , & pa_self .expected );
156+ pa_with_weak (TestDelaySpec , & pa_self .value , & pa_self .expected , & pa_current_time_ms );
153157 pa_with (TestDelayTest , pa_self .value , & pa_self .actual );
154158 pa_with_weak (TestDelayCheck , pa_self .actual , pa_self .expected );
155159 } pa_co_end ;
@@ -283,7 +287,7 @@ pa_activity (TestCo, pa_ctx(pa_co_res(4); int value; int actual; int expected;
283287
284288/* When-Abort Tests */
285289
286- pa_activity (TestWhenAbortSpec , pa_ctx (), int * value , int * expected ) {
290+ pa_activity (TestWhenAbortSpec , pa_ctx (), int * value , int * expected , pa_time_t * local_current_time_ms ) {
287291
288292 /* Test that preemption happens only when conditiopn is true. */
289293 * expected = 0 ;
@@ -345,13 +349,13 @@ pa_activity (TestWhenAbortSpec, pa_ctx(), int* value, int* expected) {
345349 pa_pause ;
346350
347351 /* Test after ms abort. */
348- pa_current_time_ms = 0 ;
352+ set_current_time_ms ( 0 ) ;
349353 * expected = 0 ;
350354 pa_pause ;
351- pa_current_time_ms = 9 ;
355+ set_current_time_ms ( 9 ) ;
352356 * expected = 1 ;
353357 pa_pause ;
354- pa_current_time_ms = 10 ;
358+ set_current_time_ms ( 10 ) ;
355359 * expected = -2 ;
356360 pa_pause ;
357361
@@ -430,7 +434,7 @@ pa_activity (TestWhenAbortCheck, pa_ctx(), int actual, int expected) {
430434pa_activity (TestWhenAbort , pa_ctx (pa_co_res (4 ); int value ; int actual ; int expected ;
431435 pa_use (TestWhenAbortSpec ); pa_use (TestWhenAbortTest ); pa_use (TestWhenAbortCheck ))) {
432436 pa_co (3 ) {
433- pa_with_weak (TestWhenAbortSpec , & pa_self .value , & pa_self .expected );
437+ pa_with_weak (TestWhenAbortSpec , & pa_self .value , & pa_self .expected , & pa_current_time_ms );
434438 pa_with (TestWhenAbortTest , pa_self .value , & pa_self .actual );
435439 pa_with_weak (TestWhenAbortCheck , pa_self .actual , pa_self .expected );
436440 } pa_co_end ;
@@ -499,7 +503,7 @@ pa_activity (TestWhenReset, pa_ctx(pa_co_res(4); int value; int actual; int expe
499503
500504/* Every Tests */
501505
502- pa_activity (TestEverySpec , pa_ctx (), int * value , int * expected ) {
506+ pa_activity (TestEverySpec , pa_ctx (), int * value , int * expected , pa_time_t * local_current_time_ms ) {
503507
504508 /* Test that we don't enter every on false condition. */
505509 * value = 0 ;
@@ -534,19 +538,19 @@ pa_activity (TestEverySpec, pa_ctx(), int* value, int* expected) {
534538 pa_pause ;
535539
536540 /* Test every_ms */
537- pa_current_time_ms = 0 ;
541+ set_current_time_ms ( 0 ) ;
538542 * value = 0 ;
539543 * expected = 1 ;
540544 pa_pause ;
541545
542- pa_current_time_ms = 1 ;
546+ set_current_time_ms ( 1 ) ;
543547 pa_pause ;
544548
545- pa_current_time_ms = 5 ;
549+ set_current_time_ms ( 5 ) ;
546550 * expected = 2 ;
547551 pa_pause ;
548552
549- pa_current_time_ms = 9 ;
553+ set_current_time_ms ( 9 ) ;
550554 pa_pause ;
551555
552556 * value = 1 ;
@@ -622,7 +626,7 @@ pa_activity (TestEveryCheck, pa_ctx(), int actual, int expected) {
622626pa_activity (TestEvery , pa_ctx (pa_co_res (4 ); int value ; int actual ; int expected ;
623627 pa_use (TestEverySpec ); pa_use (TestEveryTest ); pa_use (TestEveryCheck ))) {
624628 pa_co (3 ) {
625- pa_with (TestEverySpec , & pa_self .value , & pa_self .expected );
629+ pa_with (TestEverySpec , & pa_self .value , & pa_self .expected , & pa_current_time_ms );
626630 pa_with_weak (TestEveryTest , pa_self .value , & pa_self .actual );
627631 pa_with_weak (TestEveryCheck , pa_self .actual , pa_self .expected );
628632 } pa_co_end ;
@@ -633,7 +637,7 @@ pa_activity (TestEvery, pa_ctx(pa_co_res(4); int value; int actual; int expected
633637#define run_test (nm ) \
634638 pa_use(nm); \
635639 pa_init(nm); \
636- while (pa_tick( nm) == PA_RC_WAIT) {}
640+ while (pa_tick_tm(current_time_ms, nm) == PA_RC_WAIT) {}
637641
638642int main (int argc , char * argv []) {
639643 printf ("Start\n" );
0 commit comments