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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [net/] [ftpclient/] [current/] [tests/] [ftpclient1.c] - Blame information for rev 794

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

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      tests/dns1.c
4
//
5
//      Simple test of DNS client support
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, 2003 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      
16
// version.                                                                 
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT      
19
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
20
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
21
// for more details.                                                        
22
//
23
// You should have received a copy of the GNU General Public License        
24
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
25
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
26
//
27
// As a special exception, if other files instantiate templates or use      
28
// macros or inline functions from this file, or you compile this file      
29
// and link it with other works to produce a work based on this file,       
30
// this file does not by itself cause the resulting work to be covered by   
31
// the GNU General Public License. However the source code for this file    
32
// must still be made available in accordance with section (3) of the GNU   
33
// General Public License v2.                                               
34
//
35
// This exception does not invalidate any other reasons why a work based    
36
// on this file might be covered by the GNU General Public License.         
37
// -------------------------------------------                              
38
// ####ECOSGPLCOPYRIGHTEND####                                              
39
//==========================================================================
40
//#####DESCRIPTIONBEGIN####
41
//
42
// Author(s):    andrew.lunn
43
// Contributors: andrew.lunn, jskov
44
// Date:         2001-09-18
45
// Purpose:      
46
// Description:  Test FTPClient functions. Note that the _XXX defines below
47
//               control what addresses the test uses. These must be
48
//               changed to match the particular testing network in which
49
//               the test is to be run.
50
//              
51
//####DESCRIPTIONEND####
52
//
53
//==========================================================================
54
 
55
#include <network.h>
56
#include <ftpclient.h>
57
#include <cyg/infra/testcase.h>
58
 
59
#define STACK_SIZE (CYGNUM_HAL_STACK_SIZE_TYPICAL + 0x1000)
60
static char stack[STACK_SIZE];
61
static cyg_thread thread_data;
62
static cyg_handle_t thread_handle;
63
 
64
#define __string(_x) #_x
65
#define __xstring(_x) __string(_x)
66
 
67
#define _FTP_SRV           __xstring(172.16.19.254) // farmnet dns0 address
68
#define _FTP_SRV_V6         __xstring(fec0:0:0:2::1)
69
#define FTPBUFSIZE (1024 * 64)
70
char ftpbuf[FTPBUFSIZE];
71
char ftpbuf1[FTPBUFSIZE];
72
 
