From 1372fdc88fae999995d34aa0d58361f0e98a53a3 Mon Sep 17 00:00:00 2001 From: Vijay Kumar Banerjee Date: Wed, 10 Feb 2021 18:20:42 -0700 Subject: Add networking01 test from RTEMS testsuites --- libtest/testbeginend.c | 104 ++++++++++ libtest/testbusy.c | 37 ++++ libtest/testextension.c | 74 ++++++++ libtest/testparallel.c | 196 +++++++++++++++++++ libtest/testrun.c | 91 +++++++++ libtest/testwrappers.c | 48 +++++ lnetworking.py | 20 +- testsuites/include/buffer_test_io.h | 21 +++ testsuites/include/primode.h | 27 +++ testsuites/include/pritime.h | 27 +++ testsuites/include/test_support.h | 83 ++++++++ testsuites/include/tmacros.h | 283 ++++++++++++++++++++++++++++ testsuites/include/tmtests_empty_function.h | 23 +++ testsuites/networking01/init.c | 161 ++++++++++++++++ testsuites/networking01/networking01.doc | 26 +++ testsuites/networking01/networking01.scn | 9 + 16 files changed, 1228 insertions(+), 2 deletions(-) create mode 100644 libtest/testbeginend.c create mode 100644 libtest/testbusy.c create mode 100644 libtest/testextension.c create mode 100644 libtest/testparallel.c create mode 100644 libtest/testrun.c create mode 100644 libtest/testwrappers.c create mode 100644 testsuites/include/buffer_test_io.h create mode 100644 testsuites/include/primode.h create mode 100644 testsuites/include/pritime.h create mode 100644 testsuites/include/test_support.h create mode 100644 testsuites/include/tmacros.h create mode 100644 testsuites/include/tmtests_empty_function.h create mode 100644 testsuites/networking01/init.c create mode 100644 testsuites/networking01/networking01.doc create mode 100644 testsuites/networking01/networking01.scn diff --git a/libtest/testbeginend.c b/libtest/testbeginend.c new file mode 100644 index 0000000..89b2468 --- /dev/null +++ b/libtest/testbeginend.c @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2014, 2018 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Dornierstr. 4 + * 82178 Puchheim + * Germany + * + * + * Copyright (c) 2017 Chris Johns . All rights reserved. + * + * 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 + +rtems_printer rtems_test_printer = { + .printer = rtems_printk_printer +}; + +static const char* const test_state_strings[] = +{ + "EXPECTED_PASS", + "EXPECTED_FAIL", + "USER_INPUT", + "INDETERMINATE", + "BENCHMARK" +}; + +int rtems_test_begin(const char* name, const RTEMS_TEST_STATE state) +{ + return rtems_printf( + &rtems_test_printer, + "\n\n*** BEGIN OF TEST %s ***\n" + "*** TEST VERSION: %s\n" + "*** TEST STATE: %s\n" + "*** TEST BUILD:" +#if RTEMS_DEBUG + " RTEMS_DEBUG" +#endif +#if RTEMS_MULTIPROCESSING + " RTEMS_MULTIPROCESSING" +#endif +#if RTEMS_NETWORKING + " RTEMS_NETWORKING" +#endif +#if RTEMS_PARAVIRT + " RTEMS_PARAVIRT" +#endif +#if RTEMS_POSIX_API + " RTEMS_POSIX_API" +#endif +#if RTEMS_PROFILING + " RTEMS_PROFILING" +#endif +#if RTEMS_SMP + " RTEMS_SMP" +#endif + "\n" + "*** TEST TOOLS: " __VERSION__ "\n", + name, + rtems_version(), + test_state_strings[state] + ); +} + +int rtems_test_end(const char* name) +{ + return rtems_printf( + &rtems_test_printer, + "\n*** END OF TEST %s ***\n\n", name + ); +} + +void rtems_test_exit(int status) +{ + (void) status; + rtems_shutdown_executive(0); +} + +int rtems_test_printf( + const char* format, + ... +) +{ + va_list ap; + int len; + va_start(ap, format); + len = rtems_vprintf( + &rtems_test_printer, + format, + ap + ); + va_end(ap); + return len; +} diff --git a/libtest/testbusy.c b/libtest/testbusy.c new file mode 100644 index 0000000..c1d4427 --- /dev/null +++ b/libtest/testbusy.c @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2014, 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 + +void rtems_test_busy_cpu_usage( time_t seconds, long nanoseconds ) +{ + Thread_Control *executing; + Timestamp_Control busy; + Timestamp_Control start; + Timestamp_Control now; + + executing = _Thread_Get_executing(); + _Thread_Get_CPU_time_used( executing, &start ); + _Timestamp_Set( &busy, seconds, nanoseconds ); + + do { + _Thread_Get_CPU_time_used( executing, &now ); + } while ( now - start < busy ); +} diff --git a/libtest/testextension.c b/libtest/testextension.c new file mode 100644 index 0000000..ee9681a --- /dev/null +++ b/libtest/testextension.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2014 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 + +#if defined(RTEMS_PROFILING) +static bool report_done; + +RTEMS_INTERRUPT_LOCK_DEFINE( static, report_lock, "test report" ) +#endif + +void rtems_test_fatal_extension( + rtems_fatal_source source, + bool always_set_to_false, + rtems_fatal_code code +) +{ +#if defined(RTEMS_PROFILING) + rtems_interrupt_lock_context lock_context; + rtems_printer printer; + + rtems_print_printer_printk( &printer ); + + /* + * Ensures to report only once on SMP machines and ensures that the report is + * output completely. + */ + rtems_interrupt_lock_acquire( &report_lock, &lock_context ); + + if ( !report_done ) { + report_done = true; + + printk( + "\n*** PROFILING REPORT BEGIN %s ***\n", + rtems_test_name + ); + + rtems_profiling_report_xml( + rtems_test_name, + &printer, + 1, + " " + ); + + printk( + "*** PROFILING REPORT END %s ***\n", + rtems_test_name + ); + } + + rtems_interrupt_lock_release( &report_lock, &lock_context ); +#endif + + (void) source; + (void) always_set_to_false; + (void) code; +} diff --git a/libtest/testparallel.c b/libtest/testparallel.c new file mode 100644 index 0000000..f9845e0 --- /dev/null +++ b/libtest/testparallel.c @@ -0,0 +1,196 @@ +/* + * Copyright (c) 2013, 2016 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 + +static void stop_worker_timer(rtems_id timer_id, void *arg) +{ + rtems_test_parallel_context *ctx = arg; + + _Atomic_Store_ulong(&ctx->stop, 1, ATOMIC_ORDER_RELAXED); +} + +static void start_worker_stop_timer( + rtems_test_parallel_context *ctx, + rtems_interval duration +) +{ + rtems_status_code sc; + + _Atomic_Store_ulong(&ctx->stop, 0, ATOMIC_ORDER_RELEASE); + + sc = rtems_timer_fire_after( + ctx->stop_worker_timer_id, + duration, + stop_worker_timer, + ctx + ); + _Assert(sc == RTEMS_SUCCESSFUL); + (void) sc; +} + +static void run_tests( + rtems_test_parallel_context *ctx, + const rtems_test_parallel_job *jobs, + size_t job_count +) +{ + SMP_barrier_State bs = SMP_BARRIER_STATE_INITIALIZER; + size_t i; + + _SMP_barrier_Wait(&ctx->barrier, &bs, ctx->worker_count); + + for (i = 0; i < job_count; ++i) { + const rtems_test_parallel_job *job = &jobs[i]; + size_t n = rtems_scheduler_get_processor_maximum(); + size_t j = job->cascade ? 0 : rtems_scheduler_get_processor_maximum() - 1; + + while (j < n) { + size_t active_worker = j + 1; + size_t worker_index; + rtems_interrupt_level level; + + /* + * Determine worker index via the current processor index to get + * consistent job runs with respect to the cache topology. + */ + rtems_interrupt_local_disable(level); + _SMP_barrier_Wait(&ctx->barrier, &bs, ctx->worker_count); + worker_index = rtems_scheduler_get_processor(); + rtems_interrupt_local_enable(level); + + _Assert(worker_index < ctx->worker_count); + + if (rtems_test_parallel_is_master_worker(worker_index)) { + rtems_interval duration = (*job->init)(ctx, job->arg, active_worker); + + if (duration > 0) { + start_worker_stop_timer(ctx, duration); + } + } + + _SMP_barrier_Wait(&ctx->barrier, &bs, ctx->worker_count); + + if (worker_index <= j) { + (*job->body)(ctx, job->arg, active_worker, worker_index); + } + + _SMP_barrier_Wait(&ctx->barrier, &bs, ctx->worker_count); + + if (rtems_test_parallel_is_master_worker(worker_index)) { + (*job->fini)(ctx, job->arg, active_worker); + } + + _SMP_barrier_Wait(&ctx->barrier, &bs, ctx->worker_count); + + ++j; + } + } +} + +static void worker_task(rtems_task_argument arg) +{ + rtems_test_parallel_context *ctx = (rtems_test_parallel_context *) arg; + rtems_status_code sc; + + (void) sc; + + run_tests(ctx, ctx->jobs, ctx->job_count); + + while (true) { + /* Wait for delete by master worker */ + } +} + +void rtems_test_parallel( + rtems_test_parallel_context *ctx, + rtems_test_parallel_worker_setup worker_setup, + const rtems_test_parallel_job *jobs, + size_t job_count +) +{ + rtems_status_code sc; + size_t worker_index; + rtems_task_priority worker_priority; + + _Atomic_Init_ulong(&ctx->stop, 0); + _SMP_barrier_Control_initialize(&ctx->barrier); + ctx->worker_count = rtems_scheduler_get_processor_maximum(); + ctx->worker_ids[0] = rtems_task_self(); + ctx->jobs = jobs; + ctx->job_count = job_count; + + if (RTEMS_ARRAY_SIZE(ctx->worker_ids) < ctx->worker_count) { + rtems_fatal_error_occurred(0xdeadbeef); + } + + sc = rtems_task_set_priority( + RTEMS_SELF, + RTEMS_CURRENT_PRIORITY, + &worker_priority + ); + if (sc != RTEMS_SUCCESSFUL) { + rtems_fatal_error_occurred(0xdeadbeef); + } + + sc = rtems_timer_create( + rtems_build_name('S', 'T', 'O', 'P'), + &ctx->stop_worker_timer_id + ); + if (sc != RTEMS_SUCCESSFUL) { + rtems_fatal_error_occurred(0xdeadbeef); + } + + for (worker_index = 1; worker_index < ctx->worker_count; ++worker_index) { + rtems_id worker_id; + + sc = rtems_task_create( + rtems_build_name('W', 'O', 'R', 'K'), + worker_priority, + RTEMS_MINIMUM_STACK_SIZE, + RTEMS_DEFAULT_MODES, + RTEMS_DEFAULT_ATTRIBUTES, + &worker_id + ); + if (sc != RTEMS_SUCCESSFUL) { + rtems_fatal_error_occurred(0xdeadbeef); + } + + ctx->worker_ids[worker_index] = worker_id; + + if (worker_setup != NULL) { + (*worker_setup)(ctx, worker_index, worker_id); + } + + sc = rtems_task_start(worker_id, worker_task, (rtems_task_argument) ctx); + _Assert(sc == RTEMS_SUCCESSFUL); + } + + run_tests(ctx, jobs, job_count); + + for (worker_index = 1; worker_index < ctx->worker_count; ++worker_index) { + sc = rtems_task_delete(ctx->worker_ids[worker_index]); + _Assert(sc == RTEMS_SUCCESSFUL); + } + + sc = rtems_timer_delete(ctx->stop_worker_timer_id); + _Assert(sc == RTEMS_SUCCESSFUL); +} diff --git a/libtest/testrun.c b/libtest/testrun.c new file mode 100644 index 0000000..59418e8 --- /dev/null +++ b/libtest/testrun.c @@ -0,0 +1,91 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup RTEMSAPI + * + * @brief Implementation of rtems_test_run_default(). + */ + +/* + * Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de) + * + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +#include + +static char buffer[ 512 ]; + +static const T_action actions[] = { + T_report_hash_sha256, + T_check_task_context, + T_check_file_descriptors, + T_check_rtems_barriers, + T_check_rtems_extensions, + T_check_rtems_message_queues, + T_check_rtems_partitions, + T_check_rtems_periods, + T_check_rtems_regions, + T_check_rtems_semaphores, + T_check_rtems_tasks, + T_check_rtems_timers, + T_check_posix_keys +}; + +static const T_config config = { + .name = rtems_test_name, + .buf = buffer, + .buf_size = sizeof( buffer ), + .putchar = T_putchar_default, + .verbosity = T_VERBOSE, + .now = T_now_clock, + .allocate = malloc, + .deallocate = free, + .action_count = T_ARRAY_SIZE( actions ), + .actions = actions +}; + +void rtems_test_run( + rtems_task_argument arg, + const RTEMS_TEST_STATE state +) +{ + (void) arg; + + rtems_test_begin( rtems_test_name, state ); + T_register(); + + if ( T_main( &config ) == 0 ) { + rtems_test_end( rtems_test_name ); + } + + rtems_test_exit( 0 ); +} diff --git a/libtest/testwrappers.c b/libtest/testwrappers.c new file mode 100644 index 0000000..9679f75 --- /dev/null +++ b/libtest/testwrappers.c @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2017 Chris Johns . All rights reserved. + * + * 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 + +int __wrap_printf(const char* format, ...); +int __wrap_puts(const char *str); +int __wrap_putchar(int c); + +int __wrap_printf( + const char* format, + ... +) +{ + va_list ap; + int len; + va_start(ap, format); + len = rtems_vprintf( + &rtems_test_printer, + format, + ap + ); + va_end(ap); + return len; +} + +int __wrap_puts( + const char *str +) +{ + return rtems_test_printf( "%s\n", str ); +} + +int __wrap_putchar( + int c +) +{ + return rtems_test_printf( "%c", c ); +} diff --git a/lnetworking.py b/lnetworking.py index 8041a93..69796a8 100644 --- a/lnetworking.py +++ b/lnetworking.py @@ -24,11 +24,14 @@ # 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 + source_files = [] include_files = [] -exclude_dirs = ['pppd'] +test_source = [] +exclude_dirs = ['pppd', 'nfsclient', 'testsuites'] for root, dirs, files in os.walk("."): [dirs.remove(d) for d in list(dirs) if d in exclude_dirs] @@ -36,8 +39,13 @@ for root, dirs, files in os.walk("."): if name[-2:] == '.c': source_files.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 = ['./', os.path.relpath(bld.env.PREFIX)] + include_path = ['./', os.path.relpath(bld.env.PREFIX), './testsuites/include'] arch_lib_path = rtems.arch_bsp_lib_path(bld.env.RTEMS_VERSION, bld.env.RTEMS_ARCH_BSP) @@ -46,4 +54,12 @@ def build(bld): cflags = ['-O2', '-g'], includes = include_path, source = source_files) + + bld.program(target = 'networking01.exe', + features = 'c cprogram', + cflags = ['-O2', '-g'], + includes = include_path, + use = 'networking', + source = test_source) + bld.install_files(os.path.join('${PREFIX}', arch_lib_path), ["libnetworking.a"]) diff --git a/testsuites/include/buffer_test_io.h b/testsuites/include/buffer_test_io.h new file mode 100644 index 0000000..f0eae50 --- /dev/null +++ b/testsuites/include/buffer_test_io.h @@ -0,0 +1,21 @@ +/* + * Support for running the test output through a buffer + */ + +#ifndef __BUFFER_TEST_IO_h +#define __BUFFER_TEST_IO_h + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define TEST_BEGIN() rtems_test_begin(rtems_test_name, TEST_STATE) +#define TEST_END() rtems_test_end(rtems_test_name) + +#ifdef __cplusplus +}; +#endif + +#endif diff --git a/testsuites/include/primode.h b/testsuites/include/primode.h new file mode 100644 index 0000000..551ae22 --- /dev/null +++ b/testsuites/include/primode.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2011 by + * Ralf Corsépius, Ulm, Germany. All rights reserved. + * + * Permission to use, copy, modify, and distribute this software + * is freely granted, provided that this notice is preserved. + */ + +/* + * Helper macro to print "time_t" + */ + +#ifndef _PRIMODE_H +#define _PRIMODE_H + +#include +#include + +#if __RTEMS_SIZEOF_MODE_T__ == 8 +#define PRIomode_t PRIo64 +#elif __RTEMS_SIZEOF_MODE_T__ == 4 +#define PRIomode_t PRIo32 +#else +#error "unsupported size of mode_t" +#endif + +#endif diff --git a/testsuites/include/pritime.h b/testsuites/include/pritime.h new file mode 100644 index 0000000..fea5e62 --- /dev/null +++ b/testsuites/include/pritime.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2011 by + * Ralf Corsépius, Ulm, Germany. All rights reserved. + * + * Permission to use, copy, modify, and distribute this software + * is freely granted, provided that this notice is preserved. + */ + +/* + * Helper macro to print "time_t" + */ + +#ifndef _PRITIME_H +#define _PRITIME_H + +#include +#include + +#if __RTEMS_SIZEOF_TIME_T__ == 8 +#define PRIdtime_t PRId64 +#elif __RTEMS_SIZEOF_TIME_T__ == 4 +#define PRIdtime_t PRId32 +#else +#error "unsupported size of time_t" +#endif + +#endif diff --git a/testsuites/include/test_support.h b/testsuites/include/test_support.h new file mode 100644 index 0000000..9c30b39 --- /dev/null +++ b/testsuites/include/test_support.h @@ -0,0 +1,83 @@ +/* + * COPYRIGHT (c) 1989-2011. + * 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. + */ + +#ifndef __TEST_SUPPORT_h +#define __TEST_SUPPORT_h + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Return a pointer to the POSIX name that is slightly + * beyond the legal limit. + */ +const char *Get_Too_Long_Name(void); + +/* + * Return a pointer to the longest legal POSIX name. + */ +const char *Get_Longest_Name(void); + +/* + * Spin for specified number of ticks. The first tick we spin through is a + * partial one. + */ +void rtems_test_spin_for_ticks(rtems_interval ticks); + +/* + * Spin until the next clock tick + */ +void rtems_test_spin_until_next_tick( void ); + +/*********************************************************************/ +/*********************************************************************/ +/************** TMTEST SUPPORT **************/ +/*********************************************************************/ +/*********************************************************************/ + +/* + * Type of method used for timing operations + */ +typedef void (*rtems_time_test_method_t)( + int iteration, + void *argument +); + +/* + * Obtain baseline timing information for benchmark tests. + */ +void rtems_time_test_measure_operation( + const char *description, + rtems_time_test_method_t operation, + void *argument, + int iterations, + int overhead +); + +/*********************************************************************/ +/*********************************************************************/ +/************** TEST SUPPORT **************/ +/*********************************************************************/ +/*********************************************************************/ + +void locked_print_initialize(void); + +int locked_printf(const char *fmt, ...); + +int locked_vprintf(const char *fmt, va_list ap); + +#ifdef __cplusplus +}; +#endif + +#endif diff --git a/testsuites/include/tmacros.h b/testsuites/include/tmacros.h new file mode 100644 index 0000000..fe17bc0 --- /dev/null +++ b/testsuites/include/tmacros.h @@ -0,0 +1,283 @@ +/** + * @file + * + * This include file contains macros which are useful in the RTEMS + * test suites. + */ + +/* + * COPYRIGHT (c) 1989-2014. + * 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. + */ + +#ifndef __TMACROS_h +#define __TMACROS_h + +#include +#include +#include /* includes */ + +#include +#include +#include +#include +#include +#include +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define FOREVER 1 /* infinite loop */ + +#ifdef CONFIGURE_INIT +#define TEST_EXTERN +#else +#define TEST_EXTERN extern +#endif + +/* + * Check that that the dispatch disable level is proper for the + * mode/state of the test. Normally it should be 0 when in task space. + */ +#define check_dispatch_disable_level( _expect ) \ + do { \ + if ( (_expect) != -1 \ + && (((!_Thread_Dispatch_is_enabled()) == false && (_expect) != 0) \ + || ((!_Thread_Dispatch_is_enabled()) && (_expect) == 0)) \ + ) { \ + printf( \ + "\n_Thread_Dispatch_disable_level is (%i)" \ + " not %d detected at %s:%d\n", \ + !_Thread_Dispatch_is_enabled(), (_expect), __FILE__, __LINE__ ); \ + rtems_test_exit( 1 ); \ + } \ + } while ( 0 ) + +/* + * Check that that the allocator mutex is not owned by the executing thread. + */ +#include +#define check_if_allocator_mutex_is_not_owned() \ + do { \ + if ( _RTEMS_Allocator_is_owner() ) { \ + printf( \ + "\nRTEMS Allocator Mutex is owned by executing thread " \ + "and should not be.\n" \ + "Detected at %s:%d\n", \ + __FILE__, \ + __LINE__ \ + ); \ + rtems_test_exit( 1 ); \ + } \ + } while ( 0 ) + +/* + * These macros properly report errors within the Classic API + */ +#define directive_failed( _dirstat, _failmsg ) \ + fatal_directive_status( _dirstat, RTEMS_SUCCESSFUL, _failmsg ) + +#define directive_failed_with_level( _dirstat, _failmsg, _level ) \ + fatal_directive_status_with_level( \ + _dirstat, RTEMS_SUCCESSFUL, _failmsg, _level ) + +#define fatal_directive_status( _stat, _desired, _msg ) \ + fatal_directive_status_with_level( _stat, _desired, _msg, 0 ) + +#define fatal_directive_check_status_only( _stat, _desired, _msg ) \ + do { \ + if ( (_stat) != (_desired) ) { \ + printf( "\n%s FAILED -- expected (%s) got (%s)\n", \ + (_msg), rtems_status_text(_desired), rtems_status_text(_stat) ); \ + rtems_test_exit( _stat ); \ + } \ + } while ( 0 ) + +#define fatal_directive_status_with_level( _stat, _desired, _msg, _level ) \ + do { \ + check_dispatch_disable_level( _level ); \ + check_if_allocator_mutex_is_not_owned(); \ + fatal_directive_check_status_only( _stat, _desired, _msg ); \ + } while ( 0 ) + +/* + * These macros properly report errors from the POSIX API + */ + +#define posix_service_failed( _dirstat, _failmsg ) \ + fatal_posix_service_status( _dirstat, 0, _failmsg ) + +#define posix_service_failed_with_level( _dirstat, _failmsg, _level ) \ + fatal_posix_service_status_with_level( _dirstat, 0, _failmsg, _level ) + +#define fatal_posix_service_status_errno( _stat, _desired, _msg ) \ + if ( (_stat != -1) && (errno) != (_desired) ) { \ + long statx = _stat; \ + check_dispatch_disable_level( 0 ); \ + check_if_allocator_mutex_is_not_owned(); \ + printf( "\n%s FAILED -- expected (%d - %s) got (%ld %d - %s)\n", \ + (_msg), _desired, strerror(_desired), \ + statx, errno, strerror(errno) ); \ + rtems_test_exit( _stat ); \ + } + +#define fatal_posix_service_status( _stat, _desired, _msg ) \ + fatal_posix_service_status_with_level( _stat, _desired, _msg, 0 ) + +#define fatal_posix_service_status_with_level( _stat, _desired, _msg, _level ) \ + do { \ + check_dispatch_disable_level( _level ); \ + check_if_allocator_mutex_is_not_owned(); \ + if ( (_stat) != (_desired) ) { \ + printf( "\n%s FAILED -- expected (%d - %s) got (%d - %s)\n", \ + (_msg), _desired, strerror(_desired), _stat, strerror(_stat) ); \ + printf( "\n FAILED -- errno (%d - %s)\n", \ + errno, strerror(errno) ); \ + rtems_test_exit( _stat ); \ + } \ + } while ( 0 ) + +/* + * This macro evaluates the semaphore id returned. + */ +#define fatal_posix_sem( _ptr, _msg ) \ + if ( (_ptr != SEM_FAILED) ) { \ + check_dispatch_disable_level( 0 ); \ + printf( "\n%s FAILED -- expected (-1) got (%p - %d/%s)\n", \ + (_msg), _ptr, errno, strerror(errno) ); \ + rtems_test_exit( -1 ); \ + } + +/* + * This macro evaluates the message queue id returned. + */ +#define fatal_posix_mqd( _ptr, _msg ) \ + if ( (_ptr != (mqd_t) -1) ) { \ + check_dispatch_disable_level( 0 ); \ + printf( "\n%s FAILED -- expected (-1) got (%" PRId32 " - %d/%s)\n", \ + (_msg), _ptr, errno, strerror(errno) ); \ + rtems_test_exit( -1 ); \ + } + +/* + * Generic integer version of the error reporting + */ + +#define int_service_failed( _dirstat, _failmsg ) \ + fatal_int_service_status( _dirstat, RTEMS_SUCCESSFUL, _failmsg ) + +#define int_service_failed_with_level( _dirstat, _failmsg, _level ) \ + fatal_int_service_status_with_level( \ + _dirstat, RTEMS_SUCCESSFUL, _failmsg, _level ) + +#define fatal_int_service_status( _stat, _desired, _msg ) \ + fatal_int_service_status_with_level( _stat, _desired, _msg, 0 ) + +#define fatal_int_service_status_with_level( _stat, _desired, _msg, _level ) \ + do { \ + check_dispatch_disable_level( _level ); \ + if ( (_stat) != (_desired) ) { \ + printf( "\n%s FAILED -- expected (%d) got (%d)\n", \ + (_msg), (_desired), (_stat) ); \ + rtems_test_exit( _stat ); \ + } \ + } while ( 0 ) + + +/* + * Print the time + */ + +#define sprint_time(_str, _s1, _tb, _s2) \ + do { \ + sprintf( (_str), "%s%02d:%02d:%02d %02d/%02d/%04d%s", \ + _s1, (_tb)->hour, (_tb)->minute, (_tb)->second, \ + (_tb)->month, (_tb)->day, (_tb)->year, _s2 ); \ + } while ( 0 ) + +#define print_time(_s1, _tb, _s2) \ + do { \ + printf( "%s%02" PRIu32 ":%02" PRIu32 ":%02" PRIu32 " %02" PRIu32 "/%02" PRIu32 "/%04" PRIu32 "%s", \ + _s1, (_tb)->hour, (_tb)->minute, (_tb)->second, \ + (_tb)->month, (_tb)->day, (_tb)->year, _s2 ); \ + } while ( 0 ) + +#define put_dot( _c ) \ + do { \ + putchar( _c ); \ + } while ( 0 ) + +#define new_line puts( "" ) + +#define puts_nocr printf + +#define put_name( name, crlf ) \ +{ int c0, c1, c2, c3; \ + c0 = (name >> 24) & 0xff; \ + c1 = (name >> 16) & 0xff; \ + c2 = (name >> 8) & 0xff; \ + c3 = name & 0xff; \ + putchar( (isprint(c0)) ? c0 : '*' ); \ + if ( c1 ) putchar( (isprint(c1)) ? c1 : '*' ); \ + if ( c2 ) putchar( (isprint(c2)) ? c2 : '*' ); \ + if ( c3 ) putchar( (isprint(c3)) ? c3 : '*' ); \ + if ( crlf ) \ + putchar( '\n' ); \ +} + +#ifndef build_time +#define build_time( TB, MON, DAY, YR, HR, MIN, SEC, TK ) \ + { (TB)->year = YR; \ + (TB)->month = MON; \ + (TB)->day = DAY; \ + (TB)->hour = HR; \ + (TB)->minute = MIN; \ + (TB)->second = SEC; \ + (TB)->ticks = TK; } +#endif + +#define task_number( tid ) \ + ( rtems_object_id_get_index( tid ) - \ + rtems_configuration_get_rtems_api_configuration()-> \ + number_of_initialization_tasks ) + +#define rtems_test_assert(__exp) \ + do { \ + if (!(__exp)) { \ + printf( "%s: %d %s\n", __FILE__, __LINE__, #__exp ); \ + rtems_test_exit(0); \ + } \ + } while (0) + +/** + * This assists in clearly disabling warnings on GCC in certain very + * specific cases. + * + * + -Wnon-null - If a method is declared as never having a NULL first + * parameter. We need to explicitly disable this compiler warning to make + * the code warning free. + */ +#ifdef __GNUC__ + #define COMPILER_DIAGNOSTIC_SETTINGS_PUSH _Pragma("GCC diagnostic push") + #define COMPILER_DIAGNOSTIC_SETTINGS_POP _Pragma("GCC diagnostic pop") + #define COMPILER_DIAGNOSTIC_SETTINGS_DISABLE_NONNULL \ + _Pragma("GCC diagnostic ignored \"-Wnonnull\"") +#else + #define COMPILER_DIAGNOSTIC_SETTINGS_PUSH + #define COMPILER_DIAGNOSTIC_SETTINGS_POP + #define COMPILER_DIAGNOSTIC_SETTINGS_DISABLE_NONNULL +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/testsuites/include/tmtests_empty_function.h b/testsuites/include/tmtests_empty_function.h new file mode 100644 index 0000000..a47df61 --- /dev/null +++ b/testsuites/include/tmtests_empty_function.h @@ -0,0 +1,23 @@ +/* + * Prototypes for RTEMS tmtests_empty_function.c. + * + * COPYRIGHT (c) 2011, Ralf Corsépius, Ulm/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. + */ + +#ifndef _TMTESTS_EMPTY_FUNCTION_H +#define _TMTESTS_EMPTY_FUNCTION_H + +#include + +extern rtems_status_code benchmark_timer_empty_function( void ); + +extern void benchmark_timer_empty_operation( + int iteration, + void *argument +); + +#endif /* _TMTESTS_EMPTY_FUNCTION_H */ diff --git a/testsuites/networking01/init.c b/testsuites/networking01/init.c new file mode 100644 index 0000000..0d13ae7 --- /dev/null +++ b/testsuites/networking01/init.c @@ -0,0 +1,161 @@ +/* + * Copyright (c) 2016 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 + +const char rtems_test_name[] = "NETWORKING 1"; + +/* forward declarations to avoid warnings */ +static rtems_task Init(rtems_task_argument argument); + +static void fill_sa(struct sockaddr *sa, sa_family_t family) +{ + memset(sa, 0, sizeof(*sa)); + sa->sa_len = sizeof(*sa); + sa->sa_family = family; +} + +static void fill_sa_in(struct sockaddr_in *sa_in, + in_addr_t addr, in_port_t port) +{ + fill_sa((struct sockaddr *)sa_in, AF_INET); + sa_in->sin_port = htons(port); + sa_in->sin_addr.s_addr = htonl(addr); +} + +static void test_getnameinfo( + const struct sockaddr *sa, + int flags, + bool ask_node, + bool ask_service, + int expected_returnvalue, + const char *expected_node, + const char *expected_service +) +{ + char node[] = "255.255.255.255"; + char service[] = "65535"; + socklen_t salen = sa->sa_len; + int rv; + + char *node_p = node; + char *service_p = service; + size_t node_l = sizeof(node); + size_t service_l = sizeof(service); + + if(ask_node == false) { + node_p = NULL; + node_l = 0; + } + + if(ask_service == false) { + service_p = NULL; + service_l = 0; + } + + rv = getnameinfo(sa, salen, node_p, node_l, service_p, service_l, flags); + rtems_test_assert(rv == expected_returnvalue); + + if(expected_node != NULL) { + rtems_test_assert(strcmp(expected_node, node) == 0); + } + + if(expected_service != NULL) { + rtems_test_assert(strcmp(expected_service, service) == 0); + } +} + +static void test(void) +{ + struct sockaddr sa; + struct sockaddr_in sa_in; + struct sockaddr *sa_in_p = (struct sockaddr *) &sa_in; + + const in_addr_t ip1_num = 0x7F000001u; + const char ip1_string[] = "127.0.0.1"; + + const in_addr_t ip2_num = 0xC0A86464u; + const char ip2_string[] = "192.168.100.100"; + + const in_port_t port1_num = 7u; + const char port1_string[] = "7"; + + const in_port_t port2_num = 65534u; + const char port2_string[] = "65534"; + + + puts("Try AF_INET6"); + fill_sa(&sa, AF_INET6); + test_getnameinfo(&sa, 0, true, true, EAI_FAMILY, NULL, NULL); + + puts("force node name"); + fill_sa_in(&sa_in, ip1_num, port1_num); + test_getnameinfo(sa_in_p, NI_NAMEREQD, true, true, EAI_NONAME, NULL, NULL); + + puts("force service name"); + fill_sa_in(&sa_in, ip1_num, port1_num); + test_getnameinfo(sa_in_p, NI_NAMEREQD, true, true, EAI_NONAME, NULL, NULL); + + puts("get node only"); + fill_sa_in(&sa_in, ip1_num, port1_num); + test_getnameinfo(sa_in_p, 0, true, false, 0, ip1_string, NULL); + + puts("get service only"); + fill_sa_in(&sa_in, ip1_num, port1_num); + test_getnameinfo(sa_in_p, 0, false, true, 0, NULL, port1_string); + + puts("get node and service"); + fill_sa_in(&sa_in, ip1_num, port1_num); + test_getnameinfo(sa_in_p, 0, true, true, 0, ip1_string, port1_string); + + puts("get node and service with maximum number of characters for IP"); + fill_sa_in(&sa_in, ip2_num, port2_num); + test_getnameinfo(sa_in_p, 0, true, true, 0, ip2_string, port2_string); +} + +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_TASKS (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/networking01/networking01.doc b/testsuites/networking01/networking01.doc new file mode 100644 index 0000000..949a32c --- /dev/null +++ b/testsuites/networking01/networking01.doc @@ -0,0 +1,26 @@ +# +# Copyright (c) 2016 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: networking + +directives: + ++ getnameinfo() + +concepts: + ++ Try to get some valid and invalid name infos. + +NOTE: This test works without a network connection. diff --git a/testsuites/networking01/networking01.scn b/testsuites/networking01/networking01.scn new file mode 100644 index 0000000..75e8457 --- /dev/null +++ b/testsuites/networking01/networking01.scn @@ -0,0 +1,9 @@ +*** BEGIN OF TEST LIBNETWORKING 1 *** +Try AF_INET6 +force node name +force service name +get node only +get service only +get node and service +get node and service with maximum number of characters for IP +*** END OF TEST LIBNETWORKING 1 *** -- cgit v1.2.3