summaryrefslogtreecommitdiff
path: root/cesar/mac/sar/test/utest/host/src/segmentation.c
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/mac/sar/test/utest/host/src/segmentation.c')
-rw-r--r--cesar/mac/sar/test/utest/host/src/segmentation.c329
1 files changed, 329 insertions, 0 deletions
diff --git a/cesar/mac/sar/test/utest/host/src/segmentation.c b/cesar/mac/sar/test/utest/host/src/segmentation.c
new file mode 100644
index 0000000000..0269201ac5
--- /dev/null
+++ b/cesar/mac/sar/test/utest/host/src/segmentation.c
@@ -0,0 +1,329 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2009 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file mac/sar/test/utest/host/src/segmentation.c
+ * \brief Test segmentation cases.
+ * \ingroup mac_sar
+ *
+ */
+#include "common/std.h"
+
+#include "lib/test.h"
+#include "lib/stats.h"
+#include "mac/common/ntb.h"
+#include "mac/sar/sar.h"
+
+#include "mac/sar/inc/sar_context.h"
+#include "mac/sar/inc/sar.h"
+#include "mac/sar/inc/brg.h"
+#include "mac/sar/inc/rx.h"
+#include <string.h>
+#include "config.h"
+
+/* Override context. */
+#include "mac/pbproc/inc/context.h"
+
+#include "mac/sar/test/utest/host/tests.h"
+
+void
+sar_tx_mac_framing (sar_t *ctx, sar_msdu_t *md_data);
+
+void
+test_case_segmentation_seg_nb (test_t test)
+{
+ sar_test_t t;
+ u8 *buffer = NULL;
+ uint list[4];
+ uint i;
+ pbproc_t pbproc;
+ uint phy = 0;
+ bool added;
+
+ mfs_tx_t *mfs;
+
+ sar_test_init (&t, &phy, &pbproc);
+ sar_activate (t.sar, true);
+
+ list[0] = 1014;
+ list[1] = 214;
+ list[2] = 690;
+ list[3] = 1014;
+
+ mfs = mac_store_mfs_add_tx (t.mac_store, false, false, 1, 1, &added);
+ if (added)
+ sar_mfs_add (t.sar, (mfs_t*) mfs);
+
+ test_begin (test, "Verifying the MFS state")
+ {
+ for (i = 0; i < 4; i++)
+ {
+ /* Add a MSDU to the SAR. */
+ buffer = bufmgr_get (t.sar->bufmgr);
+ sar_msdu_add (t.sar, buffer, list[i], mfs, 123);
+ bufmgr_give_back (t.sar->bufmgr, buffer);
+ test_fail_unless (mfs->pending_seg_nb == 0, "i: %d",i);
+ switch (i)
+ {
+ case 0:
+ test_fail_unless (mfs->seg_nb == 2);
+ break;
+ case 1:
+ test_fail_unless (mfs->seg_nb == 3);
+ break;
+ case 2:
+ test_fail_unless (mfs->seg_nb == 4);
+ break;
+ case 3:
+ test_fail_unless (mfs->seg_nb == 6);
+ break;
+ }
+ }
+ }
+ test_end;
+
+ blk_release (mfs);
+ sar_cleanup (t.sar);
+ sar_test_uninit (&t);
+}
+
+void
+test_case_segmentation_message_too_short (test_t test)
+{
+ test_begin (test, "Segmentation with a Message too short.")
+ {
+ sar_msdu_t md;
+
+ md.buffer_address = (u8*) 0x12345678;
+ md.mfs = (mfs_tx_t *) 0x12345678;
+ md.length = ETH_PACKET_MIN_SIZE_ALLOWED - 1;
+
+ dbg_fatal_try_begin
+ {
+ /* Should assert before using the SAR context. */
+ sar_tx_mac_framing (INVALID_PTR, &md);
+ test_fail_unless (false);
+ }
+ dbg_fatal_try_catch (const char *fatal_message)
+ {
+ test_verbose_print (fatal_message);
+ test_fail_unless (true);
+ }
+ dbg_fatal_try_end;
+ }
+ test_end;
+}
+
+void
+test_case_segmentation (test_t test)
+{
+ test_case_begin (test, "Segmentation all offsets");
+
+ test_begin (test, "")
+ {
+ uint offset;
+ pb_t *mfs_pb_first;
+ mfs_tx_t *mfs;
+ bool added;
+ u8 *buffer;
+ sar_mf_t sar_mf;
+ sar_test_t t;
+
+ sar_test_init (&t, INVALID_PTR, INVALID_PTR);
+ /* SAR activate. */
+ sar_activate (t.sar, true);
+
+ /* Admitting the PB already contains a first Frame of 54 bytes. */
+ for (offset = 60; offset < BLK_SIZE; offset ++)
+ {
+ /* Create the Segmentation MFS. */
+ mfs = mac_store_mfs_add_tx (t.mac_store, false, false, 1, 1,
+ &added);
+ /* Add the MFS to the SAR expiration mechanism. */
+ sar_mfs_add (t.sar, (mfs_t*) mfs);
+
+ /* Create the first PB. */
+ mfs_pb_first = (pb_t*) blk_alloc_desc ();
+ mfs_pb_first->next = NULL;
+ mfs_pb_first->header.ssn = 0;
+ mfs_pb_first->header.mfbo = 0;
+ mfs_pb_first->header.vpbf = true;
+ mfs_pb_first->header.mmqf = false;
+ mfs_pb_first->header.mfbf = true;
+ mfs_pb_first->header.opsf = true;
+
+ /* Insert the PB in the MFS. */
+ mfs->head = mfs_pb_first;
+ mfs->tail = mfs_pb_first;
+ /* Update the SSN next to use. */
+ mfs->next_ssn = 1;
+ mfs->seg_nb = 1;
+
+ /* Update the MFS TX last offset. */
+ mfs->last_seg_offset = offset;
+
+ /* Add the MSDU to process. */
+ buffer = bufmgr_get (t.sar->bufmgr);
+ sar_msdu_add (t.sar, buffer, 60, mfs, mac_ntb());
+ bufmgr_give_back (t.sar->bufmgr, buffer);
+
+ /* Check the data. */
+ test_fail_unless (mfs->head != NULL);
+ /* Insert anything in sar mf. */
+ sar_mf.type = 0xdeaddead;
+ sar_mf.length = 0xdeaddead;
+ sar_mf.length_complete = 0xdeaddead;
+ sar_mf.qte = 0xdeaddead;
+
+ sar_mf_header (mfs->head, offset, &sar_mf);
+ test_fail_unless (sar_mf.type == SAR_MF_TYPE_DATA);
+ test_fail_unless (sar_mf.length == 60);
+ test_fail_unless (sar_mf.length_complete == 66);
+
+ if (sar_mf.qte == 1)
+ {
+ /* Still in the first PB. */
+ test_fail_unless (mfs->head->header.ssn == 0);
+ test_fail_unless (mfs->head->next == NULL);
+ test_fail_unless (sar_mf.qte == 1);
+ }
+ else
+ {
+ /* Result on two PBs. */
+ test_fail_unless (mfs->head->header.ssn == 0);
+ test_fail_unless (mfs->head->next != NULL);
+ test_fail_unless (mfs->head->next->header.ssn == 1);
+ test_fail_unless (sar_mf.qte == 2);
+ }
+
+ /* Release the MFS. */
+ sar_mfs_remove (t.sar, PARENT_OF (mfs_t, tx, mfs));
+ sar_mfs_free_tx (t.sar, mfs);
+ blk_release (mfs);
+ }
+
+ /* Remove the associated STA. */
+ dbg_check (mac_store_sta_remove (t.mac_store, 1));
+ /* Uninitialise the test. */
+ sar_test_uninit (&t);
+ }
+ test_end;
+}
+
+
+void
+test_case_segmentation_mfs_release (test_t test)
+{
+ sar_test_t t;
+ u8 *buffer;
+ uint length = 60;
+ mfs_tx_t *mfs, *mfs_store;
+ uint i;
+ bool added;
+
+ test_case_begin (test, "MFS in release state");
+ test_begin (test, "P/L/GLID MFSs")
+ {
+ sar_test_init (&t, INVALID_PTR, INVALID_PTR);
+ sar_activate (t.sar, true);
+ for (i = MAC_PLID_MIN; i <= MAC_LID_NONE; i++)
+ {
+ mfs = mac_store_mfs_add_tx (t.mac_store, false,
+ i == MAC_LID_NONE, i, 1,
+ &added);
+ dbg_assert (added);
+ mfs->fsm_state = MFS_FSM_CMD_RELEASE;
+ sar_mfs_add (t.sar, PARENT_OF (mfs_t, tx, mfs));
+ buffer = bufmgr_get (t.sar->bufmgr);
+ sar_msdu_add (t.sar, buffer, length, mfs, mac_ntb());
+ bufmgr_give_back (t.sar->bufmgr, buffer);
+ mfs_store = mac_store_mfs_get_tx (t.mac_store, false,
+ i == MAC_LID_NONE, i, 1);
+ if (MAC_LID_IS_PLID(i) || i == MAC_LID_NONE)
+ {
+ test_fail_unless (mfs != mfs_store);
+ test_fail_unless (mfs->head == NULL);
+ test_fail_unless (mfs_store->head != NULL);
+ }
+ else
+ {
+ test_fail_unless (mfs_store == mfs);
+ test_fail_unless (mfs->head == NULL);
+ test_fail_unless (mfs_store->head == NULL);
+ }
+ /* Release memory. */
+ blk_release (mfs);
+ blk_release (mfs_store);
+ sar_cleanup (t.sar);
+ }
+ sar_test_uninit (&t);
+ }
+ test_end;
+}
+
+void
+test_case_segmentation_em_max_pb_allowed_test (test_t test, sar_test_t ctx,
+ mfs_tx_t *mfs)
+{
+ u8 *buffer = NULL;
+ test_within (test);
+ buffer = bufmgr_get (ctx.sar->bufmgr);
+ sar_msdu_add (ctx.sar, buffer, ETH_PACKET_MIN_SIZE_ALLOWED, mfs,
+ 0x0);
+ sar_bridge_dma_free_head (ctx.sar);
+ test_fail_unless (mfs->seg_nb == MAC_SAR_EM_MAX_PB_ALLOWED + 1);
+ bufmgr_give_back (ctx.sar->bufmgr, buffer);
+}
+
+void
+test_case_segmentation_em_max_pb_allowed (test_t test)
+{
+ sar_test_t ctx;
+ bool added;
+ test_case_begin (test, "Test MAC_SAR_EM_MAX_PB_ALLOWED");
+ sar_test_init (&ctx, INVALID_PTR, INVALID_PTR);
+ mfs_tx_t *mfs = mac_store_mfs_add_tx (ctx.mac_store, false, false, 1,
+ 1, &added);
+ blk_t *head, *tail;
+ /* Allocate all available memory less some block under the slack value. */
+ head = blk_alloc_desc_range (CONFIG_BLK_NB - CONFIG_BLK_SLACK + 2, &tail);
+ sar_activate (ctx.sar, true);
+ test_begin (test, "TX > MAC_SAR_EM_MAX_PB_ALLOWED")
+ {
+ mfs->seg_nb = MAC_SAR_EM_MAX_PB_ALLOWED + 1;
+ test_case_segmentation_em_max_pb_allowed_test (test, ctx, mfs);
+ }
+ test_end;
+ test_begin (test, "TX <= MAC_SAR_EM_MAX_PB_ALLOWED")
+ {
+ mfs->seg_nb = MAC_SAR_EM_MAX_PB_ALLOWED;
+ test_case_segmentation_em_max_pb_allowed_test (test, ctx, mfs);
+ }
+ test_end;
+ blk_release_desc_range (head, tail);
+ sar_mfs_remove (ctx.sar, PARENT_OF (mfs_t, tx, mfs));
+ blk_release (mfs);
+ sar_sta_remove (ctx.sar, 1);
+ sar_test_uninit (&ctx);
+}
+
+void
+test_suite_segmentation (test_t test)
+{
+ test_suite_begin (test, "Segmentation");
+ test_case_segmentation_seg_nb (test);
+ test_case_segmentation_message_too_short (test);
+ test_case_segmentation (test);
+ test_case_segmentation_mfs_release (test);
+ test_case_segmentation_em_max_pb_allowed (test);
+
+ test_begin (test, "Memory")
+ {
+ test_fail_if (blk_check_memory() == false, "Memory not freed");
+ }
+ test_end;
+}