mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2025-12-26 14:18:20 +00:00
@@ -1,23 +0,0 @@
|
||||
SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
|
||||
build-type: test-program
|
||||
cflags: []
|
||||
copyrights:
|
||||
- Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
|
||||
cppflags: []
|
||||
cxxflags: []
|
||||
enabled-by:
|
||||
- RTEMS_NETWORKING
|
||||
features: c cprogram
|
||||
includes:
|
||||
- cpukit/libnetworking
|
||||
ldflags: []
|
||||
links: []
|
||||
source:
|
||||
- testsuites/libtests/ftp01/init.c
|
||||
stlib: []
|
||||
target: testsuites/libtests/ftp01.exe
|
||||
type: build
|
||||
use-after:
|
||||
- ftpd
|
||||
- ftpfs
|
||||
use-before: []
|
||||
@@ -124,8 +124,6 @@ links:
|
||||
uid: free
|
||||
- role: build-dependency
|
||||
uid: fstat
|
||||
- role: build-dependency
|
||||
uid: ftp01
|
||||
- role: build-dependency
|
||||
uid: ftrylockfile
|
||||
- role: build-dependency
|
||||
@@ -186,8 +184,6 @@ links:
|
||||
uid: mathl
|
||||
- role: build-dependency
|
||||
uid: md501
|
||||
- role: build-dependency
|
||||
uid: mghttpd01
|
||||
- role: build-dependency
|
||||
uid: monitor
|
||||
- role: build-dependency
|
||||
@@ -196,8 +192,6 @@ links:
|
||||
uid: mouse01
|
||||
- role: build-dependency
|
||||
uid: nanosleep
|
||||
- role: build-dependency
|
||||
uid: networking01
|
||||
- role: build-dependency
|
||||
uid: newlib01
|
||||
- role: build-dependency
|
||||
@@ -258,8 +252,6 @@ links:
|
||||
uid: stat
|
||||
- role: build-dependency
|
||||
uid: stringto01
|
||||
- role: build-dependency
|
||||
uid: syscall01
|
||||
- role: build-dependency
|
||||
uid: tar01
|
||||
- role: build-dependency
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
|
||||
build-type: script
|
||||
cflags: []
|
||||
copyrights:
|
||||
- Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
|
||||
cppflags: []
|
||||
do-build: |
|
||||
path = "testsuites/libtests/mghttpd01/"
|
||||
tar_c, tar_h = self.bin2c(bld, path + "mghttpd01.tar")
|
||||
objs = []
|
||||
objs.append(self.cc(bld, bic, tar_c))
|
||||
objs.append(self.cc(bld, bic, path + "init.c", deps=[tar_h], cppflags=bld.env.TEST_MGHTTPD01_CPPFLAGS))
|
||||
objs.append(self.cc(bld, bic, path + "test-http-client.c"))
|
||||
self.link_cc(bld, bic, objs, "testsuites/libtests/mghttpd01.exe")
|
||||
do-configure: null
|
||||
enabled-by:
|
||||
- and:
|
||||
- RTEMS_NETWORKING
|
||||
- RTEMS_POSIX_API
|
||||
- not: TEST_MGHTTPD01_EXCLUDE
|
||||
includes:
|
||||
- cpukit/libnetworking
|
||||
- testsuites/libtests/mghttpd01
|
||||
ldflags: []
|
||||
links: []
|
||||
prepare-build: null
|
||||
prepare-configure: null
|
||||
stlib: []
|
||||
type: build
|
||||
use-after:
|
||||
- mghttpd
|
||||
use-before: []
|
||||
@@ -1,21 +0,0 @@
|
||||
SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
|
||||
build-type: test-program
|
||||
cflags: []
|
||||
copyrights:
|
||||
- Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
|
||||
cppflags: []
|
||||
cxxflags: []
|
||||
enabled-by:
|
||||
- RTEMS_NETWORKING
|
||||
features: c cprogram
|
||||
includes:
|
||||
- cpukit/libnetworking
|
||||
ldflags: []
|
||||
links: []
|
||||
source:
|
||||
- testsuites/libtests/syscall01/init.c
|
||||
stlib: []
|
||||
target: testsuites/libtests/syscall01.exe
|
||||
type: build
|
||||
use-after: []
|
||||
use-before: []
|
||||
@@ -28,16 +28,12 @@ links:
|
||||
uid: hello
|
||||
- role: build-dependency
|
||||
uid: iostream
|
||||
- role: build-dependency
|
||||
uid: loopback
|
||||
- role: build-dependency
|
||||
uid: minimum
|
||||
- role: build-dependency
|
||||
uid: nsecs
|
||||
- role: build-dependency
|
||||
uid: paranoia
|
||||
- role: build-dependency
|
||||
uid: pppd
|
||||
- role: build-dependency
|
||||
uid: ticker
|
||||
- role: build-dependency
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
|
||||
build-type: test-program
|
||||
cflags: []
|
||||
copyrights:
|
||||
- Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
|
||||
cppflags: []
|
||||
cxxflags: []
|
||||
enabled-by:
|
||||
- RTEMS_NETWORKING
|
||||
features: c cprogram
|
||||
includes:
|
||||
- cpukit/libnetworking
|
||||
ldflags: []
|
||||
links: []
|
||||
source:
|
||||
- testsuites/samples/loopback/init.c
|
||||
stlib: []
|
||||
target: testsuites/samples/loopback.exe
|
||||
type: build
|
||||
use-after: []
|
||||
use-before: []
|
||||
@@ -1,25 +0,0 @@
|
||||
SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
|
||||
build-type: test-program
|
||||
cflags: []
|
||||
copyrights:
|
||||
- Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
|
||||
cppflags: []
|
||||
cxxflags: []
|
||||
enabled-by:
|
||||
- and:
|
||||
- RTEMS_NETWORKING
|
||||
- not: RTEMS_SMP
|
||||
features: c cprogram
|
||||
includes:
|
||||
- cpukit/libnetworking
|
||||
ldflags: []
|
||||
links: []
|
||||
source:
|
||||
- testsuites/samples/pppd/init.c
|
||||
- testsuites/samples/pppd/pppdapp.c
|
||||
stlib: []
|
||||
target: testsuites/samples/pppd.exe
|
||||
type: build
|
||||
use-after:
|
||||
- pppd
|
||||
use-before: []
|
||||
@@ -1,24 +0,0 @@
|
||||
#
|
||||
# Copyright (c) 2011 embedded brains GmbH. All rights reserved.
|
||||
#
|
||||
# embedded brains GmbH
|
||||
# Obere Lagerstr. 30
|
||||
# 82178 Puchheim
|
||||
# Germany
|
||||
# <rtems@embedded-brains.de>
|
||||
#
|
||||
# The license and distribution terms for this file may be
|
||||
# found in the file LICENSE in this distribution or at
|
||||
# http://www.rtems.org/license/LICENSE.
|
||||
|
||||
This file describes the directives and concepts tested by this test set.
|
||||
|
||||
test set name: ftp
|
||||
|
||||
directives:
|
||||
|
||||
FTP server and client
|
||||
|
||||
concepts:
|
||||
|
||||
+ Check if FTP server and client works.
|
||||
@@ -1,97 +0,0 @@
|
||||
*** BEGIN OF TEST FTP 1 ***
|
||||
*** TEST VERSION: 5.0.0.b38887ad22e2e28c15b4e248dac72f6eaff8cb13
|
||||
*** TEST STATE: EXPECTED_PASS
|
||||
*** TEST BUILD: RTEMS_NETWORKING
|
||||
*** TEST TOOLS: 7.3.0 20180125 (RTEMS 5, RSB 9670d7541e0621915e521fe76e7bb33de8cee661, Newlib d13c84eb07e35984bf7a974cd786a6cdac29e6b9)
|
||||
syslog: ftpd: FTP daemon started (2 sessions max)
|
||||
220 RTEMS FTP server (Version 1.1-JWJ) ready.
|
||||
login check (1): user "anonymous"
|
||||
USER anonymous
|
||||
230 User logged in.
|
||||
TYPE I
|
||||
200 Type set to I.
|
||||
SIZE a.txt
|
||||
550 Could not get file size.
|
||||
PASV
|
||||
227 Entering passive mode (127,0,0,1,4,1).
|
||||
STOR a.txt
|
||||
150 Opening BINARY mode data connection.
|
||||
226 Transfer complete.
|
||||
QUIT
|
||||
221 Goodbye.
|
||||
220 RTEMS FTP server (Version 1.1-JWJ) ready.
|
||||
login check (1): user "anonymous"
|
||||
USER anonymous
|
||||
230 User logged in.
|
||||
TYPE I
|
||||
200 Type set to I.
|
||||
SIZE a.txt
|
||||
213 1102
|
||||
PASV
|
||||
227 Entering passive mode (127,0,0,1,4,4).
|
||||
RETR a.txt
|
||||
150 Opening BINARY mode data connection.
|
||||
220 RTEMS FTP server (Version 1.1-JWJ) ready.
|
||||
login check (1): user "user"
|
||||
USER user
|
||||
331 User name okay, need password.
|
||||
login check (2): user "user", pass "pass"
|
||||
PASS pass
|
||||
230 User logged in.
|
||||
TYPE I
|
||||
200 Type set to I.
|
||||
SIZE b.txt
|
||||
550 Could not get file size.
|
||||
PASV
|
||||
227 Entering passive mode (127,0,0,1,4,7).
|
||||
STOR b.txt
|
||||
150 Opening BINARY mode data connection.
|
||||
226 Transfer complete.
|
||||
226 Transfer complete.
|
||||
QUIT
|
||||
221 Goodbye.
|
||||
QUIT
|
||||
221 Goodbye.
|
||||
220 RTEMS FTP server (Version 1.1-JWJ) ready.
|
||||
login check (1): user "user"
|
||||
USER user
|
||||
331 User name okay, need password.
|
||||
login check (2): user "user", pass "pass"
|
||||
PASS pass
|
||||
230 User logged in.
|
||||
TYPE I
|
||||
200 Type set to I.
|
||||
SIZE b.txt
|
||||
213 1102
|
||||
PASV
|
||||
227 Entering passive mode (127,0,0,1,4,10).
|
||||
RETR b.txt
|
||||
150 Opening BINARY mode data connection.
|
||||
226 Transfer complete.
|
||||
QUIT
|
||||
221 Goodbye.
|
||||
220 RTEMS FTP server (Version 1.1-JWJ) ready.
|
||||
login check (1): user "anonymous"
|
||||
USER anonymous
|
||||
230 User logged in.
|
||||
TYPE I
|
||||
200 Type set to I.
|
||||
SIZE a.txt
|
||||
213 1102
|
||||
QUIT
|
||||
221 Goodbye.
|
||||
220 RTEMS FTP server (Version 1.1-JWJ) ready.
|
||||
login check (1): user "user"
|
||||
USER user
|
||||
331 User name okay, need password.
|
||||
login check (2): user "user", pass "pass"
|
||||
PASS pass
|
||||
230 User logged in.
|
||||
TYPE I
|
||||
200 Type set to I.
|
||||
SIZE b.txt
|
||||
213 1102
|
||||
QUIT
|
||||
221 Goodbye.
|
||||
|
||||
*** END OF TEST FTP 1 ***
|
||||
@@ -1,269 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2011, 2018 embedded brains GmbH. All rights reserved.
|
||||
*
|
||||
* embedded brains GmbH
|
||||
* Dornierstr. 4
|
||||
* 82178 Puchheim
|
||||
* Germany
|
||||
* <rtems@embedded-brains.de>
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.org/license/LICENSE.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <rtems.h>
|
||||
#include <tmacros.h>
|
||||
|
||||
#include <rtems/rtems_bsdnet.h>
|
||||
#include <rtems/ftpd.h>
|
||||
#include <rtems/ftpfs.h>
|
||||
|
||||
const char rtems_test_name[] = "FTP 1";
|
||||
|
||||
/* forward declarations to avoid warnings */
|
||||
static rtems_task Init(rtems_task_argument argument);
|
||||
|
||||
struct rtems_bsdnet_config rtems_bsdnet_config;
|
||||
|
||||
#define FTP_WORKER_TASK_COUNT 2
|
||||
|
||||
#define FTP_WORKER_TASK_EXTRA_STACK (FTP_WORKER_TASK_COUNT * FTPD_STACKSIZE)
|
||||
|
||||
static bool login_check(const char *user, const char *pass)
|
||||
{
|
||||
rtems_test_assert(
|
||||
strcmp(user, "anonymous") == 0 || strcmp(user, "user") == 0
|
||||
);
|
||||
|
||||
if (pass != NULL) {
|
||||
rtems_test_assert(
|
||||
strcmp(pass, "anonymous") == 0 || strcmp(pass, "pass") == 0
|
||||
);
|
||||
printf("login check (2): user \"%s\", pass \"%s\"\n", user, pass);
|
||||
return true;
|
||||
} else {
|
||||
printf("login check (1): user \"%s\"\n", user);
|
||||
return strcmp(user, "anonymous") == 0;
|
||||
}
|
||||
}
|
||||
|
||||
struct rtems_ftpd_configuration rtems_ftpd_configuration = {
|
||||
.priority = 90,
|
||||
.max_hook_filesize = 0,
|
||||
.port = 21,
|
||||
.hooks = NULL,
|
||||
.root = NULL,
|
||||
.tasks_count = FTP_WORKER_TASK_COUNT,
|
||||
.idle = 0,
|
||||
.login = login_check,
|
||||
.access = 0
|
||||
};
|
||||
|
||||
static const char content [] =
|
||||
" LICENSE INFORMATION\n"
|
||||
"\n"
|
||||
"RTEMS is free software; you can redistribute it and/or modify it under\n"
|
||||
"terms of the GNU General Public License as published by the\n"
|
||||
"Free Software Foundation; either version 2, or (at your option) any\n"
|
||||
"later version. RTEMS is distributed in the hope that it will be useful,\n"
|
||||
"but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
|
||||
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
|
||||
"General Public License for more details. You should have received\n"
|
||||
"a copy of the GNU General Public License along with RTEMS; see\n"
|
||||
"file COPYING. If not, write to the Free Software Foundation, 675\n"
|
||||
"Mass Ave, Cambridge, MA 02139, USA.\n"
|
||||
"\n"
|
||||
"As a special exception, including RTEMS header files in a file,\n"
|
||||
"instantiating RTEMS generics or templates, or linking other files\n"
|
||||
"with RTEMS objects to produce an executable application, does not\n"
|
||||
"by itself cause the resulting executable application to be covered\n"
|
||||
"by the GNU General Public License. This exception does not\n"
|
||||
"however invalidate any other reasons why the executable file might be\n"
|
||||
"covered by the GNU Public License.\n";
|
||||
|
||||
static void initialize_ftpfs(void)
|
||||
{
|
||||
rtems_status_code sc = RTEMS_SUCCESSFUL;
|
||||
int rv = 0;
|
||||
struct timeval to = {
|
||||
.tv_sec = 10,
|
||||
.tv_usec = 0
|
||||
};
|
||||
const char *target = RTEMS_FTPFS_MOUNT_POINT_DEFAULT;
|
||||
|
||||
rv = mount_and_make_target_path(
|
||||
NULL,
|
||||
target,
|
||||
RTEMS_FILESYSTEM_TYPE_FTPFS,
|
||||
RTEMS_FILESYSTEM_READ_WRITE,
|
||||
NULL
|
||||
);
|
||||
rtems_test_assert(rv == 0);
|
||||
|
||||
sc = rtems_ftpfs_set_verbose(target, true);
|
||||
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
|
||||
|
||||
sc = rtems_ftpfs_set_timeout(target, &to);
|
||||
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
|
||||
}
|
||||
|
||||
static void change_self_priority(void)
|
||||
{
|
||||
rtems_status_code sc = RTEMS_SUCCESSFUL;
|
||||
rtems_task_priority cur = 0;
|
||||
|
||||
sc = rtems_task_set_priority(RTEMS_SUCCESSFUL, 110, &cur);
|
||||
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
|
||||
}
|
||||
|
||||
static void create_file(const char *path, const void *begin, size_t size)
|
||||
{
|
||||
int rv = 0;
|
||||
int fd = open(path, O_WRONLY);
|
||||
ssize_t n = 0;
|
||||
|
||||
rtems_test_assert(fd >= 0);
|
||||
|
||||
n = write(fd, begin, size);
|
||||
rtems_test_assert(n == (ssize_t) size);
|
||||
|
||||
rv = close(fd);
|
||||
rtems_test_assert(rv == 0);
|
||||
}
|
||||
|
||||
static void copy_file(const char *src_path, const char *dest_path)
|
||||
{
|
||||
int rv = 0;
|
||||
int in = open(src_path, O_RDONLY);
|
||||
int out = open(dest_path, O_WRONLY);
|
||||
ssize_t n_in = 0;
|
||||
char buf [64];
|
||||
struct stat st_in;
|
||||
struct stat st_out;
|
||||
|
||||
memset(&st_in, 0xff, sizeof(st_in));
|
||||
memset(&st_out, 0xff, sizeof(st_out));
|
||||
|
||||
rtems_test_assert(in >= 0);
|
||||
rtems_test_assert(out >= 0);
|
||||
|
||||
rv = fstat(out, &st_out);
|
||||
rtems_test_assert(rv == 0);
|
||||
|
||||
rtems_test_assert(st_out.st_size == 0);
|
||||
|
||||
while ((n_in = read(in, buf, sizeof(buf))) > 0) {
|
||||
ssize_t n_out = write(out, buf, (size_t) n_in);
|
||||
rtems_test_assert(n_out == n_in);
|
||||
}
|
||||
|
||||
rv = fstat(out, &st_out);
|
||||
rtems_test_assert(rv == 0);
|
||||
|
||||
rv = fstat(in, &st_in);
|
||||
rtems_test_assert(rv == 0);
|
||||
|
||||
rtems_test_assert(st_in.st_size == st_out.st_size);
|
||||
|
||||
rv = close(out);
|
||||
rtems_test_assert(rv == 0);
|
||||
|
||||
rv = close(in);
|
||||
rtems_test_assert(rv == 0);
|
||||
}
|
||||
|
||||
static void check_file_size(const char *path, size_t size)
|
||||
{
|
||||
struct stat st;
|
||||
int rv = lstat(path, &st);
|
||||
|
||||
rtems_test_assert(rv == 0);
|
||||
rtems_test_assert(st.st_size == (off_t) size);
|
||||
}
|
||||
|
||||
static void check_file(const char *path)
|
||||
{
|
||||
int rv = 0;
|
||||
int fd = open(path, O_RDONLY);
|
||||
ssize_t n = 0;
|
||||
char buf [64];
|
||||
const char *current = &content [0];
|
||||
size_t done = 0;
|
||||
|
||||
rtems_test_assert(fd >= 0);
|
||||
|
||||
while ((n = read(fd, buf, sizeof(buf))) > 0) {
|
||||
done += (size_t) n;
|
||||
rtems_test_assert(done <= sizeof(content));
|
||||
rtems_test_assert(memcmp(current, buf, (size_t) n) == 0);
|
||||
current += (size_t) n;
|
||||
}
|
||||
|
||||
rtems_test_assert(done == sizeof(content));
|
||||
|
||||
rv = close(fd);
|
||||
rtems_test_assert(rv == 0);
|
||||
}
|
||||
|
||||
static void test(void)
|
||||
{
|
||||
int rv = 0;
|
||||
const char file_a [] = "/FTP/127.0.0.1/a.txt";
|
||||
const char file_b [] = "/FTP/user:pass@127.0.0.1/b.txt";
|
||||
|
||||
rv = rtems_bsdnet_initialize_network();
|
||||
rtems_test_assert(rv == 0);
|
||||
|
||||
rv = rtems_initialize_ftpd();
|
||||
rtems_test_assert(rv == 0);
|
||||
|
||||
initialize_ftpfs();
|
||||
change_self_priority();
|
||||
create_file(file_a, &content [0], sizeof(content));
|
||||
copy_file(file_a, file_b);
|
||||
check_file(file_b);
|
||||
check_file_size(file_a, sizeof(content));
|
||||
check_file_size(file_b, sizeof(content));
|
||||
}
|
||||
|
||||
static rtems_task Init(rtems_task_argument argument)
|
||||
{
|
||||
TEST_BEGIN();
|
||||
test();
|
||||
TEST_END();
|
||||
|
||||
rtems_test_exit(0);
|
||||
}
|
||||
|
||||
#define CONFIGURE_INIT
|
||||
|
||||
#define CONFIGURE_MICROSECONDS_PER_TICK 10000
|
||||
|
||||
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
|
||||
#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
|
||||
|
||||
#define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 14
|
||||
|
||||
#define CONFIGURE_FILESYSTEM_FTPFS
|
||||
|
||||
#define CONFIGURE_MAXIMUM_TASKS (3 + FTP_WORKER_TASK_COUNT)
|
||||
#define CONFIGURE_MAXIMUM_SEMAPHORES 2
|
||||
|
||||
#define CONFIGURE_EXTRA_TASK_STACKS FTP_WORKER_TASK_EXTRA_STACK
|
||||
|
||||
#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
|
||||
|
||||
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
|
||||
|
||||
#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT
|
||||
|
||||
#include <rtems/confdefs.h>
|
||||
@@ -1,290 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2012 embedded brains GmbH. All rights reserved.
|
||||
*
|
||||
* embedded brains GmbH
|
||||
* Obere Lagerstr. 30
|
||||
* 82178 Puchheim
|
||||
* Germany
|
||||
* <rtems@embedded-brains.de>
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.org/license/LICENSE.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <rtems.h>
|
||||
|
||||
#include <tmacros.h>
|
||||
|
||||
#include <rtems/rtems_bsdnet.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <mghttpd/mongoose.h>
|
||||
|
||||
#include <rtems/imfs.h>
|
||||
#include <rtems/error.h>
|
||||
#include "mghttpd01-tar.h"
|
||||
|
||||
#include "test-http-client.h"
|
||||
|
||||
const char rtems_test_name[] = "MGHTTPD 1";
|
||||
|
||||
#define TARFILE_START mghttpd01_tar
|
||||
#define TARFILE_SIZE mghttpd01_tar_size
|
||||
|
||||
#define CBACKTEST_URI "/callbacktest.txt"
|
||||
#define CBACKTEST_TXT "HTTP/1.1 200 OK\r\n" \
|
||||
"Content-Type: text/plain\r\n" \
|
||||
"Content-Length: 47\r\n" \
|
||||
"\r\n" \
|
||||
"This is a message from the callback function.\r\n"
|
||||
|
||||
#define WSTEST_REQ "Test request"
|
||||
#define WSTEST_RESP "This is a message from the WebSocket callback function."
|
||||
|
||||
#define INDEX_HTML "HTTP/1.1 200 OK\r\n" \
|
||||
"Date: xxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n" \
|
||||
"Last-Modified: xxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n" \
|
||||
"Etag: \"21dae500.162\"\r\n" \
|
||||
"Content-Type: text/html\r\n" \
|
||||
"Content-Length: 162\r\n" \
|
||||
"Connection: close\r\n" \
|
||||
"Accept-Ranges: bytes\r\n" \
|
||||
"\r\n" \
|
||||
"<html>\r\n" \
|
||||
"<head>\r\n" \
|
||||
"<title>Second Instance</title>\r\n" \
|
||||
"</head>\r\n" \
|
||||
"\r\n" \
|
||||
"<body>\r\n" \
|
||||
"<h1>Second Instance</h1>\r\n" \
|
||||
"A test page for the Mongoose web server on RTEMS.\r\n" \
|
||||
"</body>\r\n" \
|
||||
"</html>\r\n"
|
||||
|
||||
#define DATE_TAG "Date: "
|
||||
#define LASTMOD_TAG "Last-Modified: "
|
||||
#define TIMESTAMP_SIZE (sizeof("Fri, 01 Jan 1988 00:00:26 GMT") - 1)
|
||||
|
||||
#define BUFFERSIZE 1024
|
||||
|
||||
static void test_tarfs_load(void)
|
||||
{
|
||||
rtems_status_code sc;
|
||||
|
||||
printf("Loading tarfs image ... ");
|
||||
sc = rtems_tarfs_load("/",(void *)TARFILE_START, TARFILE_SIZE);
|
||||
if (sc != RTEMS_SUCCESSFUL) {
|
||||
printf ("error: untar failed: %s\n", rtems_status_text (sc));
|
||||
rtems_test_exit(1);
|
||||
}
|
||||
printf ("successful\n");
|
||||
}
|
||||
|
||||
static int callback(struct mg_connection *conn)
|
||||
{
|
||||
int cbacktest = strncmp(mg_get_request_info(conn)->uri, CBACKTEST_URI, sizeof(CBACKTEST_URI));
|
||||
if (cbacktest == 0)
|
||||
{
|
||||
mg_write(conn, CBACKTEST_TXT, sizeof(CBACKTEST_TXT));
|
||||
|
||||
/* Mark as processed */
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int callback_websocket(struct mg_connection *connection,
|
||||
int bits,
|
||||
char *data,
|
||||
size_t data_len)
|
||||
{
|
||||
if (data_len == strlen(WSTEST_REQ) && strncmp(data, WSTEST_REQ, data_len) == 0)
|
||||
{
|
||||
mg_websocket_write(connection, WEBSOCKET_OPCODE_TEXT, WSTEST_RESP, strlen(WSTEST_RESP));
|
||||
|
||||
/* Don't close the WebSocket */
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void test_mg_index_html(void)
|
||||
{
|
||||
httpc_context httpc_ctx;
|
||||
char *buffer = malloc(BUFFERSIZE);
|
||||
char *workpos = buffer;
|
||||
bool brv = false;
|
||||
int rv = 0;
|
||||
|
||||
rtems_test_assert(buffer != NULL);
|
||||
|
||||
puts("=== Get the index.html from second Mongoose instance:");
|
||||
|
||||
httpc_init_context(&httpc_ctx);
|
||||
brv = httpc_open_connection(&httpc_ctx, "127.0.0.1", 8080);
|
||||
rtems_test_assert(brv);
|
||||
brv = httpc_send_request(&httpc_ctx, "GET /index.html", buffer, BUFFERSIZE);
|
||||
rtems_test_assert(brv);
|
||||
brv = httpc_close_connection(&httpc_ctx);
|
||||
rtems_test_assert(brv);
|
||||
puts(buffer);
|
||||
|
||||
/* remove timestamps from html-header */
|
||||
workpos = strstr(buffer, DATE_TAG);
|
||||
rtems_test_assert(workpos != NULL);
|
||||
workpos += sizeof(DATE_TAG) - 1;
|
||||
memset(workpos, 'x', TIMESTAMP_SIZE);
|
||||
|
||||
workpos = strstr(buffer, LASTMOD_TAG);
|
||||
rtems_test_assert(workpos != NULL);
|
||||
workpos += sizeof(LASTMOD_TAG) - 1;
|
||||
memset(workpos, 'x', TIMESTAMP_SIZE);
|
||||
|
||||
rv = strcmp(buffer, INDEX_HTML);
|
||||
rtems_test_assert(rv == 0);
|
||||
|
||||
puts("=== OK");
|
||||
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
static void test_mg_callback(void)
|
||||
{
|
||||
httpc_context httpc_ctx;
|
||||
char *buffer = malloc(BUFFERSIZE);
|
||||
bool brv = false;
|
||||
int rv = 0;
|
||||
|
||||
rtems_test_assert(buffer != NULL);
|
||||
|
||||
puts("=== Get a page generated from a callback function from" \
|
||||
" first Mongoose instance:");
|
||||
|
||||
httpc_init_context(&httpc_ctx);
|
||||
brv = httpc_open_connection(&httpc_ctx, "127.0.0.1", 80);
|
||||
rtems_test_assert(brv);
|
||||
brv = httpc_send_request(&httpc_ctx, "GET " CBACKTEST_URI, buffer, BUFFERSIZE);
|
||||
rtems_test_assert(brv);
|
||||
brv = httpc_close_connection(&httpc_ctx);
|
||||
rtems_test_assert(brv);
|
||||
puts(buffer);
|
||||
rv = strcmp(buffer, CBACKTEST_TXT);
|
||||
rtems_test_assert(rv == 0);
|
||||
|
||||
puts("=== OK");
|
||||
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
static void test_mg_websocket(void)
|
||||
{
|
||||
httpc_context httpc_ctx;
|
||||
char *buffer = malloc(BUFFERSIZE);
|
||||
bool brv = false;
|
||||
int rv = 0;
|
||||
|
||||
rtems_test_assert(buffer != NULL);
|
||||
|
||||
puts("=== Get a WebSocket response generated from a callback function" \
|
||||
" from first Mongoose instance:");
|
||||
|
||||
httpc_init_context(&httpc_ctx);
|
||||
brv = httpc_open_connection(&httpc_ctx, "127.0.0.1", 80);
|
||||
rtems_test_assert(brv);
|
||||
brv = httpc_ws_open_connection(&httpc_ctx);
|
||||
rtems_test_assert(brv);
|
||||
brv = httpc_ws_send_request(&httpc_ctx, WSTEST_REQ, buffer, BUFFERSIZE);
|
||||
rtems_test_assert(brv);
|
||||
brv = httpc_close_connection(&httpc_ctx);
|
||||
rtems_test_assert(brv);
|
||||
puts(buffer);
|
||||
rv = strcmp(buffer, WSTEST_RESP);
|
||||
rtems_test_assert(rv == 0);
|
||||
|
||||
puts("=== OK");
|
||||
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
static void test_mongoose(void)
|
||||
{
|
||||
const struct mg_callbacks callbacks = {
|
||||
.begin_request = callback,
|
||||
.websocket_data = callback_websocket
|
||||
};
|
||||
const char *options[] = {
|
||||
"listening_ports", "80",
|
||||
"document_root", "/www",
|
||||
"num_threads", "1",
|
||||
"thread_stack_size", "16384",
|
||||
"thread_priority", "250",
|
||||
"thread_policy", "o",
|
||||
NULL};
|
||||
const struct mg_callbacks callbacks2 = {
|
||||
NULL
|
||||
};
|
||||
const char *options2[] = {
|
||||
"listening_ports", "8080",
|
||||
"document_root", "/www2",
|
||||
"num_threads", "1",
|
||||
"thread_stack_size", "16384",
|
||||
NULL};
|
||||
|
||||
struct mg_context *mg1 = mg_start(&callbacks, NULL, options);
|
||||
struct mg_context *mg2 = mg_start(&callbacks2, NULL, options2);
|
||||
|
||||
test_mg_index_html();
|
||||
test_mg_callback();
|
||||
test_mg_websocket();
|
||||
|
||||
mg_stop(mg1);
|
||||
mg_stop(mg2);
|
||||
}
|
||||
|
||||
static void Init(rtems_task_argument arg)
|
||||
{
|
||||
int rv = 0;
|
||||
|
||||
TEST_BEGIN();
|
||||
|
||||
rv = rtems_bsdnet_initialize_network();
|
||||
rtems_test_assert(rv == 0);
|
||||
|
||||
test_tarfs_load();
|
||||
|
||||
test_mongoose();
|
||||
|
||||
TEST_END();
|
||||
|
||||
rtems_test_exit(0);
|
||||
}
|
||||
|
||||
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
|
||||
#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
|
||||
|
||||
#define CONFIGURE_FILESYSTEM_IMFS
|
||||
|
||||
#define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 16
|
||||
|
||||
#define CONFIGURE_UNLIMITED_OBJECTS
|
||||
|
||||
#define CONFIGURE_UNIFIED_WORK_AREAS
|
||||
|
||||
#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
|
||||
|
||||
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
|
||||
|
||||
#define CONFIGURE_INIT_TASK_STACK_SIZE (16 * 1024)
|
||||
#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT
|
||||
|
||||
#define CONFIGURE_INIT
|
||||
|
||||
#include <rtems/confdefs.h>
|
||||
@@ -1,11 +0,0 @@
|
||||
This file describes the directives and concepts tested by this test set.
|
||||
|
||||
test set name: mghttpd01
|
||||
|
||||
directives:
|
||||
|
||||
TBD
|
||||
|
||||
concepts:
|
||||
|
||||
- Ensure that the Mongoose HTTP server works with a basic setup
|
||||
@@ -1,33 +0,0 @@
|
||||
*** TEST MGHTTPD 01 ***
|
||||
Loading tarfs image ... successful
|
||||
=== Get the index.html from second Mongoose instance:
|
||||
HTTP/1.1 200 OK
|
||||
Date: Fri, 01 Jan 1988 00:00:01 GMT
|
||||
Last-Modified: Fri, 01 Jan 1988 00:00:01 GMT
|
||||
Etag: "21dae501.a2"
|
||||
Content-Type: text/html
|
||||
Content-Length: 162
|
||||
Connection: close
|
||||
Accept-Ranges: bytes
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>Second Instance</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Second Instance</h1>
|
||||
A test page for the Mongoose web server on RTEMS.
|
||||
</body>
|
||||
</html>
|
||||
|
||||
=== OK
|
||||
=== Get a page generated from a callback function from first Mongoose instance:
|
||||
HTTP/1.1 200 OK
|
||||
Content-Type: text/plain
|
||||
Content-Length: 47
|
||||
|
||||
This is a message from the callback function.
|
||||
|
||||
=== OK
|
||||
*** END OF TEST MGHTTPD 01 ***
|
||||
Binary file not shown.
@@ -1,224 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2012 embedded brains GmbH. All rights reserved.
|
||||
*
|
||||
* embedded brains GmbH
|
||||
* Obere Lagerstr. 30
|
||||
* 82178 Puchheim
|
||||
* Germany
|
||||
* <rtems@embedded-brains.de>
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.org/license/LICENSE.
|
||||
*/
|
||||
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <netdb.h>
|
||||
#include <limits.h>
|
||||
#include <unistd.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <tmacros.h>
|
||||
|
||||
#include "test-http-client.h"
|
||||
|
||||
#define HTTPC_WS_CONN_REQ "GET / HTTP/1.1\r\n" \
|
||||
"Host: localhost\r\n" \
|
||||
"Upgrade: websocket\r\n" \
|
||||
"Connection: Upgrade\r\n" \
|
||||
"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" \
|
||||
"Sec-WebSocket-Version: 13\r\n" \
|
||||
"\r\n"
|
||||
#define HTTPC_WS_CONN_RESP "HTTP/1.1 101 Switching Protocols\r\n" \
|
||||
"Upgrade: websocket\r\n" \
|
||||
"Connection: Upgrade\r\n" \
|
||||
"Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n" \
|
||||
"\r\n"
|
||||
|
||||
static ssize_t httpc_read_full(
|
||||
const httpc_context *ctx,
|
||||
void *response,
|
||||
size_t responsesize
|
||||
);
|
||||
|
||||
void httpc_init_context(
|
||||
httpc_context *ctx
|
||||
)
|
||||
{
|
||||
ctx->socket = -1;
|
||||
ctx->fd = NULL;
|
||||
}
|
||||
|
||||
bool httpc_open_connection(
|
||||
httpc_context *ctx,
|
||||
const char *targethost,
|
||||
int targetport
|
||||
)
|
||||
{
|
||||
struct sockaddr_in addr;
|
||||
|
||||
struct hostent *server;
|
||||
|
||||
ctx->socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
if(ctx->socket < 0) { return false; }
|
||||
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(targetport);
|
||||
|
||||
server = gethostbyname(targethost);
|
||||
if(server == NULL) { return false; }
|
||||
memcpy(&addr.sin_addr.s_addr, server->h_addr, (size_t) server->h_length);
|
||||
|
||||
if(connect(ctx->socket, (struct sockaddr *)&addr, sizeof(addr)) != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ctx->fd = fdopen(ctx->socket,"rw");
|
||||
if(ctx->fd == NULL) { return false; }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool httpc_close_connection(
|
||||
httpc_context *ctx
|
||||
)
|
||||
{
|
||||
if(close(ctx->socket) != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool httpc_send_request(
|
||||
const httpc_context *ctx,
|
||||
const char *request,
|
||||
char *response,
|
||||
int responsesize
|
||||
)
|
||||
{
|
||||
rtems_test_assert(ctx != NULL);
|
||||
rtems_test_assert(ctx->socket >= 0);
|
||||
rtems_test_assert(request != NULL);
|
||||
rtems_test_assert(response != NULL);
|
||||
rtems_test_assert(responsesize > 1);
|
||||
|
||||
static const char * const lineend = " HTTP/1.1\r\n\r\n";
|
||||
|
||||
write(ctx->socket, request, strlen(request));
|
||||
write(ctx->socket, lineend, strlen(lineend));
|
||||
|
||||
ssize_t size;
|
||||
if((size = httpc_read_full(ctx, response, responsesize - 1)) == -1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
*(response + size) = '\0';
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool httpc_ws_open_connection(
|
||||
const httpc_context *ctx
|
||||
)
|
||||
{
|
||||
rtems_test_assert(ctx != NULL);
|
||||
rtems_test_assert(ctx->socket >= 0);
|
||||
|
||||
write(ctx->socket, HTTPC_WS_CONN_REQ, strlen(HTTPC_WS_CONN_REQ));
|
||||
|
||||
char response[strlen(HTTPC_WS_CONN_RESP)];
|
||||
if(httpc_read_full(ctx, response, sizeof(response)) != sizeof(response))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(strncmp(response, HTTPC_WS_CONN_RESP, sizeof(response)) != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool httpc_ws_send_request(
|
||||
const httpc_context *ctx,
|
||||
const char *request,
|
||||
char *response,
|
||||
int responsesize
|
||||
)
|
||||
{
|
||||
rtems_test_assert(ctx != NULL);
|
||||
rtems_test_assert(ctx->socket >= 0);
|
||||
rtems_test_assert(request != NULL);
|
||||
rtems_test_assert(response != NULL);
|
||||
rtems_test_assert(responsesize > 0);
|
||||
|
||||
static const uint16_t ws_header_fin = 1U << 15;
|
||||
static const uint16_t ws_header_text = 1U << 8;
|
||||
static const uint16_t ws_header_size = 0x7FU;
|
||||
|
||||
/*
|
||||
* We don't support sending WebSocket messages which require multiple
|
||||
* chunks
|
||||
*/
|
||||
if(strlen(request) > ws_header_size) { return false; }
|
||||
|
||||
uint16_t header = htons(ws_header_fin | ws_header_text | strlen(request));
|
||||
|
||||
write(ctx->socket, &header, sizeof(header));
|
||||
write(ctx->socket, request, strlen(request));
|
||||
|
||||
if (httpc_read_full(ctx, &header, sizeof(header)) != sizeof(header))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
header = ntohs(header);
|
||||
if (!(header & ws_header_fin)) { return false; }
|
||||
if (!(header & ws_header_text)) { return false; }
|
||||
if (responsesize < (header & ws_header_size) + 1) { return false; }
|
||||
|
||||
responsesize = header & ws_header_size;
|
||||
if (httpc_read_full(ctx, response, responsesize) != responsesize)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
*(response + responsesize) = '\0';
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static ssize_t httpc_read_full(
|
||||
const httpc_context *ctx,
|
||||
void *response,
|
||||
size_t responsesize
|
||||
)
|
||||
{
|
||||
rtems_test_assert(ctx != NULL);
|
||||
rtems_test_assert(ctx->socket >= 0);
|
||||
rtems_test_assert(response != NULL);
|
||||
rtems_test_assert(responsesize > 0);
|
||||
|
||||
if (responsesize > SSIZE_MAX) { return -1; }
|
||||
|
||||
unsigned char *pos = response;
|
||||
|
||||
while(pos < (unsigned char *)response + responsesize)
|
||||
{
|
||||
ssize_t size =
|
||||
read(ctx->socket, pos, (unsigned char *)response + responsesize - pos);
|
||||
if (size == -1) { return -1; }
|
||||
if (size == 0) { break; }
|
||||
pos += size;
|
||||
}
|
||||
|
||||
return (pos - (unsigned char *)response);
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2012 embedded brains GmbH. All rights reserved.
|
||||
*
|
||||
* embedded brains GmbH
|
||||
* Obere Lagerstr. 30
|
||||
* 82178 Puchheim
|
||||
* Germany
|
||||
* <rtems@embedded-brains.de>
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.org/license/LICENSE.
|
||||
*/
|
||||
|
||||
#ifndef TEST_WEB_CLIENT_H
|
||||
#define TEST_WEB_CLIENT_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int socket;
|
||||
FILE *fd;
|
||||
}
|
||||
httpc_context;
|
||||
|
||||
void httpc_init_context(
|
||||
httpc_context *ctx
|
||||
);
|
||||
|
||||
bool httpc_open_connection(
|
||||
httpc_context *ctx,
|
||||
const char *targethost,
|
||||
int targetport
|
||||
);
|
||||
|
||||
bool httpc_close_connection(
|
||||
httpc_context *ctx
|
||||
);
|
||||
|
||||
bool httpc_send_request(
|
||||
const httpc_context *ctx,
|
||||
const char *request,
|
||||
char *response,
|
||||
int responsesize
|
||||
);
|
||||
|
||||
bool httpc_ws_open_connection(
|
||||
const httpc_context *ctx
|
||||
);
|
||||
|
||||
bool httpc_ws_send_request(
|
||||
const httpc_context *ctx,
|
||||
const char *request,
|
||||
char *response,
|
||||
int responsesize
|
||||
);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* TEST_WEB_CLIENT_H */
|
||||
@@ -1,336 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2015 embedded brains GmbH. All rights reserved.
|
||||
*
|
||||
* embedded brains GmbH
|
||||
* Dornierstr. 4
|
||||
* 82178 Puchheim
|
||||
* Germany
|
||||
* <rtems@embedded-brains.de>
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.org/license/LICENSE.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "tmacros.h"
|
||||
|
||||
#include <sys/select.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <netinet/in.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <rtems/libio.h>
|
||||
#include <rtems/rtems_bsdnet.h>
|
||||
|
||||
const char rtems_test_name[] = "SYSCALL 1";
|
||||
|
||||
static const char open_driver_path [] = "/dev/open_driver";
|
||||
|
||||
struct rtems_bsdnet_config rtems_bsdnet_config;
|
||||
|
||||
typedef struct {
|
||||
rtems_id main_task;
|
||||
rtems_id close_task;
|
||||
int fd;
|
||||
} test_context;
|
||||
|
||||
static test_context test_instance;
|
||||
|
||||
static void test_sync(void)
|
||||
{
|
||||
int rv;
|
||||
char buf [1];
|
||||
ssize_t n;
|
||||
int fd;
|
||||
|
||||
fd = open(open_driver_path, O_RDWR);
|
||||
rtems_test_assert(fd >= 0);
|
||||
|
||||
errno = 0;
|
||||
n = send(fd, buf, sizeof(buf), 0);
|
||||
rtems_test_assert(n == -1);
|
||||
rtems_test_assert(errno == ENOTSOCK);
|
||||
|
||||
errno = 0;
|
||||
n = recv(fd, buf, sizeof(buf), 0);
|
||||
rtems_test_assert(n == -1);
|
||||
rtems_test_assert(errno == ENOTSOCK);
|
||||
|
||||
rv = close(fd);
|
||||
rtems_test_assert(rv == 0);
|
||||
|
||||
fd = socket(PF_INET, SOCK_DGRAM, 0);
|
||||
rtems_test_assert(fd >= 0);
|
||||
|
||||
errno = 0;
|
||||
rv = fsync(fd);
|
||||
rtems_test_assert(rv == -1);
|
||||
rtems_test_assert(errno == EINVAL);
|
||||
|
||||
errno = 0;
|
||||
rv = fdatasync(fd);
|
||||
rtems_test_assert(rv == -1);
|
||||
rtems_test_assert(errno == EINVAL);
|
||||
|
||||
rv = close(fd);
|
||||
rtems_test_assert(rv == 0);
|
||||
}
|
||||
|
||||
static void close_task(rtems_task_argument arg)
|
||||
{
|
||||
test_context *ctx = (test_context *) arg;
|
||||
|
||||
while (true) {
|
||||
rtems_status_code sc;
|
||||
int rv;
|
||||
|
||||
sc = rtems_event_transient_receive(RTEMS_WAIT, RTEMS_NO_TIMEOUT);
|
||||
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
|
||||
|
||||
rv = close(ctx->fd);
|
||||
rtems_test_assert(rv == 0);
|
||||
|
||||
sc = rtems_event_transient_send(ctx->main_task);
|
||||
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
|
||||
}
|
||||
}
|
||||
|
||||
static void request_close(test_context *ctx)
|
||||
{
|
||||
rtems_status_code sc;
|
||||
|
||||
sc = rtems_event_transient_send(ctx->close_task);
|
||||
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
|
||||
}
|
||||
|
||||
static void wait_for_close_task(void)
|
||||
{
|
||||
rtems_status_code sc;
|
||||
|
||||
sc = rtems_event_transient_receive(RTEMS_WAIT, RTEMS_NO_TIMEOUT);
|
||||
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
|
||||
}
|
||||
|
||||
static void test_accept_and_close(test_context *ctx)
|
||||
{
|
||||
int rv;
|
||||
int fd;
|
||||
struct sockaddr_in addr;
|
||||
socklen_t addrlen = sizeof(addr);
|
||||
|
||||
ctx->fd = socket(PF_INET, SOCK_STREAM, 0);
|
||||
rtems_test_assert(ctx->fd >= 0);
|
||||
|
||||
rv = listen(ctx->fd, 1);
|
||||
rtems_test_assert(rv == 0);
|
||||
|
||||
request_close(ctx);
|
||||
|
||||
errno = 0;
|
||||
fd = accept(ctx->fd, (struct sockaddr *) &addr, &addrlen);
|
||||
rtems_test_assert(fd == -1);
|
||||
rtems_test_assert(errno == ENXIO);
|
||||
|
||||
errno = 0;
|
||||
fd = accept(ctx->fd, (struct sockaddr *) &addr, &addrlen);
|
||||
rtems_test_assert(fd == -1);
|
||||
rtems_test_assert(errno == EBADF);
|
||||
|
||||
wait_for_close_task();
|
||||
}
|
||||
|
||||
static void test_connect_and_close(test_context *ctx)
|
||||
{
|
||||
int rv;
|
||||
struct sockaddr_in addr;
|
||||
socklen_t addrlen = sizeof(addr);
|
||||
|
||||
ctx->fd = socket(PF_INET, SOCK_STREAM, 0);
|
||||
rtems_test_assert(ctx->fd >= 0);
|
||||
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(1234);
|
||||
addr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
|
||||
request_close(ctx);
|
||||
|
||||
errno = 0;
|
||||
rv = connect(ctx->fd, (struct sockaddr *) &addr, addrlen);
|
||||
rtems_test_assert(rv == -1);
|
||||
rtems_test_assert(errno == ENXIO);
|
||||
|
||||
errno = 0;
|
||||
rv = connect(ctx->fd, (struct sockaddr *) &addr, addrlen);
|
||||
rtems_test_assert(rv == -1);
|
||||
rtems_test_assert(errno == EBADF);
|
||||
|
||||
wait_for_close_task();
|
||||
}
|
||||
|
||||
static void test_recv_and_close(test_context *ctx)
|
||||
{
|
||||
int rv;
|
||||
struct sockaddr_in addr;
|
||||
socklen_t addrlen = sizeof(addr);
|
||||
char buf[1];
|
||||
ssize_t n;
|
||||
|
||||
ctx->fd = socket(PF_INET, SOCK_DGRAM, 0);
|
||||
rtems_test_assert(ctx->fd >= 0);
|
||||
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(1234);
|
||||
addr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
|
||||
rv = bind(ctx->fd, (struct sockaddr *) &addr, addrlen);
|
||||
rtems_test_assert(rv == 0);
|
||||
|
||||
request_close(ctx);
|
||||
|
||||
errno = 0;
|
||||
n = recv(ctx->fd, &buf[0], sizeof(buf), 0);
|
||||
rtems_test_assert(n == -1);
|
||||
rtems_test_assert(errno == ENXIO);
|
||||
|
||||
errno = 0;
|
||||
n = recv(ctx->fd, &buf[0], sizeof(buf), 0);
|
||||
rtems_test_assert(n == -1);
|
||||
rtems_test_assert(errno == EBADF);
|
||||
|
||||
wait_for_close_task();
|
||||
}
|
||||
|
||||
static void test_select_and_close(test_context *ctx)
|
||||
{
|
||||
int rv;
|
||||
struct sockaddr_in addr;
|
||||
socklen_t addrlen = sizeof(addr);
|
||||
int nfds;
|
||||
struct fd_set set;
|
||||
|
||||
ctx->fd = socket(PF_INET, SOCK_DGRAM, 0);
|
||||
rtems_test_assert(ctx->fd >= 0);
|
||||
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(1234);
|
||||
addr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
|
||||
rv = bind(ctx->fd, (struct sockaddr *) &addr, addrlen);
|
||||
rtems_test_assert(rv == 0);
|
||||
|
||||
nfds = ctx->fd + 1;
|
||||
FD_ZERO(&set);
|
||||
FD_SET(ctx->fd, &set);
|
||||
|
||||
request_close(ctx);
|
||||
|
||||
errno = 0;
|
||||
rv = select(nfds, &set, NULL, NULL, NULL);
|
||||
rtems_test_assert(rv == -1);
|
||||
rtems_test_assert(errno == EBADF);
|
||||
|
||||
wait_for_close_task();
|
||||
}
|
||||
|
||||
static void Init(rtems_task_argument arg)
|
||||
{
|
||||
test_context *ctx = &test_instance;
|
||||
rtems_status_code sc;
|
||||
int rv;
|
||||
|
||||
TEST_BEGIN();
|
||||
|
||||
ctx->main_task = rtems_task_self();
|
||||
|
||||
sc = rtems_task_create(
|
||||
rtems_build_name('C', 'L', 'O', 'S'),
|
||||
2,
|
||||
RTEMS_MINIMUM_STACK_SIZE,
|
||||
RTEMS_DEFAULT_MODES,
|
||||
RTEMS_DEFAULT_ATTRIBUTES,
|
||||
&ctx->close_task
|
||||
);
|
||||
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
|
||||
|
||||
sc = rtems_task_start(
|
||||
ctx->close_task,
|
||||
close_task,
|
||||
(rtems_task_argument) ctx
|
||||
);
|
||||
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
|
||||
|
||||
rv = rtems_bsdnet_initialize_network();
|
||||
rtems_test_assert(rv == 0);
|
||||
|
||||
test_sync();
|
||||
test_accept_and_close(ctx);
|
||||
test_connect_and_close(ctx);
|
||||
test_recv_and_close(ctx);
|
||||
test_select_and_close(ctx);
|
||||
|
||||
sc = rtems_task_delete(ctx->close_task);
|
||||
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
|
||||
|
||||
TEST_END();
|
||||
|
||||
rtems_test_exit(0);
|
||||
}
|
||||
|
||||
static rtems_device_driver open_driver_initialize(
|
||||
rtems_device_major_number major,
|
||||
rtems_device_minor_number minor,
|
||||
void *arg
|
||||
)
|
||||
{
|
||||
rtems_status_code sc = rtems_io_register_name(open_driver_path, major, 0);
|
||||
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
|
||||
|
||||
return RTEMS_SUCCESSFUL;
|
||||
}
|
||||
|
||||
static rtems_device_driver open_driver_open(
|
||||
rtems_device_major_number major,
|
||||
rtems_device_minor_number minor,
|
||||
void *arg
|
||||
)
|
||||
{
|
||||
rtems_libio_open_close_args_t *oc = arg;
|
||||
|
||||
oc->iop->data0 = 1;
|
||||
oc->iop->data1 = (void *) 1;
|
||||
|
||||
return RTEMS_SUCCESSFUL;
|
||||
}
|
||||
|
||||
#define OPEN_DRIVER { \
|
||||
.initialization_entry = open_driver_initialize, \
|
||||
.open_entry = open_driver_open \
|
||||
}
|
||||
|
||||
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
|
||||
#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
|
||||
#define CONFIGURE_APPLICATION_EXTRA_DRIVERS OPEN_DRIVER
|
||||
|
||||
#define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 4
|
||||
|
||||
#define CONFIGURE_MAXIMUM_TASKS 3
|
||||
|
||||
#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
|
||||
|
||||
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
|
||||
|
||||
#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT
|
||||
|
||||
#define CONFIGURE_INIT
|
||||
|
||||
#include <rtems/confdefs.h>
|
||||
@@ -1,24 +0,0 @@
|
||||
# COPYRIGHT (c) 2014.
|
||||
# On-Line Applications Research Corporation (OAR).
|
||||
# Cynthia Rempel <cynthia@rtems.org>
|
||||
# The license and distribution terms for this file may be
|
||||
# found in the file LICENSE in this distribution or at
|
||||
# http://www.rtems.org/license/LICENSE.
|
||||
#
|
||||
This file describes the directives and concepts tested by this test set.
|
||||
|
||||
test set name: stackchk
|
||||
|
||||
directives:
|
||||
+ close
|
||||
+ open
|
||||
+ send
|
||||
+ recv
|
||||
+ rtems_bsdnet_initialize_network
|
||||
+ rtems_io_register_name
|
||||
|
||||
concepts:
|
||||
+ initializes the bsd network driver
|
||||
+ registers an io driver
|
||||
+ opens a buffer, sends a buffer across the network, receives a buffer,
|
||||
and closes the file
|
||||
@@ -1,2 +0,0 @@
|
||||
*** TEST SYSCALL 1 ***
|
||||
*** END OF TEST SYSCALL 1 ***
|
||||
@@ -1,61 +0,0 @@
|
||||
Simple test of kernel network code.
|
||||
Requires no network hardware since only the loopback network address is used.
|
||||
|
||||
Output should look like:
|
||||
========================================================================
|
||||
"Network" initializing!
|
||||
"Network" initialized!
|
||||
Try running client with no server present.
|
||||
Should fail with `connection refused'.
|
||||
Connect to server.
|
||||
Can't connect to server: Connection refused
|
||||
Client closing connection.
|
||||
|
||||
Start server.
|
||||
|
||||
Try running client with server present.
|
||||
Create socket.
|
||||
Connect to server.
|
||||
Bind socket.
|
||||
Can't connect to server: Connection refused
|
||||
Client closing connection.
|
||||
Client task terminating.
|
||||
|
||||
Try running two clients.
|
||||
Connect to server.
|
||||
Connect to server.
|
||||
ACCEPTED:7F000001
|
||||
ACCEPTED:7F000001
|
||||
Write 22-byte message to server.
|
||||
Write 22-byte message to server.
|
||||
Read 43 from server: Server received 22 (Hi there, server (2).)
|
||||
Read 43 from server: Server received 22 (Hi there, server (3).)
|
||||
Client closing connection.
|
||||
Client task terminating.
|
||||
Worker task terminating.
|
||||
Client closing connection.
|
||||
Client task terminating.
|
||||
Worker task terminating.
|
||||
|
||||
Try running three clients.
|
||||
Connect to server.
|
||||
Connect to server.
|
||||
Connect to server.
|
||||
ACCEPTED:7F000001
|
||||
ACCEPTED:7F000001
|
||||
ACCEPTED:7F000001
|
||||
Write 22-byte message to server.
|
||||
Write 22-byte message to server.
|
||||
Write 22-byte message to server.
|
||||
Read 43 from server: Server received 22 (Hi there, server (4).)
|
||||
Read 43 from server: Server received 22 (Hi there, server (5).)
|
||||
Read 43 from server: Server received 22 (Hi there, server (6).)
|
||||
Client closing connection.
|
||||
Client task terminating.
|
||||
Worker task terminating.
|
||||
Client closing connection.
|
||||
Client task terminating.
|
||||
Worker task terminating.
|
||||
Client closing connection.
|
||||
Client task terminating.
|
||||
Worker task terminating.
|
||||
@@ -1,264 +0,0 @@
|
||||
/*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.org/license/LICENSE.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <tmacros.h>
|
||||
|
||||
const char rtems_test_name[] = "LOOPBACK";
|
||||
|
||||
#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
|
||||
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
|
||||
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
|
||||
|
||||
#define CONFIGURE_EXECUTIVE_RAM_SIZE (512*1024)
|
||||
#define CONFIGURE_MAXIMUM_SEMAPHORES 20
|
||||
#define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 20
|
||||
#define CONFIGURE_MAXIMUM_TASKS 20
|
||||
|
||||
#define CONFIGURE_MICROSECONDS_PER_TICK 10000
|
||||
#define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 50
|
||||
|
||||
#define CONFIGURE_INIT_TASK_STACK_SIZE (10*1024)
|
||||
#define CONFIGURE_INIT_TASK_PRIORITY 50
|
||||
#define CONFIGURE_INIT_TASK_INITIAL_MODES (RTEMS_PREEMPT | \
|
||||
RTEMS_NO_TIMESLICE | \
|
||||
RTEMS_NO_ASR | \
|
||||
RTEMS_INTERRUPT_LEVEL(0))
|
||||
#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT
|
||||
|
||||
#define CONFIGURE_INIT
|
||||
rtems_task Init(rtems_task_argument argument);
|
||||
|
||||
#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
|
||||
|
||||
#include <rtems/confdefs.h>
|
||||
|
||||
#include <rtems/rtems_bsdnet.h>
|
||||
#include <rtems/error.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
/*
|
||||
* Network configuration
|
||||
*/
|
||||
|
||||
struct rtems_bsdnet_config rtems_bsdnet_config = {
|
||||
NULL, /* Network interface */
|
||||
NULL, /* Use fixed network configuration */
|
||||
0, /* Default network task priority */
|
||||
0, /* Default mbuf capacity */
|
||||
0, /* Default mbuf cluster capacity */
|
||||
"testSystem", /* Host name */
|
||||
"nowhere.com", /* Domain name */
|
||||
"127.0.0.1", /* Gateway */
|
||||
"127.0.0.1", /* Log host */
|
||||
{"127.0.0.1" }, /* Name server(s) */
|
||||
{"127.0.0.1" }, /* NTP server(s) */
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
};
|
||||
|
||||
/*
|
||||
* Spawn a task
|
||||
*/
|
||||
static void spawnTask(rtems_task_entry entryPoint, rtems_task_priority priority, rtems_task_argument arg)
|
||||
{
|
||||
rtems_status_code sc;
|
||||
rtems_id tid;
|
||||
|
||||
sc = rtems_task_create(rtems_build_name('t','a','s','k'),
|
||||
priority,
|
||||
RTEMS_MINIMUM_STACK_SIZE+(8*1024),
|
||||
RTEMS_PREEMPT|RTEMS_TIMESLICE|RTEMS_NO_ASR|RTEMS_INTERRUPT_LEVEL(0),
|
||||
RTEMS_FLOATING_POINT|RTEMS_LOCAL,
|
||||
&tid);
|
||||
if (sc != RTEMS_SUCCESSFUL)
|
||||
rtems_panic("Can't create task: %s", rtems_status_text(sc));
|
||||
sc = rtems_task_start(tid, entryPoint, arg);
|
||||
if (sc != RTEMS_SUCCESSFUL)
|
||||
rtems_panic("Can't start task: %s", rtems_status_text(sc));
|
||||
}
|
||||
|
||||
/*
|
||||
* Server subtask
|
||||
*/
|
||||
static rtems_task workerTask(rtems_task_argument arg)
|
||||
{
|
||||
int s = arg;
|
||||
char msg[80];
|
||||
char reply[120];
|
||||
int i;
|
||||
|
||||
for (;;) {
|
||||
if ((i = read(s, msg, sizeof msg)) < 0) {
|
||||
printf("Server couldn't read message from client: %s\n", strerror(errno));
|
||||
break;
|
||||
}
|
||||
if (i == 0)
|
||||
break;
|
||||
rtems_task_wake_after(20); /* Simulate some processing delay */
|
||||
i = sprintf(reply, "Server received %d (%s)", i, msg);
|
||||
if ((i = write(s, reply, i+1)) < 0) {
|
||||
printf("Server couldn't write message to client: %s\n", strerror(errno));
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (close(s) < 0)
|
||||
printf("Can't close worker task socket: %s\n", strerror(errno));
|
||||
printf("Worker task terminating.\n");
|
||||
rtems_task_exit();
|
||||
}
|
||||
|
||||
/*
|
||||
* Server Task
|
||||
*/
|
||||
static rtems_task serverTask(rtems_task_argument arg)
|
||||
{
|
||||
int s, s1;
|
||||
socklen_t addrlen;
|
||||
struct sockaddr_in myAddr, farAddr;
|
||||
rtems_task_priority myPriority;
|
||||
|
||||
printf("Create socket.\n");
|
||||
s = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (s < 0)
|
||||
rtems_panic("Can't create socket: %s\n", strerror(errno));
|
||||
memset(&myAddr, 0, sizeof myAddr);
|
||||
myAddr.sin_family = AF_INET;
|
||||
myAddr.sin_port = htons(1234);
|
||||
myAddr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
printf("Bind socket.\n");
|
||||
if (bind(s, (struct sockaddr *)&myAddr, sizeof myAddr) < 0)
|
||||
rtems_panic("Can't bind socket: %s\n", strerror(errno));
|
||||
if (listen(s, 5) < 0)
|
||||
printf("Can't listen on socket: %s\n", strerror(errno));
|
||||
rtems_task_set_priority(RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &myPriority);
|
||||
for(;;) {
|
||||
addrlen = sizeof farAddr;
|
||||
s1 = accept(s, (struct sockaddr *)&farAddr, &addrlen);
|
||||
if (s1 < 0)
|
||||
if (errno == ENXIO)
|
||||
rtems_task_exit();
|
||||
else
|
||||
rtems_panic("Can't accept connection: %s", strerror(errno));
|
||||
else
|
||||
printf("ACCEPTED:%" PRIu32 "\n", ntohl(farAddr.sin_addr.s_addr));
|
||||
spawnTask(workerTask, myPriority, s1);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The real part of the client
|
||||
*/
|
||||
static rtems_task clientWorker(int arg)
|
||||
{
|
||||
int s;
|
||||
struct sockaddr_in myAddr, farAddr;
|
||||
char cbuf[50];
|
||||
int i;
|
||||
|
||||
s = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (s < 0) {
|
||||
printf("Can't create client socket: %s\n", strerror(errno));
|
||||
return;
|
||||
}
|
||||
memset(&myAddr, 0, sizeof myAddr);
|
||||
myAddr.sin_family = AF_INET;
|
||||
myAddr.sin_port = htons(0);
|
||||
myAddr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
if (bind(s, (struct sockaddr *)&myAddr, sizeof myAddr) < 0) {
|
||||
printf("Can't bind socket: %s\n", strerror(errno));
|
||||
goto close;
|
||||
}
|
||||
memset(&farAddr, 0, sizeof farAddr);
|
||||
farAddr.sin_family = AF_INET;
|
||||
farAddr.sin_port = htons(1234);
|
||||
farAddr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
printf("Connect to server.\n");
|
||||
if (connect(s, (struct sockaddr *)&farAddr, sizeof farAddr) < 0) {
|
||||
printf("Can't connect to server: %s\n", strerror(errno));
|
||||
goto close;
|
||||
}
|
||||
rtems_task_wake_after(20); /* Simulate client delay */
|
||||
i = sprintf(cbuf, "Hi there, server (%d).", arg);
|
||||
i++; /* Send the '\0', too */
|
||||
printf("Write %d-byte message to server.\n", i);
|
||||
if (write(s, cbuf, i) < 0) {
|
||||
printf("Can't write to server: %s\n", strerror(errno));
|
||||
goto close;
|
||||
}
|
||||
if ((i = read(s, cbuf, sizeof cbuf)) < 0) {
|
||||
printf("Can't read from server: %s\n", strerror(errno));
|
||||
goto close;
|
||||
}
|
||||
printf("Read %d from server: %.*s\n", i, i, cbuf);
|
||||
rtems_task_wake_after(20); /* Simulate client delay */
|
||||
close:
|
||||
printf("Client closing connection.\n");
|
||||
if (close(s) < 0)
|
||||
printf("Can't close client task socket: %s\n", strerror(errno));
|
||||
}
|
||||
|
||||
/*
|
||||
* Client Task
|
||||
*/
|
||||
static rtems_task clientTask(rtems_task_argument arg)
|
||||
{
|
||||
clientWorker(arg);
|
||||
printf("Client task terminating.\n");
|
||||
rtems_task_exit();
|
||||
}
|
||||
|
||||
/*
|
||||
* RTEMS Startup Task
|
||||
*/
|
||||
rtems_task
|
||||
Init (rtems_task_argument ignored)
|
||||
{
|
||||
rtems_print_printer_fprintf_putc(&rtems_test_printer);
|
||||
|
||||
TEST_BEGIN();
|
||||
|
||||
printf("\"Network\" initializing!\n");
|
||||
rtems_bsdnet_initialize_network();
|
||||
printf("\"Network\" initialized!\n");
|
||||
|
||||
printf("Try running client with no server present.\n");
|
||||
printf("Should fail with `connection refused'.\n");
|
||||
clientWorker(0);
|
||||
|
||||
printf("\nStart server.\n");
|
||||
spawnTask(serverTask, 150, 0);
|
||||
|
||||
printf("\nTry running client with server present.\n");
|
||||
spawnTask(clientTask, 120, 1);
|
||||
rtems_task_wake_after(500);
|
||||
|
||||
printf("\nTry running two clients.\n");
|
||||
spawnTask(clientTask, 120, 2);
|
||||
spawnTask(clientTask, 120, 3);
|
||||
rtems_task_wake_after(500);
|
||||
|
||||
printf("\nTry running three clients.\n");
|
||||
spawnTask(clientTask, 120, 4);
|
||||
spawnTask(clientTask, 120, 5);
|
||||
spawnTask(clientTask, 120, 6);
|
||||
|
||||
rtems_task_wake_after(500);
|
||||
TEST_END();
|
||||
exit( 0 );
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
"Network" initializing!
|
||||
"Network" initialized!
|
||||
Try running client with no server present.
|
||||
Should fail with `connection refused'.
|
||||
Connect to server.
|
||||
Can't connect to server: Connection refused
|
||||
Client closing connection.
|
||||
|
||||
Start server.
|
||||
|
||||
Try running client with server present.
|
||||
Create socket.
|
||||
Connect to server.
|
||||
Bind socket.
|
||||
Can't connect to server: Connection refused
|
||||
Client closing connection.
|
||||
Client task terminating.
|
||||
|
||||
Try running two clients.
|
||||
Connect to server.
|
||||
Connect to server.
|
||||
ACCEPTED:7F000001
|
||||
ACCEPTED:7F000001
|
||||
Write 22-byte message to server.
|
||||
Write 22-byte message to server.
|
||||
Read 43 from server: Server received 22 (Hi there, server (2).)
|
||||
Read 43 from server: Server received 22 (Hi there, server (3).)
|
||||
Client closing connection.
|
||||
Client task terminating.
|
||||
Worker task terminating.
|
||||
Client closing connection.
|
||||
Client task terminating.
|
||||
Worker task terminating.
|
||||
|
||||
Try running three clients.
|
||||
Connect to server.
|
||||
Connect to server.
|
||||
Connect to server.
|
||||
ACCEPTED:7F000001
|
||||
ACCEPTED:7F000001
|
||||
ACCEPTED:7F000001
|
||||
Write 22-byte message to server.
|
||||
Write 22-byte message to server.
|
||||
Write 22-byte message to server.
|
||||
Read 43 from server: Server received 22 (Hi there, server (4).)
|
||||
Read 43 from server: Server received 22 (Hi there, server (5).)
|
||||
Read 43 from server: Server received 22 (Hi there, server (6).)
|
||||
Client closing connection.
|
||||
Client task terminating.
|
||||
Worker task terminating.
|
||||
Client closing connection.
|
||||
Client task terminating.
|
||||
Worker task terminating.
|
||||
Client closing connection.
|
||||
Client task terminating.
|
||||
Worker task terminating.
|
||||
@@ -1,11 +0,0 @@
|
||||
This is an example user application using pppd. It is built using
|
||||
the RTEMS application Makefiles. The file Makefile-user should
|
||||
be renamed to Makefile or the -f option given to make. The file
|
||||
is renamed to avoid bootstrap -c removing it.
|
||||
|
||||
The files ppp.conf and pppd.options are sample configuration files
|
||||
that have successfully used to make ppp connections over a null
|
||||
modem serial cable to a UNIX box. Please review the man pages
|
||||
for either the ppp or pppd applications to ensure they are configured
|
||||
correctly.
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* COPYRIGHT (c) 1989-2012.
|
||||
* On-Line Applications Research Corporation (OAR).
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.org/license/LICENSE.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define CONFIGURE_INIT
|
||||
#include "system.h"
|
||||
|
||||
#include <rtems/rtems_bsdnet.h>
|
||||
#include <rtems/rtemspppd.h>
|
||||
#include <rtems/shell.h>
|
||||
#include "netconfig.h"
|
||||
#include <tmacros.h>
|
||||
|
||||
const char rtems_test_name[] = "PPPD";
|
||||
|
||||
static void notification(int fd, int seconds_remaining, void *arg)
|
||||
{
|
||||
printf(
|
||||
"Press any key to start pppd (%is remaining)\n",
|
||||
seconds_remaining
|
||||
);
|
||||
}
|
||||
|
||||
rtems_task Init(rtems_task_argument argument)
|
||||
{
|
||||
rtems_status_code status;
|
||||
|
||||
rtems_print_printer_fprintf_putc(&rtems_test_printer);
|
||||
|
||||
TEST_BEGIN();
|
||||
|
||||
status = rtems_shell_wait_for_input(
|
||||
STDIN_FILENO,
|
||||
10,
|
||||
notification,
|
||||
NULL
|
||||
);
|
||||
if (status != RTEMS_SUCCESSFUL) {
|
||||
TEST_END();
|
||||
exit( 0 );
|
||||
}
|
||||
|
||||
/* initialize network */
|
||||
rtems_bsdnet_initialize_network();
|
||||
rtems_pppd_initialize();
|
||||
pppdapp_initialize();
|
||||
rtems_task_exit();
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
#ifndef NETCONFIG_H_
|
||||
#define NETCONFIG_H_
|
||||
|
||||
#include <bsp.h>
|
||||
#include <rtems/rtemspppd.h>
|
||||
|
||||
/* Default network interface */
|
||||
static struct rtems_bsdnet_ifconfig netdriver_config = {
|
||||
"ppp0", /* name */
|
||||
rtems_ppp_driver_attach, /* attach function */
|
||||
NULL, /* No more interfaces */
|
||||
NULL, /* IP address */
|
||||
NULL, /* IP net mask */
|
||||
NULL, /* Driver supplies hardware address */
|
||||
0 /* Use default driver parameters */
|
||||
};
|
||||
|
||||
/* Network configuration */
|
||||
struct rtems_bsdnet_config rtems_bsdnet_config = {
|
||||
&netdriver_config,
|
||||
NULL,
|
||||
30, /* Default network task priority */
|
||||
(256UL *1024UL), /* Default mbuf capacity */
|
||||
(512UL *1024UL), /* Default mbuf cluster capacity */
|
||||
0, /* Host name */
|
||||
0, /* Domain name */
|
||||
0, /* Gateway */
|
||||
0, /* Log host */
|
||||
{ 0 }, /* Name server(s) */
|
||||
{ 0 }, /* NTP server(s) */
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,27 +0,0 @@
|
||||
|
||||
#
|
||||
# Example configuration file for setting up a ppp server
|
||||
# using a null-modem serial cable:
|
||||
#
|
||||
# Tested using ppp on OpenBSD 2.9
|
||||
# - just follow instructions in man page for accepting
|
||||
# ppp connections over the serial port
|
||||
# - if pap and/or chap is enabled, you must have a ppp.secret
|
||||
# file which will be used for user authentication
|
||||
# - found useful to turn on syslog for ppp
|
||||
#
|
||||
|
||||
default:
|
||||
set log Phase Chat LQM LCP IPCP CCP command
|
||||
set device /dev/cua00
|
||||
set speed 57600
|
||||
set ctsrts on
|
||||
set dial ""
|
||||
|
||||
openbsd-server:
|
||||
set timeout 0
|
||||
set ifaddr 192.168.2.100 192.168.2.123
|
||||
enable dns
|
||||
allow users
|
||||
enable chap
|
||||
enable pap
|
||||
@@ -1,9 +0,0 @@
|
||||
/dev/tty00
|
||||
57600
|
||||
crtscts
|
||||
passive
|
||||
local
|
||||
noauth
|
||||
debug
|
||||
persist
|
||||
192.168.2.222:192.168.2.111
|
||||
@@ -1,152 +0,0 @@
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
|
||||
#include <bsp.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <rtems/rtemspppd.h>
|
||||
#include "system.h"
|
||||
|
||||
|
||||
/* define global variables */
|
||||
static unsigned int pppdapp_linkcount = 0;
|
||||
static rtems_id pppdapp_taskid;
|
||||
|
||||
|
||||
static void pppdapp_linkup_hook(void)
|
||||
{
|
||||
pppdapp_linkcount++;
|
||||
printf("PPP LINK UP [%d]\n", pppdapp_linkcount);
|
||||
}
|
||||
|
||||
static void pppdapp_linkdown_hook(void)
|
||||
{
|
||||
printf("PPP LINK DOWN [%d]\n", pppdapp_linkcount);
|
||||
}
|
||||
|
||||
static void pppdapp_ipup_hook(void)
|
||||
{
|
||||
/* send ipup signal to pppdapp task */
|
||||
rtems_event_send(pppdapp_taskid, RTEMS_EVENT_10);
|
||||
}
|
||||
|
||||
static void pppdapp_ipdown_hook(void)
|
||||
{
|
||||
/* send ip down signal to pppdapp task */
|
||||
rtems_event_send(pppdapp_taskid, RTEMS_EVENT_11);
|
||||
}
|
||||
|
||||
static void pppdapp_setup(void)
|
||||
{
|
||||
const char *pUser = "oscar";
|
||||
const char *pPassword = "goldman";
|
||||
|
||||
#undef USE_MODEM
|
||||
#ifdef USE_MODEM
|
||||
const char *pTelephone = "5551234";
|
||||
const char *pInitScript = "TIMEOUT@5@@AT@@OK@";
|
||||
const char *pConnectScript = "TIMEOUT@90@@ATDT%s@CONNECT@@name:@%s@word:@%s@";
|
||||
const char *pDisconnectScript = "TIMEOUT@5@@ATH0@@OK@";
|
||||
char pConnect[128];
|
||||
|
||||
/* set the connect string */
|
||||
sprintf(pConnect, pConnectScript, pTelephone, pUser, pPassword);
|
||||
|
||||
/* set pppd options for modem */
|
||||
rtems_pppd_set_option("/dev/ttyS2", NULL);
|
||||
rtems_pppd_set_option("57600", NULL);
|
||||
rtems_pppd_set_option("crtscts", NULL);
|
||||
rtems_pppd_set_option("modem", NULL);
|
||||
rtems_pppd_set_option("noauth", NULL);
|
||||
rtems_pppd_set_option("debug", NULL);
|
||||
rtems_pppd_set_option("init", pInitScript);
|
||||
rtems_pppd_set_option("connect", pConnect);
|
||||
rtems_pppd_set_option("disconnect", pDisconnectScript);
|
||||
#else
|
||||
/* set pppd options for null modem direct link serial cable */
|
||||
rtems_pppd_set_option("/dev/ttyS1", NULL);
|
||||
rtems_pppd_set_option("57600", NULL);
|
||||
rtems_pppd_set_option("crtscts", NULL);
|
||||
rtems_pppd_set_option("local", NULL);
|
||||
rtems_pppd_set_option("noauth", NULL);
|
||||
rtems_pppd_set_option("debug", NULL);
|
||||
rtems_pppd_set_option("user", pUser);
|
||||
rtems_pppd_set_option("password", pPassword);
|
||||
#endif
|
||||
|
||||
/* set up pppd hooks */
|
||||
rtems_pppd_set_hook(RTEMS_PPPD_LINKUP_HOOK, pppdapp_linkup_hook);
|
||||
rtems_pppd_set_hook(RTEMS_PPPD_LINKDOWN_HOOK, pppdapp_linkdown_hook);
|
||||
rtems_pppd_set_hook(RTEMS_PPPD_IPUP_HOOK, pppdapp_ipup_hook);
|
||||
rtems_pppd_set_hook(RTEMS_PPPD_IPDOWN_HOOK, pppdapp_ipdown_hook);
|
||||
}
|
||||
|
||||
static rtems_task pppdapp(rtems_task_argument arg)
|
||||
{
|
||||
rtems_status_code sc = RTEMS_SUCCESSFUL;
|
||||
rtems_interval tickspersecond = 0;
|
||||
rtems_option options;
|
||||
rtems_event_set in;
|
||||
rtems_event_set out;
|
||||
|
||||
/* initialize ticks per second */
|
||||
tickspersecond = rtems_clock_get_ticks_per_second();
|
||||
if ( tickspersecond == 0 ) {
|
||||
/* ensure value is greater than zero */
|
||||
tickspersecond = 100;
|
||||
}
|
||||
|
||||
/* initiate connection */
|
||||
pppdapp_setup();
|
||||
rtems_pppd_connect();
|
||||
|
||||
/* enter processing loop */
|
||||
in = (RTEMS_EVENT_10 | RTEMS_EVENT_11);
|
||||
options = (RTEMS_EVENT_ANY | RTEMS_WAIT);
|
||||
while ( sc == RTEMS_SUCCESSFUL ) {
|
||||
/* wait for the next event */
|
||||
sc = rtems_event_receive(in, options, RTEMS_NO_TIMEOUT, &out);
|
||||
if ( sc == RTEMS_SUCCESSFUL ) {
|
||||
/* determine which event was sent */
|
||||
if ( out & RTEMS_EVENT_10 ) {
|
||||
/* ip up recived */
|
||||
/* call disconnect function */
|
||||
rtems_pppd_disconnect();
|
||||
}
|
||||
if ( out & RTEMS_EVENT_11 ) {
|
||||
/* ip down recived */
|
||||
/* sleep 10 seconds and call connect function */
|
||||
rtems_task_wake_after(10*tickspersecond);
|
||||
rtems_pppd_connect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* terminate myself */
|
||||
rtems_task_exit();
|
||||
}
|
||||
|
||||
int pppdapp_initialize(void)
|
||||
{
|
||||
int iReturn = (int)-1;
|
||||
rtems_status_code status;
|
||||
rtems_name taskName;
|
||||
|
||||
taskName = rtems_build_name( 'p', 'a', 'p', 'p' );
|
||||
status = rtems_task_create(taskName,
|
||||
CONFIGURE_INIT_TASK_PRIORITY,
|
||||
CONFIGURE_INIT_TASK_STACK_SIZE,
|
||||
CONFIGURE_INIT_TASK_INITIAL_MODES,
|
||||
RTEMS_DEFAULT_ATTRIBUTES,
|
||||
&pppdapp_taskid);
|
||||
if ( status == RTEMS_SUCCESSFUL ) {
|
||||
status = rtems_task_start(pppdapp_taskid, pppdapp, 0);
|
||||
if ( status == RTEMS_SUCCESSFUL ) {
|
||||
iReturn = (int)0;
|
||||
}
|
||||
}
|
||||
|
||||
return ( iReturn );
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
#ifndef SYSTEM_H
|
||||
#define SYSTEM_H
|
||||
|
||||
#include <rtems.h>
|
||||
#include <rtems/test-info.h>
|
||||
#include <rtems/console.h>
|
||||
#include <rtems/clockdrv.h>
|
||||
|
||||
/* functions */
|
||||
extern rtems_task Init(rtems_task_argument argument);
|
||||
extern int pppdapp_initialize(void);
|
||||
|
||||
#include <bsp.h>
|
||||
|
||||
#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
|
||||
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
|
||||
|
||||
#ifndef TTY1_DRIVER_TABLE_ENTRY
|
||||
#define TTY1_DRIVER_TABLE_ENTRY NULL_DRIVER_TABLE_ENTRY
|
||||
#endif
|
||||
#ifndef TTY2_DRIVER_TABLE_ENTRY
|
||||
#define TTY2_DRIVER_TABLE_ENTRY NULL_DRIVER_TABLE_ENTRY
|
||||
#endif
|
||||
|
||||
#define CONFIGURE_APPLICATION_EXTRA_DRIVERS \
|
||||
TTY1_DRIVER_TABLE_ENTRY, TTY2_DRIVER_TABLE_ENTRY
|
||||
|
||||
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
|
||||
|
||||
#define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 8
|
||||
|
||||
#define CONFIGURE_UNIFIED_WORK_AREAS
|
||||
|
||||
#define CONFIGURE_UNLIMITED_OBJECTS
|
||||
|
||||
#define CONFIGURE_MICROSECONDS_PER_TICK 10000
|
||||
|
||||
#define CONFIGURE_INIT_TASK_STACK_SIZE (10*1024)
|
||||
#define CONFIGURE_INIT_TASK_PRIORITY 120
|
||||
#define CONFIGURE_INIT_TASK_INITIAL_MODES (RTEMS_PREEMPT | \
|
||||
RTEMS_NO_TIMESLICE | \
|
||||
RTEMS_NO_ASR | \
|
||||
RTEMS_INTERRUPT_LEVEL(0))
|
||||
#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT
|
||||
|
||||
#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
|
||||
|
||||
#include <rtems/confdefs.h>
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user