summaryrefslogtreecommitdiff
path: root/cesar/mac/sar/test
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/mac/sar/test')
-rw-r--r--cesar/mac/sar/test/unit_test/ecos/src/stats.c97
1 files changed, 96 insertions, 1 deletions
diff --git a/cesar/mac/sar/test/unit_test/ecos/src/stats.c b/cesar/mac/sar/test/unit_test/ecos/src/stats.c
index f9a3bc5391..561ac6315a 100644
--- a/cesar/mac/sar/test/unit_test/ecos/src/stats.c
+++ b/cesar/mac/sar/test/unit_test/ecos/src/stats.c
@@ -44,7 +44,6 @@ test_case_sar_stats_tx (test_t test)
uint i;
uint nb_msdus = 10;
pbproc_t pbproc;
-
memset (&pbproc, 0, sizeof (pbproc));
sar_test_init (&t, INVALID_PTR, &pbproc);
/* Create the MFS to verify the test. */
@@ -476,12 +475,108 @@ test_sar_stats_rx_do (test_t test, bool bcast)
}
}
+/**
+ * Initialise an empty PB.
+ * \param pb the PB to initialise.
+ * \param ssn the SSN to store in the PB header.
+ */
+static void
+test_sar_stats_rx_hole_init_pb_header (pb_t *pb, u16 ssn)
+{
+ pb->header.ssn = ssn;
+ pb->header.mfbo = 0;
+ pb->header.vpbf = true;
+ pb->header.mmqf = false;
+ pb->header.mfbf = true;
+ pb->header.opsf = false;
+ pb->header.spc_encrypted = true;
+ pb->next = NULL;
+ pb->data[0] = 0;
+ pb->phy_pb.pb_rx.pb_measurement.crc_error = false;
+}
+
+/**
+ * Initialise a test to compute the missing PBs for a single oldest PB.
+ * \param test the test context.
+ * \param ssn the first SSN to initialise the single PB.
+ *
+ * This test set the ssn min of the MFS to a defined value (65534), An
+ * MPDU is created with a single PB whose ssn is provided in parameter.
+ * This should compute the number of missing PBs when this MPDU with the
+ * single PB is received by the SAR.
+ * Two cases are possible:
+ * 1. The PB has an ssn under the mfs->ssn_min, in this case the PB is
+ * dropped because it is considered as already received.
+ * 2. The Pb has an ssn greater than the mfs->ssn_min, in this case, the
+ * mfs->ssn_min is updated to match to the PB's ssn and the difference
+ * between the PB's ssn and the previous mfs->ssn_min corresponds to the
+ * number of missing PBs.
+ */
+void
+test_sar_stats_rx_hole_do (test_t test, u16 ssn)
+{
+ test_within (test);
+ sar_test_t t;
+ mfs_rx_t *mfs;
+ bool added;
+ sar_test_init (&t, INVALID_PTR, INVALID_PTR);
+ sar_activate (t.sar, true);
+ mfs = mac_store_mfs_add_rx (t.mac_store, false, false, 1, 1,
+ &added);
+ sar_mfs_add (t.sar, PARENT_OF (mfs_t, rx, mfs));
+ mfs->ssn_min = 65534;
+ mfs->window_size = 3;
+ /* Add the first PB directly into the MFS. */
+ mfs->head = (pb_t *) blk_alloc_desc ();
+ test_sar_stats_rx_hole_init_pb_header (mfs->head, mfs->ssn_min - 1);
+ /* Prepare the MPDU to receive. */
+ pbproc_rx_desc_t *desc = (pbproc_rx_desc_t *) blk_alloc_desc ();
+ sar_mpdu_t *mpdu = PARENT_OF (sar_mpdu_t, rx, desc->rx);
+ sar_test_mpdu_default_fill (mpdu, 1, 1);
+ mpdu->rx.pb_nb = 1;
+ mpdu->rx.params.bcast = false;
+ mpdu->rx.pb_first = (pb_t *) blk_alloc_desc ();
+ test_sar_stats_rx_hole_init_pb_header (mpdu->rx.pb_first, ssn);
+ mpdu->rx.pb_last = mpdu->rx.pb_first;
+ mpdu->rx.pb_first->header.opsf = true;
+ /* Test it. */
+ uint ssn_max = mfs->ssn_min + mfs->window_size - 1;
+ uint missing_pbs = (u16) (ssn - mfs->head->header.ssn - 1);
+ sar_mpdu_add (t.sar, desc);
+ if (lesseq_mod2p16 (ssn_max, ssn))
+ test_fail_unless (mfs->stats.num_segs_missed == missing_pbs);
+ else
+ test_fail_unless (!mfs->stats.num_segs_missed);
+ blk_release (mfs);
+ sar_activate (t.sar, false);
+ sar_cleanup (t.sar);
+ sar_test_uninit (&t);
+}
+
+/**
+ * Initialise a test to compute the missing PBs for a single oldest PB.
+ * \param test the test context.
+ */
+void
+test_sar_stats_rx_hole (test_t test)
+{
+ uint i;
+ test_case_begin (test, "Test an hole");
+ test_begin (test, "Small and big hole")
+ {
+ for (i = 0; i < BITS_ONES (16); i++)
+ test_sar_stats_rx_hole_do (test, i);
+ }
+ test_end;
+}
+
void
test_case_sar_stats_rx (test_t test)
{
test_case_begin (test, "Stats SAR RX - Unicast/broadcast");
test_sar_stats_rx_do (test, false);
test_sar_stats_rx_do (test, true);
+ test_sar_stats_rx_hole (test);
}
void