source: rtems/testsuites/libtests/ftp01/init.c @ 2a6ed0aa

4.115
Last change on this file since 2a6ed0aa was 2a6ed0aa, checked in by Sebastian Huber <sebastian.huber@…>, on May 6, 2011 at 9:08:07 AM

2011-05-06 Sebastian Huber <sebastian.huber@…>

  • ftp01/.cvsignore, ftp01/Makefile.am, ftp01/ftp01.doc, ftp01/ftp01.scn, ftp01/init.c: New files.
  • Makefile.am, configure.ac: Reflect changes above.
  • Property mode set to 100644
File size: 5.1 KB
Line 
1/*
2 * Copyright (c) 2011 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Obere Lagerstr. 30
6 *  82178 Puchheim
7 *  Germany
8 *  <rtems@embedded-brains.de>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.com/license/LICENSE.
13 *
14 * $Id$
15 */
16
17#ifdef HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <sys/stat.h>
22#include <fcntl.h>
23#include <string.h>
24
25#include <rtems.h>
26#include <tmacros.h>
27
28#include <rtems/rtems_bsdnet.h>
29#include <rtems/ftpd.h>
30#include <rtems/ftpfs.h>
31
32struct rtems_bsdnet_config rtems_bsdnet_config;
33
34struct rtems_ftpd_configuration rtems_ftpd_configuration = {
35  .priority = 90,
36  .max_hook_filesize = 0,
37  .port = 21,
38  .hooks = NULL,
39  .root = NULL,
40  .tasks_count = 2,
41  .idle = 0,
42  .access = 0
43};
44
45static const char content [] =
46"                      LICENSE INFORMATION\n"
47"\n"
48"RTEMS is free software; you can redistribute it and/or modify it under\n"
49"terms of the GNU General Public License as published by the\n"
50"Free Software Foundation; either version 2, or (at your option) any\n"
51"later version.  RTEMS is distributed in the hope that it will be useful,\n"
52"but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
53"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
54"General Public License for more details. You should have received\n"
55"a copy of the GNU General Public License along with RTEMS; see\n"
56"file COPYING. If not, write to the Free Software Foundation, 675\n"
57"Mass Ave, Cambridge, MA 02139, USA.\n"
58"\n"
59"As a special exception, including RTEMS header files in a file,\n"
60"instantiating RTEMS generics or templates, or linking other files\n"
61"with RTEMS objects to produce an executable application, does not\n"
62"by itself cause the resulting executable application to be covered\n"
63"by the GNU General Public License. This exception does not\n"
64"however invalidate any other reasons why the executable file might be\n"
65"covered by the GNU Public License.\n";
66
67static void initialize_ftpfs(void)
68{
69  rtems_status_code sc = RTEMS_SUCCESSFUL;
70  int rv = 0;
71  struct timeval to = {
72    .tv_sec = 10,
73    .tv_usec = 0
74  };
75  const char *target = RTEMS_FTPFS_MOUNT_POINT_DEFAULT;
76
77  rv = mount_and_make_target_path(
78    NULL,
79    target,
80    RTEMS_FILESYSTEM_TYPE_FTPFS,
81    RTEMS_FILESYSTEM_READ_WRITE,
82    NULL
83  );
84  rtems_test_assert(rv == 0);
85
86  sc = rtems_ftpfs_set_verbose(target, true);
87  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
88
89  sc = rtems_ftpfs_set_timeout(target, &to);
90  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
91}
92
93static void change_self_priority(void)
94{
95  rtems_status_code sc = RTEMS_SUCCESSFUL;
96  rtems_task_priority cur = 0;
97
98  sc = rtems_task_set_priority(RTEMS_SUCCESSFUL, 110, &cur);
99  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
100}
101
102static void create_file(const char *path)
103{
104  int rv = 0;
105  int fd = open(path, O_WRONLY);
106  ssize_t n = 0;
107
108  rtems_test_assert(fd >= 0);
109
110  n = write(fd, &content [0], sizeof(content));
111  rtems_test_assert(n == (ssize_t) sizeof(content));
112
113  rv = close(fd);
114  rtems_test_assert(rv == 0);
115}
116
117static void copy_file(const char *src_path, const char *dest_path)
118{
119  int rv = 0;
120  int in = open(src_path, O_RDONLY);
121  int out = open(dest_path, O_WRONLY);
122  ssize_t n_in = 0;
123  char buf [64];
124
125  rtems_test_assert(in >= 0);
126  rtems_test_assert(out >= 0);
127
128  while ((n_in = read(in, buf, sizeof(buf))) > 0) {
129    ssize_t n_out = write(out, buf, (size_t) n_in);
130    rtems_test_assert(n_out == n_in);
131  }
132
133  rv = close(out);
134  rtems_test_assert(rv == 0);
135
136  rv = close(in);
137  rtems_test_assert(rv == 0);
138}
139
140static void check_file(const char *path)
141{
142  int rv = 0;
143  int fd = open(path, O_RDONLY);
144  ssize_t n = 0;
145  char buf [64];
146  const char *current = &content [0];
147  size_t done = 0;
148
149  rtems_test_assert(fd >= 0);
150
151  while ((n = read(fd, buf, sizeof(buf))) > 0) {
152    done += (size_t) n;
153    rtems_test_assert(done <= sizeof(content));
154    rtems_test_assert(memcmp(current, buf, (size_t) n) == 0);
155    current += (size_t) n;
156  }
157
158  rtems_test_assert(done == sizeof(content));
159
160  rv = close(fd);
161  rtems_test_assert(rv == 0);
162}
163
164static void test(void)
165{
166  int rv = 0;
167  const char file_a [] = "/FTP/127.0.0.1/a.txt";
168  const char file_b [] = "/FTP/127.0.0.1/b.txt";
169
170  rv = rtems_bsdnet_initialize_network();
171  rtems_test_assert(rv == 0);
172
173  rv = rtems_initialize_ftpd();
174  rtems_test_assert(rv == 0);
175
176  initialize_ftpfs();
177  change_self_priority();
178  create_file(file_a);
179  copy_file(file_a, file_b);
180  check_file(file_b);
181}
182
183static rtems_task Init(rtems_task_argument argument)
184{
185  puts("\n\n*** TEST FTP 1 ***");
186  test();
187  puts("*** END OF TEST FTP 1 ***");
188
189  rtems_test_exit(0);
190}
191
192#define CONFIGURE_INIT
193
194#define CONFIGURE_MICROSECONDS_PER_TICK 10000
195
196#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
197#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
198
199#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 14
200
201#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
202#define CONFIGURE_FILESYSTEM_FTPFS
203
204#define CONFIGURE_MAXIMUM_DRIVERS 2
205
206#define CONFIGURE_MAXIMUM_TASKS 5
207#define CONFIGURE_MAXIMUM_SEMAPHORES 2
208
209#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
210
211#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.