Skip to content

Commit d6647eb

Browse files
HaavardReirlubos
authored andcommitted
tests: Bluetooth: Mesh: scheduler cancel test
Adds a unit test for the scheduler model to verify that setting the entry for the scheduled action to "NO_ACTIONS" will cancel the action. Signed-off-by: Håvard Reierstad <[email protected]>
1 parent 2b05cc3 commit d6647eb

File tree

1 file changed

+52
-0
lines changed
  • tests/subsys/bluetooth/mesh/scheduler_model/action_planning/src

1 file changed

+52
-0
lines changed

tests/subsys/bluetooth/mesh/scheduler_model/action_planning/src/main.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,4 +655,56 @@ ZTEST(scheduler_action_planning, test_second_sched_turn_off_recurring)
655655
expected_tm_check(fired_tm, expected, 8);
656656
}
657657

658+
ZTEST(scheduler_action_planning, test_sched_cancel_imminent_action)
659+
{
660+
/** Send a TURN_ON action to the sched srv in
661+
* element 1 of the mocked composition data.
662+
* Cancel the action before it is triggered by
663+
* sending a new action with the same parameters
664+
* but with the action set to NO_ACTIONS.
665+
*
666+
* Expect no events to be triggered.
667+
*/
668+
669+
const struct bt_mesh_schedule_entry test_action = {
670+
.year = BT_MESH_SCHEDULER_ANY_YEAR,
671+
.month = ANY_MONTH,
672+
.day = BT_MESH_SCHEDULER_ANY_DAY,
673+
.hour = 0,
674+
.minute = BT_MESH_SCHEDULER_ANY_MINUTE,
675+
.second = BT_MESH_SCHEDULER_EVERY_15_SECONDS,
676+
.day_of_week = ANY_DAY_OF_WEEK,
677+
.action = BT_MESH_SCHEDULER_TURN_ON,
678+
.transition_time = model_transition_encode(2500),
679+
.scene_number = 1
680+
};
681+
682+
struct sched_evt evt_list[] = {
683+
{ .elem_idx = 0, .evt = BT_MESH_SCHEDULER_TURN_ON, .transition_time = 2500 },
684+
{ .elem_idx = 1, .evt = BT_MESH_SCHEDULER_TURN_ON, .transition_time = 2500 },
685+
{ .elem_idx = 2, .evt = BT_MESH_SCHEDULER_TURN_ON, .transition_time = 2500 },
686+
};
687+
688+
sched_evt_ctx_init(evt_list, ARRAY_SIZE(evt_list));
689+
action_put(&test_action, sched_mod_elem1);
690+
k_sleep(K_SECONDS(1));
691+
692+
const struct bt_mesh_schedule_entry test_action_inactive = {
693+
.year = BT_MESH_SCHEDULER_ANY_YEAR,
694+
.month = ANY_MONTH,
695+
.day = BT_MESH_SCHEDULER_ANY_DAY,
696+
.hour = 0,
697+
.minute = BT_MESH_SCHEDULER_ANY_MINUTE,
698+
.second = BT_MESH_SCHEDULER_EVERY_15_SECONDS,
699+
.day_of_week = ANY_DAY_OF_WEEK,
700+
.action = BT_MESH_SCHEDULER_NO_ACTIONS,
701+
.transition_time = model_transition_encode(2500),
702+
.scene_number = 1
703+
};
704+
705+
action_put(&test_action_inactive, sched_mod_elem1);
706+
zassert_equal(k_sem_take(&action_fired, K_SECONDS(60)), -EAGAIN,
707+
"Unexpected event was triggered");
708+
}
709+
658710
ZTEST_SUITE(scheduler_action_planning, NULL, NULL, tc_setup, tc_teardown, NULL);

0 commit comments

Comments
 (0)