summaryrefslogtreecommitdiff
path: root/cesar/bsu/aclf/test
diff options
context:
space:
mode:
authorlaranjeiro2010-05-17 09:08:09 +0000
committerlaranjeiro2010-05-17 09:08:09 +0000
commitcd845de8614f39d44d3c518ec04591e3bf8e4134 (patch)
treed795f66b9a5a03c3fe0c42d5f5727c79e522e088 /cesar/bsu/aclf/test
parent05e9041696ed5816d4cb57bd15b99d3ca8d35c09 (diff)
cesar/bsu/aclf: add aclf sub module
git-svn-id: svn+ssh://pessac/svn/cesar/trunk@7016 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'cesar/bsu/aclf/test')
-rw-r--r--cesar/bsu/aclf/test/utest/Makefile22
-rw-r--r--cesar/bsu/aclf/test/utest/acl_period.sce12
-rw-r--r--cesar/bsu/aclf/test/utest/common.h72
-rw-r--r--cesar/bsu/aclf/test/utest/convertc.sce38
-rw-r--r--cesar/bsu/aclf/test/utest/estimateBP.sce41
-rw-r--r--cesar/bsu/aclf/test/utest/estimate_acl_freq_decrease.sce52
-rw-r--r--cesar/bsu/aclf/test/utest/estimate_acl_freq_increase.sce56
-rw-r--r--cesar/bsu/aclf/test/utest/estimate_acl_stable.sce54
-rw-r--r--cesar/bsu/aclf/test/utest/src/aclf.c35
-rw-r--r--cesar/bsu/aclf/test/utest/src/bpsd.c222
-rw-r--r--cesar/bsu/aclf/test/utest/src/common.c30
-rw-r--r--cesar/bsu/aclf/test/utest/src/freq.c82
-rw-r--r--cesar/bsu/aclf/test/utest/src/misc.c47
-rw-r--r--cesar/bsu/aclf/test/utest/zc_capture.sce18
-rw-r--r--cesar/bsu/aclf/test/utest/zc_capture_decrease.sce20
-rw-r--r--cesar/bsu/aclf/test/utest/zc_capture_increase.sce20
16 files changed, 821 insertions, 0 deletions
diff --git a/cesar/bsu/aclf/test/utest/Makefile b/cesar/bsu/aclf/test/utest/Makefile
new file mode 100644
index 0000000000..a343b40a55
--- /dev/null
+++ b/cesar/bsu/aclf/test/utest/Makefile
@@ -0,0 +1,22 @@
+PAGES= estimate_acl_freq_decrease estimate_acl_freq_increase\
+ estimate_acl_stable acl_period
+all: $(PAGES)
+
+%: %.sce
+ scilab -nw -f $<
+
+SCILAB_FILE= $(OBJ_DIR)/result_increase.csv $(OBJ_DIR)/table_increase.h \
+ $(OBJ_DIR)/result_increase.h $(OBJ_DIR)/result_stable.csv \
+ $(OBJ_DIR)/table.h $(OBJ_DIR)/result_stable.h \
+ $(OBJ_DIR)/table_decrease.h $(OBJ_DIR)/result_decrease.h \
+ $(OBJ_DIR)/result_decrease.csv $(OBJ_DIR)/zc_cross.h
+
+CLEAN_FILES+=$(SCILAB_FILE)
+
+BASE = ../../../..
+
+HOST_PROGRAMS = aclf
+aclf_SOURCES = aclf.c common.c bpsd.c freq.c misc.c
+aclf_MODULES = lib bsu/aclf
+
+include $(BASE)/common/make/top.mk
diff --git a/cesar/bsu/aclf/test/utest/acl_period.sce b/cesar/bsu/aclf/test/utest/acl_period.sce
new file mode 100644
index 0000000000..7eb2a4c080
--- /dev/null
+++ b/cesar/bsu/aclf/test/utest/acl_period.sce
@@ -0,0 +1,12 @@
+// C array writer
+getf('convertc.sce');
+
+frequency = [40:1:80];
+acl_period = 1 ./ frequency;
+bp_period_tck = 2 .* acl_period ./ 40e-9;
+zc_tck = bp_period_tck ./ 4
+
+// Write the result.
+convertc_array ('obj/zc_cross.h', 'zero_cross', zc_tck);
+
+exit;
diff --git a/cesar/bsu/aclf/test/utest/common.h b/cesar/bsu/aclf/test/utest/common.h
new file mode 100644
index 0000000000..69da95362e
--- /dev/null
+++ b/cesar/bsu/aclf/test/utest/common.h
@@ -0,0 +1,72 @@
+#ifndef bsu_aclf_test_utest_common_h
+#define bsu_aclf_test_utest_common_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2010 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file bsu/aclf/test/utest/src/common.c
+ * \brief Common functions for ACLF tests.
+ * \ingroup bsu_aclf
+ */
+#include "bsu/aclf/aclf.h"
+
+enum bsu_aclf_test_aclf_phy_t
+{
+ BSU_ACLF_TEST_ACLF_PHY_NONE,
+ BSU_ACLF_TEST_ACLF_PHY_AC_STABLE,
+ BSU_ACLF_TEST_ACLF_PHY_AC_INC,
+ BSU_ACLF_TEST_ACLF_PHY_AC_DEC,
+ BSU_ACLF_TEST_ACLF_PHY_AC_CABLE
+};
+
+struct bsu_aclf_test_phy_t
+{
+ /** Frequency simulation. */
+ uint frequency;
+ /** Phy simulation context. */
+ u32 phy;
+ /** Zero cross value. */
+ u32 zc_cross_index;
+ /** Last Zero Cross simulated. */
+ u32 zc;
+ /** ACL type. */
+ enum bsu_aclf_test_aclf_phy_t phy_type;
+ /** Table index for some tests. */
+ uint table_index;
+};
+typedef struct bsu_aclf_test_phy_t bsu_aclf_test_phy_t;
+
+struct bsu_aclf_test_t
+{
+ /** BSU ACLF context. */
+ bsu_aclf_t aclf;
+ /** Phy simulation. */
+ struct bsu_aclf_test_phy_t phy;
+ /** Mac configuration. */
+ mac_config_t mac_config;
+};
+typedef struct bsu_aclf_test_t bsu_aclf_test_t;
+
+BEGIN_DECLS
+
+/**
+ * Initialise the test.
+ * \param test the bsu aclf test context.
+ */
+void
+bsu_aclf_test_init (bsu_aclf_test_t *t);
+
+/**
+ * Uninitialise the test.
+ * \param test the bsu aclf test context.
+ */
+void
+bsu_aclf_test_uninit (bsu_aclf_test_t *t);
+
+END_DECLS
+
+#endif /* bsu_aclf_test_utest_common_h */
diff --git a/cesar/bsu/aclf/test/utest/convertc.sce b/cesar/bsu/aclf/test/utest/convertc.sce
new file mode 100644
index 0000000000..fa744b1ec6
--- /dev/null
+++ b/cesar/bsu/aclf/test/utest/convertc.sce
@@ -0,0 +1,38 @@
+// SPiDCOM Technologies.
+// Nélio Laranjeiro
+// 16-05-2008
+// Cesar project.
+
+// Convert an array of values to a C array.
+
+// @param file_name the file name to write the data in. The file shall be a
+// c file.
+// @param array_name the array name.
+// @param array the array to write.
+function convertc_array (file_name, array_name, array)
+
+nb_points = length(array);
+
+define_name = file_name + "_" + array_name;
+define_name = strsubst (define_name, ".", "_")
+define_name = strsubst (define_name, "/", "_")
+
+// Provide an array for the C unit test.
+result_file = file ('open', file_name, 'unknown');
+ fprintf (result_file, "#ifndef %s", define_name);
+ fprintf (result_file, "#define %s", define_name);
+ fprintf (result_file, "/* File generated by scilab */");
+ fprintf (result_file, "");
+ fprintf (result_file, "uint %s [%d] = {", array_name, nb_points);
+ for i = 1:nb_points - 1
+ fprintf (result_file, " %d, ", array(i));
+ end
+
+// Write the last value.
+fprintf (result_file, "%d };", array(nb_points));
+fprintf (result_file, "uint %s = %d;", array_name + '_length', nb_points);
+
+fprintf (result_file, "#endif /* %s */", define_name);
+file ('close', result_file);
+
+endfunction
diff --git a/cesar/bsu/aclf/test/utest/estimateBP.sce b/cesar/bsu/aclf/test/utest/estimateBP.sce
new file mode 100644
index 0000000000..3fe548737d
--- /dev/null
+++ b/cesar/bsu/aclf/test/utest/estimateBP.sce
@@ -0,0 +1,41 @@
+// SPiDCOM Technologies.
+// Nélio Laranjeiro
+// 16-05-2008
+// Cesar project.
+
+//Estimate the beacon period using the synchronisation of the PWL.
+//This shall use a function to generate the ACL frequency.
+
+// The function phy_clock_get_zero_cross_captured_date shall be written in
+// function of the test which is being done.
+// WARN : Import the file containing the function before using this script.
+
+// compute the estimation of the ACL period.
+// @param cp the CP context.
+// - date_ntb[2]
+// - bp_ntb
+// - zc_ntb
+// - per_ntb
+// @return the [per, date_ntb']
+function [res] = estimate_beacon_period (cp)
+
+date_ntb = [cp(1) ,cp(2)];
+bp_ntb = cp(3);
+zc_ntb = cp(4);
+per_ntb = cp(5);
+
+date_ntb(2) = date_ntb(1);
+date_ntb(1) = phy_clock_get_zero_cross (date_ntb(2));
+diff_ntb = modulo((date_ntb(1) - date_ntb(2)), bp_ntb + 10000);
+
+if diff_ntb < 3*zc_ntb
+ diff_ntb = (4-int((diff_ntb / zc_ntb))) * zc_ntb + diff_ntb;
+end
+
+// Using a WP with a K = 4.
+per_ntb = int(per_ntb + 0.0625 * (diff_ntb - per_ntb));
+
+res = [date_ntb, bp_ntb, zc_ntb, per_ntb];
+return res;
+
+endfunction
diff --git a/cesar/bsu/aclf/test/utest/estimate_acl_freq_decrease.sce b/cesar/bsu/aclf/test/utest/estimate_acl_freq_decrease.sce
new file mode 100644
index 0000000000..a57a07394b
--- /dev/null
+++ b/cesar/bsu/aclf/test/utest/estimate_acl_freq_decrease.sce
@@ -0,0 +1,52 @@
+// SPiDCOM Technologies.
+// Nélio Laranjeiro
+// 16-05-2008
+// Cesar project.
+
+// Launch a test to verify the estimation function.
+
+// load the file, containing the function to generate a stable 50hz zero
+// cross.
+getf ('zc_capture_decrease.sce');
+getf ('estimateBP.sce');
+
+// C array writer
+getf('convertc.sce');
+
+// Initialise the environment.
+date_ntb = zeros(1,2);
+// 50 Hz in ticks.
+bp_ntb = 1e6;
+zc_ntb = bp_ntb / 4;
+
+nb_points = 1e3;
+
+cp = [date_ntb, bp_ntb, zc_ntb, bp_ntb];
+
+//Vector of points.
+result = zeros(nb_points,length(cp) + 1);
+for i = 1:1000
+ cp = estimate_beacon_period (cp);
+
+ result (i,:) = [cp, cp(1) - cp(2)];
+ bp_ntb = cp(3) + 1e6;
+end
+
+// Write the result in a file.
+result_file = file('open', 'obj/result_decrease.csv', 'unknown');
+fprintf (result_file, "Per, Per(ATU), Zc 1, Zc 2, Diff\n");
+for i = 1:nb_points
+ fprintf (result_file, "%d, %d, %d, %d, %d\n", result(i,5), int(result(i,5) / 256), result(i,1), result(i,2), result(i,6));
+end
+// Close the file.
+file('close', result_file);
+
+// Write the array.
+res = result(:,1);
+convertc_array ('obj/table_decrease.h', 'ac_decrease', res);
+
+// Write the result of the simulation.
+res = result (:,5);
+convertc_array ('obj/result_decrease.h', 'result_ac_decrease', res);
+
+exit;
diff --git a/cesar/bsu/aclf/test/utest/estimate_acl_freq_increase.sce b/cesar/bsu/aclf/test/utest/estimate_acl_freq_increase.sce
new file mode 100644
index 0000000000..be357657bf
--- /dev/null
+++ b/cesar/bsu/aclf/test/utest/estimate_acl_freq_increase.sce
@@ -0,0 +1,56 @@
+// SPiDCOM Technologies.
+// Nélio Laranjeiro
+// 16-05-2008
+// Cesar project.
+
+// Launch a test to verify the estimation function.
+
+// load the file, containing the function to generate a stable 50hz zero
+// cross.
+getf ('zc_capture_increase.sce');
+getf ('estimateBP.sce');
+
+// C array writer
+getf('convertc.sce');
+
+// Initialise the environment.
+date_ntb = zeros (1,2);
+// 50 Hz in ticks.
+bp_ntb = 1e6;
+zc_ntb = bp_ntb / 4;
+
+// Number of points.
+nb_points = 1000;
+
+
+cp = [date_ntb, bp_ntb, zc_ntb, bp_ntb];
+
+//Vector of points.
+result = zeros(nb_points,length(cp) + 1);
+
+for i = 1:nb_points
+ cp = estimate_beacon_period (cp);
+
+ result (i,:) = [cp, cp(1) - cp(2)];
+ bp_ntb = cp(3) + 1e6;
+end
+
+// Write the result in a file.
+result_file = file('open', 'obj/result_increase.csv', 'unknown');
+
+fprintf (result_file, "Per, Per(ATU), Zc 1, Zc 2, diff\n");
+for i = 1:nb_points
+ fprintf (result_file, "%d, %d, %d, %d, %d\n", result(i,5), int(result(i,5) / 256), result(i,1), result(i,2), result(i,6));
+end
+// Close the file.
+file('close', result_file);
+
+// Write the array.
+res = result(:,1);
+convertc_array ('obj/table_increase.h', 'ac_increase', res);
+
+// Write the result of the simulation.
+res = result (:,5);
+convertc_array ('obj/result_increase.h', 'result_ac_increase', res);
+
+exit;
diff --git a/cesar/bsu/aclf/test/utest/estimate_acl_stable.sce b/cesar/bsu/aclf/test/utest/estimate_acl_stable.sce
new file mode 100644
index 0000000000..69b2967d98
--- /dev/null
+++ b/cesar/bsu/aclf/test/utest/estimate_acl_stable.sce
@@ -0,0 +1,54 @@
+// SPiDCOM Technologies.
+// Nélio Laranjeiro
+// 16-05-2008
+// Cesar project.
+
+// Launch a test to verify the estimation function.
+
+// load the file, containing the function to generate a stable 50hz zero
+// cross.
+getf ('zc_capture.sce');
+getf ('estimateBP.sce');
+
+// C array writer
+getf('convertc.sce');
+
+// Initialise the environment.
+date_ntb = zeros (1,2);
+// 50 Hz in ticks.
+bp_ntb = 1e6;
+zc_ntb = bp_ntb / 4;
+
+// Number of points.
+nb_points = 1e3;
+
+cp = [date_ntb, bp_ntb, zc_ntb, bp_ntb];
+
+//Vector of points.
+result = zeros(nb_points,length(cp) + 1);
+
+for i = 1:nb_points
+ cp = estimate_beacon_period (cp);
+
+ result (i,:) = [cp, cp(1) - cp(2)];
+ bp_ntb = cp(3) + 1e6;
+end
+
+// Write the result in a file.
+result_file = file('open', 'obj/result_stable.csv', 'unknown');
+fprintf (result_file, "Per, Per(ATU), Zc 1, Zc 2, diff\n");
+for i = 1:nb_points
+ fprintf (result_file, "%d, %d, %d, %d, %d\n", result(i,5), int(result(i,5) / 256), result(i,1), result(i,2), result(6));
+end
+// Close the file.
+file('close', result_file);
+
+// Write the array.
+res = result(:,1);
+convertc_array ('obj/table.h', 'ac_stable', res);
+
+// Write the result of the simulation.
+res = result (:,5);
+convertc_array ('obj/result_stable.h', 'result_ac_stable', res);
+
+exit;
diff --git a/cesar/bsu/aclf/test/utest/src/aclf.c b/cesar/bsu/aclf/test/utest/src/aclf.c
new file mode 100644
index 0000000000..ad4b6cdd19
--- /dev/null
+++ b/cesar/bsu/aclf/test/utest/src/aclf.c
@@ -0,0 +1,35 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2010 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file bsu/aclf/test/utest/src/aclf.c
+ * \brief BSU ACLF unit tests.
+ * \ingroup bsu_aclf
+ */
+#include "common/std.h"
+#include "lib/test.h"
+
+void
+test_suite_aclf__frequency (test_t t);
+
+void
+test_suite_aclf__bpsd_accurate (test_t t);
+
+void
+test_suite_aclf__misc (test_t t);
+
+int
+main (int argc, char **argv)
+{
+ test_t test;
+ test_init (test, argc, argv);
+ test_suite_aclf__frequency (test);
+ test_suite_aclf__bpsd_accurate (test);
+ test_suite_aclf__misc (test);
+ test_result (test);
+ return test_nb_failed (test) == 0 ? 0 : 1;
+}
diff --git a/cesar/bsu/aclf/test/utest/src/bpsd.c b/cesar/bsu/aclf/test/utest/src/bpsd.c
new file mode 100644
index 0000000000..45b48544bb
--- /dev/null
+++ b/cesar/bsu/aclf/test/utest/src/bpsd.c
@@ -0,0 +1,222 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2010 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \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 "bsu/aclf/test/utest/common.h"
+#include "bsu/aclf/test/utest/obj/table.h"
+#include "bsu/aclf/test/utest/obj/table_increase.h"
+#include "bsu/aclf/test/utest/obj/table_decrease.h"
+#include "bsu/aclf/test/utest/obj/result_stable.h"
+#include "bsu/aclf/test/utest/obj/result_increase.h"
+#include "bsu/aclf/test/utest/obj/result_decrease.h"
+
+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);
+ test.phy.phy_type = test_phy_type[i];
+ *((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 < 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);
+ 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;
+ 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;
+ test.aclf.beacon_period = BSU_ACLF_BP_50HZ_TCK;
+ 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) *
+ 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);
+}
diff --git a/cesar/bsu/aclf/test/utest/src/common.c b/cesar/bsu/aclf/test/utest/src/common.c
new file mode 100644
index 0000000000..662a7be2ea
--- /dev/null
+++ b/cesar/bsu/aclf/test/utest/src/common.c
@@ -0,0 +1,30 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2010 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file bsu/aclf/test/utest/src/common.c
+ * \brief Common functions for ACLF tests.
+ * \ingroup bsu_aclf
+ */
+#include "common/std.h"
+#include "bsu/aclf/test/utest/common.h"
+#include <string.h>
+
+void
+bsu_aclf_test_init (bsu_aclf_test_t *t)
+{
+ dbg_assert (t);
+ memset (t, 0, sizeof (bsu_aclf_test_t));
+ bsu_aclf_init (&t->aclf, (phy_t *) &t->phy, &t->mac_config);
+}
+
+void
+bsu_aclf_test_uninit (bsu_aclf_test_t *t)
+{
+ dbg_assert (t);
+ bsu_aclf_uninit (&t->aclf);
+}
diff --git a/cesar/bsu/aclf/test/utest/src/freq.c b/cesar/bsu/aclf/test/utest/src/freq.c
new file mode 100644
index 0000000000..46565d6dd9
--- /dev/null
+++ b/cesar/bsu/aclf/test/utest/src/freq.c
@@ -0,0 +1,82 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2010 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file bsu/aclf/test/utest/src/freq.c
+ * \brief Frequency test error.
+ * \ingroup bsu_aclf
+ */
+#include "common/std.h"
+#include "mac/common/timings.h"
+#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)
+{
+ test_case_begin (t, "All frequency possible");
+ test_begin (t, "Frequency increase.")
+ {
+ u32 acl_zc;
+ lib_rnd_t rnd;
+ lib_rnd_init (&rnd, 0x12324);
+ 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++)
+ {
+ 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;
+ bsu_aclf_acl_frequency_detection (&test.aclf);
+ 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);
+ }
+ bsu_aclf_test_uninit (&test);
+ }
+ test_end;
+}
+
+void
+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 (phy_t *ctx)
+{
+ bsu_aclf_test_phy_t *test = (bsu_aclf_test_phy_t *) ctx;
+ dbg_assert (ctx);
+ phy_zero_cross (test);
+ test->phy += 100;
+ return test->phy;
+}
diff --git a/cesar/bsu/aclf/test/utest/src/misc.c b/cesar/bsu/aclf/test/utest/src/misc.c
new file mode 100644
index 0000000000..cace0e3629
--- /dev/null
+++ b/cesar/bsu/aclf/test/utest/src/misc.c
@@ -0,0 +1,47 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2010 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file bsu/aclf/test/utest/src/misc.c
+ * \brief Miscellaneous tests.
+ * \ingroup bsu_aclf
+ *
+ */
+#include "common/std.h"
+#include "lib/test.h"
+#include "bsu/aclf/aclf.h"
+#include "bsu/aclf/test/utest/common.h"
+
+void
+test_case_aclf__beacon_period (test_t test)
+{
+ test_case_begin (test, "ACLF beacon period");
+ test_begin (test, "Get the beacon period")
+ {
+ u32 bpsd [4] = { 0, 30, 70, 150 };
+ uint i;
+ bsu_aclf_test_t t;
+ bsu_aclf_test_init (&t);
+ for (i = 0; i < COUNT(bpsd); i++)
+ t.aclf.bpsd[i] = bpsd[i];
+ for (i = 0; i < COUNT(bpsd) - 1; i++)
+ {
+ test_fail_unless (bpsd[i+1] - bpsd[i]
+ == bsu_aclf_beacon_period (&t.aclf));
+ bsu_aclf_shift_beacon_period_start_date (&t.aclf);
+ }
+ bsu_aclf_test_uninit (&t);
+ }
+ test_end;
+}
+
+void
+test_suite_aclf__misc (test_t test)
+{
+ test_suite_begin (test, "Miscellaneous tests");
+ test_case_aclf__beacon_period (test);
+}
diff --git a/cesar/bsu/aclf/test/utest/zc_capture.sce b/cesar/bsu/aclf/test/utest/zc_capture.sce
new file mode 100644
index 0000000000..e74574d021
--- /dev/null
+++ b/cesar/bsu/aclf/test/utest/zc_capture.sce
@@ -0,0 +1,18 @@
+// SPiDCOM Technologies.
+// Nélio Laranjeiro
+// 16-05-2008
+// Cesar project.
+
+// This script will provide a function to generate a perfect 50 Hz frequency
+// AC Line based on the NTB date.
+
+
+// Function to simulate the frequency of the AC line.
+// @param phy the previous value provided.
+// @Return phy + 250 000
+function phy = phy_clock_get_zero_cross (phy)
+
+phy = phy + 1000000;
+return phy;
+
+endfunction
diff --git a/cesar/bsu/aclf/test/utest/zc_capture_decrease.sce b/cesar/bsu/aclf/test/utest/zc_capture_decrease.sce
new file mode 100644
index 0000000000..e094f2e1c7
--- /dev/null
+++ b/cesar/bsu/aclf/test/utest/zc_capture_decrease.sce
@@ -0,0 +1,20 @@
+// SPiDCOM Technologies.
+// Nélio Laranjeiro
+// 16-05-2008
+// Cesar project.
+
+// This script will provide a function to generate a 50 Hz frequency
+// AC Line based on the NTB date with a little jitter.
+
+
+// Function to simulate the frequency of the AC line.
+// @param phy the previous value provided.
+// @param var The variation of frequency.
+// @Return phy + 250 000
+function phy = phy_clock_get_zero_cross (phy)
+
+var = int(rand (1) * 100000);
+phy = phy + 1000000 - var;
+return phy;
+
+endfunction
diff --git a/cesar/bsu/aclf/test/utest/zc_capture_increase.sce b/cesar/bsu/aclf/test/utest/zc_capture_increase.sce
new file mode 100644
index 0000000000..c412c6f689
--- /dev/null
+++ b/cesar/bsu/aclf/test/utest/zc_capture_increase.sce
@@ -0,0 +1,20 @@
+// SPiDCOM Technologies.
+// Nélio Laranjeiro
+// 16-05-2008
+// Cesar project.
+
+// This script will provide a function to generate a 50 Hz frequency
+// AC Line based on the NTB date with a little jitter.
+
+
+// Function to simulate the frequency of the AC line.
+// @param phy the previous value provided.
+// @param var The variation of frequency.
+// @Return phy + 250 000
+function phy = phy_clock_get_zero_cross (phy)
+
+var = int(rand (1) * 1000);
+phy = phy + 1e6 + var;
+return phy;
+
+endfunction