1 //==========================================================================
3 // tests/tftp_server_test.c
5 // Simple TFTP server test
7 //==========================================================================
8 //####BSDCOPYRIGHTBEGIN####
10 // -------------------------------------------
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.
15 // -------------------------------------------
17 //####BSDCOPYRIGHTEND####
18 //==========================================================================
19 //#####DESCRIPTIONBEGIN####
22 // Contributors: gthomas
28 //####DESCRIPTIONEND####
30 //==========================================================================
33 #include <pkgconf/system.h>
34 #include <pkgconf/net.h>
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
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
47 // Fill in the blanks if necessary
57 #ifndef TNR_PRINT_ACTIVITY
58 # define TNR_PRINT_ACTIVITY()
61 // ------------------------------------------------------------------------
64 #include <tftp_support.h>
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;
82 tftp_test(struct bootp *bp)
89 extern struct tftpd_fileops dummy_fileops;
91 server1_id = tftpd_start(0, &dummy_fileops);
93 diag_printf("TFTP server created - id: %x\n", server1_id);
95 diag_printf("Couldn't create first server!\n");
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);
103 diag_printf("Couldn't create a second server!\n");
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);
110 diag_printf("Couldn't create a third server!\n");
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);
118 diag_printf("Couldn't create a second server!\n");
120 #endif //!CYGSEM_NET_TFTPD_MULTITHREADED
122 // Only let the server run for 5 minutes
123 cyg_thread_delay(2*100); // let the tftpd start up first
125 cyg_thread_delay(5*60*100);
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);
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);
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);
143 net_test(cyg_addrword_t param)
145 diag_printf("Start TFTP server test\n");
146 init_all_network_interfaces();
148 #ifdef CYGHWR_NET_DRIVER_ETH0
150 tftp_test(ð0_bootp_data);
155 #ifdef CYGHWR_NET_DRIVER_ETH1
157 tftp_test(ð1_bootp_data);
160 TNR_PRINT_ACTIVITY();
167 // Create a main thread, so we can run the scheduler and have time 'pass'
168 cyg_thread_create(10, // Priority - just a number
170 0, // entry parameter
171 "Network test", // Name
174 &thread_handle, // Handle
175 &thread_data // Thread data structure
177 cyg_thread_resume(thread_handle); // Start it
178 cyg_scheduler_start();
181 // EOF tftp_server_test.c