73
void
74
ftp_test(cyg_addrword_t p)
75
{
76
  int ret;
77
 
78
  CYG_TEST_INIT();
79
 
80
  init_all_network_interfaces();
81
 
82
  CYG_TEST_INFO("Getting /etc/passwd from " _FTP_SRV);
83
  ret = ftp_get(_FTP_SRV,"anonymous","ftpclient1",
84
                 "/etc/passwd",ftpbuf,FTPBUFSIZE,
85
                ftpclient_printf);
86
 
87
  if (ret > 0) {
88
    diag_printf("PASS:< %d bytes received>\n",ret);
89
  } else {
90
    diag_printf("FAIL:< ftp_get returned %d>\n",ret);
91
  }
92
 
93
  CYG_TEST_INFO("Putting passwd file back in /incoming/passwd\n");
94
  ret = ftp_put(_FTP_SRV,"anonymous","ftpclient1",
95
                "/incoming/passwd",ftpbuf,ret,
96
                ftpclient_printf);
97
 
98
  if (ret > 0) {
99
    diag_printf("PASS:\n");
100
  } else {
101
    diag_printf("FAIL:< ftp_get returned %d>\n",ret);
102
  }
103
 
104
  CYG_TEST_INFO("Reading back /incoming/passwd\n");
105
  ret = ftp_get(_FTP_SRV,"anonymous","ftpclient1",
106
                 "/incoming/passwd",ftpbuf1,FTPBUFSIZE,
107
                ftpclient_printf);
108
 
109
  if (ret > 0) {
110
    diag_printf("PASS:< %d bytes received>\n",ret);
111
  } else {
112
    diag_printf("FAIL:< ftp_get returned %d>\n",ret);
113
  }
114
 
115
  CYG_TEST_PASS_FAIL(!memcmp(ftpbuf,ftpbuf1,ret),"Transfer integrity");
116
 
117
#ifdef CYGPKG_NET_INET6
118
  CYG_TEST_INFO("Getting /etc/passwd from " _FTP_SRV_V6);
119
  ret = ftp_get(_FTP_SRV_V6,"anonymous","ftpclient1",
120
                 "/etc/passwd",ftpbuf,FTPBUFSIZE,
121
                ftpclient_printf);
122
 
123
  if (ret > 0) {
124
    diag_printf("PASS:< %d bytes received>\n",ret);
125
  } else {
126
    diag_printf("FAIL:< ftp_get returned %d>\n",ret);
127
  }
128
 
129
  CYG_TEST_INFO("Putting passwd file back in /incoming/passwd\n");
130
  ret = ftp_put(_FTP_SRV_V6,"anonymous","ftpclient1",
131
                "/incoming/passwd",ftpbuf,ret,
132
                ftpclient_printf);
133
 
134
  if (ret > 0) {
135
    diag_printf("PASS:\n");
136
  } else {
137
    diag_printf("FAIL:< ftp_get returned %d>\n",ret);
138
  }
139
 
140
  CYG_TEST_INFO("Reading back /incoming/passwd\n");
141
  ret = ftp_get(_FTP_SRV_V6,"anonymous","ftpclient1",
142
                 "/incoming/passwd",ftpbuf1,FTPBUFSIZE,
143
                ftpclient_printf);
144
 
145
  if (ret > 0) {
146
    diag_printf("PASS:< %d bytes received>\n",ret);
147
  } else {
148
    diag_printf("FAIL:< ftp_get returned %d>\n",ret);
149
  }
150
 
151
  CYG_TEST_PASS_FAIL(!memcmp(ftpbuf,ftpbuf1,ret),"Transfer integrity");
152
 
153
#endif
154
 
155
  CYG_TEST_INFO("ftp_Get'ing with a bad username\n");
156
  ret = ftp_get(_FTP_SRV,"nosuchuser","ftpclient1",
157
                "/incoming/passwd",ftpbuf1,FTPBUFSIZE,
158
                ftpclient_printf);
159
  CYG_TEST_PASS_FAIL(ret==FTP_BADUSER,"Bad Username");
160
 
161
  CYG_TEST_INFO("ftp_get'ting with a bad passwd\n");
162
  ret = ftp_get(_FTP_SRV,"nobody","ftpclient1",
163
                "/incoming/passwd",ftpbuf1,FTPBUFSIZE,
164
                ftpclient_printf);
165
  CYG_TEST_PASS_FAIL(ret==FTP_BADUSER,"Bad passwd");
166
 
167
  CYG_TEST_INFO("ftp_get'ing from a with a bad passwd\n");
168
  ret = ftp_get(_FTP_SRV,"nobody","ftpclient1",
169
                "/incoming/passwd",ftpbuf1,FTPBUFSIZE,
170
                ftpclient_printf);
171
  CYG_TEST_PASS_FAIL(ret==FTP_BADUSER,"Bad passwd");
172
 
173
  CYG_TEST_INFO("ftp_get'ing from a bad server\n");
174
  ret = ftp_get("127.0.0.1","nobody","ftpclient1",
175
                "/incoming/passwd",ftpbuf1,FTPBUFSIZE,
176
                ftpclient_printf);
177
  CYG_TEST_PASS_FAIL(ret==FTP_NOSUCHHOST,"Bad server");
178
 
179
  CYG_TEST_INFO("ftp_get'ing a file which is too big");
180
  ret = ftp_get(_FTP_SRV,"anonymous","ftpclient1",
181
                "/incoming/passwd",ftpbuf,2,
182
                ftpclient_printf);
183
  CYG_TEST_PASS_FAIL(ret==FTP_TOOBIG,"File too big");
184
}
185
 
186
void
187
cyg_start(void)
188
{
189
  /* Create a main thread, so we can run the scheduler and have time 'pass' */
190
  cyg_thread_create(10,                // Priority - just a number
191
                    ftp_test,          // entry
192
                    0,                 // entry parameter
193
                    "FTP test",        // Name
194
                    &stack[0],         // Stack
195
                    STACK_SIZE,        // Size
196
                    &thread_handle,    // Handle
197
                    &thread_data       // Thread data structure
198
                    );
199
  cyg_thread_resume(thread_handle);  /* Start it */
200
  cyg_scheduler_start();
201
}

powered by: WebSVN 2.1.0

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