summaryrefslogtreecommitdiff
path: root/cesar/ce/test/tx/src/test_expiration.c
blob: d2e42b6d2886713231479d736a46de77e9d63a24 (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
/* Cesar project {{{
 *
 * Copyright (C) 2008 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    ./src/test_expiration.c
 * \brief   « brief description »
 * \ingroup « module »
 *
 * « long description »
 */
#include "common/std.h"
#include "cyg/kernel/kapi.h"
#include "ce/inc/tx.h"
#include "lib/test.h"
#include "cp/cp.h"
#include "cp/fsm/fsm.h"
#include "mac/common/tonemap.h"
#include "ce/inc/ecos_time.h"
#include "ce/test/common/print_utils.h"

#define CP_PRIORITY 20
cyg_thread cp_thread;
cyg_handle_t cp_handle;
unsigned char cp_stack[CYGNUM_HAL_STACK_SIZE_TYPICAL];

#define TEST_PRIORITY 10
cyg_thread test_thread;
cyg_handle_t test_handle;
unsigned char test_stack[CYGNUM_HAL_STACK_SIZE_TYPICAL];

test_t test;
mac_store_t *mac_store_ctx;
cp_t *cp_ctx;

void
test_process (cyg_addrword_t data)
{
    int n=0;
    test_begin (test, "txce expiration")
    {
        int i, tmi;
        bool has_tonemap = false;
        // Let CP running and simulate CEI reception. Check during 1mn if
        // tonemap that should have been expirated is still in mac_store.
        while (n++<S_TO_RTC (TONEMAPS_LIFE_DURATION_S*2))
        {
            //printf ("%d\n",n);
            cyg_thread_delay(1);
            for (i=MAC_TEI_STA_MIN; i<MAC_TEI_STA_MAX; i++)
            {
                sta_t *lsta = mac_store_sta_get (mac_store_ctx, i);
                if (lsta)
                {
                    has_tonemap = false;
                    for (tmi=0; tmi<TONEMAP_INDEX_NB; tmi++)
                    {
                        if (lsta->tx_tonemaps->tm[tmi] != NULL)
                        {
                            has_tonemap = true;
                            break;
                        }
                    }
                    test_fail_if ( has_tonemap && (cyg_current_time() > lsta->tx_tonemaps->expiration_rtc_date));
                    blk_release (lsta);
                }
            }
        }
        // Stop the simulation of received CEI.
        cp_fsm_uninit (cp_ctx);
        // Wait the life of tonemaps duration.
        // After this, all the tonemaps must have been expirated.
        cyg_thread_delay (S_TO_RTC(TONEMAPS_LIFE_DURATION_S));
        has_tonemap = false;
        for (i=MAC_TEI_STA_MIN; i<MAC_TEI_STA_MAX; i++)
        {
            sta_t *lsta = mac_store_sta_get (mac_store_ctx, i);
            if (lsta)
            {
                for (tmi=0; tmi<TONEMAP_INDEX_NB; tmi++)
                {
                    if (lsta->tx_tonemaps->tm[tmi] != NULL)
                    {
                        has_tonemap = true;
                        break;
                    }
                }
                test_fail_if ( has_tonemap );
                blk_release (lsta);
            }
        }

    } test_end;
    test_result (test);
    HAL_PLATFORM_EXIT (test_nb_failed (test) == 0 ? 0 : 1);
}


void
cyg_user_start (int argc, char **argv)
{
    test_init (test, argc, argv);
    mac_config_t mac_config;
    mac_config_init (&mac_config);
    mac_store_ctx = mac_store_init();
    cp_ctx = cp_init (&mac_config, NULL, NULL, NULL, mac_store_ctx, NULL, NULL, 0);
    cyg_thread_create (CP_PRIORITY, &cp_fsm_process,(cyg_addrword_t) cp_ctx, "cp",
                       cp_stack, CYGNUM_HAL_STACK_SIZE_TYPICAL,
                       &cp_handle, &cp_thread);

    cyg_thread_create (TEST_PRIORITY, &test_process,(cyg_addrword_t) 0, "test",
                       test_stack, CYGNUM_HAL_STACK_SIZE_TYPICAL,
                       &test_handle, &test_thread);



    cyg_thread_resume (test_handle);
    cyg_thread_resume (cp_handle);
}