summaryrefslogtreecommitdiff
path: root/cesar/hal/phy/test/tonemask/src/test_tonemask.c
blob: 65b7278f8821afd7273fd3c1e6b3e282ff050230 (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
/* Cesar project {{{
 *
 * Copyright (C) 2013 MStar Semiconductor
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    src/test_tonemask.c
 * \brief   Test tonemask tooks.
 * \ingroup test
 */
#include "common/std.h"
#include "hal/phy/inc/tonemask.h"
#include "hal/phy/defs.h"
#include "mac/common/tonemask.h"

#include "lib/test.h"

#include <string.h>

uint test_tonemask_carrier_nb;
uint test_tonemask_carrier_offset;

void
ampmap_test_suite (test_t t)
{
    test_suite_begin (t, "ampmap");
    test_case_begin (t, "basic");
    test_begin (t, "pattern")
    {
        u32 tonemask[PHY_TONEMASK_WORDS];
        u32 ampmap[PHY_TONEMAP_WORDS];
        memset (tonemask, 0, sizeof (tonemask));
        memset (ampmap, 0x42, sizeof (ampmap));
        tonemask[0] = 0xaa55f00f;
        tonemask[PHY_TONEMASK_WORDS - 1] = 0xaa55f00f;
        phy_tonemask_to_ampmap (tonemask, ampmap);
        test_fail_unless (ampmap[0] == 0x0000ffff);
        test_fail_unless (ampmap[1] == 0xffff0000);
        test_fail_unless (ampmap[2] == 0x0f0f0f0f);
        test_fail_unless (ampmap[3] == 0xf0f0f0f0);
        test_fail_unless (ampmap[PHY_TONEMAP_WORDS - 4] == 0x0000ffff);
        test_fail_unless (ampmap[PHY_TONEMAP_WORDS - 3] == 0xffff0000);
        test_fail_unless (ampmap[PHY_TONEMAP_WORDS - 2] == 0x0f0f0f0f);
        test_fail_unless (ampmap[PHY_TONEMAP_WORDS - 1] == 0xf0f0f0f0);
    } test_end;
}

void
tonemask10_test_pattern (test_t t, uint carrier_offset, uint carrier_nb,
                         uint hp10_carrier_offset, uint hp10_carrier_nb,
                         u32 tonemask_pat, u32 tonemask10_pat)
{
    uint i;
    test_within (t);
    test_tonemask_carrier_offset = carrier_offset;
    test_tonemask_carrier_nb = carrier_nb;
    test_fail_unless (PHY_HP10_CARRIER_OFFSET == hp10_carrier_offset);
    test_fail_unless (PHY_HP10_CARRIER_NB == hp10_carrier_nb);
    u32 tonemask[PHY_TONEMASK_WORDS];
    memset (tonemask, 0xff, sizeof (tonemask));
    tonemask[0] = tonemask_pat;
    u32 tonemask10[PHY_HP10_TONEMASK_WORDS];
    phy_tonemask_to_tonemask10 (tonemask, tonemask10);
    test_fail_unless (tonemask10[0] == tonemask10_pat);
    for (i = 1; i < PHY_HP10_TONEMASK_WORDS; i++)
        test_fail_unless (tonemask10[i] == 0xffffffff);
}

void
tonemask10_test_suite (test_t t)
{
    test_suite_begin (t, "tonemask10");
    test_case_begin (t, "av");
    test_begin (t, "norm")
    {
        test_tonemask_carrier_offset = 74;
        test_tonemask_carrier_nb = 1155;
        test_fail_unless (PHY_HP10_CARRIER_OFFSET == 10);
        test_fail_unless (PHY_HP10_CARRIER_NB == 144);
        u32 tonemask[PHY_TONEMASK_WORDS];
        uint unmasked_nb = tonemask_default (tonemask);
        dbg_assert (unmasked_nb == 917);
        u32 tonemask10[PHY_HP10_TONEMASK_WORDS];
        phy_tonemask_to_tonemask10 (tonemask, tonemask10);
        /* From HomePlugAV norm: */
        test_fail_unless (tonemask10[0] == 0x0c060f01);
        test_fail_unless (tonemask10[1] == 0xc0000400);
        test_fail_unless (tonemask10[2] == 0x000c0001);
        test_fail_unless (tonemask10[3] == 0x0060001e);
        test_fail_unless (tonemask10[4] == 0xffffffe0);
        test_fail_unless (tonemask10[5] == 0xffffffff);
    } test_end;
    test_case_begin (t, "basic");
    test_begin (t, "pattern aligned begin")
    {
        /*   80-v
         * _____00000000000000000000000000000000_____
         *      1-------0-------0-------0-------      */
        tonemask10_test_pattern (t, 80, 32, 10, 4, 0x00000000, 0xfffffff1);
    } test_end;
    test_begin (t, "pattern aligned end")
    {
        /*   73-v      v-80
         * _____00000000000000000000000000000000_____
         *             0-------0-------0-------1----- */
        tonemask10_test_pattern (t, 73, 32, 10, 4, 0x00000000, 0xfffffff8);
    } test_end;
    test_begin (t, "pattern unaligned")
    {
        /*   79-vv-80
         * _____00000000000000000000000000000000_____
         *       0-------0-------0-------0-------     */
        tonemask10_test_pattern (t, 79, 32, 10, 4, 0x00000000, 0xfffffff0);
    } test_end;
    test_begin (t, "bit patterns")
    {
        /*   80-v
         * _____00000001000000001000000001000000_____
         *      1-------1-------1-------1-------      */
        tonemask10_test_pattern (t, 80, 32, 10, 4, 0x02010080, 0xffffffff);
        /*   79-vv-80
         * _____00011111000111110001111100011111_____
         *       0-------0-------0-------0-------     */
        tonemask10_test_pattern (t, 79, 32, 10, 4, 0xf8f8f8f8, 0xfffffff0);
        /*   79-vv-80
         * _____00011111010001110001111100111111_____
         *       0-------1-------0-------1-------     */
        tonemask10_test_pattern (t, 79, 32, 10, 4, 0xfcf8e2f8, 0xfffffffa);
    } test_end;
}

int
main (int argc, char **argv)
{
    test_t t;
    test_init (t, argc, argv);
    ampmap_test_suite (t);
    tonemask10_test_suite (t);
    test_result (t);
    return test_nb_failed (t) == 0 ? 0 : 1;
}