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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [net/] [common/] [current/] [tests/] [tftp_server_test.c] - Blame information for rev 856

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

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

powered by: WebSVN 2.1.0

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