-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Increment microstep when scheduling action with 0 delay (#67)
- Loading branch information
Showing
3 changed files
with
108 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
#include "reactor-uc/reactor-uc.h" | ||
#include "unity.h" | ||
|
||
typedef struct { | ||
LogicalAction super; | ||
int buffer[1]; | ||
|
||
Reaction *sources[1]; | ||
Reaction *effects[1]; | ||
} MyAction; | ||
|
||
typedef struct MyStartup MyStartup; | ||
|
||
struct MyStartup { | ||
Startup super; | ||
Reaction *effects_[1]; | ||
}; | ||
|
||
typedef struct { | ||
Reaction super; | ||
Trigger *effects[1]; | ||
} MyReaction; | ||
|
||
struct MyReactor { | ||
Reactor super; | ||
MyReaction my_reaction; | ||
MyAction my_action; | ||
MyStartup startup; | ||
Reaction *_reactions[1]; | ||
Trigger *_triggers[2]; | ||
int cnt; | ||
}; | ||
|
||
void MyAction_ctor(MyAction *self, struct MyReactor *parent) { | ||
LogicalAction_ctor(&self->super, MSEC(0), MSEC(0), &parent->super, self->sources, 1, self->effects, 1, &self->buffer, | ||
sizeof(self->buffer[0]), 2); | ||
} | ||
|
||
void MyStartup_ctor(struct MyStartup *self, Reactor *parent, Reaction *effects) { | ||
self->effects_[0] = effects; | ||
Startup_ctor(&self->super, parent, self->effects_, 1); | ||
} | ||
|
||
void action_handler(Reaction *_self) { | ||
struct MyReactor *self = (struct MyReactor *)_self->parent; | ||
Environment *env = self->super.env; | ||
MyAction *my_action = &self->my_action; | ||
if (self->cnt == 0) { | ||
TEST_ASSERT_EQUAL(lf_is_present(my_action), false); | ||
} else { | ||
TEST_ASSERT_EQUAL(lf_is_present(my_action), true); | ||
} | ||
|
||
printf("Hello World\n"); | ||
printf("Action = %d\n", lf_get(my_action)); | ||
if (self->cnt > 0) { | ||
TEST_ASSERT_EQUAL(self->cnt, lf_get(my_action)); | ||
TEST_ASSERT_EQUAL(self->cnt, env->current_tag.microstep); | ||
TEST_ASSERT_EQUAL(true, lf_is_present(my_action)); | ||
} else { | ||
TEST_ASSERT_EQUAL(false, lf_is_present(my_action)); | ||
} | ||
|
||
TEST_ASSERT_EQUAL(0, env->get_elapsed_logical_time(env)); | ||
|
||
if (self->cnt < 100) { | ||
lf_schedule(my_action, ++self->cnt, 0); | ||
} | ||
} | ||
|
||
void MyReaction_ctor(MyReaction *self, Reactor *parent) { | ||
Reaction_ctor(&self->super, parent, action_handler, self->effects, 1, 0); | ||
} | ||
|
||
void MyReactor_ctor(struct MyReactor *self, Environment *env) { | ||
self->_reactions[0] = (Reaction *)&self->my_reaction; | ||
self->_triggers[0] = (Trigger *)&self->startup; | ||
self->_triggers[1] = (Trigger *)&self->my_action; | ||
Reactor_ctor(&self->super, "MyReactor", env, NULL, NULL, 0, self->_reactions, 1, self->_triggers, 2); | ||
MyAction_ctor(&self->my_action, self); | ||
MyReaction_ctor(&self->my_reaction, &self->super); | ||
MyStartup_ctor(&self->startup, &self->super, &self->my_reaction.super); | ||
ACTION_REGISTER_EFFECT(self->my_action, self->my_reaction); | ||
REACTION_REGISTER_EFFECT(self->my_reaction, self->my_action); | ||
ACTION_REGISTER_SOURCE(self->my_action, self->my_reaction); | ||
self->cnt = 0; | ||
} | ||
|
||
void test_simple() { | ||
struct MyReactor my_reactor; | ||
Environment env; | ||
Environment_ctor(&env, (Reactor *)&my_reactor); | ||
MyReactor_ctor(&my_reactor, &env); | ||
env.set_timeout(&env, SEC(1)); | ||
env.assemble(&env); | ||
env.start(&env); | ||
} | ||
|
||
int main() { | ||
UNITY_BEGIN(); | ||
RUN_TEST(test_simple); | ||
return UNITY_END(); | ||
} |