summaryrefslogtreecommitdiff
path: root/cesar/cp2/fsm/test
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/cp2/fsm/test')
-rw-r--r--cesar/cp2/fsm/test/utest/Makefile11
-rw-r--r--cesar/cp2/fsm/test/utest/inc/scenario_defs.h65
-rw-r--r--cesar/cp2/fsm/test/utest/override/cp2/fsm/src/fsm/cp.fsm30
-rw-r--r--cesar/cp2/fsm/test/utest/override/cp2/inc/context.h25
-rw-r--r--cesar/cp2/fsm/test/utest/src/actions.c33
-rw-r--r--cesar/cp2/fsm/test/utest/src/fsm_stub.c79
-rw-r--r--cesar/cp2/fsm/test/utest/src/test_fsm.c69
7 files changed, 309 insertions, 3 deletions
diff --git a/cesar/cp2/fsm/test/utest/Makefile b/cesar/cp2/fsm/test/utest/Makefile
index babe48b025..2cc09d7db8 100644
--- a/cesar/cp2/fsm/test/utest/Makefile
+++ b/cesar/cp2/fsm/test/utest/Makefile
@@ -1,10 +1,17 @@
BASE = ../../../..
+INCLUDES = cp2/fsm/test/utest cp2/fsm/test/utest/override
+
HOST_PROGRAMS = test_fsm
-test_fsm_SOURCES = test_fsm.c
-test_fsm_MODULES = lib cp2/fsm
+test_fsm_SOURCES = test_fsm.c fsm_stub.c actions.c
+test_fsm_MODULES = lib lib/scenario cp2/fsm
+cp2_fsm_MODULE_SOURCES = fsm.c events.c
include $(BASE)/common/make/top.mk
$(call src2obj,src/test_fsm.c,host): $(BASE)/cp2/fsm/fsm.h
$(call src2obj,src/test_fsm.c,target): $(BASE)/cp2/fsm/fsm.h
+
+# Override fsm.
+vpath %.fsm
+vpath %.fsm override
diff --git a/cesar/cp2/fsm/test/utest/inc/scenario_defs.h b/cesar/cp2/fsm/test/utest/inc/scenario_defs.h
new file mode 100644
index 0000000000..d83996530b
--- /dev/null
+++ b/cesar/cp2/fsm/test/utest/inc/scenario_defs.h
@@ -0,0 +1,65 @@
+#ifndef inc_scenario_defs_h
+#define inc_scenario_defs_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file inc/scenario_defs.h
+ * \brief Scenario definitions.
+ * \ingroup test
+ */
+
+#include "cp2/types.h"
+#include "cp2/mme.h"
+#include "cp2/fsm/fsm.h"
+
+/* Scenario globals. */
+#define SCENARIO_DEFS_GLOBALS \
+ cp_t *cp;
+
+/* Scenario actions. */
+#define SCENARIO_DEFS_ACTIONS \
+ post_and_process
+
+typedef struct
+{
+ cp_fsm_event_type_t type;
+ cp_mme_rx_t *mme;
+ cp_beacon_desc_t *beacon;
+ cp_net_t *net;
+ cp_sta_t *sta;
+} scenario_action_post_and_process_t;
+
+void
+scenario_action_post_and_process_cb (scenario_globals_t *globals,
+ scenario_params_t *params);
+
+/* Scenario events. */
+#define SCENARIO_DEFS_EVENTS \
+ cp_fsm__STATE1__event1, \
+ cp_fsm__STATE1__event2, \
+ cp_fsm__STATE2__event3, \
+ cp_fsm__STATE3__event1, \
+ cp_fsm__STATE3__event2, \
+ cp_fsm__STATE4__event1
+
+typedef struct
+{
+ cp_fsm_branch_t branch;
+} scenario_event_transition_with_branch_t;
+
+typedef scenario_empty_t scenario_event_cp_fsm__STATE1__event1_t;
+typedef scenario_empty_t scenario_event_cp_fsm__STATE1__event2_t;
+typedef scenario_event_transition_with_branch_t
+scenario_event_cp_fsm__STATE2__event3_t;
+typedef scenario_event_transition_with_branch_t
+scenario_event_cp_fsm__STATE3__event1_t;
+typedef scenario_empty_t scenario_event_cp_fsm__STATE3__event2_t;
+typedef scenario_event_transition_with_branch_t
+scenario_event_cp_fsm__STATE4__event1_t;
+
+#endif /* inc_scenario_defs_h */
diff --git a/cesar/cp2/fsm/test/utest/override/cp2/fsm/src/fsm/cp.fsm b/cesar/cp2/fsm/test/utest/override/cp2/fsm/src/fsm/cp.fsm
new file mode 100644
index 0000000000..d6b77202cf
--- /dev/null
+++ b/cesar/cp2/fsm/test/utest/override/cp2/fsm/src/fsm/cp.fsm
@@ -0,0 +1,30 @@
+Test Control Plane FSM
+ Test FSM for engine test.
+
+States:
+ STATE1
+ STATE2
+ STATE3
+ STATE4
+
+Events:
+ event1
+ event2
+ event3
+ event4
+
+STATE1:
+ event1 -> .
+ event2 -> STATE2
+
+STATE2:
+ event3: branch1 -> STATE3
+ event3: branch2 -> STATE4
+
+STATE3:
+ event2 -> STATE2
+
+STATE3, STATE4:
+ event1: branch1 -> STATE1
+ event1: branch2 -> .
+
diff --git a/cesar/cp2/fsm/test/utest/override/cp2/inc/context.h b/cesar/cp2/fsm/test/utest/override/cp2/inc/context.h
new file mode 100644
index 0000000000..bdc48598dd
--- /dev/null
+++ b/cesar/cp2/fsm/test/utest/override/cp2/inc/context.h
@@ -0,0 +1,25 @@
+#ifndef override_cp2_inc_context_h
+#define override_cp2_inc_context_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file override/cp2/inc/context.h
+ * \brief Control plane context override.
+ * \ingroup test
+ */
+
+#include "cp2/fsm/fsm.h"
+#include "cp2/fsm/inc/context.h"
+
+struct cp_t
+{
+ /** FSM context. */
+ cp_fsm_t fsm;
+};
+
+#endif /* override_cp2_inc_context_h */
diff --git a/cesar/cp2/fsm/test/utest/src/actions.c b/cesar/cp2/fsm/test/utest/src/actions.c
new file mode 100644
index 0000000000..93f65fded7
--- /dev/null
+++ b/cesar/cp2/fsm/test/utest/src/actions.c
@@ -0,0 +1,33 @@
+/* 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
+ 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
new file mode 100644
index 0000000000..1e1bbba6d9
--- /dev/null
+++ b/cesar/cp2/fsm/test/utest/src/fsm_stub.c
@@ -0,0 +1,79 @@
+/* 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 (void);
+
+void
+cp_fsm__STATE1__event2 (void);
+
+void
+cp_fsm__STATE2__event3 (void);
+
+void
+cp_fsm__STATE3__event1 (void);
+
+void
+cp_fsm__STATE3__event2 (void);
+
+void
+cp_fsm__STATE4__event1 (void);
+
+/* Include generated tables. */
+#include "cp_fsm_tables.h"
+
+void
+cp_fsm__STATE1__event1 (void)
+{
+ scenario_event (cp_fsm__STATE1__event1);
+}
+
+void
+cp_fsm__STATE1__event2 (void)
+{
+ scenario_event (cp_fsm__STATE1__event2);
+}
+
+void
+cp_fsm__STATE2__event3 (void)
+{
+ scenario_event (cp_fsm__STATE2__event3, param, globals);
+ cp_fsm_branch (globals->cp, param->branch);
+}
+
+void
+cp_fsm__STATE3__event1 (void)
+{
+ scenario_event (cp_fsm__STATE3__event1, param, globals);
+ cp_fsm_branch (globals->cp, param->branch);
+}
+
+void
+cp_fsm__STATE3__event2 (void)
+{
+ scenario_event (cp_fsm__STATE3__event2);
+}
+
+void
+cp_fsm__STATE4__event1 (void)
+{
+ scenario_event (cp_fsm__STATE4__event1, param, globals);
+ cp_fsm_branch (globals->cp, param->branch);
+}
+
diff --git a/cesar/cp2/fsm/test/utest/src/test_fsm.c b/cesar/cp2/fsm/test/utest/src/test_fsm.c
index 0e556c7f8e..15ef64425a 100644
--- a/cesar/cp2/fsm/test/utest/src/test_fsm.c
+++ b/cesar/cp2/fsm/test/utest/src/test_fsm.c
@@ -13,10 +13,77 @@
#include "common/std.h"
#include "lib/test.h"
+#include "lib/scenario/scenario.h"
-/* For the moment, only test headers compilation. */
#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;
+ cp_fsm_init (&cp);
+ test_begin (t, "fsm")
+ {
+ scenario_entry_t entries[] = {
+ /* STATE1 */
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_event1, .mme = NULL),
+ SCENARIO_EVENT (cp_fsm__STATE1__event1),
+ /* STATE1 */
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_event2, .mme = NULL),
+ SCENARIO_EVENT (cp_fsm__STATE1__event2),
+ /* STATE2 */
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_event3, .mme = NULL),
+ 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, .mme = NULL),
+ SCENARIO_EVENT (cp_fsm__STATE2__event3,
+ .branch = CP_FSM_BRANCH (STATE3, event1, branch2)),
+ /* STATE3 */
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_event2, .mme = NULL),
+ SCENARIO_EVENT (cp_fsm__STATE3__event2),
+ /* STATE2 */
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_event3, .mme = NULL),
+ 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, .mme = NULL),
+ SCENARIO_EVENT (cp_fsm__STATE2__event3,
+ .branch = CP_FSM_BRANCH (STATE4, event1, branch2)),
+ /* STATE4 */
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_event1, .mme = NULL),
+ SCENARIO_EVENT (cp_fsm__STATE2__event3,
+ .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.state == CP_FSM_STATE_STATE1);
+ } test_end;
+ cp_fsm_uninit (&cp);
+}
+
+void
+test_fsm_test_suite (test_t t)
+{
+ test_suite_begin (t, "fsm");
+ test_fsm_basic_test_case (t);
+}
+
int
main (int argc, char **argv)
{