summaryrefslogtreecommitdiff
path: root/cesar/cp2/fsm/test/utest/src
diff options
context:
space:
mode:
authorschodet2008-08-29 14:52:33 +0000
committerschodet2008-08-29 14:52:33 +0000
commit61addbb1e20e382581c3bee165b8c253adb69d84 (patch)
treef106646632de478a1bc08b12a043f83336435e98 /cesar/cp2/fsm/test/utest/src
parent1b5b41d79cf71a1d5a784576aa1fa9d9bd704a71 (diff)
* cp2 -> cp:
- renamed. git-svn-id: svn+ssh://pessac/svn/cesar/trunk@2798 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'cesar/cp2/fsm/test/utest/src')
-rw-r--r--cesar/cp2/fsm/test/utest/src/actions.c35
-rw-r--r--cesar/cp2/fsm/test/utest/src/fsm_stub.c205
-rw-r--r--cesar/cp2/fsm/test/utest/src/test_fsm.c322
3 files changed, 0 insertions, 562 deletions
diff --git a/cesar/cp2/fsm/test/utest/src/actions.c b/cesar/cp2/fsm/test/utest/src/actions.c
deleted file mode 100644
index 3c74de91a1..0000000000
--- a/cesar/cp2/fsm/test/utest/src/actions.c
+++ /dev/null
@@ -1,35 +0,0 @@
-/* Cesar project {{{
- *
- * Copyright (C) 2008 Spidcom
- *
- * <<<Licence>>>
- *
- * }}} */
-/**
- * \file src/actions.c
- * \brief Scenario actions.
- * \ingroup test
- */
-#include "common/std.h"
-
-#include "lib/scenario/scenario.h"
-
-void
-scenario_action_post_and_process_cb (scenario_globals_t *globals,
- scenario_params_t *params)
-{
- scenario_action_post_and_process_t *p = &params->action_post_and_process;
- cp_fsm_event_t *event;
- if (p->mme)
- event = cp_fsm_event_mme_new (globals->cp, p->type, p->mme);
- else if (p->beacon)
- event = cp_fsm_event_beacon_new (globals->cp, p->type, p->beacon,
- p->net, p->sta);
- else if (p->sta)
- event = cp_fsm_event_sta_new (globals->cp, p->type, p->net, p->sta);
- else
- event = cp_fsm_event_bare_new (globals->cp, p->type);
- cp_fsm_post (globals->cp, event);
- cp_fsm_process (globals->cp);
-}
-
diff --git a/cesar/cp2/fsm/test/utest/src/fsm_stub.c b/cesar/cp2/fsm/test/utest/src/fsm_stub.c
deleted file mode 100644
index 212e914e6f..0000000000
--- a/cesar/cp2/fsm/test/utest/src/fsm_stub.c
+++ /dev/null
@@ -1,205 +0,0 @@
-/* Cesar project {{{
- *
- * Copyright (C) 2008 Spidcom
- *
- * <<<Licence>>>
- *
- * }}} */
-/**
- * \file src/fsm_stub.c
- * \brief Override FSM tables.
- * \ingroup test
- */
-#include "common/std.h"
-
-#include "lib/scenario/scenario.h"
-
-#include "cp2/fsm/fsm.h"
-#include "cp2/fsm/inc/tables.h"
-
-void
-cp_fsm__STATE1__event1 (cp_t *ctx);
-
-void
-cp_fsm__STATE1__event2 (cp_t *ctx);
-
-void
-cp_fsm__STATE1__error_event_no_branch (cp_t *ctx);
-
-void
-cp_fsm__STATE1__error_event_bad_branch (cp_t *ctx);
-
-void
-cp_fsm__STATE1__error_event_dup_branch (cp_t *ctx);
-
-void
-cp_fsm__STATE1__event_mme (cp_t *ctx, cp_mme_rx_t *mme);
-
-void
-cp_fsm__STATE1__event_sta (cp_t *ctx, cp_net_t *net, cp_sta_t *sta);
-
-void
-cp_fsm__STATE1__event_beacon (cp_t *ctx, cp_beacon_desc_t *beacon,
- cp_net_t *net, cp_sta_t *sta);
-
-void
-cp_fsm__STATE1__eventb (cp_t *ctx);
-
-void
-cp_fsm__STATE2__event3 (cp_t *ctx);
-
-void
-cp_fsm__STATE3__event1 (cp_t *ctx);
-
-void
-cp_fsm__STATE3__event2 (cp_t *ctx);
-
-void
-cp_fsm__STATE4__event1 (cp_t *ctx);
-
-void
-cp_fsm__STATE5__enter (cp_t *ctx);
-
-void
-cp_fsm__STATE5__leave (cp_t *ctx);
-
-void
-cp_fsm__STATE6__enter (cp_t *ctx);
-
-void
-cp_fsm__STATE6__leave (cp_t *ctx);
-
-void
-cp_fsm__STATEA__eventb (cp_t *ctx);
-
-void
-cp_fsm__STATEB__eventa (cp_t *ctx);
-
-/* Include generated tables. */
-#include "cp_fsm_tables.h"
-
-void
-cp_fsm__STATE1__event1 (cp_t *ctx)
-{
- scenario_event (cp_fsm__STATE1__event1);
-}
-
-void
-cp_fsm__STATE1__event2 (cp_t *ctx)
-{
- scenario_event (cp_fsm__STATE1__event2);
-}
-
-void
-cp_fsm__STATE1__error_event_no_branch (cp_t *ctx)
-{
- /* Do not choose branch. */
-}
-
-void
-cp_fsm__STATE1__error_event_bad_branch (cp_t *ctx)
-{
- cp_fsm_branch (ctx, STATE2, event3, branch1);
-}
-
-void
-cp_fsm__STATE1__error_event_dup_branch (cp_t *ctx)
-{
- cp_fsm_branch (ctx, STATE1, error_event_dup_branch, branch1);
- cp_fsm_branch (ctx, STATE1, error_event_dup_branch, branch2);
-}
-
-void
-cp_fsm__STATE1__event_mme (cp_t *ctx, cp_mme_rx_t *mme)
-{
- scenario_event (cp_fsm__STATE1__event_mme, param);
- test_fail_unless (mme == param->mme);
-}
-
-void
-cp_fsm__STATE1__event_sta (cp_t *ctx, cp_net_t *net, cp_sta_t *sta)
-{
- scenario_event (cp_fsm__STATE1__event_sta, param);
- test_fail_unless (net == param->net);
- test_fail_unless (sta == param->sta);
-}
-
-void
-cp_fsm__STATE1__event_beacon (cp_t *ctx, cp_beacon_desc_t *beacon,
- cp_net_t *net, cp_sta_t *sta)
-{
- scenario_event (cp_fsm__STATE1__event_beacon, param);
- test_fail_unless (beacon == param->beacon);
- test_fail_unless (net == param->net);
- test_fail_unless (sta == param->sta);
-}
-
-void
-cp_fsm__STATE1__eventb (cp_t *ctx)
-{
- scenario_event (cp_fsm__STATE1__eventb);
-}
-
-void
-cp_fsm__STATE2__event3 (cp_t *ctx)
-{
- scenario_event (cp_fsm__STATE2__event3, param);
- cp_fsm_branch_ (ctx, param->branch);
-}
-
-void
-cp_fsm__STATE3__event1 (cp_t *ctx)
-{
- scenario_event (cp_fsm__STATE3__event1, param);
- cp_fsm_branch_ (ctx, param->branch);
-}
-
-void
-cp_fsm__STATE3__event2 (cp_t *ctx)
-{
- scenario_event (cp_fsm__STATE3__event2);
-}
-
-void
-cp_fsm__STATE4__event1 (cp_t *ctx)
-{
- scenario_event (cp_fsm__STATE4__event1, param);
- cp_fsm_branch_ (ctx, param->branch);
-}
-
-void
-cp_fsm__STATE5__enter (cp_t *ctx)
-{
- scenario_event (cp_fsm__STATE5__enter);
-}
-
-void
-cp_fsm__STATE5__leave (cp_t *ctx)
-{
- scenario_event (cp_fsm__STATE5__leave);
-}
-
-void
-cp_fsm__STATE6__enter (cp_t *ctx)
-{
- scenario_event (cp_fsm__STATE6__enter);
-}
-
-void
-cp_fsm__STATE6__leave (cp_t *ctx)
-{
- scenario_event (cp_fsm__STATE6__leave);
-}
-
-void
-cp_fsm__STATEA__eventb (cp_t *ctx)
-{
- scenario_event (cp_fsm__STATEA__eventb);
-}
-
-void
-cp_fsm__STATEB__eventa (cp_t *ctx)
-{
- scenario_event (cp_fsm__STATEB__eventa);
-}
-
diff --git a/cesar/cp2/fsm/test/utest/src/test_fsm.c b/cesar/cp2/fsm/test/utest/src/test_fsm.c
deleted file mode 100644
index 92c2e8e94c..0000000000
--- a/cesar/cp2/fsm/test/utest/src/test_fsm.c
+++ /dev/null
@@ -1,322 +0,0 @@
-/* Cesar project {{{
- *
- * Copyright (C) 2008 Spidcom
- *
- * <<<Licence>>>
- *
- * }}} */
-/**
- * \file src/test_fsm.c
- * \brief Test FSM module.
- * \ingroup test
- */
-#include "common/std.h"
-
-#include "lib/blk.h"
-#include "lib/test.h"
-#include "lib/scenario/scenario.h"
-
-#include "cp2/fsm/fsm.h"
-
-#include "cp2/inc/context.h"
-
-void
-test_fsm_basic_test_case (test_t t)
-{
- test_case_begin (t, "basic");
- cp_t cp;
- slab_cache_t cache;
- slab_cache_init (&cache, "dummy", 1, NULL);
- cp_mme_rx_t *mme = slab_alloc (&cache);
- cp_sta_t *sta = slab_alloc (&cache);
- cp_net_t *net = (void *) 0x9abcdef0;
- cp_beacon_desc_t *beacon = (cp_beacon_desc_t *) blk_alloc_desc ();
- test_begin (t, "bare")
- {
- cp_fsm_init (&cp);
- scenario_entry_t entries[] = {
- /* STATE1 */
- SCENARIO_ACTION (post_and_process,
- .type = CP_FSM_EVENT_TYPE_event1),
- SCENARIO_EVENT (cp_fsm__STATE1__event1),
- /* STATE1 */
- SCENARIO_ACTION (post_and_process,
- .type = CP_FSM_EVENT_TYPE_event2),
- SCENARIO_EVENT (cp_fsm__STATE1__event2),
- /* STATE2 */
- SCENARIO_ACTION (post_and_process,
- .type = CP_FSM_EVENT_TYPE_event3),
- SCENARIO_EVENT (cp_fsm__STATE2__event3,
- .branch = CP_FSM_BRANCH (STATE2, event3, branch1)),
- /* STATE3 */
- SCENARIO_ACTION (post_and_process,
- .type = CP_FSM_EVENT_TYPE_event1),
- SCENARIO_EVENT (cp_fsm__STATE3__event1,
- .branch = CP_FSM_BRANCH (STATE3, event1, branch2)),
- /* STATE3 */
- SCENARIO_ACTION (post_and_process,
- .type = CP_FSM_EVENT_TYPE_event2),
- SCENARIO_EVENT (cp_fsm__STATE3__event2),
- /* STATE2 */
- SCENARIO_ACTION (post_and_process,
- .type = CP_FSM_EVENT_TYPE_event3),
- SCENARIO_EVENT (cp_fsm__STATE2__event3,
- .branch = CP_FSM_BRANCH (STATE2, event3, branch2)),
- /* STATE4 */
- SCENARIO_ACTION (post_and_process,
- .type = CP_FSM_EVENT_TYPE_event1),
- SCENARIO_EVENT (cp_fsm__STATE4__event1,
- .branch = CP_FSM_BRANCH (STATE4, event1, branch2)),
- /* STATE4 */
- SCENARIO_ACTION (post_and_process,
- .type = CP_FSM_EVENT_TYPE_event1),
- SCENARIO_EVENT (cp_fsm__STATE4__event1,
- .branch = CP_FSM_BRANCH (STATE4, event1, branch1)),
- /* STATE1 */
- SCENARIO_END
- };
- scenario_globals_t globals = {
- .cp = &cp,
- };
- scenario_run (t, entries, &globals);
- test_fail_unless (cp.fsm.active_states[0] == CP_FSM_STATE_STATE1);
- cp_fsm_uninit (&cp);
- } test_end;
- test_begin (t, "mme")
- {
- cp_fsm_init (&cp);
- scenario_entry_t entries[] = {
- SCENARIO_ACTION (post_and_process,
- .type = CP_FSM_EVENT_TYPE_event_mme, .mme = mme),
- SCENARIO_EVENT (cp_fsm__STATE1__event_mme, .mme = mme),
- SCENARIO_END
- };
- scenario_globals_t globals = {
- .cp = &cp,
- };
- scenario_run (t, entries, &globals);
- test_fail_unless (cp.fsm.active_states[0] == CP_FSM_STATE_STATE1);
- cp_fsm_uninit (&cp);
- } test_end;
- test_begin (t, "sta")
- {
- cp_fsm_init (&cp);
- scenario_entry_t entries[] = {
- SCENARIO_ACTION (post_and_process,
- .type = CP_FSM_EVENT_TYPE_event_sta,
- .net = net, .sta = sta),
- SCENARIO_EVENT (cp_fsm__STATE1__event_sta,
- .net = net, .sta = sta),
- SCENARIO_END
- };
- scenario_globals_t globals = {
- .cp = &cp,
- };
- scenario_run (t, entries, &globals);
- test_fail_unless (cp.fsm.active_states[0] == CP_FSM_STATE_STATE1);
- cp_fsm_uninit (&cp);
- } test_end;
- test_begin (t, "beacon")
- {
- cp_fsm_init (&cp);
- scenario_entry_t entries[] = {
- SCENARIO_ACTION (post_and_process,
- .type = CP_FSM_EVENT_TYPE_event_beacon,
- .beacon = beacon, .net = net, .sta = sta),
- SCENARIO_EVENT (cp_fsm__STATE1__event_beacon,
- .beacon = beacon, .net = net, .sta = sta),
- SCENARIO_END
- };
- scenario_globals_t globals = {
- .cp = &cp,
- };
- scenario_run (t, entries, &globals);
- test_fail_unless (cp.fsm.active_states[0] == CP_FSM_STATE_STATE1);
- cp_fsm_uninit (&cp);
- } test_end;
- test_begin (t, "dual")
- {
- cp_fsm_init (&cp);
- scenario_entry_t entries[] = {
- /* STATE1, STATEA */
- SCENARIO_ACTION (post_and_process,
- .type = CP_FSM_EVENT_TYPE_eventb),
- SCENARIO_EVENT (cp_fsm__STATE1__eventb),
- SCENARIO_EVENT (cp_fsm__STATEA__eventb),
- /* STATE3, STATEB */
- SCENARIO_ACTION (post_and_process,
- .type = CP_FSM_EVENT_TYPE_eventa),
- SCENARIO_EVENT (cp_fsm__STATEB__eventa),
- /* STATE3, STATEA */
- SCENARIO_ACTION (post_and_process,
- .type = CP_FSM_EVENT_TYPE_event1),
- SCENARIO_EVENT (cp_fsm__STATE3__event1,
- .branch = CP_FSM_BRANCH (STATE3, event1, branch1)),
- /* STATE1, STATEA */
- SCENARIO_END
- };
- scenario_globals_t globals = {
- .cp = &cp,
- };
- scenario_run (t, entries, &globals);
- test_fail_unless (cp.fsm.active_states[0] == CP_FSM_STATE_STATE1);
- test_fail_unless (cp.fsm.active_states[1] == CP_FSM_STATE_STATEA);
- cp_fsm_uninit (&cp);
- } test_end;
- test_begin (t, "no action")
- {
- cp_fsm_init (&cp);
- scenario_entry_t entries[] = {
- /* STATE1 */
- SCENARIO_ACTION (post_and_process,
- .type = CP_FSM_EVENT_TYPE_event_no_action),
- /* STATE3 */
- SCENARIO_ACTION (post_and_process,
- .type = CP_FSM_EVENT_TYPE_event1),
- SCENARIO_EVENT (cp_fsm__STATE3__event1,
- .branch = CP_FSM_BRANCH (STATE3, event1, branch1)),
- /* STATE1 */
- SCENARIO_END
- };
- scenario_globals_t globals = {
- .cp = &cp,
- };
- scenario_run (t, entries, &globals);
- test_fail_unless (cp.fsm.active_states[0] == CP_FSM_STATE_STATE1);
- cp_fsm_uninit (&cp);
- } test_end;
- test_begin (t, "enter leave")
- {
- cp_fsm_init (&cp);
- scenario_entry_t entries[] = {
- /* STATE1 */
- SCENARIO_ACTION (post_and_process,
- .type = CP_FSM_EVENT_TYPE_event5),
- SCENARIO_EVENT (cp_fsm__STATE5__enter),
- /* STATE5 */
- SCENARIO_ACTION (post_and_process,
- .type = CP_FSM_EVENT_TYPE_event6),
- SCENARIO_EVENT (cp_fsm__STATE5__leave),
- SCENARIO_EVENT (cp_fsm__STATE6__enter),
- /* STATE6 */
- SCENARIO_ACTION (post_and_process,
- .type = CP_FSM_EVENT_TYPE_event1),
- SCENARIO_EVENT (cp_fsm__STATE6__leave),
- /* STATE1 */
- SCENARIO_END
- };
- scenario_globals_t globals = {
- .cp = &cp,
- };
- scenario_run (t, entries, &globals);
- test_fail_unless (cp.fsm.active_states[0] == CP_FSM_STATE_STATE1);
- cp_fsm_uninit (&cp);
- } test_end;
- slab_release (mme);
- slab_release (sta);
- slab_cache_uninit (&cache);
- blk_release_desc ((blk_t *) beacon);
-}
-
-void
-test_fsm_error_test_case (test_t t)
-{
- test_case_begin (t, "error");
- cp_t cp;
- test_begin (t, "no branch")
- {
- cp_fsm_init (&cp);
- cp_fsm_event_t *event = cp_fsm_event_bare_new (
- &cp, CP_FSM_EVENT_TYPE_error_event_no_branch);
- cp_fsm_post (&cp, event);
- const char *asserted = NULL;
- dbg_fatal_try_begin
- {
- cp_fsm_process (&cp);
- }
- dbg_fatal_try_catch (const char *msg)
- {
- slab_release (event); /* Was not release due to assert. */
- asserted = msg;
- }
- dbg_fatal_try_end;
- test_fail_unless (asserted);
- } test_end;
- test_begin (t, "bad branch")
- {
- cp_fsm_init (&cp);
- cp_fsm_event_t *event = cp_fsm_event_bare_new (
- &cp, CP_FSM_EVENT_TYPE_error_event_bad_branch);
- cp_fsm_post (&cp, event);
- const char *asserted = NULL;
- dbg_fatal_try_begin
- {
- cp_fsm_process (&cp);
- }
- dbg_fatal_try_catch (const char *msg)
- {
- slab_release (event); /* Was not release due to assert. */
- asserted = msg;
- }
- dbg_fatal_try_end;
- test_fail_unless (asserted);
- } test_end;
- test_begin (t, "dup branch")
- {
- cp_fsm_init (&cp);
- cp_fsm_event_t *event = cp_fsm_event_bare_new (
- &cp, CP_FSM_EVENT_TYPE_error_event_dup_branch);
- cp_fsm_post (&cp, event);
- const char *asserted = NULL;
- dbg_fatal_try_begin
- {
- cp_fsm_process (&cp);
- }
- dbg_fatal_try_catch (const char *msg)
- {
- slab_release (event); /* Was not release due to assert. */
- asserted = msg;
- }
- dbg_fatal_try_end;
- test_fail_unless (asserted);
- } test_end;
- test_begin (t, "not in transition")
- {
- cp_fsm_init (&cp);
- const char *asserted = NULL;
- dbg_fatal_try_begin
- {
- cp_fsm_branch (&cp, STATE1, error_event_no_branch, branch1);
- }
- dbg_fatal_try_catch (const char *msg)
- {
- asserted = msg;
- }
- dbg_fatal_try_end;
- test_fail_unless (asserted);
- } test_end;
-}
-
-void
-test_fsm_test_suite (test_t t)
-{
- test_suite_begin (t, "fsm");
- test_fsm_basic_test_case (t);
- test_fsm_error_test_case (t);
- test_case_begin (t, "memory");
- test_begin (t, "memory")
- {
- test_fail_unless (blk_check_memory ());
- } test_end;
-}
-
-int
-main (int argc, char **argv)
-{
- test_t t;
- test_init (t, argc, argv);
- test_fsm_test_suite (t);
- test_result (t);
- return test_nb_failed (t) == 0 ? 0 : 1;
-}
-