summaryrefslogtreecommitdiff
path: root/cesar/cp/eoc/sta/action/test/utest_eoc/src/test_sta_action.c
blob: 3481cb0e37c407631a52d62a5605eede63710f25 (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
/* Cesar project {{{
 *
 * Copyright (C) 2008 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    src/test_sta_action.c
 * \brief   Test sta/action.
 * \ingroup test
 */
#include "common/std.h"

#include "inc/test_sta_action.h"

#include "lib/test.h"

#include "mac/common/store.h"

blk_t nsr_block;

void
assoc_test_suite (test_t t);

void
drv_test_suite (test_t t);

void
test_sta_action_init (test_sta_action_t *ctx)
{
#if CONFIG_TRACE
    static trace_namespace_t namespace;
    trace_buffer_add (&ctx->cp.trace, "cp", 8, 1, false, &namespace);
#endif
    memset (ctx, 0, sizeof (test_sta_action_t));
    lib_rnd_init (&ctx->cp.rnd, 1234);
    ctx->cp.mac_config = &ctx->mac_config;
    ctx->cp.mac_store = mac_store_init ();
    ctx->cp.sar = (void *) &ctx->cp;
    ctx->cp.pbproc = NULL;
    ctx->cp.cl = INVALID_PTR;
    ctx->cp.bsu_aclf = &ctx->bsu_aclf;
    cp_sta_mgr_init (&ctx->cp);
}

void
test_sta_action_mfs_remove (mac_store_t *mac_store, mfs_t *mfs, void *user)
{
    mac_store_mfs_remove (mac_store, mfs);
}

void
test_sta_action_uninit (test_sta_action_t *ctx)
{
    cp_sta_mgr_uninit (&ctx->cp);
    /* Remove all the stations from the store. */
    uint tei;
    for (tei = MAC_TEI_STA_MIN; tei <= MAC_TEI_STA_MAX; tei++)
    {
        sta_t *sta = mac_store_sta_get (ctx->cp.mac_store, tei);
        if (sta)
        {
            mac_store_mfs_travel_by_tei (ctx->cp.mac_store, tei,
                                         test_sta_action_mfs_remove,
                                         ctx);
            dbg_check (mac_store_sta_remove (ctx->cp.mac_store, tei));
        }
    }
    mac_store_mfs_travel (ctx->cp.mac_store, test_sta_action_mfs_remove, ctx);
    mac_store_uninit (ctx->cp.mac_store);
#if CONFIG_TRACE
    trace_buffer_remove (&ctx->cp.trace);
#endif
}

void
test_sta_action_reset (test_sta_action_t *ctx)
{
    cp_sta_mgr_uninit (&ctx->cp);
    cp_sta_mgr_init (&ctx->cp);
}

void
test_sta_action_create_our_net (test_sta_action_t *ctx, cp_nid_t nid,
                                cp_snid_t snid)
{
    cp_t *cp = &ctx->cp;
    cp_sta_own_data_set_nid (cp, nid);
    cp_sta_own_data_set_snid (cp, snid);
    cp_net_t *our_net = cp_sta_mgr_add_avln (cp, snid, nid);
    cp_sta_mgr_set_our_avln (cp, our_net);
}

void
test_sta_action_beacon_create (
    bsu_beacon_t *beacon, cp_nid_t nid, cp_snid_t snid, cp_tei_t stei,
    mac_t mac)
{
    memset (beacon, 0, sizeof (bsu_beacon_t));
    beacon->vf.bt = BSU_BEACON_TYPE_CENTRAL;
    beacon->vf.nid = nid;
    beacon->params.rx_parameters.snid = snid;
    beacon->vf.stei = stei;
    beacon->bmis.mac_address.present = MAC_IS_VALID (mac);
    beacon->bmis.mac_address.mac_address = mac;
}

int
main (int argc, char **argv)
{
    test_t t;
    test_init (t, argc, argv);
    trace_init ();
    lib_stats_init ();
    drv_test_suite (t);
    assoc_test_suite (t);
    lib_stats_uninit ();
    trace_uninit ();
    test_result (t);
    return test_nb_failed (t) == 0 ? 0 : 1;
}