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/utest/host/Makefile3
-rw-r--r--cesar/mac/sar/test/utest/host/src/sar.c4
-rw-r--r--cesar/mac/sar/test/utest/host/src/sar_pbproc_override_mfs.c6
-rw-r--r--cesar/mac/sar/test/utest/host/src/trim.c116
4 files changed, 128 insertions, 1 deletions
diff --git a/cesar/mac/sar/test/utest/host/Makefile b/cesar/mac/sar/test/utest/host/Makefile
index dc6fc66f85..7c5d9aac24 100644
--- a/cesar/mac/sar/test/utest/host/Makefile
+++ b/cesar/mac/sar/test/utest/host/Makefile
@@ -8,7 +8,8 @@ HOST_PROGRAMS = test_sar test_sar_pbproc_override
test_sar_SOURCES = sar.c activate.c mfs_ssn_resize.c \
crc_error.c mfs_create.c mfs_cmd.c reassembly.c \
- reassembly_measurement.c expiration.c sar_call_back_ul.c \
+ reassembly_measurement.c expiration.c trim.c \
+ sar_call_back_ul.c \
sar_remove_sta.c segmentation.c detect_mf.c \
get_associated_mfs.c sar_tx_job_desc_create.c misc.c \
stats.c sar_pb_stats.c ca_stub.c pbproc_stub.c tests.c \
diff --git a/cesar/mac/sar/test/utest/host/src/sar.c b/cesar/mac/sar/test/utest/host/src/sar.c
index e2257a545a..7f06c4d72c 100644
--- a/cesar/mac/sar/test/utest/host/src/sar.c
+++ b/cesar/mac/sar/test/utest/host/src/sar.c
@@ -28,6 +28,9 @@ void
test_suite_expiration (test_t test);
void
+test_suite_trim (test_t test);
+
+void
test_suite_rx_get_associated_mfs (test_t test);
void
@@ -82,6 +85,7 @@ main (int argc, char** argv)
test_suite_sar_crc_error (test);
test_suite_sar_detect_mf (test);
test_suite_expiration (test);
+ test_suite_trim (test);
test_suite_rx_get_associated_mfs (test);
test_suite_sar_mfs_cmd (test);
test_suite_sar_create_mfs (test);
diff --git a/cesar/mac/sar/test/utest/host/src/sar_pbproc_override_mfs.c b/cesar/mac/sar/test/utest/host/src/sar_pbproc_override_mfs.c
index b89f4eac8d..80b03184d2 100644
--- a/cesar/mac/sar/test/utest/host/src/sar_pbproc_override_mfs.c
+++ b/cesar/mac/sar/test/utest/host/src/sar_pbproc_override_mfs.c
@@ -47,3 +47,9 @@ pbproc_mfs_expire (pbproc_t *ctx, mfs_tx_t *mfs, u32 expiration_ntb,
{
return false;
}
+
+uint
+pbproc_mfs_trim (pbproc_t *ctx, mfs_tx_t *mfs, int trim_nb)
+{
+ return 0;
+}
diff --git a/cesar/mac/sar/test/utest/host/src/trim.c b/cesar/mac/sar/test/utest/host/src/trim.c
new file mode 100644
index 0000000000..ff3311d572
--- /dev/null
+++ b/cesar/mac/sar/test/utest/host/src/trim.c
@@ -0,0 +1,116 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2012 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file src/trim.c
+ * \brief Test MFS trimming.
+ * \ingroup test
+ */
+#include "common/std.h"
+#include "lib/test.h"
+#include "mac/sar/sar.h"
+#include "mac/sar/inc/sar.h"
+
+#include "tests.h"
+
+#include "mac/pbproc/inc/context.h"
+
+#include <string.h>
+
+static void
+test_case_trim__add_mfs (sar_test_t *t, u8 lid, bool tx, int seg_nb)
+{
+ bool added;
+ mfs_t *mfs = mac_store_mfs_add (t->mac_store, tx, false, false, lid, 2,
+ &added);
+ dbg_assert (added);
+ sar_mfs_add (t->sar, mfs);
+ blk_t *head, *tail;
+ head = blk_alloc_desc_range (seg_nb, &tail);
+ pb_t *pb_head, *pb_tail;
+ pb_head = PARENT_OF (pb_t, blk, head);
+ pb_tail = PARENT_OF (pb_t, blk, tail);
+ if (tx)
+ {
+ mfs->tx.head = pb_head;
+ mfs->tx.tail = pb_tail;
+ mfs->tx.seg_nb = seg_nb;
+ }
+ else
+ {
+ tail->next = NULL;
+ mfs->rx.head = pb_head;
+ }
+ blk_release (mfs);
+}
+
+/** Should match SAR_TRIM_SEG_NB. */
+#define TEST_TRIM_SEG_NB 20
+
+void
+test_case_trim (test_t test)
+{
+ test_case_begin (test, "trim");
+ /* Initialise contexts and MFS. */
+ sar_test_t ctx;
+ pbproc_t pbproc;
+ memset (&pbproc, 0, sizeof (pbproc_t));
+ sar_test_init (&ctx, INVALID_PTR, &pbproc);
+ uint cap;
+ for (cap = 0; cap < MAC_CAP_NB; cap++)
+ {
+ test_case_trim__add_mfs (&ctx, cap, true, TEST_TRIM_SEG_NB * 3);
+ test_case_trim__add_mfs (&ctx, cap, false, TEST_TRIM_SEG_NB * 3);
+ }
+ /* Tests. */
+ test_begin (test, "none")
+ {
+ uint slack = blk_slack ();
+ sar_mfs_trim (ctx.sar, 0);
+ test_fail_unless (blk_slack () == slack + 0 * TEST_TRIM_SEG_NB);
+ } test_end;
+ test_begin (test, "half")
+ {
+ uint slack = blk_slack ();
+ int limit = mfs_tx_max_seg_nb;
+ sar_mfs_trim (ctx.sar, 2);
+ test_fail_unless (blk_slack () == slack + 2 * TEST_TRIM_SEG_NB);
+ test_fail_unless (mfs_tx_max_seg_nb == limit);
+ } test_end;
+ test_begin (test, "all")
+ {
+ uint slack = blk_slack ();
+ int limit = mfs_tx_max_seg_nb;
+ sar_mfs_trim (ctx.sar, 4);
+ test_fail_unless (blk_slack () == slack + 4 * TEST_TRIM_SEG_NB);
+ test_fail_unless (mfs_tx_max_seg_nb == limit);
+ } test_end;
+ test_begin (test, "update limit")
+ {
+ int limit = mfs_tx_max_seg_nb;
+ sar_mfs_trim (ctx.sar, 4);
+ test_fail_unless (mfs_tx_max_seg_nb > limit);
+ limit = mfs_tx_max_seg_nb;
+ sar_mfs_trim (ctx.sar, 4);
+ test_fail_unless (mfs_tx_max_seg_nb > limit);
+ } test_end;
+ /* Cleanup. */
+ sar_cleanup (ctx.sar);
+ sar_test_uninit (&ctx);
+ /* Test for leftovers. */
+ test_begin (test, "memory")
+ {
+ test_fail_unless (blk_check_memory ());
+ } test_end;
+}
+
+void
+test_suite_trim (test_t test)
+{
+ test_suite_begin (test, "MFS trim");
+ test_case_trim (test);
+}