/* Cesar project {{{ * * Copyright (C) 2010 Spidcom * * <<>> * * }}} */ /** * \file bsu/aclf/test/utest/src/bpsd.c * \brief Beacon Period Start Date accurate test. * \ingroup bsu_aclf */ #include "common/std.h" #include "lib/test.h" #include "common.h" #include "table_stable.h" #include "table_increase.h" #include "table_decrease.h" #include "result_stable.h" #include "result_increase.h" #include "result_decrease.h" void bsu_aclf_ac_compute_beacon_period_start_date (bsu_aclf_t *ctx); void bsu_aclf_shift_beacon_period_start_date (bsu_aclf_t *ctx); static u32 zc_test [] = {0, 740000, 1480000}; static u32 zc_test_len = 3; enum test_pwl_phy_t { TEST_ACLF_PHY_NONE, TEST_ACLF_PHY_AC_STABLE, TEST_ACLF_PHY_AC_INC, TEST_ACLF_PHY_AC_DEC, TEST_ACLF_PHY_ZC_TEST, TEST_ACLF_PHY_AC_CABLE }; u32 phy_clock_get_zero_cross_captured_date (phy_t *ctx) { bsu_aclf_test_phy_t *test = (bsu_aclf_test_phy_t *) ctx; switch (test->phy_type) { case TEST_ACLF_PHY_NONE: return test->zc; break; case TEST_ACLF_PHY_AC_STABLE: return ac_stable[test->table_index++]; break; case TEST_ACLF_PHY_AC_INC: return ac_increase[test->table_index++]; break; case TEST_ACLF_PHY_AC_DEC: return ac_decrease[test->table_index++]; break; case TEST_ACLF_PHY_ZC_TEST: return zc_test[test->table_index++]; break; default: return 0; break; } } void test_case_aclf_estimate_beacon_period (test_t t) { u32 *tables[3] = {result_ac_stable, result_ac_increase, result_ac_decrease}; enum bsu_aclf_test_aclf_phy_t test_phy_type[3] = {BSU_ACLF_TEST_ACLF_PHY_AC_STABLE, BSU_ACLF_TEST_ACLF_PHY_AC_INC, BSU_ACLF_TEST_ACLF_PHY_AC_DEC}; bsu_aclf_test_t test; uint nb_iter; test_case_begin (t, "Beacon period estimation"); test_begin (t, "AC Stable, increase, decrease") { uint i; for (i = 0; i < 3; i++) { bsu_aclf_test_init (&test); *((bsu_aclf_frequency_t*) &test.aclf->frequency) = BSU_ACLF_FREQ_50HZ; *((bsu_aclf_bp_t*) &test.aclf->bp) = BSU_ACLF_BP_50HZ_TCK; *((uint*) &test.aclf->zc) = BSU_ACLF_ZC_50HZ_TCK; test.aclf->beacon_period = test.aclf->bp; test.phy->phy_type = test_phy_type[i]; for (nb_iter = 0; nb_iter < ac_stable_length; nb_iter ++) { bsu_aclf_ac_compute_beacon_period_start_date (test.aclf); test_fail_if (test.aclf->beacon_period != tables[i][nb_iter], "Estimation is false"); } bsu_aclf_test_uninit (&test); } } test_end; test_begin (t, "AC stable, ZC = 740 000 tick") { bsu_aclf_test_init (&test); test.phy->phy_type = TEST_ACLF_PHY_NONE; *((uint*) &test.aclf->frequency) = BSU_ACLF_FREQ_50HZ; *((uint*) &test.aclf->bp) = BSU_ACLF_BP_50HZ_TCK; *((uint*) &test.aclf->zc) = BSU_ACLF_ZC_50HZ_TCK; test.aclf->beacon_period = test.aclf->bp; for (nb_iter = 0; nb_iter < zc_test_len; nb_iter ++) { bsu_aclf_ac_compute_beacon_period_start_date (test.aclf); test_fail_unless (test.aclf->beacon_period == BSU_ACLF_BP_50HZ_TCK); } bsu_aclf_test_uninit (&test); } test_end; } void test_case_aclf_compute_bto (test_t t) { u32 *tables[3] = {result_ac_stable, result_ac_increase, result_ac_decrease}; enum bsu_aclf_test_aclf_phy_t test_phy_type[3] = {BSU_ACLF_TEST_ACLF_PHY_AC_STABLE, BSU_ACLF_TEST_ACLF_PHY_AC_INC, BSU_ACLF_TEST_ACLF_PHY_AC_DEC}; bsu_aclf_test_t test_cco, test_sta; uint nb_iter; test_case_begin (t, "BTO compute"); test_begin (t, "AC Stable, increase and decrease") { uint i, j, bto_nb = 4, bpsd_nb = 6; s16 btos_cco[bto_nb], btos_sta[bto_nb]; u32 bpsd_cco[bpsd_nb], bpsd_sta[bpsd_nb], bts; int bto; for (i = 0; i < 3; i++) { bsu_aclf_test_init (&test_cco); bsu_aclf_test_init (&test_sta); test_cco.phy->phy_type = test_phy_type[i]; *((uint*) &test_cco.aclf->frequency) = BSU_ACLF_FREQ_50HZ; *((uint*) &test_cco.aclf->bp) = BSU_ACLF_BP_50HZ_TCK; *((uint*) &test_cco.aclf->zc) = BSU_ACLF_ZC_50HZ_TCK; *((uint*) &test_sta.aclf->frequency) = BSU_ACLF_FREQ_50HZ; *((uint*) &test_sta.aclf->bp) = BSU_ACLF_BP_50HZ_TCK; *((uint*) &test_sta.aclf->zc) = BSU_ACLF_ZC_50HZ_TCK; test_cco.aclf->beacon_period = test_cco.aclf->bp; test_sta.aclf->beacon_period = test_sta.aclf->bp; for (nb_iter = 0; nb_iter < ac_stable_length; nb_iter ++) { test_cco.phy->phy += tables[i][nb_iter]; test_cco.phy->zc = test_cco.phy->phy - BSU_ACLF_ZC_50HZ_TCK; bsu_aclf_ac_compute_beacon_period_start_date (test_cco.aclf); bsu_aclf_bto (test_cco.aclf, btos_cco, bto_nb); bsu_aclf_beacon_period_start_date (test_cco.aclf, bpsd_cco, bpsd_nb); /* BTS value is use to simulate the STA beacon reception which * compute the beacon period start date using the BTS and the * BTOs of the central beacon. */ bts = bpsd_cco[1]; bsu_aclf_compute_beacon_period_start_date (test_sta.aclf, bts, btos_cco, 0, 0); bsu_aclf_bto (test_sta.aclf, btos_sta, bto_nb); bsu_aclf_beacon_period_start_date (test_sta.aclf, bpsd_sta, bpsd_nb); test_fail_unless (bpsd_sta[0] == bpsd_cco[1]); for (j = 0; j < HPAV_BEACON_BTO_NB; j++) { if (btos_sta[j] != HPAV_BEACON_BTO_INVALID) test_fail_unless (bpsd_sta[j+1] == bpsd_cco[j+2]); else test_fail_unless (bpsd_sta[j+1] == bts + (j+1)*test_sta.aclf->bp); } for (j = 0; j < HPAV_BEACON_BTO_NB; j++) { bto = bpsd_cco[j+2] - bts - (j+1)*test_cco.aclf->bp; if (ABS(bto) >> 15 == 0) { test_fail_unless (bts + (j+1) * test_cco.aclf->bp + btos_cco[j] == bpsd_cco[2+j]); } else test_fail_unless (btos_cco[j] == HPAV_BEACON_BTO_INVALID); } } bsu_aclf_test_uninit (&test_cco); } } test_end; } void test_case_aclf_shift_bpsd (test_t t) { test_case_begin (t, "Shift bpsd"); test_begin (t, "shift") { uint i; u32 now = phy_date (); bsu_aclf_test_t test; bsu_aclf_test_init (&test); for (i = 0; i < COUNT (test.aclf->bpsd); i++) test.aclf->bpsd[i] = i * BSU_ACLF_BP_50HZ_TCK + now; test.aclf->beacon_period = BSU_ACLF_BP_50HZ_TCK; test.phy->phy = test.aclf->bpsd[1]; bsu_aclf_shift_beacon_period_start_date (test.aclf); test_fail_unless ( test.aclf->bpsd[1] == bsu_aclf_beacon_period_start_date_next (test.aclf)); for (i = 0; i < BSU_ACLF_BPSD_NB - 1; i++) test_fail_unless (test.aclf->bpsd[i] == now + (i+1) * BSU_ACLF_BP_50HZ_TCK); bsu_aclf_test_uninit (&test); } test_end; } void test_suite_aclf__bpsd_accurate (test_t t) { test_suite_begin (t, "Beacon Period Start Date accurate"); test_case_aclf_estimate_beacon_period (t); test_case_aclf_compute_bto (t); test_case_aclf_shift_bpsd (t); }