summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlaranjeiro2010-05-17 09:08:16 +0000
committerlaranjeiro2010-05-17 09:08:16 +0000
commitd86b0f6443693b5c2db8106f9cb3f3f6136cebd7 (patch)
treee819919090141bdb2d65b07a2fa27de3bed4d261
parent502fd4b44320ff0760eadeb6030241c73925fe10 (diff)
cesar/bsu: add test structure
git-svn-id: svn+ssh://pessac/svn/cesar/trunk@7018 017c9cb6-072f-447c-8318-d5b54f68fe89
-rw-r--r--cesar/bsu/Module2
-rw-r--r--cesar/bsu/src/bsu.c77
-rw-r--r--cesar/bsu/src/interface.c33
-rw-r--r--cesar/bsu/test/utest/Makefile8
-rw-r--r--cesar/bsu/test/utest/src/bsu.c42
-rw-r--r--cesar/bsu/test/utest/src/bsut.c22
-rw-r--r--cesar/bsu/test/utest/src/ca.c24
-rw-r--r--cesar/bsu/test/utest/src/interface.c38
-rw-r--r--cesar/bsu/test/utest/src/phy.c36
-rw-r--r--cesar/bsu/test/utest/src/sar.c29
-rw-r--r--cesar/bsu/test/utest/src/schedules.c21
-rw-r--r--cesar/bsu/test/utest/src/tests.c429
-rw-r--r--cesar/bsu/test/utest/tests.h105
13 files changed, 866 insertions, 0 deletions
diff --git a/cesar/bsu/Module b/cesar/bsu/Module
new file mode 100644
index 0000000000..bc0074ecfa
--- /dev/null
+++ b/cesar/bsu/Module
@@ -0,0 +1,2 @@
+SOURCES:=interface.c bsu.c
+MODULES:=bsu/aclf bsu/ntb bsu/beacon
diff --git a/cesar/bsu/src/bsu.c b/cesar/bsu/src/bsu.c
new file mode 100644
index 0000000000..c7b78fccbb
--- /dev/null
+++ b/cesar/bsu/src/bsu.c
@@ -0,0 +1,77 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2010 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file bsu/src/bsu.c
+ * \brief BSU core functions.
+ * \ingroup bsu
+ */
+#include "common/std.h"
+#include "bsu/bsu.h"
+#include "bsu/inc/context.h"
+#include "bsu/inc/interface.h"
+
+/* Define the delay to program the timer. */
+#define BSU_WAKEUP_DELAY_MS 2
+
+/** Static declaration. */
+static bsu_t bsu_global;
+
+bsu_t *
+bsu_init (mac_config_t *mac_config, phy_t *phy, mac_store_t *mac_store,
+ ca_t *ca, sar_t *sar, hal_timer_t *timer,
+ bsu_beacon_processed_t cb, void *cb_ud)
+{
+ bsu_t *ctx = &bsu_global;
+ dbg_assert (mac_config);
+ dbg_assert (phy);
+ dbg_assert (mac_store);
+ dbg_assert (ca);
+ dbg_assert (sar);
+ dbg_assert (timer);
+ dbg_assert (cb);
+ /* Initialise the context. */
+ ctx->mac_config = mac_config;
+ ctx->phy = phy;
+ ctx->mac_store = mac_store;
+ ctx->ca = ca;
+ ctx->sar = sar;
+ ctx->ul_cb = cb;
+ ctx->ul_data = cb_ud;
+ ctx->hal_timer = timer;
+ /* Initialise the ACLF. */
+ bsu_aclf_init (&ctx->aclf, phy, mac_config);
+ /* Initialise the NTB. */
+ bsu_ntb_init (&ctx->sta_avln.sync);
+ uint i;
+ for (i = 0; i < BSU_FOREIGN_AVLNS_NB; i++)
+ bsu_ntb_init (&ctx->avlns[i].sync);
+ /* Initialise the SAR callback. */
+ sar_init_beacon_cb (sar, ctx, (sar_beacon_cb_t) bsu_beacon_recv);
+ return ctx;
+}
+
+void
+bsu_uninit (bsu_t *ctx)
+{
+ dbg_assert (ctx);
+ bsu_aclf_uninit (&ctx->aclf);
+ bsu_ntb_uninit (&ctx->sta_avln.sync);
+ uint i;
+ for (i = 0; i < BSU_FOREIGN_AVLNS_NB; i++)
+ bsu_ntb_uninit (&ctx->avlns[i].sync);
+}
+
+void
+bsu_beacon_process (bsu_t *ctx, pb_beacon_t *beacon,
+ pbproc_rx_beacon_params_t *params)
+{
+ dbg_assert (ctx);
+ dbg_assert (beacon);
+ dbg_assert (params);
+ dbg_assert_default ();
+}
diff --git a/cesar/bsu/src/interface.c b/cesar/bsu/src/interface.c
new file mode 100644
index 0000000000..71973823a2
--- /dev/null
+++ b/cesar/bsu/src/interface.c
@@ -0,0 +1,33 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2010 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file bsu/src/interface.c
+ * \brief BSU interface functions.
+ * \ingroup bsu
+ *
+ * BSU interface functions with the SAR and upper layer.
+ */
+#include "common/std.h"
+#include "bsu/bsu.h"
+#include "bsu/inc/bsu.h"
+
+#include "bsu/inc/context.h"
+
+void
+bsu_beacon_recv (bsu_t *ctx, pb_beacon_t *beacon,
+ pbproc_rx_beacon_params_t *params)
+{
+ dbg_assert (ctx);
+ dbg_assert (beacon);
+ dbg_assert (params);
+ /* Process the beacon received from the SAR. */
+ bsu_beacon_params_t *bsu_params =
+ bsu_beacon_process (ctx, beacon, params);
+ /* Send it to the upper layer. */
+ ctx->ul_cb (ctx->ul_data, beacon, params, bsu_params);
+}
diff --git a/cesar/bsu/test/utest/Makefile b/cesar/bsu/test/utest/Makefile
new file mode 100644
index 0000000000..33a98336bc
--- /dev/null
+++ b/cesar/bsu/test/utest/Makefile
@@ -0,0 +1,8 @@
+BASE = ../../..
+
+HOST_PROGRAMS = bsu
+bsu_SOURCES = tests.c bsu.c interface.c bsut.c schedules.c \
+ ca.c sar.c phy.c
+bsu_MODULES = lib bsu mac/common hal/timer/stub
+
+include $(BASE)/common/make/top.mk
diff --git a/cesar/bsu/test/utest/src/bsu.c b/cesar/bsu/test/utest/src/bsu.c
new file mode 100644
index 0000000000..040d429038
--- /dev/null
+++ b/cesar/bsu/test/utest/src/bsu.c
@@ -0,0 +1,42 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2010 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file bsu/test/utest/src/bsu.c
+ * \brief bsu unit tests.
+ * \ingroup bsu
+ */
+#include "common/std.h"
+#include "lib/test.h"
+#include "bsu/test/utest/tests.h"
+
+void
+test_suite_bsu_interface (test_t t);
+
+void
+test_suite_bsu (test_t t);
+
+void
+test_suite_bsu_schedule (test_t t);
+
+int
+main (int argc, char **argv)
+{
+ test_t test;
+ test_init (test, argc, argv);
+// test_suite_bsu_interface (test);
+// test_suite_bsu (test);
+// test_suite_bsu_schedule (test);
+ test_begin (test, "Memory")
+ {
+ test_fail_if (blk_check_memory() == false, "Memory not freed");
+ }
+ test_end;
+ test_result (test);
+ return test_nb_failed (test) == 0 ? 0 : 1;
+}
+
diff --git a/cesar/bsu/test/utest/src/bsut.c b/cesar/bsu/test/utest/src/bsut.c
new file mode 100644
index 0000000000..c965bd5432
--- /dev/null
+++ b/cesar/bsu/test/utest/src/bsut.c
@@ -0,0 +1,22 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2010 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file bsu/test/utest/src/bsut.c
+ * \brief BSU unit test.
+ * \ingroup bsu
+ */
+#include "common/std.h"
+#include "lib/test.h"
+
+void
+test_suite_bsu (test_t t)
+{
+ test_suite_begin (t, "BSU test");
+ dbg_assert_default ();
+}
+
diff --git a/cesar/bsu/test/utest/src/ca.c b/cesar/bsu/test/utest/src/ca.c
new file mode 100644
index 0000000000..5e37a52aa4
--- /dev/null
+++ b/cesar/bsu/test/utest/src/ca.c
@@ -0,0 +1,24 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2010 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file bsu/test/utest/src/ca.c
+ * \brief CA stub functions.
+ * \ingroup bsu
+ */
+#include "common/std.h"
+#include "mac/ca/ca.h"
+
+void
+ca_mfs_add (ca_t *ctx, mfs_tx_t *mfs)
+{
+}
+
+void
+ca_mfs_hold (ca_t *ctx, mfs_tx_t *mfs)
+{
+}
diff --git a/cesar/bsu/test/utest/src/interface.c b/cesar/bsu/test/utest/src/interface.c
new file mode 100644
index 0000000000..cad7123619
--- /dev/null
+++ b/cesar/bsu/test/utest/src/interface.c
@@ -0,0 +1,38 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2010 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file bsu/test/utest/src/interface.c
+ * \brief Interface unit tests.
+ * \ingroup bsu
+ */
+#include "common/std.h"
+#include "lib/test.h"
+#include "bsu/test/utest/tests.h"
+#include "bsu/inc/interface.h"
+
+void
+test_case_bsu_interface__sar (test_t t)
+{
+ test_case_begin (t, "SAR");
+ dbg_assert_default ();
+}
+
+void
+test_case_bsu_interface__upperlayer (test_t t)
+{
+ test_case_begin (t, "Upper layer");
+ dbg_assert_default ();
+}
+
+void
+test_suite_bsu_interface (test_t t)
+{
+ test_suite_begin (t, "BSU interface");
+ test_case_bsu_interface__sar (t);
+ test_case_bsu_interface__upperlayer (t);
+}
diff --git a/cesar/bsu/test/utest/src/phy.c b/cesar/bsu/test/utest/src/phy.c
new file mode 100644
index 0000000000..071f98ef0c
--- /dev/null
+++ b/cesar/bsu/test/utest/src/phy.c
@@ -0,0 +1,36 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2010 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file bsu/test/utest/src/phy.c
+ * \brief Phy stubs.
+ * \ingroup bsu
+ */
+#include "common/std.h"
+#include "hal/phy/phy.h"
+
+u32
+phy_clock_get_zero_cross_captured_date (phy_t *ctx) __attribute__((weak));
+
+u32
+phy_clock_get_zero_cross_captured_date (phy_t *ctx)
+{
+ return 0;
+}
+
+u32
+phy_sysdate (phy_t *ctx) __attribute__((weak));
+
+u32
+phy_sysdate (phy_t *ctx)
+{
+ return 0;
+}
+
+void
+phy_clock_set_numerator (phy_t *ctx, uint numerator)
+{}
diff --git a/cesar/bsu/test/utest/src/sar.c b/cesar/bsu/test/utest/src/sar.c
new file mode 100644
index 0000000000..3fbc383ae5
--- /dev/null
+++ b/cesar/bsu/test/utest/src/sar.c
@@ -0,0 +1,29 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2010 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file bsu/test/utest/src/sar.c
+ * \brief SAR stub functions.
+ * \ingroup bsu
+ */
+#include "common/std.h"
+#include "mac/sar/sar.h"
+
+void
+sar_beacon_send (sar_t *sar, pb_beacon_t *beacon, mfs_tx_t *beacon_mfs,
+ void *bto_bpsto)
+{
+ /* release the beacon. */
+ blk_release_desc ((blk_t*) beacon);
+ /* Release reference on the MFS. */
+ blk_release (beacon_mfs);
+}
+
+void
+sar_init_beacon_cb (sar_t *sar, void *user_data, sar_beacon_cb_t uf)
+{
+}
diff --git a/cesar/bsu/test/utest/src/schedules.c b/cesar/bsu/test/utest/src/schedules.c
new file mode 100644
index 0000000000..0fb6f11165
--- /dev/null
+++ b/cesar/bsu/test/utest/src/schedules.c
@@ -0,0 +1,21 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2010 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file bsu/test/utest/src/schedules.c
+ * \brief BSU schedule tests.
+ * \ingroup bsu
+ */
+#include "common/std.h"
+#include "lib/test.h"
+
+void
+test_suite_bsu_schedule (test_t t)
+{
+ test_suite_begin (t, "BSU schedules");
+ dbg_assert_default ();
+}
diff --git a/cesar/bsu/test/utest/src/tests.c b/cesar/bsu/test/utest/src/tests.c
new file mode 100644
index 0000000000..20fe9d978e
--- /dev/null
+++ b/cesar/bsu/test/utest/src/tests.c
@@ -0,0 +1,429 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2010 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file bsu/test/utest/src/tests.c
+ * \brief Test environment.
+ * \ingroup bsu
+ */
+#include "common/std.h"
+#include "lib/bitstream.h"
+#include "lib/test.h"
+#include "bsu/bsu.h"
+#include "bsu/test/utest/tests.h"
+#include <string.h>
+#include "bsu/inc/context.h"
+
+static void
+bsu_test_upper_layer_beacon_received (void *ctx, pb_beacon_t *beacon,
+ pbproc_rx_beacon_params_t *params,
+ bsu_beacon_params_t *bparams)
+{
+}
+
+void
+bsu_test_init (bsu_test_t *ctx)
+{
+ static uint ca;
+ static uint sar;
+ dbg_assert (ctx);
+ ctx->mac_store = mac_store_init ();
+ ctx->ca = (ca_t*) &ca;
+ ctx->sar = (sar_t*) &sar;
+ ctx->mac_config.tei = 0x0;
+ ctx->mac_config.sta_mac_address = 0x123456789abcull;
+ ctx->timer = hal_timer_init ((phy_t *) &ctx->phy);
+ ctx->bsu = bsu_init (&ctx->mac_config, (phy_t*) &ctx->phy, ctx->mac_store,
+ ctx->ca, ctx->sar, ctx->timer,
+ bsu_test_upper_layer_beacon_received, ctx);
+}
+
+void
+bsu_test_uninit (bsu_test_t *ctx)
+{
+ dbg_assert (ctx);
+ mac_store_uninit (ctx->mac_store);
+}
+
+void
+bsu_test_create_beacon (bsu_test_t *ctx, bsu_beacon_t *beacon)
+{
+ dbg_assert (ctx);
+ dbg_assert (beacon);
+
+ memset (beacon, 0, sizeof (bsu_beacon_t));
+ beacon->vf.hm = MAC_COEXISTENCE_FULL_HYBRID_MODE;
+ beacon->vf.ncnr = false;
+ beacon->vf.npsm = false;
+ beacon->vf.numslots = 0;
+ beacon->vf.slotusage = 0;
+ beacon->vf.slotid = 0;
+ beacon->vf.aclsss = true;
+ beacon->vf.hoip = false;
+ beacon->vf.rtsbf = false;
+ beacon->vf.nm = false;
+ beacon->vf.ccocap = 0;
+ beacon->vf.rsvd = 0;
+ /* Regions. */
+ beacon->bmis.region.nb = 2;
+ beacon->bmis.region.region[0].rt = BSU_BEACON_REGION_BEACON;
+ beacon->bmis.region.region[0].end_time_atu = 50;
+ beacon->bmis.region.region[1].rt = BSU_BEACON_REGION_SHARED_CSMA;
+ beacon->bmis.region.region[1].end_time_atu = 3907;
+ /* Persistent schedules. */
+ beacon->bmis.ps.nb = 2;
+ beacon->bmis.ps.ps[0].pscd = 1;
+ beacon->bmis.ps.ps[0].cscd = 5;
+ beacon->bmis.ps.ps[0].ns = 1;
+ beacon->bmis.ps.ps[0].sais[0].stpf = true;
+ beacon->bmis.ps.ps[0].sais[0].glid = 0;
+ beacon->bmis.ps.ps[0].sais[0].start_time_atu = 50;
+ beacon->bmis.ps.ps[0].sais[0].end_time_atu = 500;
+ beacon->bmis.ps.ps[1].pscd = 2;
+ beacon->bmis.ps.ps[1].cscd = 5;
+ beacon->bmis.ps.ps[1].ns = 1;
+ beacon->bmis.ps.ps[1].sais[0].stpf = true;
+ beacon->bmis.ps.ps[1].sais[0].glid = 0;
+ beacon->bmis.ps.ps[1].sais[0].start_time_atu = 700;
+ beacon->bmis.ps.ps[1].sais[0].end_time_atu = 1000;
+ /* Non persistent schedules. */
+ beacon->bmis.nps.ns = 2;
+ beacon->bmis.nps.sais[0].stpf = false;
+ beacon->bmis.nps.sais[0].glid = 0;
+ beacon->bmis.nps.sais[0].start_time_atu = 500;
+ beacon->bmis.nps.sais[0].end_time_atu = 700;
+ beacon->bmis.nps.sais[1].stpf = false;
+ beacon->bmis.nps.sais[1].glid = 0;
+ beacon->bmis.nps.sais[1].start_time_atu = 1000;
+ beacon->bmis.nps.sais[1].end_time_atu = 3907;
+ /* BSPTO. */
+ beacon->bmis.bpsto.present = true;
+ beacon->bmis.bpsto.bpsto = 0xfed0;
+ /* Discover. */
+ beacon->bmis.discover.present = true;
+ beacon->bmis.discover.tei = 0xc;
+ /* Discover info. */
+ beacon->bmis.discover_info.present = true;
+ beacon->bmis.discover_info.info_data = 0xcafecafe;
+ /* Encryption key change. */
+ beacon->bmis.eks.present = true;
+ beacon->bmis.eks.kccd = 5;
+ beacon->bmis.eks.kbc = 1;
+ beacon->bmis.eks.new_eks = 2;
+ /* Handover. */
+ beacon->bmis.handover.present = true;
+ beacon->bmis.handover.hcd = true;
+ beacon->bmis.handover.tei = 0xd;
+ /* Beacon relocation. */
+ beacon->bmis.relocation.present = true;
+ beacon->bmis.relocation.rcd = 3;
+ beacon->bmis.relocation.rlt = true;
+ beacon->bmis.relocation.lgf = true;
+ beacon->bmis.relocation.rlo = 3;
+ beacon->bmis.relocation.rlslotid = 4;
+ /* Relocation ACLS. */
+ beacon->bmis.aclsc.present = true;
+ beacon->bmis.aclsc.countdown = 5;
+ beacon->bmis.aclsc.reason_code = 0;
+ /* CNS. */
+ beacon->bmis.cns.present = true;
+ beacon->bmis.cns.nsccd = 5;
+ beacon->bmis.cns.newnumslot = 4;
+ /* Hybrid mode. */
+ beacon->bmis.change_hm.present = true;
+ beacon->bmis.change_hm.hmccd = 7;
+ beacon->bmis.change_hm.newhm = 2;
+ /* Change snid. */
+ beacon->bmis.change_snid.present = true;
+ beacon->bmis.change_snid.snidccd = 4;
+ beacon->bmis.change_snid.new_snid = 0xf;
+ /* Mac address. */
+ beacon->bmis.mac_address_present.present = true;
+ /* Number of beacon entries. */
+ beacon->bmis.nbe = 14;
+}
+
+void
+bsu_test_beacon_check_generation (test_t t, bsu_test_t *ctx,
+ bsu_beacon_t *beacon,
+ pb_beacon_t *phy_beacon,
+ bsu_beacon_type_t type)
+{
+ bitstream_t stream;
+ u64 nid;
+ uint i, nbe, nb_ps = 0, length;
+ bsu_beacon_entry_header_t header;
+ uint nb_sai = 0;
+ uint nb_nsai = 0;
+ dbg_assert (ctx);
+ dbg_assert (beacon);
+ dbg_assert (phy_beacon);
+
+ test_begin (t, "Beacon verification")
+ {
+ nid = phy_beacon->first_data_word;
+ bitstream_read_init (&stream, phy_beacon->data, BLK_SIZE);
+ nid |= (u64) bitstream_read (&stream, 22) << 32;
+ test_fail_unless (nid == beacon->vf.nid);
+ test_fail_unless (beacon->vf.hm == bitstream_read (&stream, 2));
+ test_fail_unless (ctx->mac_config.tei == bitstream_read (&stream, 8));
+ test_fail_unless (type == bitstream_read (&stream, 3));
+ test_fail_unless (beacon->vf.ncnr == bitstream_read (&stream, 1));
+ test_fail_unless (beacon->vf.npsm == bitstream_read (&stream, 1));
+ test_fail_unless (beacon->vf.numslots == bitstream_read (&stream, 3));
+ test_fail_unless (beacon->vf.slotusage == bitstream_read (&stream, 8));
+ test_fail_unless (beacon->vf.slotid == bitstream_read (&stream, 3));
+ test_fail_unless (beacon->vf.aclsss == bitstream_read (&stream, 3));
+ test_fail_unless (beacon->vf.hoip == bitstream_read (&stream, 1));
+ test_fail_unless (beacon->vf.rtsbf == bitstream_read (&stream, 1));
+ test_fail_unless (beacon->vf.nm == bitstream_read (&stream, 2));
+ test_fail_unless (beacon->vf.ccocap == bitstream_read (&stream, 2));
+ /* Reserved bits. */
+ bitstream_skip (&stream, 4);
+ /* Number of Beacon Entries. */
+ nbe = bitstream_read (&stream, 8);
+ test_fail_unless (beacon->bmis.nbe == nbe);
+ test_fail_unless (nbe != 0);
+ // Processing beacon entries.
+ for (; nbe; nbe --)
+ {
+ header = bitstream_read (&stream, 8);
+ length = bitstream_read (&stream, 8);
+ switch (header)
+ {
+ case BSU_BEACON_ENTRY_HEADER_REGIONS:
+ /* Region beacon entry (Mandatory). */
+ test_fail_unless (length ==
+ BSU_BEACON_ENTRY_SIZE_REGION
+ (beacon->bmis.region.nb));
+ test_fail_unless (bitstream_read (&stream, 6) ==
+ beacon->bmis.region.nb);
+ bitstream_skip (&stream, 2);
+ for (i = 0; i < beacon->bmis.region.nb; i++)
+ {
+ test_fail_unless (bitstream_read (&stream, 4) ==
+ beacon->bmis.region.region[i].rt);
+ test_fail_unless (bitstream_read (&stream, 12) ==
+ beacon->bmis.region.region[i].end_time_atu);
+ }
+ break;
+ case BSU_BEACON_ENTRY_HEADER_NON_PERSISTENT_SCHEDULE:
+ nb_sai = 0;
+ nb_nsai = 0;
+ test_fail_unless (beacon->bmis.nps.ns ==
+ bitstream_read (&stream, 6));
+ bitstream_skip (&stream, 2);
+ for (i = 0; i < beacon->bmis.nps.ns; i++)
+ {
+ test_fail_unless (bitstream_read (&stream, 1) ==
+ beacon->bmis.nps.sais[i].stpf);
+ test_fail_unless (bitstream_read (&stream, 7) ==
+ beacon->bmis.nps.sais[i].glid);
+ if (beacon->bmis.nps.sais[i].stpf)
+ {
+ test_fail_unless (bitstream_read (&stream, 12) ==
+ beacon->bmis.nps.sais[i].start_time_atu);
+ nb_sai++;
+ }
+ else
+ nb_nsai++;
+ test_fail_unless (bitstream_read (&stream, 12) ==
+ beacon->bmis.nps.sais[i].end_time_atu);
+ }
+ test_fail_unless (length ==
+ BSU_BEACON_ENTRY_SIZE_NON_PERSISTENT_SCHED
+ (nb_sai, nb_nsai));
+ break;
+ case BSU_BEACON_ENTRY_HEADER_PERSISTENT_SCHEDULE:
+ nb_sai = 0;
+ nb_nsai = 0;
+ test_fail_unless (beacon->bmis.ps.ps[nb_ps].pscd ==
+ bitstream_read (&stream, 3));
+ test_fail_unless (beacon->bmis.ps.ps[nb_ps].cscd ==
+ bitstream_read (&stream, 3));
+ bitstream_skip (&stream, 2);
+ test_fail_unless (beacon->bmis.ps.ps[nb_ps].ns ==
+ bitstream_read (&stream, 6));
+ bitstream_skip (&stream, 2);
+ for (i = 0; i < beacon->bmis.ps.ps[nb_ps].ns; i++)
+ {
+ test_fail_unless (bitstream_read (&stream, 1) ==
+ beacon->bmis.ps.ps[nb_ps].sais[i].stpf);
+ test_fail_unless (bitstream_read (&stream, 7) ==
+ beacon->bmis.ps.ps[nb_ps].sais[i].glid);
+ if (beacon->bmis.ps.ps[nb_ps].sais[i].stpf)
+ {
+ test_fail_unless (bitstream_read (&stream, 12) ==
+ beacon->bmis.ps.ps[nb_ps].sais[i].start_time_atu);
+ nb_sai++;
+ }
+ else
+ nb_nsai++;
+ test_fail_unless (bitstream_read (&stream, 12) ==
+ beacon->bmis.ps.ps[nb_ps].sais[i].end_time_atu);
+ }
+ test_fail_unless (length ==
+ BSU_BEACON_ENTRY_SIZE_PERSISTENT_SCHED
+ (nb_sai, nb_nsai));
+ nb_ps++;
+ break;
+ case BSU_BEACON_ENTRY_HEADER_MAC_ADDRESS:
+ test_fail_unless (beacon->bmis.mac_address_present.present ==
+ true);
+ test_fail_unless (ctx->mac_config.sta_mac_address ==
+ bitstream_read_large (&stream, 48));
+ test_fail_unless (length == BSU_BEACON_ENTRY_SIZE_MAC_ADDRESS);
+ break;
+ case BSU_BEACON_ENTRY_HEADER_DISCOVER:
+ test_fail_unless (beacon->bmis.discover.present == true);
+ test_fail_unless (beacon->bmis.discover.tei ==
+ bitstream_read (&stream, 8));
+ test_fail_unless (length == BSU_BEACON_ENTRY_SIZE_DISCOVER);
+ break;
+ case BSU_BEACON_ENTRY_HEADER_DISCOVERED_INFO:
+ test_fail_unless (beacon->bmis.discover_info.present == true);
+ test_fail_unless (beacon->bmis.discover_info.info_data ==
+ bitstream_read (&stream, 32));
+ test_fail_unless (length ==
+ BSU_BEACON_ENTRY_SIZE_DISCOVER_INFO);
+ break;
+ case BSU_BEACON_ENTRY_HEADER_BEACON_PERIOD_START_TIME_OFFSET:
+ test_fail_unless (beacon->bmis.bpsto.present == true);
+ test_fail_unless (bitstream_read (&stream, 24) == 0);
+ test_fail_unless (length == BSU_BEACON_ENTRY_SIZE_BPSTO);
+ break;
+ case BSU_BEACON_ENTRY_HEADER_CCO_HANDOVER:
+ test_fail_unless (beacon->bmis.handover.present == true);
+ test_fail_unless (bitstream_read (&stream, 6) ==
+ beacon->bmis.handover.hcd);
+ bitstream_skip (&stream, 2);
+ test_fail_unless (bitstream_read (&stream, 8) ==
+ beacon->bmis.handover.tei);
+ test_fail_unless (length == BSU_BEACON_ENTRY_SIZE_HOIP);
+ break;
+ case BSU_BEACON_ENTRY_HEADER_CHANGE_HM:
+ test_fail_unless (beacon->bmis.change_hm.present == true);
+ test_fail_unless (length == BSU_BEACON_ENTRY_SIZE_CHANGE_HM);
+ test_fail_unless (bitstream_read (&stream, 6) ==
+ beacon->bmis.change_hm.hmccd);
+ test_fail_unless (bitstream_read (&stream, 2) ==
+ beacon->bmis.change_hm.newhm);
+ break;
+ case BSU_BEACON_ENTRY_HEADER_CHANGE_SNID:
+ test_fail_unless (beacon->bmis.change_snid.present == true);
+ test_fail_unless (length == BSU_BEACON_ENTRY_SIZE_CHANGE_SNID);
+ test_fail_unless (bitstream_read (&stream, 4) ==
+ beacon->bmis.change_snid.snidccd);
+ test_fail_unless (bitstream_read (&stream, 4) ==
+ beacon->bmis.change_snid.new_snid);
+ break;
+ case BSU_BEACON_ENTRY_HEADER_ENCRYPTION_KEY_CHANGE:
+ test_fail_unless (beacon->bmis.eks.present == true);
+ test_fail_unless (length == BSU_BEACON_ENTRY_SIZE_EKC);
+ test_fail_unless (bitstream_read (&stream, 6) ==
+ beacon->bmis.eks.kccd);
+ test_fail_unless (bitstream_read (&stream, 1) ==
+ beacon->bmis.eks.kbc);
+ bitstream_skip (&stream, 1);
+ test_fail_unless (bitstream_read (&stream, 4) ==
+ beacon->bmis.eks.new_eks);
+ bitstream_skip (&stream, 4);
+ break;
+ case BSU_BEACON_ENTRY_HEADER_BEACON_RELOCATION:
+ test_fail_unless (beacon->bmis.relocation.present == true);
+ test_fail_unless (length == BSU_BEACON_ENTRY_SIZE_RLO);
+ test_fail_unless (bitstream_read (&stream, 6) ==
+ beacon->bmis.relocation.rcd);
+ test_fail_unless (bitstream_read (&stream, 1) ==
+ beacon->bmis.relocation.rlt);
+ test_fail_unless (bitstream_read (&stream, 1) ==
+ beacon->bmis.relocation.lgf);
+ test_fail_unless (bitstream_read (&stream, 17) ==
+ beacon->bmis.relocation.rlo);
+ test_fail_unless (bitstream_read (&stream, 3) ==
+ beacon->bmis.relocation.rlslotid);
+ bitstream_skip (&stream, 4);
+ break;
+ case BSU_BEACON_ENTRY_HEADER_AC_LINE_SYNC_COUNTDOWN:
+ test_fail_unless (length == BSU_BEACON_ENTRY_SIZE_ACL);
+ test_fail_unless (beacon->bmis.aclsc.present == true);
+ test_fail_unless (bitstream_read (&stream, 6) ==
+ beacon->bmis.aclsc.countdown);
+ bitstream_skip (&stream, 2);
+ test_fail_unless (bitstream_read (&stream, 2) ==
+ beacon->bmis.aclsc.reason_code);
+ bitstream_skip (&stream, 6);
+ break;
+ case BSU_BEACON_ENTRY_HEADER_CHANGE_NUMSLOTS:
+ test_fail_unless (length ==
+ BSU_BEACON_ENTRY_SIZE_CHANGE_NUMSLOTS);
+ test_fail_unless (beacon->bmis.cns.present == true);
+ test_fail_unless (bitstream_read (&stream, 6) ==
+ beacon->bmis.cns.nsccd);
+ bitstream_skip (&stream, 2);
+ test_fail_unless (bitstream_read (&stream, 3) ==
+ beacon->bmis.cns.newnumslot);
+ bitstream_skip (&stream, 5);
+ break;
+ default:
+ test_fail_unless (false);
+ }
+ }
+ }
+ test_end;
+}
+
+void
+bsu_test_beacon_check_read (test_t t, bsu_test_t *ctx, bsu_beacon_t *beacon,
+ bsu_avln_t *sched)
+{
+ uint i,j;
+ test_begin (t, "Beacon check read")
+ {
+ /* Only verify the schedules. */
+ test_fail_unless (beacon->bmis.ps.nb == sched->bs.schedules.ps.nb);
+ for (i = 0; i < beacon->bmis.ps.nb; i++)
+ {
+ test_fail_unless (beacon->bmis.ps.ps[i].pscd ==
+ sched->bs.schedules.ps.ps[i].pscd);
+ test_fail_unless (beacon->bmis.ps.ps[i].cscd ==
+ sched->bs.schedules.ps.ps[i].cscd);
+ test_fail_unless (beacon->bmis.ps.ps[i].ns ==
+ sched->bs.schedules.ps.ps[i].ns);
+ for (j = 0; j < sched->bs.schedules.ps.ps[i].ns; j ++)
+ {
+ test_fail_unless (beacon->bmis.ps.ps[i].sais[j].stpf ==
+ sched->bs.schedules.ps.ps[i].sais[j].stpf);
+ test_fail_unless (beacon->bmis.ps.ps[i].sais[j].glid ==
+ sched->bs.schedules.ps.ps[i].sais[j].glid);
+ if (sched->bs.schedules.ps.ps[i].sais[j].stpf)
+ test_fail_unless (
+ beacon->bmis.ps.ps[i].sais[j].start_time_atu ==
+ sched->bs.schedules.ps.ps[i].sais[j].start_time_atu);
+ test_fail_unless (
+ beacon->bmis.ps.ps[i].sais[j].end_time_atu ==
+ sched->bs.schedules.ps.ps[i].sais[j].end_time_atu);
+ }
+ }
+ test_fail_unless (beacon->bmis.nps.ns ==
+ sched->bs.schedules.nps.ns);
+ for (i = 0; i < beacon->bmis.nps.ns; i++)
+ {
+ test_fail_unless (beacon->bmis.nps.sais[i].stpf ==
+ sched->bs.schedules.nps.sais[i].stpf);
+ test_fail_unless (beacon->bmis.nps.sais[i].glid ==
+ sched->bs.schedules.nps.sais[i].glid);
+ if (sched->bs.schedules.nps.sais[i].stpf)
+ test_fail_unless (
+ beacon->bmis.nps.sais[i].start_time_atu ==
+ sched->bs.schedules.nps.sais[i].start_time_atu);
+ test_fail_unless (beacon->bmis.nps.sais[i].end_time_atu ==
+ sched->bs.schedules.nps.sais[i].end_time_atu);
+ }
+ }
+ test_end;
+}
diff --git a/cesar/bsu/test/utest/tests.h b/cesar/bsu/test/utest/tests.h
new file mode 100644
index 0000000000..dd049368d4
--- /dev/null
+++ b/cesar/bsu/test/utest/tests.h
@@ -0,0 +1,105 @@
+#ifndef bsu_test_utest_tests_h
+#define bsu_test_utest_tests_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2010 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file bsu/test/utest/tests.h
+ * \brief Test environment.
+ * \ingroup bsu
+ */
+#include "bsu/bsu.h"
+#include "mac/common/store.h"
+#include "mac/common/config.h"
+#include "mac/pbproc/pbproc.h"
+#include "mac/sar/sar.h"
+
+struct bsu_test_phy_t
+{
+ /** Phy date. */
+ u32 phy_date;
+};
+typedef struct bsu_test_phy_t bsu_test_phy_t;
+
+struct bsu_test_t
+{
+ /** Mac config. */
+ mac_config_t mac_config;
+ /** Mac store. */
+ mac_store_t *mac_store;
+ /** Channel Access context. */
+ ca_t *ca;
+ /** Phy simulated context. */
+ bsu_test_phy_t phy;
+ /** Sar context. */
+ sar_t *sar;
+ /** BSU. */
+ bsu_t *bsu;
+ /** Hal timer. */
+ hal_timer_t *timer;
+};
+typedef struct bsu_test_t bsu_test_t;
+
+BEGIN_DECLS
+
+/**
+ * Initialise the test unit.
+ * \param ctx the tests context.
+ */
+void
+bsu_test_init (bsu_test_t *ctx);
+
+/**
+ * Uninitialise the test unit.
+ * \param ctx the tests context.
+ */
+void
+bsu_test_uninit (bsu_test_t *ctx);
+
+/**
+ * Create a beacon.
+ * \param beacon structure to fill.
+ *
+ * Creates a beacon with 2 regions, 2 non persistent allocations, 2 Persistent
+ * allocations.
+ */
+void
+bsu_test_create_beacon (bsu_test_t *ctx, bsu_beacon_t *beacon);
+
+/**
+ * Verify the data present in the generated beacon are equal to the one in the
+ * bsu beacon.
+ * \param t test context.
+ * \param ctx the bsu_test context.
+ * \param beacon the bsu data beacon.
+ * \param phy_beacon the beacon generated by the bsu.
+ * \param type the beacon type.
+ *
+ * \Warn the TEI in the phy_beacon is compared with the TEI in the mac
+ * config.
+ */
+void
+bsu_test_beacon_check_generation (test_t t, bsu_test_t *ctx,
+ bsu_beacon_t *beacon,
+ pb_beacon_t *phy_beacon,
+ bsu_beacon_type_t type);
+
+/**
+ * Verify the read data corresponds to the one provided to generate the
+ * beacon.
+ * \param t test context.
+ * \param ctx the bsu_test context.
+ * \param beacon the bsu data beacon.
+ * \param sched the schedules filled with the data in the real beacon.
+ */
+void
+bsu_test_beacon_check_read (test_t t, bsu_test_t *ctx, bsu_beacon_t *beacon,
+ bsu_avln_t *sched);
+
+END_DECLS
+
+#endif /* bsu_test_utest_tests_h */