summaryrefslogtreecommitdiff
path: root/cesar/bsu/test/utest/src/interface.c
blob: b7b34d2353d9354f3871ed9e97284d29d90985d0 (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
/* Cesar project {{{
 *
 * Copyright (C) 2010 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    bsu/test/utest/src/interface.c
 * \brief   Interface unit tests.
 * \ingroup bsu
 */
#include "common/std.h"
#include "lib/test.h"
#include "lib/fixed.h"
#include "bsu/test/utest/tests.h"
#include "bsu/beacon/beacon.h"
#include <string.h>
#include "bsu/inc/interface.h"
#include "bsu/inc/context.h"

void
test_case_bsu_interface_tx (test_t t, bsu_beacon_type_t type)
{
    test_case_begin (t, "SAR and upper layer");

    test_begin (t, "Send beacon")
    {
        bsu_test_t test;
        pb_beacon_t *beacon;
        bsu_beacon_t bsu_beacon;
        pbproc_tx_beacon_params_t params;
        bsu_test_init (&test);
        bsu_test_create_beacon (&test, &bsu_beacon);
        beacon = bsu_beacon_write (&bsu_beacon, type, &test.mac_config,
                                   &params);
        beacon->phy_pb.pb_rx.pb_measurement.crc_error = false;
        if (type == BSU_BEACON_TYPE_PROXY)
        {
            dbg_fatal_try_begin
            {
                bsu_beacon_send (test.bsu, type, beacon, &params);
                test_fail_unless (0);
            }
            dbg_fatal_try_catch (const char *fatal_message)
            {
                test_verbose_print (fatal_message);
                test_fail_unless (true);
                blk_release_desc ((blk_t*) beacon);
            }
            dbg_fatal_try_end;
        }
        else
        {
            test.bsu->avlns[0].sync.ntb_offset_tck = 0x3;
            test.bsu->avlns[0].sync.fe = 0.34;
            test.bsu->sta_avln = &test.bsu->avlns[0];
            bsu_beacon_send (test.bsu, type, beacon, &params);
            if (type == BSU_BEACON_TYPE_CENTRAL)
                test_fail_unless (test.sar.mfs->cap == 0x3);
            else
                test_fail_unless (test.sar.mfs->cap == 0x2);
            /* Remove the MFS from the store. */
            mac_store_mfs_remove (test.mac_store,
                                  PARENT_OF (mfs_t, tx, test.sar.mfs));
        }
        bsu_test_uninit (&test);
    }
    test_end;
}

void
test_case_bsu_interface_rx (test_t t)
{
    test_case_begin (t, "Beacon Reception");
    test_begin (t, "Receive CRC Ok, CRC False")
    {
        bsu_test_t test;
        pb_beacon_t *beacon;
        bsu_beacon_t bbeacon;
        pbproc_rx_beacon_params_t rx_params;
        pbproc_tx_beacon_params_t tx_params;
        memset (&rx_params, 0, sizeof (pbproc_rx_beacon_params_t));
        bsu_test_init (&test);
        bsu_test_create_beacon (&test, &bbeacon);
        test.bsu->avlns[0].sync.ntb_offset_tck = 0x3;
        test.bsu->avlns[0].sync.fe = 0.34;
        beacon = bsu_beacon_write (&bbeacon,
                                   BSU_BEACON_TYPE_CENTRAL,
                                   &test.mac_config,
                                   &tx_params);
        beacon->phy_pb.pb_rx.pb_measurement.crc_error = false;
        rx_params.snid = 0x1;
        bsu_beacon_recv (test.bsu, beacon, &rx_params);
        test_fail_unless (test.ul.beacon != INVALID_PTR);
        test_fail_unless (test.ul.beacon->params.direction
                          == BSU_BEACON_DIRECTION_FROM_PLC);
        bsu_avln_t *avln = bsu_avln_get (
            test.bsu, bbeacon.vf.nid, rx_params.snid,
            bbeacon.bmis.mac_address.mac_address);
        test_fail_unless (avln != NULL);
        test_fail_unless (test.ul.beacon->params.frequency_error
                          == FIXED(avln->sync.fe,
                                   BSU_NTB_FIXED_POINT));
        test_fail_unless (test.ul.beacon->params.ntb_offset_tck
                          == avln->sync.ntb_offset_tck);
        blk_release (test.ul.beacon);
        bsu_test_upper_layer_beacon_received_init (&test);
        beacon = bsu_beacon_write (&bbeacon,
                                   BSU_BEACON_TYPE_CENTRAL,
                                   &test.mac_config,
                                   &tx_params);
        beacon->phy_pb.pb_rx.pb_measurement.crc_error = true;
        bsu_beacon_recv (test.bsu, beacon, &rx_params);
        test_fail_unless (test.ul.beacon == INVALID_PTR);
        bsu_test_uninit (&test);
    }
    test_end;
}

void
test_suite_bsu_interface (test_t t)
{
    test_suite_begin (t, "BSU interface");
    test_case_bsu_interface_tx (t, BSU_BEACON_TYPE_CENTRAL);
    test_case_bsu_interface_tx (t, BSU_BEACON_TYPE_DISCOVER);
    test_case_bsu_interface_tx (t, BSU_BEACON_TYPE_PROXY);
    test_case_bsu_interface_rx (t);
}