summaryrefslogtreecommitdiff
path: root/cesar/bsu/test/utest/src/interface.c
blob: 5c1d95264a83f296b9c62c2ae682296705665e73 (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
/* 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 "bsu/test/utest/tests.h"
#include "bsu/beacon/beacon.h"
#include <string.h>
#include "bsu/inc/interface.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;
        bsu_beacon_params_t bsu_params;
        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, &bsu_params, &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
        {
            bsu_beacon_send (test.bsu, type, beacon, &bsu_params, &params);
            test_fail_unless (test.sar.beacon == beacon);
            test_fail_unless (test.sar.mfs->beacon == true);
            if (type == BSU_BEACON_TYPE_CENTRAL)
                test_fail_unless (test.sar.mfs->cap == 0x3);
            else
                test_fail_unless (test.sar.mfs->cap == 0x2);
            test_fail_unless (test.ul.beacon == beacon);
            test_fail_unless (test.ul.pparams == NULL);
            test_fail_unless (test.ul.bparams == &bsu_params);
            /* Free the beacon. */
            blk_release_desc ((blk_t*) beacon);
            /* 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")
    {
        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);
        beacon = bsu_beacon_write (&bbeacon,
                                   BSU_BEACON_TYPE_CENTRAL,
                                   &test.mac_config,
                                   &tx_params);
        beacon->phy_pb.pb_rx.pb_measurement.crc_error = false;
        bsu_beacon_recv (test.bsu, beacon, &rx_params);
        test_fail_unless (test.ul.beacon == beacon);
        test_fail_unless (test.ul.pparams == &rx_params);
        bsu_test_uninit (&test);
        blk_release_desc ((blk_t*) beacon);
    }
    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);
}