summaryrefslogtreecommitdiff
path: root/cesar/mac/sar/test/functional/src/test_functions.c
diff options
context:
space:
mode:
authorlaranjeiro2009-11-23 13:28:32 +0000
committerlaranjeiro2009-11-23 13:28:32 +0000
commit7674b62619729b4a3d19b2ec243a56cec5087521 (patch)
treeaf781f74636d8814aa257299cb14291159f5ec97 /cesar/mac/sar/test/functional/src/test_functions.c
parent5667dfd7ff8014927adae9039eecb58aee3c9bd5 (diff)
cesar/mac/sar: add a performance rx test
sar_rx_perf: Full initialised test with MFS already created to put the SAR in a normal performance flow test. This only simulate reception of a single MPDU containing a full Ethernet packet i.e. 1518 bytes long. sar_rx_perf_hudge_mpdu: A MPDU containing 200 Ethernet frames of 60 bytes each in a single MPDU. git-svn-id: svn+ssh://pessac/svn/cesar/trunk@6449 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'cesar/mac/sar/test/functional/src/test_functions.c')
-rw-r--r--cesar/mac/sar/test/functional/src/test_functions.c311
1 files changed, 311 insertions, 0 deletions
diff --git a/cesar/mac/sar/test/functional/src/test_functions.c b/cesar/mac/sar/test/functional/src/test_functions.c
new file mode 100644
index 0000000000..7ea8b45a39
--- /dev/null
+++ b/cesar/mac/sar/test/functional/src/test_functions.c
@@ -0,0 +1,311 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2009 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file mac/sar/test/functional/src/test_functions.c
+ * \brief Common functions for tests.
+ * \ingroup mac_sar
+ */
+#include "common/std.h"
+#include "common/defs/homeplugAV.h"
+
+#include "lib/test.h"
+#include "lib/trace.h"
+#include "lib/blk.h"
+#include "lib/crc.h"
+#include "lib/bitstream.h"
+
+#include "mac/common/ntb.h"
+#include "lib/bitstream.h"
+#include "mac/sar/test/functional/test_functions.h"
+
+#include "hal/arch/arch.h"
+#include "hal/trace/trace.h"
+#include "hal/phy/inc/bridgedma_soft.h"
+
+#include <stdio.h>
+#include <cyg/kernel/kapi.h>
+#include <cyg/hal/hal_arch.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;
+
+/* Stubbed Functions. */
+static bool
+ce_measurements (void *user, pbproc_rx_params_t *rx_params, uint pb_nb,
+ blk_t **first, blk_t **last, pb_t *chandata, uint nb_chandata, uint
+ *blk_offset)
+{
+ if (nb_chandata)
+ blk_release_desc_range_nb ((blk_t *) chandata, nb_chandata);
+ return false;
+}
+
+static void
+sar_test_segmentation_done__do_nothing (void *user,
+ u8* buffer,
+ void *user_data) { }
+
+static void
+sar_reassembly_done__do_nothing (void *user, u8* buffer, uint length,
+ mfs_rx_t *mfs, bool encrypted)
+{
+ nb_frames++;
+}
+/*-- End stubbed functions. --*/
+
+void
+sar_test_init (sar_test_ctx_t *test_ctx)
+{
+ dbg_assert (test_ctx);
+
+ /* Initialise the mac NTB. */
+ mac_ntb_init (INVALID_PTR, &test_ctx->mac_config);
+
+ /* Initialise the store. */
+ test_ctx->mac_store = mac_store_init ();
+
+ /* Initialise the SAR. */
+ test_ctx->sar = sar_init (test_ctx->mac_store, INVALID_PTR, INVALID_PTR,
+ 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 = 0;
+}
+
+void
+sar_test_uninit (sar_test_ctx_t *test_ctx)
+{
+ dbg_assert (test_ctx);
+
+ sar_cleanup (test_ctx->sar);
+ sar_uninit (test_ctx->sar);
+ mac_store_uninit (test_ctx->mac_store);
+}
+
+static void
+sar_test_change_pb (bitstream_t *ctx, void *user_data)
+{
+ pb_t **pb = user_data;
+ dbg_assert (ctx);
+ dbg_assert (user_data);
+
+ *pb = (*pb)->next;
+ bitstream_set_buffer (ctx, (*pb)->data, BLK_SIZE);
+}
+
+void
+test_simulate_mpdu_reception (sar_test_ctx_t *ctx, uint eth_frame_nb,
+ uint eth_frame_len)
+{
+ crc_t crc_ctx;
+ u32 enc_tab[256];
+ u32 crc;
+ u8 *buffer;
+ blk_t *pb_first, *pb_last;
+ pb_t *pb_current;
+ mfs_rx_t *mfs;
+ bool added;
+ pbproc_rx_desc_t *sar_mpdu;
+ uint pb_nb;
+ u16 ssn = 0;
+ uint i, j;
+ bitstream_t stream;
+
+ dbg_assert (eth_frame_nb <= BUFFERS_MAX);
+
+ /* Compute PB number. */
+ pb_nb = (eth_frame_nb * (eth_frame_len + 6) + BLK_SIZE - 1) / BLK_SIZE;
+ dbg_assert (pb_nb <= 200);
+
+ /* Store the Frame in the PBs. */
+ pb_first = blk_alloc_desc_range (pb_nb, &pb_last);
+ ((pb_t*)pb_last)->next = NULL;
+
+ for (pb_current = (pb_t*) pb_first;
+ pb_current;
+ pb_current = pb_current->next, ssn++)
+ {
+ pb_current->phy_pb.pb_rx.pb_measurement.crc_error = false;
+ pb_current->header.ssn = ssn;
+ pb_current->header.vpbf = true;
+ pb_current->header.mmqf = false;
+ pb_current->header.opsf = false;
+ pb_current->header.mfbf = false;
+ pb_current->header.mfbo = 0;
+ }
+
+ /* Compute the CRC. */
+ crc_ctx.width = 32;
+ crc_ctx.generator = HPAV_CRC32_GENERATOR;
+ crc_ctx.init = HPAV_CRC32_INIT;
+ crc_ctx.refin = true;
+ crc_ctx.refout = true;
+ crc_ctx.xorout = 0xffffffff;
+ crc_ctx.reg_init = 0;
+ crc_ctx.table.t32 = enc_tab;
+ crc_init(&crc_ctx);
+
+ buffer = buffers[0];
+ memset (buffer, 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,
+ eth_frame_len);
+ crc = crc_compute_end (&crc_ctx, crc);
+
+ /* Store a Full size Ethernet Packet in it. */
+ pb_current = (pb_t*) pb_first;
+ bitstream_write_init (&stream, pb_current->data, BLK_SIZE);
+ for (i = 0; i < eth_frame_nb; i++)
+ {
+ bitstream_init_buffer_cb (&stream, sar_test_change_pb,
+ &pb_current);
+ if (pb_current->header.mfbf == false)
+ {
+ pb_current->header.mfbf = true;
+ pb_current->header.mfbo = bitstream_written_bits (&stream) / 8;
+ }
+
+ bitstream_write (&stream, SAR_MF_TYPE_DATA, 2);
+ bitstream_write (&stream, eth_frame_len - 1, 14);
+ for (j = 0; j < eth_frame_len; j++)
+ bitstream_write (&stream, 0xff, 8);
+ bitstream_write (&stream, crc, 32);
+ }
+
+ /* Request the Leon processor to write all the data buffered. */
+ arch_write_buffer_flush ();
+
+ /* Activate the SAR. */
+ sar_activate (ctx->sar, true);
+
+ /* Provide the buffer to the SAR. */
+ for (i = 0; i < eth_frame_nb; 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;
+ sar_mpdu->rx->params.lid = 2;
+ sar_mpdu->rx->params.eks = 0;
+ sar_mpdu->rx->params.mfs_cmd_data = MFS_FSM_CMD_NOP;
+ sar_mpdu->rx->params.mfs_cmd_mme = MFS_FSM_CMD_NOP;
+ sar_mpdu->rx->params.multi_net_bcast = false;
+ sar_mpdu->rx->params.bcast = false;
+ sar_mpdu->rx->params.sound = false;
+ sar_mpdu->rx->mfs = NULL;
+ sar_mpdu->rx->mfs_mme = NULL;
+ sar_mpdu->rx->pb_first = (pb_t*) pb_first;
+ sar_mpdu->rx->pb_last = (pb_t*) pb_last;
+ sar_mpdu->rx->pb_nb = pb_nb;
+ sar_mpdu->rx->chandata_first = NULL;
+ sar_mpdu->rx->chandata_nb = 0;
+ sar_mpdu->rx->params.preamble_ntb = mac_ntb();
+
+ /* Crete the necessary MFS. */
+ mfs = mac_store_mfs_add_rx (ctx->mac_store, sar_mpdu->rx->params.bcast,
+ false /* mme */, sar_mpdu->rx->params.lid,
+ sar_mpdu->rx->params.tei, &added);
+ mfs->ssn_min = 0;
+ dbg_assert (added);
+ /* Add the MFS to the expiration mechanism of the SAR. */
+ sar_mfs_add (ctx->sar, (mfs_t*) mfs);
+ /* Release the current reference on the MFS. */
+ blk_release (mfs);
+
+ /* Add the mpdu. */
+ sar_mpdu_add (ctx->sar, sar_mpdu);
+}
+
+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_nb_ethernet_frames_received (void)
+{
+ return nb_frames;
+}
+
+void
+sar_test_rx_multiple_frames (uint frames_nb, uint frames_len)
+{
+ test_t test;
+ u8 *buffer;
+ sar_test_ctx_t ctx;
+
+ trace_init ();
+ hal_trace_init ();
+ test_init (test, 0, NULL);
+
+ /* Initialise the test. */
+ sar_test_init (&ctx);
+
+ /* 200 frames of 60 bytes each. */
+ test_simulate_mpdu_reception (&ctx, frames_nb, frames_len);
+
+ /* Wait some time. */
+ cyg_thread_delay (50);
+
+ /* Uninitialise the test. */
+ sar_test_uninit (&ctx);
+
+ test_case_begin (test, "Verify reassembly");
+
+ test_begin (test, "Sar reassembly")
+ {
+ uint i, j;
+ test_fail_unless (frames_nb ==
+ sar_test_nb_ethernet_frames_received());
+
+ for (j = 0; j < frames_nb; j++)
+ {
+ buffer = sar_test_get_buffer (j);
+ for (i = 0; i < frames_len; i++)
+ test_fail_unless (bitstream_direct_read (buffer, i*8, 8)
+ == 0xFF);
+ }
+ }
+ test_end;
+
+ test_result (test);
+#ifndef __sparc__
+ HAL_PLATFORM_EXIT (test_nb_failed (test) == 0 ? 0 : 1);
+#endif
+}