OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [net/] [autotest/] [current/] [tests/] [tftp_serv.inl] - Blame information for rev 825

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      tests/auto/tftp_serv.inl
4
//
5
//      Automated Multiple TFTP server GET test
6
//
7
//==========================================================================
8
// ####ECOSGPLCOPYRIGHTBEGIN####
9
// -------------------------------------------
10
// This file is part of eCos, the Embedded Configurable Operating System.
11
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
12
//
13
// eCos is free software; you can redistribute it and/or modify it under
14
// the terms of the GNU General Public License as published by the Free
15
// Software Foundation; either version 2 or (at your option) any later
16
// version.
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT
19
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
21
// for more details.
22
//
23
// You should have received a copy of the GNU General Public License
24
// along with eCos; if not, write to the Free Software Foundation, Inc.,
25
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
26
//
27
// As a special exception, if other files instantiate templates or use
28
// macros or inline functions from this file, or you compile this file
29
// and link it with other works to produce a work based on this file,
30
// this file does not by itself cause the resulting work to be covered by
31
// the GNU General Public License. However the source code for this file
32
// must still be made available in accordance with section (3) of the GNU
33
// General Public License v2.
34
//
35
// This exception does not invalidate any other reasons why a work based
36
// on this file might be covered by the GNU General Public License.
37
// -------------------------------------------
38
// ####ECOSGPLCOPYRIGHTEND####
39
// ####BSDALTCOPYRIGHTBEGIN####
40
// -------------------------------------------
41
// Portions of this software may have been derived from FreeBSD, OpenBSD,
42
// or other sources, and if so are covered by the appropriate copyright
43
// and license included herein.
44
// -------------------------------------------
45
// ####BSDALTCOPYRIGHTEND####
46
//==========================================================================
47
//#####DESCRIPTIONBEGIN####
48
//
49
// Author(s):    hmt,gthomas
50
// Contributors: hmt,gthomas
51
// Date:         2000-10-10
52
// Purpose:
53
// Description:
54
//
55
//
56
//####DESCRIPTIONEND####
57
//
58
//==========================================================================
59
// TFTP test code
60
 
61
#ifdef CYGBLD_DEVS_ETH_DEVICE_H    // Get the device config if it exists
62
#include CYGBLD_DEVS_ETH_DEVICE_H  // May provide CYGTST_DEVS_ETH_TEST_NET_REALTIME
63
#endif
64
 
65
#ifdef CYGPKG_NET_TESTS_USE_RT_TEST_HARNESS // do we use the rt test?
66
# ifdef CYGTST_DEVS_ETH_TEST_NET_REALTIME // Get the test ancilla if it exists
67
#  include CYGTST_DEVS_ETH_TEST_NET_REALTIME
68
# endif
69
#endif
70
 
71
 
72
// Fill in the blanks if necessary
73
#ifndef TNR_OFF
74
# define TNR_OFF()
75
#endif
76
#ifndef TNR_ON
77
# define TNR_ON()
78
#endif
79
#ifndef TNR_INIT
80
# define TNR_INIT()
81
#endif
82
#ifndef TNR_PRINT_ACTIVITY
83
# define TNR_PRINT_ACTIVITY()
84
#endif
85
 
86
// ------------------------------------------------------------------------
87
 
88
#include 
89
#include 
90
#include 
91
 
92
#include "autohost.inl"
93
 
94
#define STACK_SIZE (CYGNUM_HAL_STACK_SIZE_TYPICAL + 0x10000)
95
static char stack[STACK_SIZE];
96
static cyg_thread thread_data;
97
static cyg_handle_t thread_handle;
98
 
99
static void
100
do_tftp_tests(struct bootp *bp, int N, int testtime, int filesize)
101
{
102
    int i;
103
    char order[256];
104
    diag_printf( "INFO: telling %s to run %d tests for %d seconds, %d+/-%d bytes\n",
105
          inet_ntoa(bp->bp_siaddr), N, testtime, filesize, N-1 );
106
 
107
    // For 2nd and subsequent orders, we vary the filesize, thus testing
108
    // together: 0 and 1 bytes; 512 and 513 bytes; 1Mb and 1Mb-1; in the
109
    // standard invocations of this test.  Don't go over 1Mb.
110
    for ( i = 0; i < N; i++ ) {
111
        sprintf( order, "%s %s %d %d", OPERATION,
112
                 inet_ntoa(bp->bp_yiaddr),
113
                 testtime,
114
                 filesize + ((filesize < (1024*1024)) ? i : -i ) );
115
        autohost_tell( bp, order );
116
    }
117
}
118
 
