source: rtems/testsuites/libtests/ftp01/init.c @ ad0e103

4.115
Last change on this file since ad0e103 was ad0e103, checked in by Sebastian Huber <sebastian.huber@…>, on Oct 26, 2011 at 10:34:11 AM

2011-10-26 Sebastian Huber <sebastian.huber@…>

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