]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/net/autotest/v2_0/tests/slowping.c
Initial revision
[karo-tx-redboot.git] / packages / net / autotest / v2_0 / tests / slowping.c
1 //==========================================================================
2 //
3 //      autotest/current/tests/slowping.c
4 //
5 //      Simple pinging test, the server pings me and little else.
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-23
54 // Purpose:      
55 // Description:  
56 //              
57 //
58 //####DESCRIPTIONEND####
59 //
60 //==========================================================================
61
62 #include <pkgconf/system.h>
63
64 #include <cyg/infra/testcase.h>         // testing infrastructure
65
66 #include <pkgconf/net.h>
67
68 #ifdef CYGBLD_DEVS_ETH_DEVICE_H    // Get the device config if it exists
69 #include CYGBLD_DEVS_ETH_DEVICE_H  // May provide CYGTST_DEVS_ETH_TEST_NET_REALTIME
70 #endif
71
72 #ifdef CYGPKG_NET_TESTS_USE_RT_TEST_HARNESS // do we use the rt test?
73 # ifdef CYGTST_DEVS_ETH_TEST_NET_REALTIME // Get the test ancilla if it exists
74 #  include CYGTST_DEVS_ETH_TEST_NET_REALTIME
75 # endif
76 #endif
77
78
79 // Fill in the blanks if necessary
80 #ifndef TNR_OFF
81 # define TNR_OFF()
82 #endif
83 #ifndef TNR_ON
84 # define TNR_ON()
85 #endif
86 #ifndef TNR_INIT
87 # define TNR_INIT()
88 #endif
89 #ifndef TNR_PRINT_ACTIVITY
90 # define TNR_PRINT_ACTIVITY()
91 #endif
92
93 // ------------------------------------------------------------------------
94
95 #include <errno.h>
96 #include <network.h>
97
98 #include "autohost.inl"
99
100 #define STACK_SIZE (CYGNUM_HAL_STACK_SIZE_TYPICAL + 0x10000)
101 static char stack[STACK_SIZE];
102 static cyg_thread thread_data;
103 static cyg_handle_t thread_handle;
104
105 static void
106 do_ping_tests(struct bootp *bp, int N, int testtime, int filesize)
107 {
108     int i;
109     char order[256];
110     diag_printf( "INFO: telling %s to run %d pings for %d seconds, %d bytes and up\n",
111           inet_ntoa(bp->bp_siaddr), N, testtime, filesize );
112
113     // For 2nd and subsequent orders, we vary the ping data size:
114     for ( i = 0; i < N; i++ ) {
115         sprintf( order, "%s %s %d %d", "SLOW_PING",
116                  inet_ntoa(bp->bp_yiaddr),
117                  testtime,
118                  filesize + 50 * i );
119         autohost_tell( bp, order );
120     }
121 }
122
123 #define TESTTIME (5 * 60) // Seconds
124
125 #define NUM_SESSIONS 10 // why not?
126
127 void
128 net_test(cyg_addrword_t param)
129 {
130     int i;
131     int numtests;
132     CYG_TEST_INIT();
133     CYG_TEST_INFO("Start PING server test");
134     init_all_network_interfaces();
135
136     autohost_init();
137
138     TNR_INIT();
139     
140     numtests = NUM_SESSIONS; // The number of pingers started OK
141     i = numtests;
142     // Now command the host to do ping to us...
143 #ifdef CYGHWR_NET_DRIVER_ETH0
144     if (eth0_up) {
145         // 2 small tests by default and a couple of larger ones
146         do_ping_tests(&eth0_bootp_data, 2, TESTTIME, 64);
147         do_ping_tests(&eth0_bootp_data, 2, TESTTIME, 1000);
148         do_ping_tests(&eth0_bootp_data, 2, TESTTIME, 10000);
149         i -= 6;
150     }
151 #endif
152 #ifdef CYGHWR_NET_DRIVER_ETH1
153     if (eth1_up && i > 0) {
154         // rest of the tests depending...
155         do_ping_tests(&eth1_bootp_data, 1, TESTTIME, 64);
156         i--;
157         if ( i > 0 ) {
158             do_ping_tests(&eth1_bootp_data, 1, TESTTIME, 4000);
159             i--;
160         }
161         if ( i > 0 ) {
162             do_ping_tests(&eth1_bootp_data, i, TESTTIME, 1200);
163             i = 0;
164         }
165     }
166 #endif
167     numtests -= i; // Adjust to how many we *actually* requested
168
169     // Let the server run for 5 minutes
170     cyg_thread_delay(2*100); // let the stuff start up first
171     TNR_ON();
172     cyg_thread_delay(TESTTIME*100); // FIXME - assume cS clock.
173     // Additional delay 'cos host may be slower than us - and it has to
174     // complete a transfer anyway:
175     cyg_thread_delay(  30    *100); // FIXME - assume cS clock.
176     TNR_OFF();
177
178     autohost_end( numtests ); // check for N pass messages from hosts
179
180     TNR_PRINT_ACTIVITY();
181     CYG_TEST_EXIT("Done");
182 }
183
184 void
185 cyg_start(void)
186 {
187     // Create a main thread, so we can run the scheduler and have time 'pass'
188     cyg_thread_create(10,                // Priority - just a number
189                       net_test,          // entry
190                       0,                 // entry parameter
191                       "Network test",    // Name
192                       &stack[0],         // Stack
193                       STACK_SIZE,        // Size
194                       &thread_handle,    // Handle
195                       &thread_data       // Thread data structure
196             );
197     cyg_thread_resume(thread_handle);  // Start it
198     cyg_scheduler_start();
199 }
200
201 // EOF slowping.c