119
#define NUM_SERVERS 4
120
static int servers[NUM_SERVERS] = { 0 };
121
 
122
#define TESTTIME (5 * 60) // Seconds
123
 
124
#define NUM_SESSIONS 3 // the dummy fileops system can only accept 3 new files
125
 
126
void
127
net_test(cyg_addrword_t param)
128
{
129
    int i;
130
    int numtests;
131
    CYG_TEST_INIT();
132
    CYG_TEST_INFO("Start TFTP server test");
133
    init_all_network_interfaces();
134
 
135
    autohost_init();
136
 
137
    TNR_INIT();
138
 
139
    // Create TFTP servers
140
    for ( i = 0; i < NUM_SERVERS; i++ ) {
141
        extern struct tftpd_fileops dummy_fileops;
142
        int server_id = tftpd_start(0, &dummy_fileops);
143
        if (server_id > 0) {
144
            diag_printf("INFO: TFTP server %d created - id: %x\n", i, server_id);
145
            servers[i] = server_id;
146
        }
147
        else {
148
            diag_printf("INFO: TFTP server %d NOT created [%x]\n", i, server_id);
149
            i--;
150
            break;
151
        }
152
    }
153
 
154
    numtests = i; // The number of servers started OK
155
    if ( numtests > NUM_SESSIONS )
156
        numtests = NUM_SESSIONS;
157
    i = numtests;
158
 
159
    if ( i < 1 ) {
160
        CYG_TEST_FAIL_EXIT( "Not enough TFTP servers created" );
161
    }
162
 
163
    // Now command the host to do tftp to us...
164
#ifdef CYGHWR_NET_DRIVER_ETH0
165
    if (eth0_up) {
166
        // 2 tests by default - if we have enough servers
167
        if ( i > 1 ) {
168
            do_tftp_tests(ð0_bootp_data, 2, TESTTIME, FILESIZE);
169
            i -= 2;
170
        }
171
        else {
172
            do_tftp_tests(ð0_bootp_data, 1, TESTTIME, FILESIZE);
173
            i -= 1;
174
        }
175
    }
176
#endif
177
#ifdef CYGHWR_NET_DRIVER_ETH1
178
    if (eth1_up && i > 0) {
179
        // rest of the tests depending...
180
        do_tftp_tests(ð1_bootp_data, i, TESTTIME, FILESIZE);
181
        i = 0;
182
    }
183
#endif
184
    numtests -= i; // Adjust to how many we *actually* requested
185
 
186
    // Let the server run for 5 minutes
187
    cyg_thread_delay(2*100); // let the tftpds start up first
188
    TNR_ON();
189
    cyg_thread_delay(TESTTIME*100); // FIXME - assume cS clock.
190
    // Additional delay 'cos host may be slower than us - and it has to
191
    // complete a transfer anyway:
192
    cyg_thread_delay(  30    *100); // FIXME - assume cS clock.
193
    TNR_OFF();
194
 
195
    for ( i = 0; i < NUM_SERVERS; i++ ) {
196
        int server_id = servers[i];
197
        if ( server_id ) {
198
            int res = tftpd_stop(servers[i]);
199
            diag_printf("INFO: TFTP server %d stopped - res: %d\n", i, res);
200
            CYG_TEST_CHECK( res > 0, "TFTP server did not die" );
201
        }
202
    }
203
 
204
    autohost_end( numtests ); // check for 3 pass messages from hosts
205
 
206
    TNR_PRINT_ACTIVITY();
207
    CYG_TEST_EXIT("Done");
208
}
209
 
210
void
211
cyg_start(void)
212
{
213
    // Create a main thread, so we can run the scheduler and have time 'pass'
214
    cyg_thread_create(10,                // Priority - just a number
215
                      net_test,          // entry
216
                      0,                 // entry parameter
217
                      "Network test",    // Name
218
                      &stack[0],         // Stack
219
                      STACK_SIZE,        // Size
220
                      &thread_handle,    // Handle
221
                      &thread_data       // Thread data structure
222
            );
223
    cyg_thread_resume(thread_handle);  // Start it
224
    cyg_scheduler_start();
225
}
226
 
227
// EOF tftp_serv.inl

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.