summaryrefslogtreecommitdiff
path: root/cesar/mac/sar/test/utest/host/src/trim.c
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/mac/sar/test/utest/host/src/trim.c')
-rw-r--r--cesar/mac/sar/test/utest/host/src/trim.c116
1 files changed, 116 insertions, 0 deletions
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);
+}