/* Cesar project {{{ * * Copyright (C) 2010 Spidcom * * <<>> * * }}} */ /** * \file bsu/test/utest/src/schedules.c * \brief BSU schedule tests. * \ingroup bsu */ #include "common/std.h" #include "lib/test.h" #include "bsu/bsu.h" #include "mac/common/timings.h" #include "bsu/test/utest/tests.h" #include "bsu/inc/bsu.h" #include "bsu/inc/context.h" void bsu_schedules_merge (bsu_t *ctx, bsu_beacon_schedules_t *avln, ca_schedule_t *schedules, uint nb); void bsu_ca_schedules (bsu_t *ctx, bsu_avln_t *avln); void test_case_ca_schedules (test_t test) { bsu_test_t t; bsu_avln_t avln; bsu_test_init (&t); test_case_begin (test, "CA Schedules"); test_begin (test, "Merge function") { uint i, j; ca_schedule_t scheds_cmp [3]; scheds_cmp[0].allocations[0].end_offset_tck = MAC_ATU_TO_TCK (500); scheds_cmp[0].allocations[0].glid = MAC_LID_SPC_HOLE; scheds_cmp[0].allocations[1].end_offset_tck = MAC_ATU_TO_TCK (700); scheds_cmp[0].allocations[1].glid = 0; scheds_cmp[0].allocations[2].end_offset_tck = MAC_ATU_TO_TCK (1000); scheds_cmp[0].allocations[2].glid = 0; scheds_cmp[0].allocations[3].end_offset_tck = MAC_ATU_TO_TCK (1600); scheds_cmp[0].allocations[3].glid = MAC_LID_SPC_HOLE; scheds_cmp[0].allocations[4].end_offset_tck = MAC_ATU_TO_TCK (2500); scheds_cmp[0].allocations[4].glid = 0; scheds_cmp[0].allocations[5].end_offset_tck = MAC_ATU_TO_TCK (3907); scheds_cmp[0].allocations[5].glid = 0; /* next */ scheds_cmp[1].allocations[0].end_offset_tck = MAC_ATU_TO_TCK (500); scheds_cmp[1].allocations[0].glid = MAC_LID_SPC_HOLE; scheds_cmp[1].allocations[1].end_offset_tck = MAC_ATU_TO_TCK (700); scheds_cmp[1].allocations[1].glid = 0; scheds_cmp[1].allocations[2].end_offset_tck = MAC_ATU_TO_TCK (1000); scheds_cmp[1].allocations[2].glid = 0; scheds_cmp[1].allocations[3].end_offset_tck = MAC_ATU_TO_TCK (1600); scheds_cmp[1].allocations[3].glid = MAC_LID_SPC_HOLE; scheds_cmp[1].allocations[4].end_offset_tck = MAC_ATU_TO_TCK (2500); scheds_cmp[1].allocations[4].glid = 0; scheds_cmp[1].allocations[5].end_offset_tck = MAC_ATU_TO_TCK (3907); scheds_cmp[1].allocations[5].glid = 0; /* next */ scheds_cmp[2].allocations[0].end_offset_tck = MAC_ATU_TO_TCK (50); scheds_cmp[2].allocations[0].glid = MAC_LID_SPC_HOLE; scheds_cmp[2].allocations[1].end_offset_tck = MAC_ATU_TO_TCK (500); scheds_cmp[2].allocations[1].glid = 0; scheds_cmp[2].allocations[2].end_offset_tck = MAC_ATU_TO_TCK (700); scheds_cmp[2].allocations[2].glid = 0; scheds_cmp[2].allocations[3].end_offset_tck = MAC_ATU_TO_TCK (1600); scheds_cmp[2].allocations[3].glid = 0; scheds_cmp[2].allocations[4].end_offset_tck = MAC_ATU_TO_TCK (2500); scheds_cmp[2].allocations[4].glid = 0; scheds_cmp[2].allocations[5].end_offset_tck = MAC_ATU_TO_TCK (3907); scheds_cmp[2].allocations[5].glid = 0; ca_schedule_t scheds; bsu_test_avln_create (&t, &avln); for (i = 0; i < COUNT(scheds_cmp); i++) { bsu_schedules_merge (t.bsu, &avln.bs.schedules, &scheds, i); for (j = 0; j < scheds.allocations_nb; j++) { test_fail_unless (scheds.allocations[j].end_offset_tck == scheds_cmp[i].allocations[j].end_offset_tck); test_fail_unless (scheds.allocations[j].glid == scheds_cmp[i].allocations[j].glid); } } } test_end; test_begin (test, "Ca schedules") { uint i, index; u32 bpsd[BSU_ACLF_BPSD_NB-1]; ca_schedule_t *sched; index = t.bsu->ca_index; bsu_test_avln_create (&t, &avln); bsu_ca_schedules (t.bsu, t.bsu->sta_avln); bsu_aclf_beacon_period_start_date (t.bsu->aclf, bpsd, COUNT (bpsd)); for (i = 0; i < t.ca.nb_beacon_periods; i++) { sched = ca_alloc_get_schedule (t.bsu->ca, i + index); test_fail_unless (bpsd[i] == t.ca.beacon_periods[i].start_date); test_fail_unless (i + index == t.ca.beacon_periods[i].schedule_index); } } test_end; bsu_test_uninit (&t); } void test_suite_bsu_schedule (test_t t) { test_suite_begin (t, "BSU schedules"); test_case_ca_schedules (t); }