summaryrefslogtreecommitdiff
path: root/cesar/cp/eoc/cco/action/test/utest_eoc/src/test_fsm.c
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/cp/eoc/cco/action/test/utest_eoc/src/test_fsm.c')
-rw-r--r--cesar/cp/eoc/cco/action/test/utest_eoc/src/test_fsm.c429
1 files changed, 429 insertions, 0 deletions
diff --git a/cesar/cp/eoc/cco/action/test/utest_eoc/src/test_fsm.c b/cesar/cp/eoc/cco/action/test/utest_eoc/src/test_fsm.c
new file mode 100644
index 0000000000..bb556d83ef
--- /dev/null
+++ b/cesar/cp/eoc/cco/action/test/utest_eoc/src/test_fsm.c
@@ -0,0 +1,429 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2009 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file src/test_fsm.c
+ * \brief Test FSM module.
+ * \ingroup test
+ */
+#include "common/std.h"
+
+#include "lib/scenario/scenario.h"
+#include "lib/blk.h"
+#include "lib/test.h"
+
+#include "cp/fsm/fsm.h"
+#include "cp/inc/context.h"
+#include "cp/sta/core/core.h"
+
+void
+test_fsm_basic_test_case (test_t t)
+{
+ test_case_begin (t, "basic");
+ cp_t cp;
+ cp.sta_core_urgent_flag = false;
+ cp_trace_init (&cp);
+
+ test_begin (t, "CCO")
+ {
+ cp_fsm_init (&cp);
+ cp.sta_core_flag = false;
+ scenario_entry_t entries[] = {
+ /* STOPPED */
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_DRV_STA_MAC_START_REQ),
+ SCENARIO_EVENT (cp_fsm__STOPPED__drv_sta_mac_start_req),
+ /* STARTED */
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_to_poweron),
+ SCENARIO_EVENT (cp_fsm__STARTED__poweron__idle__to_poweron),
+ /* POWER_ON */
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_BEACON_NOT_RECEIVED),
+ SCENARIO_EVENT (cp_fsm__CCO__send_central_beacon),
+ /* CCO, DRV_STA_GET_KEY_REQ */
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_DRV_STA_GET_KEY_REQ),
+ SCENARIO_EVENT (cp_fsm__CCO__drv_sta_get_key_req),
+ /* CCO, VS_EOC_GET_TOPO_REQ */
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_VS_EOC_GET_TOPO_REQ),
+ SCENARIO_EVENT (cp_fsm__CCO__vs_eoc__cco__vs_eoc_get_topo_req),
+ /* CCO, VS_EOC_CCO_SET_WL_REQ */
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_VS_EOC_CCO_SET_WL_REQ),
+ SCENARIO_EVENT (cp_fsm__CCO__vs_eoc__cco__vs_eoc_set_wl_req),
+ /* CCO, VS_EOC_CCO_GET_WL_REQ */
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_VS_EOC_CCO_GET_WL_REQ),
+ SCENARIO_EVENT (cp_fsm__CCO__vs_eoc__cco__vs_eoc_get_wl_req),
+ /* CCO, NEK change */
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_cco__nek_change),
+ SCENARIO_EVENT (cp_fsm__CCO__nek_provide),
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_CM_SET_KEY_CNF),
+ SCENARIO_EVENT (cp_fsm__CCO__set_key_cnf),
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_nek_timeout),
+ SCENARIO_EVENT (cp_fsm__CCO__nek_change_timeout,
+ .branch = CP_FSM_BRANCH (CCO, nek_timeout, yes)),
+ /* CCO*/
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_DRV_STA_MAC_STOP_REQ),
+ SCENARIO_EVENT (cp_fsm__STARTED__drv_sta_mac_stop_req),
+ /* STOPPING */
+ SCENARIO_END
+ };
+ scenario_globals_t globals = {
+ .cp = &cp,
+ };
+ scenario_run (t, entries, &globals);
+ test_fail_unless (cp.fsm.active_states[0] == CP_FSM_STATE_STOPPING);
+ cp_fsm_uninit (&cp);
+ } test_end;
+
+ test_begin (t, "CCO -> Multi_sta")
+ {
+ cp_fsm_init (&cp);
+ cp.sta_core_flag = false;
+ scenario_entry_t entries[] = {
+ /* STOPPED */
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_DRV_STA_MAC_START_REQ),
+ SCENARIO_EVENT (cp_fsm__STOPPED__drv_sta_mac_start_req),
+ /* STARTED */
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_to_poweron),
+ SCENARIO_EVENT (cp_fsm__STARTED__poweron__idle__to_poweron),
+ /* POWER_ON */
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_BEACON_NOT_RECEIVED),
+ SCENARIO_EVENT (cp_fsm__CCO__send_central_beacon),
+ /* CCO*/
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_MULTI_STA_MME),
+ SCENARIO_EVENT (cp_fsm__CCO__event_dispatch),
+ /* CCO */
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_DRV_STA_MAC_STOP_REQ),
+ SCENARIO_EVENT (cp_fsm__STARTED__drv_sta_mac_stop_req),
+ /* STOPPING */
+ SCENARIO_END
+ };
+ scenario_globals_t globals = {
+ .cp = &cp,
+ };
+ scenario_run (t, entries, &globals);
+ test_fail_unless (cp.fsm.active_states[0] == CP_FSM_STATE_STOPPING);
+ cp_fsm_uninit (&cp);
+ } test_end;
+
+ test_begin (t, "BCCO")
+ {
+ cp_fsm_init (&cp);
+ cp.sta_core_flag = false;
+ scenario_entry_t entries[] = {
+ /* STOPPED */
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_DRV_STA_MAC_START_REQ),
+ SCENARIO_EVENT (cp_fsm__STOPPED__drv_sta_mac_start_req),
+ /* STARTED */
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_to_poweron),
+ SCENARIO_EVENT (cp_fsm__STARTED__poweron__idle__to_poweron),
+ /* POWER_ON */
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_rx_beacon),
+ SCENARIO_EVENT (cp_fsm__POWER_ON__power_on_rx_beacon),
+ /* BCCO*/
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_DRV_STA_MAC_STOP_REQ),
+ SCENARIO_EVENT (cp_fsm__BCCO__bcco_drv_mac_stop),
+ /* STOPPING */
+ SCENARIO_END
+ };
+ scenario_globals_t globals = {
+ .cp = &cp,
+ };
+ scenario_run (t, entries, &globals);
+ test_fail_unless (cp.fsm.active_states[0] == CP_FSM_STATE_STOPPING);
+ cp_fsm_uninit (&cp);
+ } test_end;
+
+ test_begin (t, "BCCO -> CCO")
+ {
+ cp_fsm_init (&cp);
+ cp.sta_core_flag = false;
+ scenario_entry_t entries[] = {
+ /* STOPPED */
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_DRV_STA_MAC_START_REQ),
+ SCENARIO_EVENT (cp_fsm__STOPPED__drv_sta_mac_start_req),
+ /* STARTED */
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_to_poweron),
+ SCENARIO_EVENT (cp_fsm__STARTED__poweron__idle__to_poweron),
+ /* POWER_ON */
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_rx_beacon),
+ SCENARIO_EVENT (cp_fsm__POWER_ON__power_on_rx_beacon),
+ /* BCCO*/
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_BEACON_NOT_RECEIVED),
+ SCENARIO_EVENT (cp_fsm__BCCO__bcco_no_beacons),
+ /* CCO */
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_DRV_STA_MAC_STOP_REQ),
+ SCENARIO_EVENT (cp_fsm__STARTED__drv_sta_mac_stop_req),
+ /* STOPPING */
+ SCENARIO_END
+ };
+ scenario_globals_t globals = {
+ .cp = &cp,
+ };
+ scenario_run (t, entries, &globals);
+ test_fail_unless (cp.fsm.active_states[0] == CP_FSM_STATE_STOPPING);
+ cp_fsm_uninit (&cp);
+ } test_end;
+
+#if CONFIG_TRACE
+ trace_buffer_dbg_dump (&cp.trace);
+#endif /* CONFIG_TRACE */
+ cp_trace_uninit (&cp);
+}
+
+void
+test_vs_eoc_test_case (test_t t)
+{
+ test_case_begin (t, "vs eoc");
+ cp_t cp;
+ cp.sta_core_urgent_flag = false;
+ cp_trace_init (&cp);
+
+ test_begin (t, "VS_EOC_GET_TOPO")
+ {
+ cp_fsm_init (&cp);
+ cp.sta_core_flag = false;
+ scenario_entry_t entries[] = {
+ /* STOPPED */
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_DRV_STA_MAC_START_REQ),
+ SCENARIO_EVENT (cp_fsm__STOPPED__drv_sta_mac_start_req),
+ /* STARTED */
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_to_poweron),
+ SCENARIO_EVENT (cp_fsm__STARTED__poweron__idle__to_poweron),
+ /* POWER_ON */
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_BEACON_NOT_RECEIVED),
+ SCENARIO_EVENT (cp_fsm__CCO__send_central_beacon),
+ /* CCO */
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_VS_EOC_GET_TOPO_REQ),
+ SCENARIO_EVENT (cp_fsm__CCO__vs_eoc__cco__vs_eoc_get_topo_req),
+ /* CCO */
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_DRV_STA_MAC_STOP_REQ),
+ SCENARIO_EVENT (cp_fsm__STARTED__drv_sta_mac_stop_req),
+ /* STOPPING */
+ SCENARIO_END
+ };
+ scenario_globals_t globals = {
+ .cp = &cp,
+ };
+ scenario_run (t, entries, &globals);
+ test_fail_unless (cp.fsm.active_states[0] == CP_FSM_STATE_STOPPING);
+ cp_fsm_uninit (&cp);
+ } test_end;
+
+ test_begin (t, "VS_EOC_CCO_GET_WL")
+ {
+ cp_fsm_init (&cp);
+ cp.sta_core_flag = false;
+ scenario_entry_t entries[] = {
+ /* STOPPED */
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_DRV_STA_MAC_START_REQ),
+ SCENARIO_EVENT (cp_fsm__STOPPED__drv_sta_mac_start_req),
+ /* STARTED */
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_to_poweron),
+ SCENARIO_EVENT (cp_fsm__STARTED__poweron__idle__to_poweron),
+ /* POWER_ON */
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_BEACON_NOT_RECEIVED),
+ SCENARIO_EVENT (cp_fsm__CCO__send_central_beacon),
+ /* CCO */
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_VS_EOC_CCO_GET_WL_REQ),
+ SCENARIO_EVENT (cp_fsm__CCO__vs_eoc__cco__vs_eoc_get_wl_req),
+ /* CCO */
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_DRV_STA_MAC_STOP_REQ),
+ SCENARIO_EVENT (cp_fsm__STARTED__drv_sta_mac_stop_req),
+ /* STOPPING */
+ SCENARIO_END
+ };
+ scenario_globals_t globals = {
+ .cp = &cp,
+ };
+ scenario_run (t, entries, &globals);
+ test_fail_unless (cp.fsm.active_states[0] == CP_FSM_STATE_STOPPING);
+ cp_fsm_uninit (&cp);
+ } test_end;
+
+ test_begin (t, "VS_EOC_CCO_SET_WL")
+ {
+ cp_fsm_init (&cp);
+ cp.sta_core_flag = false;
+ scenario_entry_t entries[] = {
+ /* STOPPED */
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_DRV_STA_MAC_START_REQ),
+ SCENARIO_EVENT (cp_fsm__STOPPED__drv_sta_mac_start_req),
+ /* STARTED */
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_to_poweron),
+ SCENARIO_EVENT (cp_fsm__STARTED__poweron__idle__to_poweron),
+ /* POWER_ON */
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_BEACON_NOT_RECEIVED),
+ SCENARIO_EVENT (cp_fsm__CCO__send_central_beacon),
+ /* CCO */
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_VS_EOC_CCO_SET_WL_REQ),
+ SCENARIO_EVENT (cp_fsm__CCO__vs_eoc__cco__vs_eoc_set_wl_req),
+ /* CCO */
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_DRV_STA_MAC_STOP_REQ),
+ SCENARIO_EVENT (cp_fsm__STARTED__drv_sta_mac_stop_req),
+ /* STOPPING */
+ SCENARIO_END
+ };
+ scenario_globals_t globals = {
+ .cp = &cp,
+ };
+ scenario_run (t, entries, &globals);
+ test_fail_unless (cp.fsm.active_states[0] == CP_FSM_STATE_STOPPING);
+ cp_fsm_uninit (&cp);
+ } test_end;
+
+ test_begin (t, "VS_EOC_SEND_CENTRAL_BEACON")
+ {
+ cp_fsm_init (&cp);
+ cp.sta_core_flag = false;
+ scenario_entry_t entries[] = {
+ /* STOPPED */
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_DRV_STA_MAC_START_REQ),
+ SCENARIO_EVENT (cp_fsm__STOPPED__drv_sta_mac_start_req),
+ /* STARTED */
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_to_poweron),
+ SCENARIO_EVENT (cp_fsm__STARTED__poweron__idle__to_poweron),
+ /* POWER_ON */
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_BEACON_NOT_RECEIVED),
+ SCENARIO_EVENT (cp_fsm__CCO__send_central_beacon),
+ /* CCO */
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_BEACON_TIMER_EXPIRES),
+ SCENARIO_EVENT (cp_fsm__CCO__send_central_beacon),
+ SCENARIO_END
+ };
+ scenario_globals_t globals = {
+ .cp = &cp,
+ };
+ scenario_run (t, entries, &globals);
+ test_fail_unless (cp.fsm.active_states[0] == CP_FSM_STATE_CCO);
+ cp_fsm_uninit (&cp);
+ } test_end;
+
+ test_begin (t, "leave_remove_timeout")
+ {
+ cp_fsm_init (&cp);
+ cp.sta_core_flag = false;
+ scenario_entry_t entries[] = {
+ /* STOPPED */
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_DRV_STA_MAC_START_REQ),
+ SCENARIO_EVENT (cp_fsm__STOPPED__drv_sta_mac_start_req),
+ /* STARTED */
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_to_poweron),
+ SCENARIO_EVENT (cp_fsm__STARTED__poweron__idle__to_poweron),
+ /* POWER_ON */
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_BEACON_NOT_RECEIVED),
+ SCENARIO_EVENT (cp_fsm__CCO__send_central_beacon),
+ /* CCO */
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_leave_remove_delay),
+ SCENARIO_EVENT (cp_fsm__CCO__vs_eoc__cco__leave_remove_timeout),
+ /* CCO */
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_DRV_STA_MAC_STOP_REQ),
+ SCENARIO_EVENT (cp_fsm__STARTED__drv_sta_mac_stop_req),
+ /* STOPPING */
+ SCENARIO_END
+ };
+ scenario_globals_t globals = {
+ .cp = &cp,
+ };
+ scenario_run (t, entries, &globals);
+ test_fail_unless (cp.fsm.active_states[0] == CP_FSM_STATE_STOPPING);
+ cp_fsm_uninit (&cp);
+ } test_end;
+
+
+
+#if CONFIG_TRACE
+ trace_buffer_dbg_dump (&cp.trace);
+#endif /* CONFIG_TRACE */
+ cp_trace_uninit (&cp);
+}
+
+void
+test_fsm_test_suite (test_t t)
+{
+ test_suite_begin (t, "cco fsm");
+ test_fsm_basic_test_case (t);
+ test_vs_eoc_test_case (t);
+}
+
+void
+cp_sta_core_signal_fsm_event (cp_t *ctx)
+{
+ dbg_assert (ctx);
+ ctx->sta_core_flag = true;
+}
+
+void
+cp_sta_core_signal_fsm_urgent_event (cp_t *ctx)
+{
+ dbg_assert (ctx);
+ ctx->sta_core_urgent_flag = true;
+}
+
+int
+main (int argc, char **argv)
+{
+ test_t t;
+ trace_init ();
+ test_init (t, argc, argv);
+ test_fsm_test_suite (t);
+ trace_uninit ();
+ test_case_begin (t, "Memory allocation");
+ test_begin (t, "memory leaks")
+ {
+ test_fail_if (blk_check_memory () != true, "Memory leaks");
+ }
+ test_end;
+ test_result (t);
+ return test_nb_failed (t) == 0 ? 0 : 1;
+}