From 81a5cc1a10453342a74a59ac84e6fd7e406d5b0b Mon Sep 17 00:00:00 2001 From: Vijay Kumar Banerjee Date: Fri, 26 Feb 2021 23:26:07 -0700 Subject: Add legacy networking tests from RTEMS --- netlegacy.py | 12 -- testsuites/ftp01/ftp01.doc | 24 +++ testsuites/ftp01/ftp01.scn | 97 +++++++++++ testsuites/ftp01/init.c | 269 +++++++++++++++++++++++++++++ testsuites/ftp01/wscript | 52 ++++++ testsuites/loopback/README | 61 +++++++ testsuites/loopback/init.c | 264 +++++++++++++++++++++++++++++ testsuites/loopback/loopback.scn | 56 +++++++ testsuites/loopback/wscript | 46 +++++ testsuites/networking01/wscript | 46 +++++ testsuites/pppd/README | 11 ++ testsuites/pppd/init.c | 61 +++++++ testsuites/pppd/netconfig.h | 33 ++++ testsuites/pppd/ppp.conf | 27 +++ testsuites/pppd/pppd.options | 9 + testsuites/pppd/pppdapp.c | 152 +++++++++++++++++ testsuites/pppd/system.h | 50 ++++++ testsuites/pppd/wscript | 47 ++++++ testsuites/syscall01/init.c | 336 +++++++++++++++++++++++++++++++++++++ testsuites/syscall01/syscall01.doc | 24 +++ testsuites/syscall01/syscall01.scn | 2 + testsuites/syscall01/wscript | 46 +++++ testsuites/telnetd01/init.c | 120 +++++++++++++ testsuites/telnetd01/telnetd01.doc | 24 +++ testsuites/telnetd01/telnetd01.scn | 11 ++ testsuites/telnetd01/wscript | 46 +++++ testsuites/wscript | 49 ++++++ wscript | 2 +- 28 files changed, 1964 insertions(+), 13 deletions(-) create mode 100644 testsuites/ftp01/ftp01.doc create mode 100644 testsuites/ftp01/ftp01.scn create mode 100644 testsuites/ftp01/init.c create mode 100644 testsuites/ftp01/wscript create mode 100644 testsuites/loopback/README create mode 100644 testsuites/loopback/init.c create mode 100644 testsuites/loopback/loopback.scn create mode 100644 testsuites/loopback/wscript create mode 100644 testsuites/networking01/wscript create mode 100644 testsuites/pppd/README create mode 100644 testsuites/pppd/init.c create mode 100644 testsuites/pppd/netconfig.h create mode 100644 testsuites/pppd/ppp.conf create mode 100644 testsuites/pppd/pppd.options create mode 100644 testsuites/pppd/pppdapp.c create mode 100644 testsuites/pppd/system.h create mode 100644 testsuites/pppd/wscript create mode 100644 testsuites/syscall01/init.c create mode 100644 testsuites/syscall01/syscall01.doc create mode 100644 testsuites/syscall01/syscall01.scn create mode 100644 testsuites/syscall01/wscript create mode 100644 testsuites/telnetd01/init.c create mode 100644 testsuites/telnetd01/telnetd01.doc create mode 100644 testsuites/telnetd01/telnetd01.scn create mode 100644 testsuites/telnetd01/wscript create mode 100644 testsuites/wscript diff --git a/netlegacy.py b/netlegacy.py index 91cbedd..037e2ee 100644 --- a/netlegacy.py +++ b/netlegacy.py @@ -31,7 +31,6 @@ import os source_files = [] include_files = {} -test_source = [] exclude_dirs = ['pppd', 'nfsclient', 'testsuites', 'librpc/include', 'bsps'] exclude_headers = ['rtems-bsd-user-space.h', 'rtems-bsd-kernel-space.h'] @@ -45,11 +44,6 @@ for root, dirs, files in os.walk("."): if name[-2:] == '.h' and name not in exclude_headers: include_files[root[2:]].append(os.path.join(root, name)) -for root, dirs, files in os.walk('./testsuites'): - for name in files: - if name[-2:] == '.c': - test_source.append(os.path.join(root, name)) - def build(bld): include_path = [] @@ -98,12 +92,6 @@ def build(bld): features='c cstlib', use=['bsp_objs', 'network_objects']) - bld.program(target='networking01.exe', - features='c cprogram', - cflags=['-O2', '-g'], - includes=ip, - use='networking', - source=test_source) bld.stlib(target='pppd', features='c', includes=ip, diff --git a/testsuites/ftp01/ftp01.doc b/testsuites/ftp01/ftp01.doc new file mode 100644 index 0000000..99601dd --- /dev/null +++ b/testsuites/ftp01/ftp01.doc @@ -0,0 +1,24 @@ +# +# Copyright (c) 2011 embedded brains GmbH. All rights reserved. +# +# embedded brains GmbH +# Obere Lagerstr. 30 +# 82178 Puchheim +# Germany +# +# +# 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. diff --git a/testsuites/ftp01/ftp01.scn b/testsuites/ftp01/ftp01.scn new file mode 100644 index 0000000..78fe236 --- /dev/null +++ b/testsuites/ftp01/ftp01.scn @@ -0,0 +1,97 @@ +*** 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 *** diff --git a/testsuites/ftp01/init.c b/testsuites/ftp01/init.c new file mode 100644 index 0000000..aa91938 --- /dev/null +++ b/testsuites/ftp01/init.c @@ -0,0 +1,269 @@ +/* + * Copyright (c) 2011, 2018 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Dornierstr. 4 + * 82178 Puchheim + * Germany + * + * + * 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 +#include +#include + +#include +#include + +#include +#include +#include + +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 diff --git a/testsuites/ftp01/wscript b/testsuites/ftp01/wscript new file mode 100644 index 0000000..340c7ed --- /dev/null +++ b/testsuites/ftp01/wscript @@ -0,0 +1,52 @@ +# +# RTEMS Project (https://www.rtems.org/) +# +# Copyright (c) 2021 Vijay Kumar Banerjee . +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +from rtems_waf import rtems +import os + + +def init(ctx): + pass + + +def configure(conf): + pass + + +def build(bld): + arch_lib_path = rtems.arch_bsp_lib_path(bld.env.RTEMS_VERSION, + bld.env.RTEMS_ARCH_BSP) + lib_path = os.path.join(bld.env.PREFIX, arch_lib_path) + bld.read_stlib('ftpfs', paths=[lib_path]) + bld.read_stlib('ftpd', paths=[lib_path]) + + bld.program(target='ftp01.exe', + features='c cprogram', + cfags=['-O2', '-g'], + includes='. .. ../include ../../', + use=['ftpfs', 'ftpd', 'networking'], + source='init.c') diff --git a/testsuites/loopback/README b/testsuites/loopback/README new file mode 100644 index 0000000..9090e93 --- /dev/null +++ b/testsuites/loopback/README @@ -0,0 +1,61 @@ +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. diff --git a/testsuites/loopback/init.c b/testsuites/loopback/init.c new file mode 100644 index 0000000..891225c --- /dev/null +++ b/testsuites/loopback/init.c @@ -0,0 +1,264 @@ +/* + * 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 + +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 + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * 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 ); +} diff --git a/testsuites/loopback/loopback.scn b/testsuites/loopback/loopback.scn new file mode 100644 index 0000000..ec6207f --- /dev/null +++ b/testsuites/loopback/loopback.scn @@ -0,0 +1,56 @@ +"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. diff --git a/testsuites/loopback/wscript b/testsuites/loopback/wscript new file mode 100644 index 0000000..1b48589 --- /dev/null +++ b/testsuites/loopback/wscript @@ -0,0 +1,46 @@ +# +# RTEMS Project (https://www.rtems.org/) +# +# Copyright (c) 2021 Vijay Kumar Banerjee . +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +from rtems_waf import rtems +import os + + +def init(ctx): + pass + + +def configure(conf): + pass + + +def build(bld): + bld.program(target='loopback.exe', + features='c cprogram', + cfags=['-O2', '-g'], + includes='. .. ../include ../../', + use=['networking'], + source='init.c') diff --git a/testsuites/networking01/wscript b/testsuites/networking01/wscript new file mode 100644 index 0000000..b02fb06 --- /dev/null +++ b/testsuites/networking01/wscript @@ -0,0 +1,46 @@ +# +# RTEMS Project (https://www.rtems.org/) +# +# Copyright (c) 2021 Vijay Kumar Banerjee . +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +from rtems_waf import rtems +import os + + +def init(ctx): + pass + + +def configure(conf): + pass + + +def build(bld): + bld.program(target='networking01.exe', + features='c cprogram', + cfags=['-O2', '-g'], + includes='. .. ../include ../../', + use=['networking'], + source='init.c') diff --git a/testsuites/pppd/README b/testsuites/pppd/README new file mode 100644 index 0000000..49fb2be --- /dev/null +++ b/testsuites/pppd/README @@ -0,0 +1,11 @@ +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. + diff --git a/testsuites/pppd/init.c b/testsuites/pppd/init.c new file mode 100644 index 0000000..95e0d53 --- /dev/null +++ b/testsuites/pppd/init.c @@ -0,0 +1,61 @@ +/* + * 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 +#include +#include + +#define CONFIGURE_INIT +#include "system.h" + +#include +#include +#include +#include "netconfig.h" +#include + +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(); +} diff --git a/testsuites/pppd/netconfig.h b/testsuites/pppd/netconfig.h new file mode 100644 index 0000000..f1d6494 --- /dev/null +++ b/testsuites/pppd/netconfig.h @@ -0,0 +1,33 @@ +#ifndef NETCONFIG_H_ +#define NETCONFIG_H_ + +#include +#include + +/* 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 diff --git a/testsuites/pppd/ppp.conf b/testsuites/pppd/ppp.conf new file mode 100644 index 0000000..094b194 --- /dev/null +++ b/testsuites/pppd/ppp.conf @@ -0,0 +1,27 @@ + +# +# 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 diff --git a/testsuites/pppd/pppd.options b/testsuites/pppd/pppd.options new file mode 100644 index 0000000..c0706e6 --- /dev/null +++ b/testsuites/pppd/pppd.options @@ -0,0 +1,9 @@ +/dev/tty00 +57600 +crtscts +passive +local +noauth +debug +persist +192.168.2.222:192.168.2.111 diff --git a/testsuites/pppd/pppdapp.c b/testsuites/pppd/pppdapp.c new file mode 100644 index 0000000..bf8cd52 --- /dev/null +++ b/testsuites/pppd/pppdapp.c @@ -0,0 +1,152 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + + +#include + +#include +#include +#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 ); +} diff --git a/testsuites/pppd/system.h b/testsuites/pppd/system.h new file mode 100644 index 0000000..c9972fe --- /dev/null +++ b/testsuites/pppd/system.h @@ -0,0 +1,50 @@ +#ifndef SYSTEM_H +#define SYSTEM_H + +#include +#include +#include +#include + +/* functions */ +extern rtems_task Init(rtems_task_argument argument); +extern int pppdapp_initialize(void); + +#include + +#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 + +#endif diff --git a/testsuites/pppd/wscript b/testsuites/pppd/wscript new file mode 100644 index 0000000..47871a8 --- /dev/null +++ b/testsuites/pppd/wscript @@ -0,0 +1,47 @@ +# +# RTEMS Project (https://www.rtems.org/) +# +# Copyright (c) 2021 Vijay Kumar Banerjee . +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +from rtems_waf import rtems +import os + + +def init(ctx): + pass + + +def configure(conf): + pass + + +def build(bld): + bld(target='pppd.exe', + features='c cprogram', + cfags=['-O2', '-g'], + includes='. .. ../../include ../include ../../', + use=['pppd', 'networking'], + libpath=['.', '../../build'], + source=['init.c', 'pppdapp.c']) diff --git a/testsuites/syscall01/init.c b/testsuites/syscall01/init.c new file mode 100644 index 0000000..788a293 --- /dev/null +++ b/testsuites/syscall01/init.c @@ -0,0 +1,336 @@ +/* + * Copyright (c) 2012-2015 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Dornierstr. 4 + * 82178 Puchheim + * Germany + * + * + * 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 +#include +#include +#include +#include +#include +#include + +#include +#include + +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 diff --git a/testsuites/syscall01/syscall01.doc b/testsuites/syscall01/syscall01.doc new file mode 100644 index 0000000..d19eb3a --- /dev/null +++ b/testsuites/syscall01/syscall01.doc @@ -0,0 +1,24 @@ +# COPYRIGHT (c) 2014. +# On-Line Applications Research Corporation (OAR). +# Cynthia Rempel +# 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 \ No newline at end of file diff --git a/testsuites/syscall01/syscall01.scn b/testsuites/syscall01/syscall01.scn new file mode 100644 index 0000000..598a0f4 --- /dev/null +++ b/testsuites/syscall01/syscall01.scn @@ -0,0 +1,2 @@ +*** TEST SYSCALL 1 *** +*** END OF TEST SYSCALL 1 *** diff --git a/testsuites/syscall01/wscript b/testsuites/syscall01/wscript new file mode 100644 index 0000000..5ad7006 --- /dev/null +++ b/testsuites/syscall01/wscript @@ -0,0 +1,46 @@ +# +# RTEMS Project (https://www.rtems.org/) +# +# Copyright (c) 2021 Vijay Kumar Banerjee . +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +from rtems_waf import rtems +import os + + +def init(ctx): + pass + + +def configure(conf): + pass + + +def build(bld): + bld.program(target='syscall01.exe', + features='c cprogram', + cfags=['-O2', '-g'], + includes='. .. ../include ../../', + use=['networking'], + source='init.c') diff --git a/testsuites/telnetd01/init.c b/testsuites/telnetd01/init.c new file mode 100644 index 0000000..a17126b --- /dev/null +++ b/testsuites/telnetd01/init.c @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2018 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Dornierstr. 4 + * 82178 Puchheim + * Germany + * + * + * 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 +#include +#include + +#include +#include +#include + +#include + +const char rtems_test_name[] = "TELNETD 1"; + +struct rtems_bsdnet_config rtems_bsdnet_config; + +static void command(char *device_name, void *arg) +{ +} + +static void test_command_null(void) +{ + static const rtems_telnetd_config_table config = { + .command = NULL + }; + rtems_status_code sc; + + sc = rtems_telnetd_start(&config); + rtems_test_assert(sc == RTEMS_INVALID_ADDRESS); +} + +static void test_cannot_start_server_task(void) +{ + static const rtems_telnetd_config_table config = { + .command = command, + .priority = UINT32_MAX + }; + rtems_status_code sc; + + sc = rtems_telnetd_start(&config); + rtems_test_assert(sc == RTEMS_UNSATISFIED); +} + +static void test_successful_start(void) +{ + static const rtems_telnetd_config_table config = { + .command = command, + .stack_size = RTEMS_MINIMUM_STACK_SIZE + }; + rtems_status_code sc; + + sc = rtems_telnetd_start(&config); + rtems_test_assert(sc == RTEMS_SUCCESSFUL); +} + +static void test_already_started(void) +{ + static const rtems_telnetd_config_table config = { + .command = command + }; + rtems_status_code sc; + + sc = rtems_telnetd_start(&config); + rtems_test_assert(sc == RTEMS_RESOURCE_IN_USE); +} + +static rtems_task Init(rtems_task_argument argument) +{ + int rv; + + TEST_BEGIN(); + + rv = rtems_bsdnet_initialize_network(); + rtems_test_assert(rv == 0); + + test_command_null(); + test_cannot_start_server_task(); + test_successful_start(); + test_already_started(); + + 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 (3 + 1 + 5 * 4) + +#define CONFIGURE_MAXIMUM_TASKS 8 + +#define CONFIGURE_MAXIMUM_POSIX_KEYS 1 + +#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION + +#define CONFIGURE_RTEMS_INIT_TASKS_TABLE + +#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT + +#include diff --git a/testsuites/telnetd01/telnetd01.doc b/testsuites/telnetd01/telnetd01.doc new file mode 100644 index 0000000..fe1a4d3 --- /dev/null +++ b/testsuites/telnetd01/telnetd01.doc @@ -0,0 +1,24 @@ +# +# Copyright (c) 2018 embedded brains GmbH. All rights reserved. +# +# embedded brains GmbH +# Dornierstr. 4 +# 82178 Puchheim +# Germany +# +# +# 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: telnetd01 + +directives: + + - rtems_telnetd_start() + +concepts: + ++ Check if Telnet server works. diff --git a/testsuites/telnetd01/telnetd01.scn b/testsuites/telnetd01/telnetd01.scn new file mode 100644 index 0000000..3e9cc00 --- /dev/null +++ b/testsuites/telnetd01/telnetd01.scn @@ -0,0 +1,11 @@ +*** BEGIN OF TEST TELNETD 1 *** +*** TEST VERSION: 5.0.0.dc32b6aa0807fb70f9b26bc0bc6e164ddb49bd3a +*** TEST STATE: EXPECTED_PASS +*** TEST BUILD: RTEMS_NETWORKING +*** TEST TOOLS: 7.3.0 20180125 (RTEMS 5, RSB 9670d7541e0621915e521fe76e7bb33de8cee661, Newlib d13c84eb07e35984bf7a974cd786a6cdac29e6b9) +syslog: telnetd: configuration with invalid command +syslog: telnetd: cannot create session task +syslog: telnetd: started successfully on port 23 +syslog: telnetd: cannot bind server socket + +*** END OF TEST TELNETD 1 *** diff --git a/testsuites/telnetd01/wscript b/testsuites/telnetd01/wscript new file mode 100644 index 0000000..6b388cd --- /dev/null +++ b/testsuites/telnetd01/wscript @@ -0,0 +1,46 @@ +# +# RTEMS Project (https://www.rtems.org/) +# +# Copyright (c) 2021 Vijay Kumar Banerjee . +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +from rtems_waf import rtems +import os + + +def init(ctx): + pass + + +def configure(conf): + pass + + +def build(bld): + bld.program(target='telnetd01.exe', + features='c cprogram', + cfags=['-O2', '-g'], + includes='. .. ../include ../../', + use=['networking'], + source='init.c') diff --git a/testsuites/wscript b/testsuites/wscript new file mode 100644 index 0000000..11ff55a --- /dev/null +++ b/testsuites/wscript @@ -0,0 +1,49 @@ +# +# RTEMS Project (https://www.rtems.org/) +# +# Copyright (c) 2021 Vijay Kumar Banerjee . +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +from rtems_waf import rtems + +subdirs = ['ftp01', 'loopback', + 'networking01', 'pppd', + 'syscall01', 'telnetd01'] + + +def recurse(ctx): + for sd in subdirs: + ctx.recurse(sd) + + +def init(ctx): + pass + + +def configure(conf): + recurse(conf) + + +def build(bld): + recurse(bld) diff --git a/wscript b/wscript index 32daa0b..07f774d 100644 --- a/wscript +++ b/wscript @@ -33,7 +33,7 @@ import sys top = '.' rtems_version = "6" -subdirs = ['pppd', 'nfsclient'] +subdirs = ['nfsclient', 'testsuites'] try: import rtems_waf.rtems as rtems -- cgit v1.2.3