summaryrefslogtreecommitdiff
path: root/cesar/mac/common/test/tonemap/src
diff options
context:
space:
mode:
authorsave2008-04-07 14:17:42 +0000
committersave2008-04-07 14:17:42 +0000
commit3d58a62727346b7ac1a6cb36fed1a06ed72228dd (patch)
treed7788c3cf9f76426aef0286d0202e2097f0fa0eb /cesar/mac/common/test/tonemap/src
parent095dca4b0a8d4924093bab424f71f588fdd84613 (diff)
Moved the complete svn base into the cesar directory.
git-svn-id: svn+ssh://pessac/svn/cesar/trunk@1769 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'cesar/mac/common/test/tonemap/src')
-rw-r--r--cesar/mac/common/test/tonemap/src/test_tonemap.c258
1 files changed, 258 insertions, 0 deletions
diff --git a/cesar/mac/common/test/tonemap/src/test_tonemap.c b/cesar/mac/common/test/tonemap/src/test_tonemap.c
new file mode 100644
index 0000000000..d7484c9c5d
--- /dev/null
+++ b/cesar/mac/common/test/tonemap/src/test_tonemap.c
@@ -0,0 +1,258 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file src/test_tonemap.c
+ * \brief Test tonemap functions.
+ * \ingroup test
+ */
+#include "common/std.h"
+
+#include "lib/test.h"
+#include "lib/rnd.h"
+
+#include "mac/common/tonemap.h"
+#include "mac/common/tonemask.h"
+#include "mac/common/timings.h"
+
+void
+tonemap_comp_test_case (test_t t)
+{
+ test_case_begin (t, "comp");
+ test_begin (t, "ble")
+ {
+ struct ble_param_t
+ {
+ phy_fecrate_t fecrate;
+ u32 p_pberror_uf32;
+ phy_gil_t gil;
+ uint symbol_us;
+ };
+ static const struct ble_param_t ble_param[] = {
+ { PHY_FEC_RATE_1_2, CONST_UF32 (0.0), PHY_GIL_567,
+ MAC_TCK_TO_US (MAC_DX567_TCK) },
+ { PHY_FEC_RATE_1_2, CONST_UF32 (0.05), PHY_GIL_567,
+ MAC_TCK_TO_US (MAC_DX567_TCK) },
+ { PHY_FEC_RATE_1_2, CONST_UF32 (0.25), PHY_GIL_567,
+ MAC_TCK_TO_US (MAC_DX567_TCK) },
+ { PHY_FEC_RATE_1_2, CONST_UF32 (0.5), PHY_GIL_567,
+ MAC_TCK_TO_US (MAC_DX567_TCK) },
+ { PHY_FEC_RATE_1_2, CONST_UF32 (0.75), PHY_GIL_567,
+ MAC_TCK_TO_US (MAC_DX567_TCK) },
+ { PHY_FEC_RATE_16_21, CONST_UF32 (0.33), PHY_GIL_417,
+ MAC_TCK_TO_US (MAC_DX417_TCK) },
+ { PHY_FEC_RATE_1_2, CONST_UF32 (0.03), PHY_GIL_3534,
+ MAC_TCK_TO_US (MAC_DX3534_TCK) },
+ { PHY_FEC_RATE_16_21, CONST_UF32 (0.01), PHY_GIL_417,
+ MAC_TCK_TO_US (MAC_DX417_TCK) },
+ };
+ uint i;
+ for (i = 0; i < COUNT (ble_param); i++)
+ {
+ const struct ble_param_t *p = &ble_param[i];
+ uint bits_per_symbol;
+ for (bits_per_symbol = 1;
+ bits_per_symbol < TONEMAP_BITS_PER_SYMBOL_MAX;
+ bits_per_symbol++)
+ {
+ double ble_f = (double) bits_per_symbol
+ * (p->fecrate == PHY_FEC_RATE_1_2 ? 0.5 : 16.0 / 21.0)
+ * (1.0 - ((double) p->p_pberror_uf32 / (1ull << 32)))
+ / p->symbol_us;
+ uint ble_uf5 = (1u << 5) * ble_f + 0.5;
+ u8 ble = tonemap_ble (bits_per_symbol, p->fecrate,
+ p->p_pberror_uf32, p->gil);
+ uint mant, exp;
+ uint ble_l_uf5, ble_m_uf5;
+ /* One less. */
+ if (ble != 0)
+ {
+ u8 ble_l = ble >> 3 | ble << 5;
+ ble_l--;
+ ble_l = ble_l >> 5 | ble_l << 3;
+ mant = ble_l >> 3; exp = ble_l & 0x7;
+ ble_l_uf5 = ((mant + 32) << (exp + 1)) + (1 << exp);
+ }
+ else
+ ble_l_uf5 = 0;
+ /* One more. */
+ if (ble != 0xff)
+ {
+ u8 ble_m = ble >> 3 | ble << 5;
+ ble_m++;
+ ble_m = ble_m >> 5 | ble_m << 3;
+ mant = ble_m >> 3; exp = ble_m & 0x7;
+ ble_m_uf5 = ((mant + 32) << (exp + 1)) + (1 << exp);
+ }
+ else
+ ble_m_uf5 = 0xffffffff;
+ /* Is it in between? */
+ test_fail_unless (ble_l_uf5 <= ble_uf5
+ && ble_uf5 < ble_m_uf5);
+ }
+ }
+ } test_end;
+ test_begin (t, "bits per pb")
+ {
+ phy_fecrate_t fecrate;
+ phy_pb_size_t pb_size;
+ for (fecrate = 0; fecrate < PHY_FEC_RATE_NONE; fecrate++)
+ for (pb_size = 0; pb_size < PHY_PB_SIZE_NONE; pb_size++)
+ {
+ uint bits;
+ switch (pb_size)
+ {
+ case PHY_PB_SIZE_136:
+ bits = 136 * 8;
+ break;
+ case PHY_PB_SIZE_520:
+ bits = 520 * 8;
+ break;
+ default:
+ dbg_assert_default ();
+ }
+ switch (fecrate)
+ {
+ case PHY_FEC_RATE_1_2:
+ bits = bits * 2;
+ break;
+ case PHY_FEC_RATE_16_21:
+ bits = bits * 21 / 16;
+ break;
+ default:
+ dbg_assert_default ();
+ }
+ test_fail_unless (tonemap_bits_per_pb (fecrate, pb_size)
+ == bits);
+ }
+ } test_end;
+}
+
+void
+tonemap_lookup_test_case (test_t t)
+{
+ tonemaps_t tms;
+ lib_rnd_t rnd[1];
+ lib_rnd_init (rnd, 1234);
+ test_case_begin (t, "lookup");
+ test_begin (t, "interval find")
+ {
+ uint iter;
+ tms.intervals = tms.swap_intervals;
+ for (iter = 0; iter < 10000; iter++)
+ for (tms.intervals->intervals_nb = 0; tms.intervals->intervals_nb < TONEMAP_INTERVAL_NB;
+ tms.intervals->intervals_nb++)
+ {
+ /* Fill intervals. */
+ uint i;
+ uint bot = 1;
+ for (i = 0; i < tms.intervals->intervals_nb; i++)
+ {
+ bot = lib_rnd_uniform (rnd, 9) + bot;
+ tms.intervals->interval[i].end_offset_atu = bot;
+ bot++;
+ }
+ /* Test. */
+ uint ti;
+ for (i = 0, ti = 0; i < bot - 1; )
+ {
+ dbg_assert (ti != tms.intervals->intervals_nb);
+ test_fail_unless (tonemap_interval_find (&tms, i) == ti);
+ i++;
+ if (i == tms.intervals->interval[ti].end_offset_atu)
+ ti++;
+ }
+ test_fail_unless (tonemap_interval_find (&tms, i)
+ == tms.intervals->intervals_nb);
+ }
+ } test_end;
+}
+
+void
+tonemap_tonemask_test_case (test_t t)
+{
+ tonemask_info_t ti;
+ uint carrier_nb;
+ test_case_begin (t, "tonemask");
+ test_begin (t, "default")
+ {
+ carrier_nb = tonemask_default (ti.tonemask);
+ test_fail_unless (carrier_nb == 917);
+ test_fail_unless (ti.tonemask[0 / 8] == 0); /* 74 */
+ test_fail_unless (ti.tonemask[11 / 8] == 0xf0); /* 85 */
+ test_fail_unless (ti.tonemask[345 / 8] == 0xfc); /* 419 */
+ test_fail_unless (ti.tonemask[495 / 8] == 0xff); /* 569 */
+ test_fail_unless (ti.tonemask[782 / 8] == 0x7f); /* 856 */
+ test_fail_unless (ti.tonemask[1069 / 8] == 0x3f); /* 1143 */
+ test_fail_unless (ti.tonemask[1070 / 8] == 0x3f); /* 1144 */
+ test_fail_unless (ti.tonemask[1155 / 8] == 0x00); /* 1229 */
+ } test_end;
+ test_begin (t, "carrier nb")
+ {
+ test_fail_unless (carrier_nb == tonemask_carrier_nb (ti.tonemask));
+ } test_end;
+ test_begin (t, "update")
+ {
+ tonemask_update (&ti);
+ test_fail_unless (ti.carrier_nb == carrier_nb);
+ phy_mod_t mod;
+ for (mod = PHY_MOD_ROBO; mod < PHY_MOD_ROBO_NB; mod++)
+ {
+ tonemap_t *tm = &ti.tonemap_robo[mod];
+ uint bits_per_symbol;
+ u8 ble;
+ switch (mod)
+ {
+ case PHY_MOD_ROBO:
+ bits_per_symbol = carrier_nb / 4 * 2;
+ ble = tonemap_ble (bits_per_symbol, PHY_FEC_RATE_1_2,
+ CONST_UF32 (0.0), PHY_GIL_417);
+ break;
+ case PHY_MOD_HS_ROBO:
+ bits_per_symbol = carrier_nb / 2 * 2;
+ ble = tonemap_ble (bits_per_symbol, PHY_FEC_RATE_1_2,
+ CONST_UF32 (0.0), PHY_GIL_417);
+ break;
+ case PHY_MOD_MINI_ROBO:
+ bits_per_symbol = carrier_nb / 5 * 2;
+ ble = tonemap_ble (bits_per_symbol, PHY_FEC_RATE_1_2,
+ CONST_UF32 (0.0), PHY_GIL_567);
+ break;
+ default:
+ dbg_assert_default ();
+ }
+ test_fail_unless (!tm->strict && tm->cpf
+ && tm->fecrate == PHY_FEC_RATE_1_2
+ && ((mod == PHY_MOD_MINI_ROBO
+ && tm->gil == PHY_GIL_567)
+ || tm->gil == PHY_GIL_417)
+ && tm->ble == ble
+ && tm->tmdma_desc_head == NULL
+ && tm->bits_per_symbol == bits_per_symbol
+ );
+ }
+ } test_end;
+}
+
+void
+tonemap_test_suite (test_t t)
+{
+ test_suite_begin (t, "tonemap");
+ tonemap_comp_test_case (t);
+ tonemap_lookup_test_case (t);
+ tonemap_tonemask_test_case (t);
+}
+
+int
+main (int argc, char **argv)
+{
+ test_t t;
+ test_init (t, argc, argv);
+ tonemap_test_suite (t);
+ test_result (t);
+ return test_nb_failed (t) == 0 ? 0 : 1;
+}