summaryrefslogtreecommitdiff
path: root/ecos/packages/net/lwip_tcpip/current/tests/sys_timeout.c
blob: 36f5a06e07cc236b681cf0e4b9c30b82cedffbde (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
130
131
132
133
134
135
136
137
138
139
140
141
142
//==========================================================================
//
//      sys_timeout.c
//
//      Simple test-case for the lwip system timeout functionality.
//
//==========================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 2009 Free Software Foundation
//
// eCos is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 or (at your option) any later version.
//
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License along
// with eCos; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or inline functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. However the source code for this file must still be made available
// in accordance with section (3) of the GNU General Public License.
//
// This exception does not invalidate any other reasons why a work based on
// this file might be covered by the GNU General Public License.
// -------------------------------------------
//####ECOSGPLCOPYRIGHTEND####
//==========================================================================
//#####DESCRIPTIONBEGIN####
//
// Author(s):    Simon Kallweit
// Contributors:
// Date:         2009-05-18
// Purpose:
// Description:  Simple test-case for the lwip system timeout functionality.
//
//####DESCRIPTIONEND####
//
//==========================================================================

#include <cyg/hal/hal_arch.h>
#include <cyg/infra/diag.h>
#include <cyg/infra/testcase.h>

#include <pkgconf/net_lwip.h>

#include <lwip.h>

#define TIMERS 10

#ifdef CYGFUN_LWIP_MODE_SEQUENTIAL
#if MEMP_NUM_SYS_TIMEOUT >= (TIMERS + 6)

#define STACK_SIZE CYGNUM_HAL_STACK_SIZE_TYPICAL

static char main_stack[STACK_SIZE];
static cyg_thread main_thread;
static cyg_handle_t main_handle;

static char timeout_stack[STACK_SIZE];

static int timeouts = 0;

static void timeout_fn(void * arg)
{
    int i = (int) arg;

    diag_printf("Timeout timer #%d\n", i);

    if (i != timeouts++)
        CYG_TEST_FAIL_EXIT("Timeout out of order");

    if (timeouts == TIMERS)
        CYG_TEST_FINISH("Test successful");
}

static void timeout_thread_entry(void *arg)
{
    int i;

    for (i = 0; i < TIMERS; i++) {
        diag_printf("Adding timer #%d\n", i);
        sys_timeout((i + 1) * 100, timeout_fn, (void *) i);
    }
    sys_msleep(0);
}

void main_thread_entry(cyg_addrword_t p)
{
    cyg_lwip_sequential_init();
    cyg_lwip_thread_new("timeout", timeout_thread_entry, NULL,
                        timeout_stack, STACK_SIZE, 7);
}

externC void
cyg_start(void)
{
    CYG_TEST_INIT();
    CYG_TEST_INFO("Testing timeouts");

    // Create a main thread, so we can run the scheduler and have time 'pass'
    cyg_thread_create(
        10,                 // Priority - just a number
        main_thread_entry,  // Entry
        0,                  // Entry parameter
        "main",         // Name
        main_stack,         // Stack
        STACK_SIZE,         // Size
        &main_handle,       // Handle
        &main_thread        // Thread data structure
    );
    cyg_thread_resume(main_handle);
    cyg_scheduler_start();

    CYG_TEST_FAIL_FINISH("Not reached");
}

#else // MEMP_NUM_SYS_TIMEOUT >= (TIMERS + 6)
#define N_A_MSG "Timeout memory pool is too small"
#endif // MEMP_NUM_SYS_TIMEOUT >= (TIMERS + 6)

#else // CYGFUN_LWIP_MODE_SEQUENTIAL
#define N_A_MSG "Not configured in 'Sequential' mode"
#endif // CYGFUN_LWIP_MODE_SEQUENTIAL

#ifdef N_A_MSG
externC void
cyg_start(void)
{
    CYG_TEST_INIT();
    CYG_TEST_NA(N_A_MSG);
}
#endif // N_A_MSG