summaryrefslogtreecommitdiff
path: root/cesar/cp2/beacon/test
diff options
context:
space:
mode:
authorlaranjeiro2008-05-23 16:00:59 +0000
committerlaranjeiro2008-05-23 16:00:59 +0000
commit05be90b8689c5b61232ec77b9cba82482468e273 (patch)
tree154b822b4fabb7d8851a61c6d7d88261235e03e6 /cesar/cp2/beacon/test
parentc891797e6e17b9894ca5ea608812b73f0a90ceca (diff)
beacon: Implemented and tested the regions, headers and schedules bentry generation and read. Update the specification.
git-svn-id: svn+ssh://pessac/svn/cesar/trunk@2092 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'cesar/cp2/beacon/test')
-rw-r--r--cesar/cp2/beacon/test/Makefile9
-rw-r--r--cesar/cp2/beacon/test/src/bentry.c264
-rw-r--r--cesar/cp2/beacon/test/src/bw_stub.c136
3 files changed, 375 insertions, 34 deletions
diff --git a/cesar/cp2/beacon/test/Makefile b/cesar/cp2/beacon/test/Makefile
index 08da489202..8a31b59648 100644
--- a/cesar/cp2/beacon/test/Makefile
+++ b/cesar/cp2/beacon/test/Makefile
@@ -2,15 +2,14 @@ BASE = ../../..
ECOS = y
-TARGET_PROGRAMS = beacon bentry beacon_schedules
+TARGET_PROGRAMS = beacon bentry
beacon_SOURCES = beacon.c hal_timer_stub.c cl_stub.c
beacon_MODULES = lib cp2/beacon cp2/sta/mgr mac/common
-bentry_SOURCES = bentry.c region_stub.c
-bentry_MODULES = lib cp2/beacon cp2/sta/mgr mac/common
+bentry_SOURCES = bentry.c region_stub.c bw_stub.c
+bentry_MODULES = lib cp2/beacon cp2/sta/mgr mac/common cp2/cco/bw
-beacon_schedules_SOURCES = beacon_schedules.c
-beacon_schedules_MODULES = lib cp2/beacon
+cp2_cco_bw_MODULE_SOURCES = bw_lib_alloc.c
include $(BASE)/common/make/top.mk
diff --git a/cesar/cp2/beacon/test/src/bentry.c b/cesar/cp2/beacon/test/src/bentry.c
index aba091b37b..37744ab23c 100644
--- a/cesar/cp2/beacon/test/src/bentry.c
+++ b/cesar/cp2/beacon/test/src/bentry.c
@@ -21,6 +21,9 @@
#include "cp2/cp.h"
#include "cp2/inc/context.h"
#include "cp2/beacon/inc/bentry_size.h"
+#include "cp2/cco/bw/bw_lib_alloc.h"
+
+#include "string.h"
/** init
@@ -100,41 +103,41 @@ void
test_case_bentry_process_header (test_t test)
{
u8 buffer_test[256] __attribute__((aligned(256)));
- uint length;
- uint header;
- u8 *next_addr;
+ cp_beacon_bentry_t bentry;
test_case_begin (test, "Process header");
buffer_test[0] = CP_BENTRY_REGIONS;
buffer_test[1] = 5;
- next_addr = cp_beacon_bentry_mgr_process_header (buffer_test,
- (u8*) &header,
- (u8*) &length,
- CP_BEACON_BENTRY_READ);
+ bentry.read_write = CP_BEACON_BENTRY_READ;
+ bentry.bentry_addr = buffer_test;
+ cp_beacon_bentry_mgr_process_header (&bentry);
test_begin (test, "Read")
{
- test_fail_if (next_addr != &buffer_test[2], "Wrong address returned");
- test_fail_if (header != buffer_test[0], "Wrong header");
- test_fail_if (length != buffer_test[1], "Wrong length");
+ test_fail_if (bentry.bentry_addr != &buffer_test[2],
+ "Wrong address returned");
+ test_fail_if (bentry.header != buffer_test[0], "Wrong header");
+ test_fail_if (bentry.length != buffer_test[1], "Wrong length");
}
test_end;
- header = CP_BENTRY_AC_LINE_SYNC_COUNTDOWN;
- length = 7;
- next_addr = cp_beacon_bentry_mgr_process_header (buffer_test,
- (u8 *) &header,
- (u8 *) &length,
- CP_BEACON_BENTRY_WRITE);
+ bentry.header = CP_BENTRY_AC_LINE_SYNC_COUNTDOWN;
+ bentry.length = 7;
+ bentry.bentry_addr = buffer_test;
+ bentry.read_write = CP_BEACON_BENTRY_WRITE;
+
+ cp_beacon_bentry_mgr_process_header (&bentry);
+
test_begin (test, "write")
{
- test_fail_if (next_addr != &buffer_test[2], "Wrong address returned");
- test_fail_if (read_u8_from_word (buffer_test) != header,
+ test_fail_if (bentry.bentry_addr != &buffer_test[2],
+ "Wrong address returned");
+ test_fail_if (read_u8_from_word (buffer_test) != bentry.header,
"Wrong header");
- test_fail_if (read_u8_from_word (buffer_test+1) != length,
+ test_fail_if (read_u8_from_word (buffer_test+1) != bentry.length,
"Wrong length");
}
test_end;
@@ -189,11 +192,11 @@ test_case_bentry_mgr_region (test_t test)
{
cp_t cp;
u8 buffer[256] __attribute__((aligned(256)));
- u8 *addr;
cp_cco_region_inl_alloc_t *region;
bitstream_t bitstream;
uint nr;
uint data;
+ cp_beacon_bentry_t bentry;
test_case_begin (test, "test_case_bentry_mgr_region : Read");
@@ -219,11 +222,16 @@ test_case_bentry_mgr_region (test_t test)
bitstream_finalise (&bitstream);
// Try to read.
- addr = cp_beacon_bentry_mgr_regions (&cp, buffer, CP_BEACON_BENTRY_READ);
+ bentry.read_write = CP_BEACON_BENTRY_READ;
+ bentry.bentry_addr = buffer;
+ bentry.header = CP_BENTRY_REGIONS;
+ bentry.length = CP_BEACON_ENTRY_REGION(nr);
+ cp_beacon_bentry_mgr_regions (&cp, &bentry);
test_begin (test, "verify")
{
- test_fail_if (addr != &buffer[5], "Wrong address returned");
+ test_fail_if (bentry.bentry_addr != &buffer[5],
+ "Wrong address returned");
}
test_end;
@@ -233,8 +241,11 @@ test_case_bentry_mgr_region (test_t test)
test_case_begin (test, "test_case_bentry_mgr_region : Write");
cp_cco_region_init (&cp);
- addr = NULL;
- addr = cp_beacon_bentry_mgr_regions (&cp, buffer, CP_BEACON_BENTRY_WRITE);
+ bentry.bentry_addr = buffer;
+ bentry.read_write = CP_BEACON_BENTRY_WRITE;
+ bentry.header = CP_BENTRY_REGIONS;
+ bentry.length = CP_BEACON_ENTRY_REGION(nr);
+ cp_beacon_bentry_mgr_regions (&cp, &bentry);
test_begin (test, "verify")
{
@@ -242,7 +253,8 @@ test_case_bentry_mgr_region (test_t test)
CP_BEACON_ENTRY_REGION(nr),
BITSTREAM_READ);
- test_fail_if (addr != &buffer[7], "Wrong address returned");
+ test_fail_if (bentry.bentry_addr != &buffer[7],
+ "Wrong address returned");
test_fail_if (read_u8_from_word (buffer) != nr,
"Wrong number of sessions.");
@@ -291,13 +303,16 @@ void
test_case_bentry_persistent_schedules (test_t test)
{
cp_t cp;
+ set_t set;
u8 buffer [256] __attribute__((aligned(256)));
bitstream_t bitstream;
uint data;
+ cp_cco_bw_alloc_conn_t *alloc;
+ cp_beacon_bentry_t bentry;
test_case_begin (test, "Persistent schedules : Read");
- cp_cco_bw_init (&cp);
+ cp_cco_bw_schedules_init (&set);
// Write header.
buffer[0] = CP_BENTRY_PERSISTENT_SCHEDULE;
@@ -306,6 +321,26 @@ test_case_bentry_persistent_schedules (test_t test)
bitstream_init (&bitstream, buffer + CP_BEACON_ENTRY_HEADER,
CP_BEACON_ENTRY_NON_PERSISTENT_SCHED (2,1),
BITSTREAM_WRITE);
+ // PSCD = 3
+ data = 3;
+ bitstream_access (&bitstream, &data, 3);
+
+ // CSCD = 4
+ data = 4;
+ bitstream_access (&bitstream, &data, 3);
+
+ // RSVD.
+ data = 0;
+ bitstream_access (&bitstream, &data, 2);
+
+ // Number of sessions.
+ data = 3;
+ bitstream_access (&bitstream, &data, 6);
+
+ // RSVD.
+ data = 0;
+ bitstream_access (&bitstream, &data, 2);
+
// STPF
data = true;
@@ -343,15 +378,185 @@ test_case_bentry_persistent_schedules (test_t test)
data = 3000;
bitstream_access (&bitstream, &data, 12);
- cp_beacon_bentry_mgr_persistent_schedules (&cp, buffer,
- CP_BEACON_BENTRY_READ);
+ bitstream_finalise (&bitstream);
- cp_cco_bw_uninit (&cp);
+ bentry.read_write = CP_BEACON_BENTRY_READ;
+ bentry.bentry_addr = buffer;
+ cp_beacon_bentry_mgr_process_header (&bentry);
+ cp_beacon_bentry_mgr_schedules (&cp, &bentry, &set);
+
+ test_begin (test, "verify data")
+ {
+ // Get the first allocation read.
+ alloc = cp_cco_bw_schedules_get_first
+ (&set);
+
+ test_fail_if (alloc == NULL, "Allocation shall exist");
+ test_fail_if (alloc->stpf != true, "Wrong present start time");
+ test_fail_if (alloc->st_atu != 0, "Wrong start time");
+ test_fail_if (alloc->et_atu != 10, "Wrong end time");
+ test_fail_if (alloc->glid != 1, "Wrong GLID");
+
+ // Get the second allocation read.
+ alloc = cp_cco_bw_schedules_get_next
+ (&set, alloc);
+
+ test_fail_if (alloc == NULL, "Allocation shall exist");
+ test_fail_if (alloc->stpf != false, "Wrong present start time");
+ test_fail_if (alloc->et_atu != 50, "Wrong end time");
+ test_fail_if (alloc->glid != 2, "Wrong GLID");
+
+ // Get the second allocation read.
+ alloc = cp_cco_bw_schedules_get_next
+ (&set, alloc);
+
+ test_fail_if (alloc == NULL, "Allocation shall exist");
+ test_fail_if (alloc->stpf != true, "Wrong present start time");
+ test_fail_if (alloc->st_atu != 1500, "Wrong start time");
+ test_fail_if (alloc->et_atu != 3000, "Wrong end time");
+ test_fail_if (alloc->glid != 3, "Wrong GLID");
+
+ }
+ test_end;
+
+ cp_cco_bw_schedules_uninit (&set);
+ cp_cco_bw_uninit(&cp);
test_case_begin (test, "Persistent schedules : Write");
cp_cco_bw_init (&cp);
+ cp_cco_bw_schedules_init (&set);
+
+ // Create the schedules.
+ alloc = blk_alloc();
+ alloc->stpf = true;
+ alloc->glid = 1;
+ alloc->st_atu = 0;
+ alloc->et_atu = 10;
+ list_init_node (&alloc->node);
+ list_push (&cp.bw.finalised_schedule, &alloc->node);
+
+ // Create the schedules.
+ alloc = blk_alloc();
+ alloc->stpf = false;
+ alloc->glid = 2;
+ alloc->et_atu = 50;
+ list_init_node (&alloc->node);
+ list_push (&cp.bw.finalised_schedule, &alloc->node);
+
+ // Create the schedules.
+ alloc = blk_alloc();
+ alloc->stpf = true;
+ alloc->glid = 3;
+ alloc->st_atu = 1500;
+ alloc->et_atu = 3000;
+ list_init_node (&alloc->node);
+ list_push (&cp.bw.finalised_schedule, &alloc->node);
+
+
+ // Get the schedules.
+ alloc = cp_cco_bw_get_first_alloc (&cp, CP_CCO_BW_PERSISTENCE_PERSISTENT);
+ while (alloc)
+ {
+ cp_cco_bw_schedules_add (&set, alloc);
+ alloc = cp_cco_bw_get_next_alloc (&cp, alloc);
+ }
+
+ cp.beacon.bentry.persistent_schedule_pscd = 0x3;
+ cp.beacon.bentry.persistent_schedule_cscd = 0x4;
+
+ bentry.read_write = CP_BEACON_BENTRY_WRITE;
+ bentry.header = CP_BENTRY_PERSISTENT_SCHEDULE;
+ bentry.length = CP_BEACON_ENTRY_PERSISTENT_SCHED(2,1);
+ bentry.bentry_addr = buffer;
+ cp_beacon_bentry_mgr_process_header (&bentry);
+ cp_beacon_bentry_mgr_schedules (&cp, &bentry, &set);
+
+ test_begin (test, "reading buffer")
+ {
+ test_fail_if (read_u8_from_word(buffer) !=
+ CP_BENTRY_PERSISTENT_SCHEDULE,
+ "Wrong header type");
+ test_fail_if (read_u8_from_word(buffer + 1) !=
+ CP_BEACON_ENTRY_PERSISTENT_SCHED(2, 1),
+ "Wrong length");
+
+ bitstream_init (&bitstream, buffer + 2, sizeof(buffer), BITSTREAM_READ);
+ // Get the previous schedule.
+ bitstream_access (&bitstream, &data, 3);
+ test_fail_if (data != cp.beacon.bentry.persistent_schedule_pscd,
+ "Wong pscd");
+
+ // Get the current schedule countdown.
+ bitstream_access (&bitstream, &data, 3);
+ test_fail_if (data != cp.beacon.bentry.persistent_schedule_cscd,
+ "Wong cscd");
+
+ // Get the reserved data.
+ bitstream_access (&bitstream, &data, 2);
+
+ // Get the Number of sessions.
+ bitstream_access (&bitstream, &data, 6);
+
+ test_fail_if (data != 3, "Wrong number of sessions");
+
+ // Get the reserved data.
+ bitstream_access (&bitstream, &data, 2);
+
+ // Get the first SAI.
+
+ // Get the stpf
+ bitstream_access (&bitstream, &data, 1);
+ test_fail_if (data != true, "STPF shall be true");
+
+ // Get the GLID.
+ bitstream_access (&bitstream, &data, 7);
+ test_fail_if (data != 1, "GLID shall be 1");
+
+ // Get the start time.
+ bitstream_access (&bitstream, &data, 12);
+ test_fail_if (data != 0, "Start time shall be 0");
+
+ // Get the end time.
+ bitstream_access (&bitstream, &data, 12);
+ test_fail_if (data != 10, "end time shall be 10");
+
+ // Second SAI.
+
+ // Get the STPF
+ bitstream_access (&bitstream, &data, 1);
+ test_fail_if (data != false, "STPF shall be false");
+
+ // Get the GLID.
+ bitstream_access (&bitstream, &data, 7);
+ test_fail_if (data != 2, "GLID shall be 2");
+
+ // Get the end time.
+ bitstream_access (&bitstream, &data, 12);
+ test_fail_if (data != 50, "end time shall be 10");
+
+ // Third one.
+
+ // Get the stpf
+ bitstream_access (&bitstream, &data, 1);
+ test_fail_if (data != true, "STPF shall be true");
+
+ // Get the GLID.
+ bitstream_access (&bitstream, &data, 7);
+ test_fail_if (data != 3, "GLID shall be 3");
+
+ // Get the start time.
+ bitstream_access (&bitstream, &data, 12);
+ test_fail_if (data != 1500, "Start time shall be 1500");
+
+ // Get the end time.
+ bitstream_access (&bitstream, &data, 12);
+ test_fail_if (data != 3000, "end time shall be 3000");
+ }
+ test_end;
+ bitstream_finalise(&bitstream);
+ cp_cco_bw_schedules_uninit (&set);
cp_cco_bw_uninit (&cp);
}
@@ -365,6 +570,7 @@ main (void)
test_case_bentry_init (test);
test_case_bentry_process_header (test);
test_case_bentry_mgr_region (test);
+ test_case_bentry_persistent_schedules (test);
test_case_begin (test, "Memory allocation");
test_begin (test, "memory leaks")
diff --git a/cesar/cp2/beacon/test/src/bw_stub.c b/cesar/cp2/beacon/test/src/bw_stub.c
new file mode 100644
index 0000000000..da8a3bf8fb
--- /dev/null
+++ b/cesar/cp2/beacon/test/src/bw_stub.c
@@ -0,0 +1,136 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file test/src/bw.c
+ * \brief BW stub
+ * \ingroup cp2_beacon
+ *
+ */
+#include "common/std.h"
+
+#include "lib/list.h"
+#include "cp2/cco/bw/bw.h"
+#include "cp2/cp.h"
+#include "cp2/inc/context.h"
+
+#include "string.h"
+
+/**
+ * Init of the BW manager.
+ * \param ctx Control Plane Context
+ *
+ */
+void
+cp_cco_bw_init (cp_t* ctx)
+{
+ dbg_assert (ctx);
+
+ memset (&ctx->bw, 0, sizeof (cp_cco_bw_t));
+
+ list_init (&ctx->bw.finalised_schedule);
+}
+
+/**
+ * uninit the bandwidth manager allocations.
+ * \param ctx control plane context
+ *
+ */
+void
+cp_cco_bw_uninit (cp_t* ctx)
+{
+ dbg_assert (ctx);
+}
+
+/**
+ * Return the first element of schedule persistent or not
+ * persistent.
+ * \param ctx Control Plane Context
+ * \param persistence persistent or not persistent
+ * \return the first element of the schedule
+ *
+ *
+ */
+cp_cco_bw_alloc_conn_t*
+cp_cco_bw_get_first_alloc (cp_t *ctx, cp_cco_bw_persistence_t persistence)
+{
+ list_node_t *node;
+ cp_cco_bw_alloc_conn_t *alloc;
+
+ node = list_begin (&ctx->bw.finalised_schedule);
+
+ while (node)
+ {
+ alloc = PARENT_OF (cp_cco_bw_alloc_conn_t, node, node);
+
+ if (persistence == alloc->persistence)
+ {
+ return alloc;
+ }
+ else
+ {
+ node = list_next (node);
+ }
+ }
+
+ return NULL;
+}
+
+/**
+ * Return the next allocation persistent or not
+ * \param ctx control plane context
+ * \param prev_alloc previous allocation
+ * \return the next allocation
+ *
+ */
+cp_cco_bw_alloc_conn_t*
+cp_cco_bw_get_next_alloc (cp_t *ctx, cp_cco_bw_alloc_conn_t *prev_alloc)
+{
+ list_node_t *node;
+ cp_cco_bw_alloc_conn_t *alloc;
+
+ node = &prev_alloc->node;
+
+ while (node)
+ {
+ node = list_next (node);
+ if (node == list_end(&ctx->bw.finalised_schedule))
+ return NULL;
+ alloc = PARENT_OF (cp_cco_bw_alloc_conn_t, node, node);
+
+ if (prev_alloc->persistence == alloc->persistence)
+ {
+ return alloc;
+ }
+ else
+ {
+ node = list_next (node);
+ }
+ }
+
+ return NULL;
+}
+
+
+/**
+ * Return the number of allocation persistent or not
+ * \param ctx control plane context
+ * \param persistence persistent or not persistent
+ * \return return the number of allocation
+ *
+ */
+u16
+cp_cco_bw_get_nb_alloc(cp_t *ctx, cp_cco_bw_persistence_t persistence)
+{
+ dbg_assert (ctx);
+
+ if (!list_empty(&ctx->bw.finalised_schedule))
+ return 3;
+
+ return 0;
+}
+