summaryrefslogtreecommitdiff
path: root/cesar/ce/rx/bitloading/test/src/test_fsm.c
blob: 5a53ab3557f69b6a6b57264774e9c6f3d3f066b1 (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/* Cesar project {{{
 *
 * Copyright (C) 2010 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    ce/rx/bitloading/test/src/test_fsm.c
 * \brief   Test bit loading FSM.
 * \ingroup test
 */
#include "common/std.h"

#include "ce/rx/inc/rx.h"
#include "ce/rx/bitloading/fsm/event.h"
#include "ce/rx/inc/measure.h"
#include "mac/common/sta.h"
#include "ce_rx_bl_fsm_defs.h"

#include "lib/test.h"
#include "lib/scenario/scenario.h"

static void
test_ce_rx_bl_measure_empty (ce_rx_measure_mbox_t *m)
{
    m->pb_measurements = NULL;
    m->chan_data = NULL;
    m->pb_measurements_count = m->chan_data_count = 0;
    m->rx_params.sound = false;
    m->rx_params.sound_complete = false;
}

static void
test_ce_rx_bl_fsm_base (test_t t)
{
    test_suite_begin (t, "CE:RX:BL:FSM");

    ce_rx_t ce = { .mac_config = INVALID_PTR, };
    scenario_globals_t globals = {
        .ce = &ce,
    };

    sta_t sta;
    ce_rx_bitloading_fsm_event_param_t data;
    ce_rx_measure_mbox_t measure;
    data.measure = &measure;

    test_case_begin (t, "sound not received yet");

    test_begin (t, "IDLE, not sound, do nothing")
    {
        test_ce_rx_bl_measure_empty (&measure);
        scenario_entry_t fsm_base[] =
        {
            SCENARIO_ACTION (IDLE__channel_data_received,
                             .sta = &sta,
                             .data = data,
                             .branch = ce_rx_bl_fsm_next_branch
                             (IDLE, channel_data_received, not_sound)),
            /* Nothing should happen. */
            SCENARIO_END,
        };
        scenario_run (t, fsm_base, &globals);
    } test_end;

    test_case_begin (t, "many sounds, one sound complete, bit loading "
                     "initial");

    test_begin (t, "IDLE, many sound, one sound complete")
    {
        test_ce_rx_bl_measure_empty (&measure);
        measure.rx_params.sound = true;
        ce_rx_bitloading_fsm_event_param_t data_sc;
        ce_rx_measure_mbox_t measure_sc;
        data_sc.measure = &measure_sc;
        test_ce_rx_bl_measure_empty (&measure_sc);
        measure_sc.rx_params.sound = true;
        measure_sc.rx_params.sound_complete = true;
        scenario_entry_t fsm_base[] =
        {
            SCENARIO_ACTION (IDLE__channel_data_received,
                             .sta = &sta,
                             .data = data,
                             .branch = ce_rx_bl_fsm_next_branch
                             (IDLE, channel_data_received, sound)),
            /* Init NSR. */
            SCENARIO_EVENT (ce_rx_bl_nsr_sum_init),
            SCENARIO_ACTION (INITIAL__channel_data_received,
                             .sta = &sta,
                             .data = data,
                             .branch = ce_rx_bl_fsm_next_branch
                             (INITIAL, channel_data_received,
                              sound_not_last)),
            /* Increase NSR. */
            SCENARIO_EVENT (ce_rx_bl_nsr_sum_add),
            SCENARIO_ACTION (INITIAL__channel_data_received,
                             .sta = &sta,
                             .data = data,
                             .branch = ce_rx_bl_fsm_next_branch
                             (INITIAL, channel_data_received,
                              sound_not_last)),
            /* Increase NSR. */
            SCENARIO_EVENT (ce_rx_bl_nsr_sum_add),
            SCENARIO_ACTION (INITIAL__channel_data_received,
                             .sta = &sta,
                             .data = data_sc,
                             .branch = ce_rx_bl_fsm_next_branch
                             (INITIAL, channel_data_received, sound_last)),
            /* Increase NSR. */
            SCENARIO_EVENT (ce_rx_bl_nsr_sum_add),
            /* Compute Mean. */
            SCENARIO_EVENT (ce_rx_bl_nsr_compute_mean),
            /* Start BL. */
            SCENARIO_EVENT (ce_rx_bl_start_bl),
            SCENARIO_END,
        };
        scenario_run (t, fsm_base, &globals);
    } test_end;

    test_case_begin (t, "one sound complete, bit loading initial");

    test_begin (t, "IDLE, one sound complete")
    {
        test_ce_rx_bl_measure_empty (&measure);
        measure.rx_params.sound = true;
        measure.rx_params.sound_complete = true;
        scenario_entry_t fsm_base[] =
        {
            SCENARIO_ACTION (IDLE__channel_data_received,
                             .sta = &sta,
                             .data = data,
                             .branch = ce_rx_bl_fsm_next_branch
                             (IDLE, channel_data_received, sound_last)),
            /* Init NSR. */
            SCENARIO_EVENT (ce_rx_bl_nsr_sum_init),
            /* Compute NSR mean (required because of NSR rescaling). */
            SCENARIO_EVENT (ce_rx_bl_nsr_compute_mean),
            /* Start BL. */
            SCENARIO_EVENT (ce_rx_bl_start_bl),
            SCENARIO_END,
        };
        scenario_run (t, fsm_base, &globals);
    } test_end;

    test_case_begin (t, "many sound complete, one bit loading");

    test_begin (t, "TRACKING, many sound complete")
    {
        test_ce_rx_bl_measure_empty (&measure);
        measure.rx_params.sound = true;
        measure.rx_params.sound_complete = true;
        scenario_entry_t fsm_base[] =
        {
            SCENARIO_ACTION (TODO,
                             .sta = &sta,
                             .data = data,
                             .branch = ce_rx_bl_fsm_next
                             (TRACKING, channel_data_received)),
            /* Nothing should happen. */
            SCENARIO_END,
        };
        scenario_run (t, fsm_base, &globals);
    } test_end;

}

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

    test_ce_rx_bl_fsm_base (t);

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