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