summaryrefslogtreecommitdiff
path: root/cesar/mac/sar/test/utest/host/src/expiration.c
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/mac/sar/test/utest/host/src/expiration.c')
-rw-r--r--cesar/mac/sar/test/utest/host/src/expiration.c184
1 files changed, 184 insertions, 0 deletions
diff --git a/cesar/mac/sar/test/utest/host/src/expiration.c b/cesar/mac/sar/test/utest/host/src/expiration.c
new file mode 100644
index 0000000000..7fd452e5e9
--- /dev/null
+++ b/cesar/mac/sar/test/utest/host/src/expiration.c
@@ -0,0 +1,184 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file reassembly_mfs_update_expiration_ntb.c
+ * \brief test to verify the mfs update expiration date
+ * \ingroup mac/sar/test/unit_test/reassembly_mfs_update_expiration_ntb/src
+ *
+ */
+#include "common/std.h"
+#include "lib/test.h"
+#include "lib/trace.h"
+#include "lib/stats.h"
+#include "mac/common/ntb.h"
+#include "mac/common/timings.h"
+#include "mac/sar/test/utest/host/tests.h"
+#include <string.h>
+
+/* Override context. */
+#include "mac/pbproc/inc/context.h"
+
+void
+test_case_expiration__add (sar_test_t *t, u8 tei, u8 lid, bool tx,
+ u32 expiration_ntb)
+{
+ bool added;
+ mfs_t *mfs =
+ mac_store_mfs_add (t->mac_store, tx, false, false, lid, tei, &added);
+ dbg_assert (added);
+ sar_mfs_add (t->sar, mfs);
+ mfs->common.expiration_ntb = expiration_ntb;
+ pb_t *pb = (pb_t*) blk_alloc_desc ();
+ pb->next = NULL;
+ pb->expiration_ntb = expiration_ntb / 2;
+ if (tx)
+ {
+ mfs->tx.head = mfs->tx.tail = pb;
+ mfs->tx.seg_nb = 1;
+ }
+ else
+ mfs->rx.head = pb;
+ blk_release (mfs);
+}
+
+void
+test_case_expiration (test_t test)
+{
+ uint phy_date = 0;
+ sar_test_t t;
+ uint pbproc = 0;
+ test_case_begin (test, "Expiration");
+ sar_test_init (&t, &phy_date, &pbproc);
+ u32 expiration_ntb[] = { 10, 20, 30, 40 };
+ test_begin (test, "MFS expiration")
+ {
+ uint i,j;
+ mfs_t *mfs;
+ for (i = 1; i <= COUNT (expiration_ntb); i++)
+ {
+ test_case_expiration__add (&t, i, 1, true,
+ expiration_ntb[i-1]);
+ test_case_expiration__add (&t, i, 1, false,
+ expiration_ntb[i-1]);
+ }
+ for (phy_date = 0;
+ phy_date < expiration_ntb[COUNT(expiration_ntb) - 1];
+ phy_date += 5)
+ {
+ sar_expiration_mfs (t.sar);
+ for (j = 0; j < COUNT (expiration_ntb); j++)
+ {
+ mfs = mac_store_mfs_get (t.mac_store, true, false, false, 1,
+ j + 1);
+ test_fail_unless (mfs != NULL);
+ if (phy_date < expiration_ntb [j])
+ {
+ test_fail_unless (mfs->tx.fsm_state == MFS_FSM_CMD_INIT);
+ if (phy_date < expiration_ntb [j] / 2)
+ test_fail_unless (mfs->tx.head != NULL);
+ else
+ test_fail_unless (mfs->tx.head == NULL);
+ }
+ else
+ {
+ test_fail_unless (
+ mfs->tx.fsm_state == MFS_FSM_CMD_RELEASE);
+ test_fail_unless (mfs->tx.head == NULL);
+ }
+ blk_release (mfs);
+ mfs = mac_store_mfs_get (t.mac_store, false, false, false, 1,
+ j + 1);
+ if (phy_date < expiration_ntb [j])
+ {
+ test_fail_unless (mfs->rx.release == false);
+ if (phy_date < expiration_ntb [j] / 2)
+ test_fail_unless (mfs->rx.head != NULL);
+ else
+ test_fail_unless (mfs->rx.head == NULL);
+ }
+ else
+ {
+ test_fail_unless (mfs->rx.release == true);
+ test_fail_unless (mfs->rx.head == NULL);
+ }
+ blk_release (mfs);
+ }
+ }
+ }
+ test_end;
+ sar_cleanup (t.sar);
+ sar_test_uninit (&t);
+}
+
+mfs_t*
+test_case_expiration_bcast__common (sar_test_t *ctx, test_t t, bool tx)
+{
+ test_within (t);
+ bool added;
+ mfs_t *mfs = mac_store_mfs_add (ctx->mac_store, tx, true, false, 1,
+ tx ? MAC_TEI_BCAST : 1, &added);
+ test_fail_unless (added);
+ pb_t *pb = (pb_t*) blk_alloc_desc ();
+ pb->next = NULL;
+ pb->expiration_ntb =
+ mac_ntb () - MAC_MS_TO_TCK (MFS_PB_TX_DELAY_MS) - 10;
+ if (tx)
+ {
+ mfs->tx.head = mfs->tx.tail = pb;
+ mfs->tx.seg_nb = 1;
+ }
+ else
+ mfs->rx.head = pb;
+ /* Set expiration date. */
+ mfs->common.expiration_ntb = mac_ntb ()
+ - MAC_MS_TO_TCK (MFS_RELEASE_DELAY_MS) - 10;
+ sar_expiration_mfs (ctx->sar);
+ return mfs;
+}
+
+void
+test_case_expiration_bcast (test_t test)
+{
+ test_case_begin (test, "Broadcast MFS expiration");
+ sar_test_t ctx;
+ pbproc_t pbproc;
+ memset (&pbproc, 0, sizeof (pbproc_t));
+ sar_test_init (&ctx, INVALID_PTR, &pbproc);
+ test_begin (test, "TX")
+ {
+ mfs_t *mfs = test_case_expiration_bcast__common (&ctx, test, true);
+ /* TX bcast MFS should not be released. */
+ test_fail_unless (mfs->tx.fsm_state != MFS_FSM_CMD_RELEASE);
+ test_fail_unless (!mfs->tx.head);
+ blk_release (mfs);
+ }
+ test_end;
+ test_begin (test, "RX")
+ {
+ mfs_t *mfs = test_case_expiration_bcast__common (&ctx, test, false);
+ /* RX bcast MFS should be released. */
+ test_fail_unless (mfs->rx.release);
+ blk_release (mfs);
+ }
+ test_end;
+ sar_cleanup (ctx.sar);
+ sar_test_uninit (&ctx);
+}
+
+void
+test_suite_expiration (test_t test)
+{
+ test_suite_begin (test, "MFS expiration");
+ test_case_expiration (test);
+ test_case_expiration_bcast (test);
+ test_begin (test, "Memory")
+ {
+ test_fail_if (blk_check_memory() == false, "Memory not freed");
+ }
+ test_end;
+}