summaryrefslogtreecommitdiff
path: root/cesar/ce/test/rx/general/src/test_cei.c
blob: f31e92b6bab680cbb06c3e1e35ad15044b3f665d (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
/* Cesar project {{{
 *
 * Copyright (C) 2007 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    ./src/test_cei.c
 * \brief   « brief description »
 * \ingroup « module »
 *
 * « long description »
 */
#include "common/std.h"
#define RXCE
#define TXCE
#include "ce/inc/cei.h"
#include "lib/test.h"
#include "mac/common/tonemask.h"
#include "ce/test/common/tonemap_utils.h"
#include "ce/test/common/print_utils.h"

void
test_exchange (test_t test, tonemaps_t *rx_tms, tonemaps_t *tx_tms,
               u32 *mask, uint tmi, uint max_rnd, uint offset)
{
    u8 buffer[1536];
    bitstream_t bitstream_ctx;
    bitstream_t reader;
    int i; for (i=0; i<1536; i++) buffer[i]=0;
    bitstream_write_init (&bitstream_ctx, buffer, 1536);
    create_tm (rx_tms, mask, tmi, max_rnd, offset);
    ce_print_tonemaps (rx_tms);
    cei_create (buffer, &bitstream_ctx, mask, rx_tms, tmi, TONEMAP_INDEX_NULL);
    bitstream_read_init (&reader, buffer, 1536);
    cei_decode (tx_tms, CM_CHAN_EST_IND, &reader, mask);
    compare_tonemaps (test, rx_tms, tx_tms, mask);
}

int
main (int argc, char **argv)
{
    int i;
    u32 mask[(PHY_CARRIER_NB+31)/32];
    for (i=0; i<(PHY_CARRIER_NB+31)/32; i++) mask[i] = ~0xFFFFFFFF;
    mask[i-1] = ~((1<<(PHY_CARRIER_NB%32))-1);
    test_t test;
    lib_rnd_init (&rnd, 12);
    test_init (test, argc, argv);
    tonemaps_t *rx_tms = tonemaps_alloc();
    tonemaps_t *tx_tms = tonemaps_alloc();
    test_case_begin (test, "CE-cei-full mask");
    test_exchange (test, rx_tms, tx_tms, mask, 4, 3, 1);
    test_exchange (test, rx_tms, tx_tms, mask, 5, 2, 6);
    test_exchange (test, rx_tms, tx_tms, mask, 6, 1, 3);
    test_exchange (test, rx_tms, tx_tms, mask, 7, 0, 3);
    tonemaps_release (rx_tms);
    tonemaps_release (tx_tms);
    test_begin (test, "check alloc/free")
    {
        test_fail_unless (blk_check_memory());
    } test_end;

    rx_tms = tonemaps_alloc();
    tx_tms = tonemaps_alloc();
    tonemask_default (mask);
    test_case_begin (test, "CE-cei-default mask");
    test_exchange (test, rx_tms, tx_tms, mask, 4, 3, 1);
    test_exchange (test, rx_tms, tx_tms, mask, 5, 2, 6);
    test_exchange (test, rx_tms, tx_tms, mask, 6, 1, 3);
    test_exchange (test, rx_tms, tx_tms, mask, 7, 0, 3);
    tonemaps_release (rx_tms);
    tonemaps_release (tx_tms);
    test_begin (test, "check alloc/free")
    {
        test_fail_unless (blk_check_memory());
    } test_end;
    test_result (test);
    return (test_nb_failed (test) == 0 ? 0 : 1);
}