source: rtems-libbsd/testsuite/media01/test_main.c @ 81edae4

55-freebsd-126-freebsd-12freebsd-9.3
Last change on this file since 81edae4 was 81edae4, checked in by Sebastian Huber <sebastian.huber@…>, on 03/31/15 at 07:42:01

media01: Add network and SMP support

  • Property mode set to 100644
File size: 5.1 KB
Line 
1/*
2 * Copyright (c) 2010-2015 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Dornierstr. 4
6 *  82178 Puchheim
7 *  Germany
8 *  <rtems@embedded-brains.de>
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32#include <assert.h>
33#include <stdio.h>
34
35#include <rtems/bdbuf.h>
36#include <rtems/console.h>
37#include <rtems/ftpd.h>
38#include <rtems/media.h>
39#include <rtems/shell.h>
40
41#define TEST_NAME "LIBBSD MEDIA 1"
42
43struct rtems_ftpd_configuration rtems_ftpd_configuration = {
44        /* FTPD task priority */
45        .priority = 100,
46
47        /* Maximum buffersize for hooks */
48        .max_hook_filesize = 0,
49
50        /* Well-known port */
51        .port = 21,
52
53        /* List of hooks */
54        .hooks = NULL,
55
56        /* Root for FTPD or NULL for "/" */
57        .root = NULL,
58
59        /* Max. connections */
60        .tasks_count = 4,
61
62        /* Idle timeout in seconds  or 0 for no (infinite) timeout */
63        .idle = 5 * 60,
64
65        /* Access: 0 - r/w, 1 - read-only, 2 - write-only, 3 - browse-only */
66        .access = 0
67};
68
69static rtems_status_code
70media_listener(rtems_media_event event, rtems_media_state state,
71    const char *src, const char *dest, void *arg)
72{
73        printf(
74                "media listener: event = %s, state = %s, src = %s",
75                rtems_media_event_description(event),
76                rtems_media_state_description(state),
77                src
78        );
79
80        if (dest != NULL) {
81                printf(", dest = %s", dest);
82        }
83
84        if (arg != NULL) {
85                printf(", arg = %p\n", arg);
86        }
87
88        printf("\n");
89
90        if (event == RTEMS_MEDIA_EVENT_MOUNT && state == RTEMS_MEDIA_STATE_SUCCESS) {
91                char name[256];
92                int n = snprintf(&name[0], sizeof(name), "%s/test.txt", dest);
93                FILE *file;
94
95                assert(n < (int) sizeof(name));
96
97                printf("write file %s\n", &name[0]);
98                file = fopen(&name[0], "w");
99                if (file != NULL) {
100                        const char hello[] = "Hello, world!\n";
101
102                        fwrite(&hello[0], sizeof(hello) - 1, 1, file);
103                        fclose(file);
104                }
105        }
106
107        return RTEMS_SUCCESSFUL;
108}
109
110static void
111test_main(void)
112{
113        int rv;
114        rtems_status_code sc;
115
116        rv = rtems_initialize_ftpd();
117        assert(rv == 0);
118
119        sc = rtems_shell_init("SHLL", 16 * 1024, 1, CONSOLE_DEVICE_NAME,
120            false, true, NULL);
121        assert(sc == RTEMS_SUCCESSFUL);
122
123        exit(0);
124}
125
126#define DEFAULT_EARLY_INITIALIZATION
127
128static void
129early_initialization(void)
130{
131        rtems_status_code sc;
132
133        sc = rtems_bdbuf_init();
134        assert(sc == RTEMS_SUCCESSFUL);
135
136        sc = rtems_media_initialize();
137        assert(sc == RTEMS_SUCCESSFUL);
138
139        sc = rtems_media_listener_add(media_listener, NULL);
140        assert(sc == RTEMS_SUCCESSFUL);
141
142        sc = rtems_media_server_initialize(
143                200,
144                32 * 1024,
145                RTEMS_DEFAULT_MODES,
146                RTEMS_DEFAULT_ATTRIBUTES
147        );
148        assert(sc == RTEMS_SUCCESSFUL);
149}
150
151#define DEFAULT_NETWORK_DHCPCD_ENABLE
152
153#define CONFIGURE_FILESYSTEM_DOSFS
154
155#define CONFIGURE_SMP_APPLICATION
156
157#define CONFIGURE_SMP_MAXIMUM_PROCESSORS 32
158
159#include <rtems/bsd/test/default-network-init.h>
160
161#define CONFIGURE_SHELL_COMMANDS_INIT
162
163#include <bsp/irq-info.h>
164
165#include <rtems/netcmds-config.h>
166
167#define CONFIGURE_SHELL_USER_COMMANDS \
168  &bsp_interrupt_shell_command, \
169  &rtems_shell_BSD_Command, \
170  &rtems_shell_HOSTNAME_Command, \
171  &rtems_shell_PING_Command, \
172  &rtems_shell_ROUTE_Command, \
173  &rtems_shell_NETSTAT_Command, \
174  &rtems_shell_IFCONFIG_Command
175
176#define CONFIGURE_SHELL_COMMAND_CPUUSE
177#define CONFIGURE_SHELL_COMMAND_PERIODUSE
178#define CONFIGURE_SHELL_COMMAND_STACKUSE
179#define CONFIGURE_SHELL_COMMAND_PROFREPORT
180
181#define CONFIGURE_SHELL_COMMAND_CP
182#define CONFIGURE_SHELL_COMMAND_PWD
183#define CONFIGURE_SHELL_COMMAND_LS
184#define CONFIGURE_SHELL_COMMAND_LN
185#define CONFIGURE_SHELL_COMMAND_LSOF
186#define CONFIGURE_SHELL_COMMAND_CHDIR
187#define CONFIGURE_SHELL_COMMAND_CD
188#define CONFIGURE_SHELL_COMMAND_MKDIR
189#define CONFIGURE_SHELL_COMMAND_RMDIR
190#define CONFIGURE_SHELL_COMMAND_CAT
191#define CONFIGURE_SHELL_COMMAND_MV
192#define CONFIGURE_SHELL_COMMAND_RM
193#define CONFIGURE_SHELL_COMMAND_MALLOC_INFO
194
195#define CONFIGURE_SHELL_COMMAND_FDISK
196#define CONFIGURE_SHELL_COMMAND_BLKSTATS
197#define CONFIGURE_SHELL_COMMAND_BLKSYNC
198#define CONFIGURE_SHELL_COMMAND_MSDOSFMT
199#define CONFIGURE_SHELL_COMMAND_DF
200
201#include <rtems/shellconfig.h>
Note: See TracBrowser for help on using the repository browser.