]> git.karo-electronics.de Git - karo-tx-redboot.git/blob - packages/net/common/v2_0/tests/tftp_server_test.c
Initial revision
[karo-tx-redboot.git] / packages / net / common / v2_0 / tests / tftp_server_test.c
1 //==========================================================================
2 //
3 //      tests/tftp_server_test.c
4 //
5 //      Simple TFTP server test
6 //
7 //==========================================================================
8 //####BSDCOPYRIGHTBEGIN####
9 //
10 // -------------------------------------------
11 //
12 // Portions of this software may have been derived from OpenBSD or other sources,
13 // and are covered by the appropriate copyright disclaimers included herein.
14 //
15 // -------------------------------------------
16 //
17 //####BSDCOPYRIGHTEND####
18 //==========================================================================
19 //#####DESCRIPTIONBEGIN####
20 //
21 // Author(s):    gthomas
22 // Contributors: gthomas
23 // Date:         2000-04-07
24 // Purpose:      
25 // Description:  
26 //              
27 //
28 //####DESCRIPTIONEND####
29 //
30 //==========================================================================
31 // TFTP test code
32
33 #include <pkgconf/system.h>
34 #include <pkgconf/net.h>
35
36 #ifdef CYGBLD_DEVS_ETH_DEVICE_H    // Get the device config if it exists
37 #include CYGBLD_DEVS_ETH_DEVICE_H  // May provide CYGTST_DEVS_ETH_TEST_NET_REALTIME
38 #endif
39
40 #ifdef CYGPKG_NET_TESTS_USE_RT_TEST_HARNESS // do we use the rt test?
41 # ifdef CYGTST_DEVS_ETH_TEST_NET_REALTIME // Get the test ancilla if it exists
42 #  include CYGTST_DEVS_ETH_TEST_NET_REALTIME
43 # endif
44 #endif
45
46
47 // Fill in the blanks if necessary
48 #ifndef TNR_OFF
49 # define TNR_OFF()
50 #endif
51 #ifndef TNR_ON
52 # define TNR_ON()
53 #endif
54 #ifndef TNR_INIT
55 # define TNR_INIT()
56 #endif
57 #ifndef TNR_PRINT_ACTIVITY
58 # define TNR_PRINT_ACTIVITY()
59 #endif
60
61 // ------------------------------------------------------------------------
62
63 #include <network.h>
64 #include <tftp_support.h>
65
66 #define STACK_SIZE (CYGNUM_HAL_STACK_SIZE_TYPICAL + 0x1000)
67 static char stack[STACK_SIZE];
68 static cyg_thread thread_data;
69 static cyg_handle_t thread_handle;
70
71 extern void
72 cyg_test_exit(void);
73
74 void
75 pexit(char *s)
76 {
77     perror(s);
78     cyg_test_exit();
79 }
80
81 static void
82 tftp_test(struct bootp *bp)
83 {
84     int res;
85     int server1_id = 0;
86     int server2_id = 0;
87     int server3_id = 0;
88
89     extern struct tftpd_fileops dummy_fileops;
90
91     server1_id = tftpd_start(0, &dummy_fileops);
92     if (server1_id > 0) {
93       diag_printf("TFTP server created - id: %x\n", server1_id);
94     } else {
95       diag_printf("Couldn't create first server!\n");
96     }
97
98 #ifdef CYGSEM_NET_TFTPD_MULTITHREADED
99     server2_id = tftpd_start(0, &dummy_fileops);
100     if (server2_id > 0) {
101       diag_printf("Second TFTP server created - id: %x\n", server2_id);
102     } else {
103       diag_printf("Couldn't create a second server!\n");
104     }
105 #if CYGNUM_NET_TFTPD_MULTITHREADED_PORTS > 1
106     server3_id = tftpd_start(1025, &dummy_fileops);
107     if (server3_id > 0) {
108       diag_printf("Third TFTP server created - id: %x\n", server3_id);
109     } else {
110       diag_printf("Couldn't create a third server!\n");
111     }
112 #endif //CYGNUM_NET_TFTPD_MULTITHREADED_PORTS > 1
113 #else  //CYGSEM_NET_TFTPD_MULTITHREADED
114     server2_id = tftpd_start(1025, &dummy_fileops);
115     if (server2_id > 0) {
116       diag_printf("Second TFTP server created - id: %x\n", server2_id);
117     } else {
118       diag_printf("Couldn't create a second server!\n");
119     }
120 #endif //!CYGSEM_NET_TFTPD_MULTITHREADED
121     
122     // Only let the server run for 5 minutes
123     cyg_thread_delay(2*100); // let the tftpd start up first
124     TNR_ON();
125     cyg_thread_delay(5*60*100);
126     TNR_OFF();
127     
128     if (server1_id > 0) {
129       res = tftpd_stop(server1_id);
130       diag_printf("TFTP server - id: %x stopped - res: %d\n", server1_id, res);
131     }
132     if (server2_id > 0) {
133       res = tftpd_stop(server2_id);
134       diag_printf("TFTP server - id: %x stopped - res: %d\n", server2_id, res);
135     }
136     if (server3_id > 0) {
137       res = tftpd_stop(server2_id);
138       diag_printf("TFTP server - id: %x stopped - res: %d\n", server2_id, res);
139     }
140
141
142 void
143 net_test(cyg_addrword_t param)
144 {
145     diag_printf("Start TFTP server test\n");
146     init_all_network_interfaces();
147     TNR_INIT();
148 #ifdef CYGHWR_NET_DRIVER_ETH0
149     if (eth0_up) {
150         tftp_test(&eth0_bootp_data);
151     }
152 #else
153     if ( 0 ) ; 
154 #endif
155 #ifdef CYGHWR_NET_DRIVER_ETH1
156     else if (eth1_up) {
157         tftp_test(&eth1_bootp_data);
158     }
159 #endif
160     TNR_PRINT_ACTIVITY();
161     cyg_test_exit();
162 }
163
164 void
165 cyg_start(void)
166 {
167     // Create a main thread, so we can run the scheduler and have time 'pass'
168     cyg_thread_create(10,                // Priority - just a number
169                       net_test,          // entry
170                       0,                 // entry parameter
171                       "Network test",    // Name
172                       &stack[0],         // Stack
173                       STACK_SIZE,        // Size
174                       &thread_handle,    // Handle
175                       &thread_data       // Thread data structure
176             );
177     cyg_thread_resume(thread_handle);  // Start it
178     cyg_scheduler_start();
179 }
180
181 // EOF tftp_server_test.c