summaryrefslogtreecommitdiff
path: root/cesar/mac/sar/test/functional/src
diff options
context:
space:
mode:
authorIPMbox Team2012-02-03 14:32:28 +0100
committerNicolas Schodet2012-02-20 10:08:46 +0100
commit3ed571f9d933e5c5dadef650c07e20e8aad06213 (patch)
tree761bfe80d4660605e00f52afb8532d9a2ef847b6 /cesar/mac/sar/test/functional/src
parent89328e8cc096f8c9f340a3eb8910d06748a3e572 (diff)
cesar, cleopatre, common: new ipmbox design, closes #848
Diffstat (limited to 'cesar/mac/sar/test/functional/src')
-rw-r--r--cesar/mac/sar/test/functional/src/bufmgr_stub.c81
-rw-r--r--cesar/mac/sar/test/functional/src/test_functions.c113
2 files changed, 121 insertions, 73 deletions
diff --git a/cesar/mac/sar/test/functional/src/bufmgr_stub.c b/cesar/mac/sar/test/functional/src/bufmgr_stub.c
new file mode 100644
index 0000000000..ec3d8da577
--- /dev/null
+++ b/cesar/mac/sar/test/functional/src/bufmgr_stub.c
@@ -0,0 +1,81 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2012 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file unit_test/ecos/src/bufmgr_stub.c
+ * \brief Buffer manager stub functions
+ * \ingroup mac_sar_test
+ *
+ * « long description »
+ */
+#include "common/std.h"
+
+#include "common/defs/ethernet.h"
+
+#include "hal/arch/arch.h"
+
+#include "bufmgr/bufmgr.h"
+
+#include "mac/sar/test/functional/test_functions.h"
+
+#include <string.h>
+
+
+/* Variables needed by the test. */
+#ifdef __sparc__
+static u8 buffer[SAR_TEST_BUFFER_NB][2048] __attribute__ ((section(".private")));
+#else
+static u8 buffer[SAR_TEST_BUFFER_NB][2048];
+#endif
+
+u8*
+bufmgr_get (bufmgr_t *ctx)
+{
+ struct sar_test_bufmgr_t *bufmgr = (struct sar_test_bufmgr_t *) ctx;
+ if (bufmgr->free_buffer_nb)
+ {
+ u8 *buffer_to_give = buffer[bufmgr->free_buffer_nb - 1];
+ bufmgr->free_buffer_nb--;
+ return ARCH_CPU_TO_UNCACHEABLE (buffer_to_give);
+ }
+ return NULL;
+}
+
+void
+bufmgr_give_back (bufmgr_t *ctx, u8 *buffer)
+{
+ struct sar_test_bufmgr_t *bufmgr = (struct sar_test_bufmgr_t *) ctx;
+ bufmgr->free_buffer_nb++;
+ dbg_assert (bufmgr->free_buffer_nb <= SAR_TEST_BUFFER_NB);
+ bufmgr->nb_given_back++;
+}
+
+void
+bufmgr_keep_buffer (bufmgr_t *ctx, u8 *buffer)
+{
+ struct sar_test_bufmgr_t *bufmgr = (struct sar_test_bufmgr_t *) ctx;
+ bufmgr->free_buffer_nb++;
+ dbg_assert (bufmgr->free_buffer_nb <= SAR_TEST_BUFFER_NB);
+ bufmgr->nb_given_back++;
+}
+
+bufmgr_t *
+bufmgr_init (ipmbox_t *ctx)
+{
+ struct sar_test_bufmgr_t *bufmgr = (struct sar_test_bufmgr_t *) ctx;
+ uint i;
+ for (i = 0; i < SAR_TEST_BUFFER_NB; i++)
+ bufmgr->buffer[i] = buffer[i];
+ bufmgr->nb_given_back = 0;
+ bufmgr->free_buffer_nb = SAR_TEST_BUFFER_NB;
+ return (bufmgr_t *) ctx;
+}
+
+void
+bufmgr_client_register (bufmgr_t *ctx, bufmgr_callback_t cb, void *user_data)
+{
+}
diff --git a/cesar/mac/sar/test/functional/src/test_functions.c b/cesar/mac/sar/test/functional/src/test_functions.c
index dc44faeeff..74ccbc2916 100644
--- a/cesar/mac/sar/test/functional/src/test_functions.c
+++ b/cesar/mac/sar/test/functional/src/test_functions.c
@@ -35,18 +35,6 @@
#include "hal/phy/soft/bridgedma/bridgedma_crc.h"
#include <string.h>
-#define BUFFERS_MAX 100
-
-/* Variables needed by the test. */
-#ifdef __sparc__
-static u8 buffers[BUFFERS_MAX][2048] __attribute__ ((section(".private")));
-#else
-static u8 buffers[BUFFERS_MAX][2048];
-#endif
-
-static uint nb_frames_tx;
-static uint nb_frames_rx;
-
/* Stubbed Functions. */
void
ce_measurements (void *data, pbproc_rx_params_t *rx_params,
@@ -58,38 +46,25 @@ ce_measurements (void *data, pbproc_rx_params_t *rx_params,
}
static void
-sar_test_segmentation_done__do_nothing (void *user,
- u8* buffer,
- void *user_data)
-{
- nb_frames_tx++;
-}
-
-static void
sar_reassembly_done__do_nothing (void *user, u8* buffer, uint length,
mfs_rx_t *mfs, bool encrypted)
{
- nb_frames_rx++;
+ sar_test_ctx_t *ctx = user;
+ ctx->nb_frames_rx++;
+ bufmgr_give_back ((bufmgr_t*) &ctx->bufmgr, buffer);
}
/*-- End stubbed functions. --*/
-u8*
-sar_test_get_buffer (uint buffer_nb)
-{
- dbg_assert (buffer_nb < BUFFERS_MAX);
- return ARCH_CPU_TO_UNCACHEABLE (buffers[buffer_nb]);
-}
-
uint
-sar_test_rx_frames (void)
+sar_test_rx_frames (sar_test_ctx_t *ctx)
{
- return nb_frames_rx;
+ return ctx->nb_frames_rx;
}
uint
-sar_test_tx_frames (void)
+sar_test_tx_frames (sar_test_ctx_t *ctx)
{
- return nb_frames_tx;
+ return ctx->nb_frames_tx;
}
void
@@ -103,25 +78,21 @@ sar_test_init (sar_test_ctx_t *test_ctx)
/* Initialise the store. */
test_ctx->mac_store = mac_store_init ();
+ /* Initialise the fake buffer manager. */
+ bufmgr_init ((ipmbox_t *) &test_ctx->bufmgr);
+
/* Initialise the SAR. */
test_ctx->sar = sar_init (test_ctx->mac_store, INVALID_PTR, INVALID_PTR,
- 2);
+ (bufmgr_t *) &test_ctx->bufmgr, 2);
/* CE. */
sar_init_measure_context (test_ctx->sar, INVALID_PTR);
sar_init_measurement_cb (test_ctx->sar, ce_measurements);
- sar_init_data_context (test_ctx->sar, INVALID_PTR);
- sar_init_segmentation_data_cb (test_ctx->sar,
- sar_test_segmentation_done__do_nothing);
- sar_init_mme_context (test_ctx->sar, INVALID_PTR);
- sar_init_segmentation_mme_cb (test_ctx->sar,
- sar_test_segmentation_done__do_nothing);
- sar_init_reassembly_data_cb (test_ctx->sar,
- sar_reassembly_done__do_nothing);
- sar_init_reassembly_mme_cb (test_ctx->sar,
- sar_reassembly_done__do_nothing);
-
- nb_frames_tx = 0;
- nb_frames_rx = 0;
+ sar_init_reassembly_callbacks (test_ctx->sar,
+ sar_reassembly_done__do_nothing,
+ sar_reassembly_done__do_nothing,
+ test_ctx);
+ test_ctx->nb_frames_rx = 0;
+ test_ctx->nb_frames_tx = 0;
}
void
@@ -152,17 +123,8 @@ test_mpdu_reception (sar_test_ctx_t *ctx, pb_t *pb_head, pb_t *pb_tail,
mfs_rx_t *mfs;
bool added;
pbproc_rx_desc_t *sar_mpdu;
- uint i;
- u8 *buffer;
/* Activate the SAR. */
sar_activate (ctx->sar, true);
- /* Provide the buffer to the SAR. */
- for (i = 0; i < COUNT (buffers); i++)
- {
- buffer = ARCH_CPU_TO_UNCACHEABLE (buffers[i]);
- memset (buffer, 0x0, ETH_PACKET_MAX_SIZE);
- sar_data_buffer_add (ctx->sar, buffer);
- }
/* Prepare the MPDU for the SAR. */
sar_mpdu = (pbproc_rx_desc_t*) blk_alloc_desc ();
sar_mpdu->rx->params.tei = 1;
@@ -203,7 +165,6 @@ test_simulate_mpdu_reception (sar_test_ctx_t *ctx, uint eth_frame_nb,
crc_t crc_ctx;
u32 enc_tab[256];
u32 crc;
- u8 *buffer;
blk_t *pb_first, *pb_last;
pb_t *pb_current;
uint pb_nb;
@@ -211,7 +172,7 @@ test_simulate_mpdu_reception (sar_test_ctx_t *ctx, uint eth_frame_nb,
uint i, j;
bitstream_t stream;
- dbg_assert (eth_frame_nb <= BUFFERS_MAX);
+ dbg_assert (eth_frame_nb <= SAR_TEST_BUFFER_NB);
/* Compute PB number. */
pb_nb = (eth_frame_nb * (eth_frame_len + 6) + BLK_SIZE - 1) / BLK_SIZE;
@@ -245,15 +206,16 @@ test_simulate_mpdu_reception (sar_test_ctx_t *ctx, uint eth_frame_nb,
crc_ctx.table.t32 = enc_tab;
crc_init(&crc_ctx);
- buffer = buffers[0];
- memset (buffer, 0xff, 2048);
+ u8 *buffer_internal = bufmgr_get ((bufmgr_t *) &ctx->bufmgr);
+ memset (buffer_internal, 0xff, 2048);
/* Request the Leon processor to write all the data buffered. */
arch_write_buffer_flush ();
crc = crc_compute_begin (&crc_ctx);
- crc = bridgedma_crc_compute_continue_block (&crc_ctx, crc, buffer,
+ crc = bridgedma_crc_compute_continue_block (&crc_ctx, crc, buffer_internal,
eth_frame_len);
crc = crc_compute_end (&crc_ctx, crc);
+ bufmgr_give_back ((bufmgr_t *) &ctx->bufmgr, buffer_internal);
/* Store a Full size Ethernet Packet in it. */
pb_current = (pb_t*) pb_first;
@@ -285,7 +247,6 @@ void
test_simulate_mpdu_reception_check (sar_test_ctx_t *ctx, test_t test,
uint frames_nb, uint frames_len)
{
- u8 *buffer;
dbg_assert (ctx);
test_case_begin (test, "Verify reassembly");
@@ -293,14 +254,16 @@ test_simulate_mpdu_reception_check (sar_test_ctx_t *ctx, test_t test,
test_begin (test, "Sar reassembly")
{
uint i, j;
- test_fail_unless (frames_nb == sar_test_rx_frames ());
+ test_fail_unless (frames_nb == sar_test_rx_frames (ctx));
for (j = 0; j < frames_nb; j++)
{
- buffer = sar_test_get_buffer (j);
for (i = 0; i < frames_len; i++)
+ {
+ u8 *buffer = ctx->bufmgr.buffer[SAR_TEST_BUFFER_NB - 1 - j];
test_fail_unless (bitstream_direct_read (buffer, i*8, 8)
== 0xFF);
+ }
}
}
test_end;
@@ -335,7 +298,7 @@ sar_test_rx_multiple_frames (uint frames_nb, uint frames_len)
#endif
}
-static void
+void
test_simulate_msdu_emission (sar_test_ctx_t *ctx,
uint frames_nb, uint frames_len)
{
@@ -353,16 +316,20 @@ test_simulate_msdu_emission (sar_test_ctx_t *ctx,
if (added)
sar_mfs_add (ctx->sar, (mfs_t*) mfs);
- /* Get the buffer. */
- buffer = sar_test_get_buffer (0);
- memset (buffer, 0xff, 2048);
-
+ ctx->bufmgr.nb_given_back = 0;
/* Disallow the SAR to expire MFS. */
for (i = 0; i < frames_nb; i++)
- sar_msdu_add (ctx->sar, buffer, frames_len, mfs, INVALID_PTR,
- mac_ntb());
+ {
+ /* Get the buffer. */
+ buffer = bufmgr_get ((bufmgr_t *) &ctx->bufmgr);
+ memset (buffer, 0xff, 2048);
+ sar_msdu_add (ctx->sar, buffer, frames_len, mfs, mac_ntb());
+ bufmgr_give_back ((bufmgr_t *) &ctx->bufmgr, buffer);
+ }
blk_release (mfs);
+ /* Store number of frames given back to bufmgr. */
+ ctx->nb_frames_tx = ctx->bufmgr.nb_given_back;
}
void
@@ -373,7 +340,6 @@ test_simulate_msdu_emission_check (sar_test_ctx_t *ctx, test_t test,
crc_t crc_ctx;
u32 enc_tab[256];
u32 crc;
- u8 *buffer;
pb_t *pb_current;
bitstream_t stream;
uint i;
@@ -391,7 +357,7 @@ test_simulate_msdu_emission_check (sar_test_ctx_t *ctx, test_t test,
crc_ctx.table.t32 = enc_tab;
crc_init(&crc_ctx);
- buffer = buffers[0];
+ u8 *buffer = bufmgr_get ((bufmgr_t *) &ctx->bufmgr);
memset (buffer, 0xff, 2048);
/* Request the Leon processor to write all the data buffered. */
arch_write_buffer_flush ();
@@ -400,10 +366,11 @@ test_simulate_msdu_emission_check (sar_test_ctx_t *ctx, test_t test,
crc = bridgedma_crc_compute_continue_block (&crc_ctx, crc, buffer,
frames_len);
crc = crc_compute_end (&crc_ctx, crc);
+ bufmgr_give_back ((bufmgr_t *) &ctx->bufmgr, buffer);
test_begin (test, "Sar")
{
- test_fail_unless (frames_nb == sar_test_tx_frames ());
+ test_fail_unless (frames_nb == sar_test_tx_frames (ctx));
pb_current = mfs->head;
bitstream_read_init (&stream, pb_current->data, BLK_SIZE);