summaryrefslogtreecommitdiff
path: root/cesar/ce/rx/bitloading/test/src/test_poly.c
blob: e95ef2f9d5fdd6c3d8f189a11e94dbbfeefd660f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/* Cesar project {{{
 *
 * Copyright (C) 2012 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    ce/rx/bitloading/test/src/test_poly.c
 * \brief   Test CE RX polynomials.
 * \ingroup test
 */
#include "common/std.h"

#include "lib/test.h"

#include "ce/rx/rx.h"
#include "ce/rx/bitloading/inc/ber.h"

/* Global CE/RX behavior stub. */
ce_rx_behavior_t ce_rx_behavior = CE_RX_BEHAVIOR_INTERVALS_DISABLE;

void
test_ce_rx_poly (test_t t)
{
    u64 ber, ber_prev = 0;
    u32 nsr;
    u8 mod_index;
    ce_rx_bl_ber_poly_coef_t *poly;

    test_begin (t, "output BER values should increase when NSR increase")
    {
        for (mod_index = 1; mod_index < CE_MOD_COUNT; mod_index++)
        {
            poly = &ce_rx_bl_ber_poly_coef[mod_index - 1];
            ber_prev = 0;

            for (nsr = poly->range[0];
                 nsr <= poly->range[poly->poly_count];
                 nsr++)
            {
                ber = ce_rx_bl_ber_for_mod
                    (ce_rx_bl_ber_poly_coef, nsr, mod_index);
                test_fail_if (ber_prev > ber,
                              "previous BER is over current one ("
                              "mod_index = %d, nsr = %d, "
                              "ber_prev = %lld, ber_value = %lld)",
                              mod_index, nsr, ber_prev, ber);
                test_fail_if (ber >= CE_RX_BL_BER_DEFAULT_OVER,
                              "BER at max (mod_index = %d, nsr = %d)",
                              mod_index, nsr);
                test_fail_if (ber <= CE_RX_BL_BER_DEFAULT_UNDER,
                              "BER at min (mod_index = %d, nsr = %d)",
                              mod_index, nsr);
                ber_prev = ber;
            }
        }
    } test_end;

    test_begin (t, "output BER values should increase when modulation "
                "increase (with fixed NSR)")
    {
        /* Get NSR range min, max. */
        uint nsr_min = (uint) -1, nsr_max = 0;
        for (mod_index = 1; mod_index < CE_MOD_COUNT; mod_index++)
        {
            poly = &ce_rx_bl_ber_poly_coef[mod_index - 1];
            nsr_min = MIN (nsr_min, poly->range[0]);
            nsr_max = MAX (nsr_max, poly->range[poly->poly_count]);
        }
        /* Go through all supported NSR. */
        for (nsr = nsr_min; nsr < nsr_max; nsr++)
        {
            ber_prev = 0;
            for (mod_index = 1; mod_index < CE_MOD_COUNT; mod_index++)
            {
                ber = ce_rx_bl_ber_for_mod
                    (ce_rx_bl_ber_poly_coef, nsr, mod_index);
                test_fail_if (ber_prev > ber,
                              "previous BER is over current one ("
                              "mod_index = %d, nsr = %d, "
                              "ber_prev = %lld, ber_value = %lld)",
                              mod_index, nsr, ber_prev, ber);
                test_fail_if (ber > CE_RX_BL_BER_DEFAULT_OVER);
                ber_prev = ber;
            }
        }
    } test_end;
}


int
main (int argc, char **argv)
{
    test_t t;
    test_init (t, argc, argv);

    test_suite_begin (t, "CE:RX:POLY");

    test_ce_rx_poly (t);

    test_result (t);
    return test_nb_failed (t) == 0 ? 0 : 1;
}