@@ -48,14 +48,6 @@ class TestPolledEvent : public BaseEvent {
4848 int getExecCalls () const { return execCalls; }
4949} polledEvent;
5050
51- testF (TimingHelpFixture, testRepeatedRaisingOfEvent) {
52- fail ();
53- }
54-
55- testF (TimingHelpFixture, testInterruptTestStartsTask) {
56- fail ();
57- }
58-
5951typedef bool (*TMPredicate)();
6052
6153bool runScheduleUntilMatchOrTimeout (TMPredicate predicate) {
@@ -68,11 +60,13 @@ bool runScheduleUntilMatchOrTimeout(TMPredicate predicate) {
6860}
6961
7062testF (TimingHelpFixture, testRaiseEventStartTaskCompleted) {
71- EnsureExecutionWithin timelyChecker (500 );
63+ EnsureExecutionWithin timelyChecker (600 );
7264
73- // taskManager.registerEvent(&polledEvent);
65+ // first register the event
66+ taskManager.registerEvent (&polledEvent);
7467
75- assertTrue (runScheduleUntilMatchOrTimeout ([] { return polledEvent.getScheduleCalls () >= 10 ; } ));
68+ // then we
69+ assertTrue (runScheduleUntilMatchOrTimeout ([] { return polledEvent.getScheduleCalls () >= 3 ; } ));
7670
7771 // and now we tell the event to trigger itself
7872 polledEvent.startTriggering ();
@@ -85,3 +79,65 @@ testF(TimingHelpFixture, testRaiseEventStartTaskCompleted) {
8579
8680 assertTrue (timelyChecker.ensureTimely ());
8781}
82+
83+ class TestExternalEvent : public BaseEvent {
84+ private:
85+ int execCalls;
86+ bool nextCheckCalled = false ;
87+ public:
88+ TestExternalEvent () {
89+ execCalls = 0 ;
90+ taskWithinEvent = false ;
91+ }
92+
93+ ~TestExternalEvent () override = default ;
94+
95+ void exec () override {
96+ execCalls++;
97+ taskManager.execute ([] {
98+ taskWithinEvent = true ;
99+ });
100+ }
101+
102+ uint32_t timeOfNextCheck () override {
103+ nextCheckCalled = true ;
104+ return 100000000UL ;
105+ }
106+
107+ void resetStats () {
108+ nextCheckCalled = false ;
109+ execCalls = 0 ;
110+ }
111+ bool wasNextCheckCalled () const { return nextCheckCalled; }
112+ int getExecCalls () const { return execCalls; }
113+ } externalEvent;
114+
115+ testF (TimingHelpFixture, testNotifyEventThatStartsAnotherTask) {
116+ EnsureExecutionWithin timelyChecker (100 );
117+ auto taskId = taskManager.registerEvent (&externalEvent);
118+
119+ for (int i=0 ; i<100 ; i++) {
120+ taskWithinEvent = false ;
121+ externalEvent.markTriggeredAndNotify ();
122+ taskManager.yieldForMicros (100 );
123+ assertTrue (runScheduleUntilMatchOrTimeout ([] { return taskWithinEvent; }));
124+ assertEqual (i + 1 , externalEvent.getExecCalls ());
125+ }
126+
127+ // now we let the task complete and after one more cycle it should be removed by task manager.
128+ externalEvent.setCompleted (true );
129+ externalEvent.markTriggeredAndNotify ();
130+ taskManager.yieldForMicros (100 );
131+
132+ // now it should be completely removed, and whatever we do should not affect task manager
133+ externalEvent.resetStats ();
134+ externalEvent.markTriggeredAndNotify ();
135+ taskManager.yieldForMicros (200 );
136+ assertFalse (externalEvent.wasNextCheckCalled ());
137+ assertEqual (0 , externalEvent.getExecCalls ());
138+
139+ // it should not be in task manager any longer.
140+ assertFalse (taskManager.getTask (taskId)->isEvent ());
141+
142+ assertTrue (timelyChecker.ensureTimely ());
143+ }
0 commit comments