summaryrefslogtreecommitdiff
path: root/cesar/bsu/aclf
diff options
context:
space:
mode:
authorlaranjeiro2010-05-17 09:53:08 +0000
committerlaranjeiro2010-05-17 09:53:08 +0000
commitb8e567af74a622c703f17b82cd1055b096a4787c (patch)
tree28df19fba552418ff71c6d8854bcda6f59c23a96 /cesar/bsu/aclf
parent839ad4e7615d5f5bc8724b38cc52eed2c52427b4 (diff)
cesar/bsu/aclf: fix unit tests
git-svn-id: svn+ssh://pessac/svn/cesar/trunk@7056 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'cesar/bsu/aclf')
-rw-r--r--cesar/bsu/aclf/test/utest/common.h2
-rw-r--r--cesar/bsu/aclf/test/utest/src/aclf.c1
-rw-r--r--cesar/bsu/aclf/test/utest/src/bpsd.c19
-rw-r--r--cesar/bsu/aclf/test/utest/src/common.c28
-rw-r--r--cesar/bsu/aclf/test/utest/src/freq.c42
5 files changed, 48 insertions, 44 deletions
diff --git a/cesar/bsu/aclf/test/utest/common.h b/cesar/bsu/aclf/test/utest/common.h
index c9c60ac495..d1f8a27c82 100644
--- a/cesar/bsu/aclf/test/utest/common.h
+++ b/cesar/bsu/aclf/test/utest/common.h
@@ -45,7 +45,7 @@ struct bsu_aclf_test_t
/** BSU ACLF context. */
bsu_aclf_t *aclf;
/** Phy simulation. */
- struct bsu_aclf_test_phy_t phy;
+ struct bsu_aclf_test_phy_t *phy;
/** Mac configuration. */
mac_config_t mac_config;
};
diff --git a/cesar/bsu/aclf/test/utest/src/aclf.c b/cesar/bsu/aclf/test/utest/src/aclf.c
index ad4b6cdd19..651669ffb8 100644
--- a/cesar/bsu/aclf/test/utest/src/aclf.c
+++ b/cesar/bsu/aclf/test/utest/src/aclf.c
@@ -12,6 +12,7 @@
*/
#include "common/std.h"
#include "lib/test.h"
+#include "bsu/aclf/test/utest/common.h"
void
test_suite_aclf__frequency (test_t t);
diff --git a/cesar/bsu/aclf/test/utest/src/bpsd.c b/cesar/bsu/aclf/test/utest/src/bpsd.c
index 1eb02af309..299a7d835d 100644
--- a/cesar/bsu/aclf/test/utest/src/bpsd.c
+++ b/cesar/bsu/aclf/test/utest/src/bpsd.c
@@ -82,7 +82,7 @@ test_case_aclf_estimate_beacon_period (test_t t)
*((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];
+ 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);
@@ -97,7 +97,7 @@ test_case_aclf_estimate_beacon_period (test_t t)
test_begin (t, "AC stable, ZC = 740 000 tick")
{
bsu_aclf_test_init (&test);
- test.phy.phy_type = TEST_ACLF_PHY_NONE;
+ 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;
@@ -134,7 +134,7 @@ test_case_aclf_compute_bto (test_t t)
{
bsu_aclf_test_init (&test_cco);
bsu_aclf_test_init (&test_sta);
- test_cco.phy.phy_type = test_phy_type[i];
+ 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;
@@ -145,8 +145,8 @@ test_case_aclf_compute_bto (test_t t)
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;
+ 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,
@@ -189,7 +189,6 @@ test_case_aclf_compute_bto (test_t t)
test_end;
}
-
void
test_case_aclf_shift_bpsd (test_t t)
{
@@ -197,17 +196,19 @@ test_case_aclf_shift_bpsd (test_t t)
test_begin (t, "shift")
{
uint i;
+ u32 now = phy_date ();
bsu_aclf_test_t test;
bsu_aclf_test_init (&test);
- for (i = 0; i < BSU_ACLF_BPSD_NB; i++)
- test.aclf->bpsd[i] = i * BSU_ACLF_BP_50HZ_TCK;
+ 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] == (i+1) *
+ test_fail_unless (test.aclf->bpsd[i] == now + (i+1) *
BSU_ACLF_BP_50HZ_TCK);
bsu_aclf_test_uninit (&test);
}
diff --git a/cesar/bsu/aclf/test/utest/src/common.c b/cesar/bsu/aclf/test/utest/src/common.c
index a240a698cd..5e2a8dab62 100644
--- a/cesar/bsu/aclf/test/utest/src/common.c
+++ b/cesar/bsu/aclf/test/utest/src/common.c
@@ -11,15 +11,20 @@
* \ingroup bsu_aclf
*/
#include "common/std.h"
+#include "bsu/aclf/test/utest/obj/zc_cross.h"
#include "bsu/aclf/test/utest/common.h"
#include <string.h>
+static struct bsu_aclf_test_phy_t phy_test_global;
+
void
bsu_aclf_test_init (bsu_aclf_test_t *t)
{
dbg_assert (t);
memset (t, 0, sizeof (bsu_aclf_test_t));
- t->aclf = bsu_aclf_init ((phy_t *) &t->phy, &t->mac_config);
+ memset (&phy_test_global, 0, sizeof (bsu_aclf_test_phy_t));
+ t->aclf = bsu_aclf_init ((phy_t *) &phy_test_global, &t->mac_config);
+ t->phy = &phy_test_global;
}
void
@@ -28,3 +33,24 @@ bsu_aclf_test_uninit (bsu_aclf_test_t *t)
dbg_assert (t);
bsu_aclf_uninit (t->aclf);
}
+
+static void
+phy_zero_cross (bsu_aclf_test_phy_t *test)
+{
+ u32 last_zc;
+ /* Compute last ZC. */
+ if (test->frequency)
+ {
+ last_zc = test->zc + zero_cross[test->zc_cross_index];
+ if (lesseq_mod2p32 (last_zc, test->phy))
+ test->zc = last_zc;
+ }
+}
+
+u32
+phy_date (void)
+{
+ phy_zero_cross (&phy_test_global);
+ phy_test_global.phy += 100;
+ return phy_test_global.phy;
+}
diff --git a/cesar/bsu/aclf/test/utest/src/freq.c b/cesar/bsu/aclf/test/utest/src/freq.c
index 81380b9dc2..679fac6235 100644
--- a/cesar/bsu/aclf/test/utest/src/freq.c
+++ b/cesar/bsu/aclf/test/utest/src/freq.c
@@ -15,10 +15,6 @@
#include "lib/test.h"
#include "lib/rnd.h"
#include "bsu/aclf/test/utest/common.h"
-#include "bsu/aclf/test/utest/obj/zc_cross.h"
-
-/** Will be used for the zc cross detection simulation. */
-static bsu_aclf_test_t test;
void
test_case_aclf_all_frequencies (test_t t)
@@ -29,19 +25,20 @@ test_case_aclf_all_frequencies (test_t t)
u32 acl_zc;
lib_rnd_t rnd;
lib_rnd_init (&rnd, 0x12324);
+ bsu_aclf_test_t test;
bsu_aclf_test_init (&test);
- for (test.phy.frequency = 40, test.phy.zc_cross_index = 0;
- test.phy.frequency <= 80;
- test.phy.frequency++, test.phy.zc_cross_index++)
+ for (test.phy->frequency = 40, test.phy->zc_cross_index = 0;
+ test.phy->frequency <= 80;
+ test.phy->frequency++, test.phy->zc_cross_index++)
{
- if (test.phy.frequency)
- acl_zc = MAC_MS_TO_TCK (1000 / test.phy.frequency) / 2;
+ if (test.phy->frequency)
+ acl_zc = MAC_MS_TO_TCK (1000 / test.phy->frequency) / 2;
else
acl_zc = 0;
- test.phy.phy = lib_rnd32 (&rnd);
- test.phy.zc = test.phy.phy - acl_zc + 1000;
+ test.phy->phy = lib_rnd32 (&rnd);
+ test.phy->zc = test.phy->phy - acl_zc + 1000;
bsu_aclf_acl_frequency_detection (test.aclf);
- if (test.phy.frequency < 56)
+ if (test.phy->frequency < 56)
test_fail_unless (test.aclf->frequency == BSU_ACLF_FREQ_50HZ);
else
test_fail_unless (test.aclf->frequency == BSU_ACLF_FREQ_60HZ);
@@ -57,24 +54,3 @@ test_suite_aclf__frequency (test_t t)
test_suite_begin (t, "Frequency tests");
test_case_aclf_all_frequencies (t);
}
-
-static void
-phy_zero_cross (bsu_aclf_test_phy_t *test)
-{
- u32 last_zc;
- /* Compute last ZC. */
- if (test->frequency)
- {
- last_zc = test->zc + zero_cross[test->zc_cross_index];
- if (lesseq_mod2p32 (last_zc, test->phy))
- test->zc = last_zc;
- }
-}
-
-u32
-phy_date (void)
-{
- phy_zero_cross (&test.phy);
- test.phy.phy += 100;
- return test.phy.phy;
-}