summaryrefslogtreecommitdiff
path: root/cesar/mac/sar/test/functional/src/sar_tx.c
diff options
context:
space:
mode:
authorlaranjeiro2009-03-25 12:51:48 +0000
committerlaranjeiro2009-03-25 12:51:48 +0000
commit01f82e8b1938d436f5f272284b283a1997131d02 (patch)
tree3ba43441a282a07c769ffa8cdce52f242872668e /cesar/mac/sar/test/functional/src/sar_tx.c
parentfe29ccfc0fc0c1c62540e7a07884f077111b5e53 (diff)
mac/sar:
* Moved the SAR functional test to the mac/sar instead of leaving it in the test_general/hard directory. git-svn-id: svn+ssh://pessac/svn/cesar/trunk@4301 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'cesar/mac/sar/test/functional/src/sar_tx.c')
-rw-r--r--cesar/mac/sar/test/functional/src/sar_tx.c218
1 files changed, 218 insertions, 0 deletions
diff --git a/cesar/mac/sar/test/functional/src/sar_tx.c b/cesar/mac/sar/test/functional/src/sar_tx.c
new file mode 100644
index 0000000000..213497132a
--- /dev/null
+++ b/cesar/mac/sar/test/functional/src/sar_tx.c
@@ -0,0 +1,218 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2009 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file src/sar_tx.c
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+#include "common/std.h"
+#include "lib/test.h"
+#include "lib/bitstream.h"
+
+#include <cyg/kernel/kapi.h>
+#include <cyg/hal/hal_arch.h>
+#include <string.h>
+
+#include "hal/arch/arch.h"
+
+#include "mac/common/ntb.h"
+#include "mac/common/store.h"
+
+#include "mac/pbproc/pbproc.h"
+#include "mac/sar/sar.h"
+
+/* Variables needed by the test. */
+#ifdef __sparc__
+static u8 skbuffer[2048] __attribute__ ((section(".private")));
+#else
+static u8 skbuffer[2048];
+#endif
+static sar_t *sar_ctx = NULL;
+static mac_store_t *mac_store = NULL;
+
+/* Thread data for the test. */
+cyg_thread my_test_thread;
+cyg_handle_t my_test_thread_handle;
+u8 my_test_thread_stack [CYGNUM_HAL_STACK_SIZE_TYPICAL];
+
+/* Functions. */
+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;
+}
+
+void
+segmentation_done (void *ctx, u8 *buffer, void *user_data)
+{
+}
+
+void
+prepare_test (test_t test)
+{
+ u8 *buffer = NULL;
+ mfs_tx_t *mfs = NULL;
+ bool added = false;
+
+ /* Prepare the buffer. */
+ buffer = ARCH_CPU_TO_UNCACHEABLE (skbuffer);
+ memset (buffer, 0xFF, 2048);
+
+ /* Add the MFS. */
+ mfs = mac_store_mfs_add_tx (mac_store, false, false, 1, 1, &added);
+ dbg_assert (mfs);
+
+ if (added)
+ sar_mfs_add (sar_ctx, (mfs_t *)mfs);
+
+ /* Add the first frame. */
+ sar_msdu_add (sar_ctx, buffer, 1434, 0x0, mfs, NULL);
+ /* Add the second frame. */
+ sar_msdu_add (sar_ctx, buffer, 1334, 0x0, mfs, NULL);
+
+ /* Release the reference on the MFS. */
+ blk_release (mfs);
+}
+
+void
+verify_test (test_t test)
+{
+ mfs_tx_t *mfs = NULL;
+ pb_t *pb_first = NULL;
+ pb_t *pb_last = NULL;
+ bool added = false;
+ sar_mf_t sar_mf;
+ pb_t *pb_list[6 + 1];
+ pb_t *pb_current = NULL;
+ uint i = 0;
+ u32 crc;
+
+ mfs = mac_store_mfs_add_tx (mac_store, false, false, 1, 1, &added);
+ dbg_assert (mfs);
+
+ test_case_begin (test, "SAR TX");
+
+ test_begin (test, "Verify PBs")
+ {
+ test_fail_unless (mfs->head != NULL);
+ test_fail_unless (mfs->tail!= NULL);
+ test_fail_unless (mfs->head != mfs->tail);
+ test_fail_unless (mfs->seg_nb == 6);
+
+ pb_first = mfs->head;
+ pb_last = mfs->tail;
+ pb_last->next = NULL;
+ mfs->head = NULL;
+ mfs->tail = NULL;
+
+ for (i = 0, pb_current = pb_first;
+ pb_current;
+ i++, pb_current = pb_current->next)
+ {
+ pb_list[i] = pb_current;
+#ifdef __sparc__
+ arch_load_cache ((u32*) &(pb_current->header), 1);
+ arch_load_cache ((u32*) (pb_current->data), BLK_SIZE / 4);
+#endif
+ test_fail_unless (pb_current->header.ssn == i);
+ }
+
+ /* Test the header mfbf and mfbo. */
+ test_fail_unless (pb_list[0]->header.mfbf == true);
+ test_fail_unless (pb_list[0]->header.mfbo == 0);
+ test_fail_unless (pb_list[2]->header.mfbf == true);
+ test_fail_unless (pb_list[2]->header.mfbo == 416);
+
+ /* Verify the headers. */
+ sar_mf_header (pb_list[0], 0, &sar_mf);
+ test_fail_unless (sar_mf.type == SAR_MF_TYPE_DATA);
+ test_fail_unless (sar_mf.length == 1434);
+
+ sar_mf_header (pb_list[2], 416, &sar_mf);
+ test_fail_unless (sar_mf.type == SAR_MF_TYPE_DATA);
+ test_fail_unless (sar_mf.length == 1334);
+
+ /* Verify the CRC. */
+ crc = bitstream_direct_read (pb_list[2]->data, 412 * 8, 32);
+ test_fail_unless (crc == 0xcbc4fcd7);
+
+ crc = bitstream_direct_read (pb_list[5]->data, 216 * 8, 32);
+ test_fail_unless (crc == 0x6bbcffe7);
+
+ sar_mfs_remove (sar_ctx, (mfs_t *) mfs);
+ blk_release_desc_range_nb ((blk_t *) pb_first, 6);
+ }
+ test_end;
+
+ blk_release (mfs);
+}
+
+void
+test_thread_process (cyg_addrword_t data)
+{
+ test_t test;
+ mac_config_t mac_config;
+ uint ca;
+ uint phy;
+ uint pbproc;
+
+ test_init (test, 0, NULL);
+
+ /* Initialise the test. */
+ mac_ntb_init ((phy_t *) &phy, &mac_config);
+ mac_store = mac_store_init ();
+ sar_ctx = sar_init (mac_store, (pbproc_t *) &pbproc, (ca_t *) &ca);
+ sar_activate (sar_ctx, true);
+
+ sar_init_data_context (sar_ctx, sar_ctx);
+ sar_init_mme_context (sar_ctx, sar_ctx);
+ sar_init_measurement_cb (sar_ctx, ce_measurements);
+ sar_init_segmentation_data_cb (sar_ctx, segmentation_done);
+ sar_init_segmentation_mme_cb (sar_ctx, segmentation_done);
+
+ prepare_test (test);
+
+ /* Wait the bridgedma ends its job. */
+ cyg_thread_delay (10);
+ verify_test (test);
+
+ test_result (test);
+
+ sar_uninit (sar_ctx);
+ pbproc_uninit ((pbproc_t *) &pbproc);
+
+ dbg_check (mac_store_sta_remove (mac_store, 0x1));
+ mac_store_uninit (mac_store);
+ mac_ntb_uninit();
+
+#ifndef __sparc__
+ HAL_PLATFORM_EXIT (test_nb_failed (test) == 0 ? 0 : 1);
+#endif
+}
+
+int
+cyg_user_start (void)
+{
+ // Create the thread.
+ cyg_thread_create( 10,
+ &test_thread_process,
+ (cyg_addrword_t) 0,
+ "TEST_THREAD",
+ my_test_thread_stack,
+ CYGNUM_HAL_STACK_SIZE_TYPICAL,
+ &my_test_thread_handle,
+ &my_test_thread);
+ cyg_thread_resume (my_test_thread_handle);
+
+ return 0;
+}