From fadb741410280c4977db6d1b1677f0937b731278 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Tue, 3 Aug 2021 16:30:07 +0200 Subject: validation: Test system termination --- spec/build/testsuites/validation/grp.yml | 2 + spec/build/testsuites/validation/terminate.yml | 22 ++ testsuites/validation/tc-terminate.c | 383 +++++++++++++++++++++++++ testsuites/validation/tc-terminate.h | 61 ++++ testsuites/validation/ts-default.h | 2 + testsuites/validation/ts-terminate.c | 82 ++++++ 6 files changed, 552 insertions(+) create mode 100644 spec/build/testsuites/validation/terminate.yml create mode 100644 testsuites/validation/tc-terminate.c create mode 100644 testsuites/validation/tc-terminate.h create mode 100644 testsuites/validation/ts-terminate.c diff --git a/spec/build/testsuites/validation/grp.yml b/spec/build/testsuites/validation/grp.yml index 7379b61c5b..1157d37674 100644 --- a/spec/build/testsuites/validation/grp.yml +++ b/spec/build/testsuites/validation/grp.yml @@ -40,6 +40,8 @@ links: uid: model-0 - role: build-dependency uid: performance-0 +- role: build-dependency + uid: terminate - role: build-dependency uid: validation-0 - role: build-dependency diff --git a/spec/build/testsuites/validation/terminate.yml b/spec/build/testsuites/validation/terminate.yml new file mode 100644 index 0000000000..e04c819ea1 --- /dev/null +++ b/spec/build/testsuites/validation/terminate.yml @@ -0,0 +1,22 @@ +SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause +build-type: test-program +cflags: [] +copyrights: +- Copyright (C) 2021 embedded brains GmbH (http://www.embedded-brains.de) +cppflags: [] +cxxflags: [] +enabled-by: true +features: c cprogram +includes: [] +ldflags: +- -Wl,--wrap=_CPU_Fatal_halt +links: [] +source: +- testsuites/validation/tc-terminate.c +- testsuites/validation/ts-terminate.c +stlib: [] +target: testsuites/validation/ts-terminate.exe +type: build +use-after: +- validation +use-before: [] diff --git a/testsuites/validation/tc-terminate.c b/testsuites/validation/tc-terminate.c new file mode 100644 index 0000000000..3d31f4720b --- /dev/null +++ b/testsuites/validation/tc-terminate.c @@ -0,0 +1,383 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup RTEMSTestCaseScoreInterrValTerminate + */ + +/* + * Copyright (C) 2021 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. + */ + +/* + * This file is part of the RTEMS quality process and was automatically + * generated. If you find something that needs to be fixed or + * worded better please post a report or patch to an RTEMS mailing list + * or raise a bug report: + * + * https://www.rtems.org/bugs.html + * + * For information on updating and regenerating please refer to the How-To + * section in the Software Requirements Engineering chapter of the + * RTEMS Software Engineering manual. The manual is provided as a part of + * a release. For development sources please refer to the online + * documentation at: + * + * https://docs.rtems.org + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "tc-terminate.h" + +#include + +/** + * @defgroup RTEMSTestCaseScoreInterrValTerminate \ + * spec:/score/interr/val/terminate + * + * @ingroup RTEMSTestSuiteTestsuitesTerminate + * + * @brief Tests system termination procedure. + * + * This test case performs the following actions: + * + * - Create three dynamic extensions. Call the system termination procedure. + * Delete one dynamic extension during the fatal extension invocation. + * Delete the two remaining dynamic extensions. + * + * - Check that the fatal extensions were invoked with the expected source. + * + * - Check that the fatal extensions were invoked with the expected always + * set to false argument. + * + * - Check that the fatal extensions were invoked with the expected code. + * + * - Check that the fatal extensions were invoked in forward order. + * + * - Check that the fatal extension in the deleted extension set was not + * invoked. + * + * - Check that the system state is terminated. + * + * - Where the system was built with SMP support enabled, check that a + * shutdown request was issued. + * + * - Check that the system was halted with the expected fatal source. + * + * - Check that the system was halted with the expected fatal code. + * + * - Check that the system was finally halted. + * + * @{ + */ + +typedef struct { + unsigned int counter; + rtems_fatal_source source; + bool always_set_to_false; + rtems_fatal_code code; +} FatalInfo; + +static Atomic_Uint counter; + +static FatalInfo info[ 5 ]; + +static bool test_case_active; + +static const rtems_extensions_table bsp = BSP_INITIAL_EXTENSION; + +static jmp_buf before_terminate; + +static unsigned int halt_counter; + +static rtems_fatal_source halt_source; + +static rtems_fatal_code halt_code; + +static rtems_id extension_id_4; + +static unsigned int GetCounter( void ) +{ + return _Atomic_Fetch_add_uint( &counter, 1, ATOMIC_ORDER_RELAXED ) + 1; +} + +void __real__CPU_Fatal_halt( uint32_t source, CPU_Uint32ptr code ); + +void __wrap__CPU_Fatal_halt( uint32_t source, CPU_Uint32ptr code ); + +void __wrap__CPU_Fatal_halt( uint32_t source, CPU_Uint32ptr code ) +{ + if ( test_case_active ) { + halt_counter = GetCounter(); + halt_source = source; + halt_code = code; + longjmp( before_terminate, 1 ); + } else { +#if defined(RTEMS_COVERAGE) + _IO_Dump_gcov_info( rtems_put_char, NULL ); +#endif + __real__CPU_Fatal_halt( source, code ); + } +} + +static void FatalExtension( + rtems_fatal_source source, + bool always_set_to_false, + rtems_fatal_code code, + size_t index +) +{ + if ( test_case_active ) { + info[ index ].counter = GetCounter(); + info[ index ].source = source; + info[ index ].always_set_to_false = always_set_to_false; + info[ index ].code = code; + } else { + ( *bsp.fatal )( source, always_set_to_false, code ); + } +} + +void FatalExtension0( + rtems_fatal_source source, + bool always_set_to_false, + rtems_fatal_code code +) +{ + FatalExtension( source, always_set_to_false, code, 0 ); +} + +void FatalExtension1( + rtems_fatal_source source, + bool always_set_to_false, + rtems_fatal_code code +) +{ + FatalExtension( source, always_set_to_false, code, 1 ); +} + +static void FatalExtension2( + rtems_fatal_source source, + bool always_set_to_false, + rtems_fatal_code code +) +{ + FatalExtension( source, always_set_to_false, code, 2 ); +} + +static void FatalExtension3( + rtems_fatal_source source, + bool always_set_to_false, + rtems_fatal_code code +) +{ + rtems_status_code sc; + + FatalExtension( source, always_set_to_false, code, 3 ); + + sc = rtems_extension_delete( extension_id_4 ); + T_quiet_rsc_success( sc ); +} + +static void FatalExtension4( + rtems_fatal_source source, + bool always_set_to_false, + rtems_fatal_code code +) +{ + FatalExtension( source, always_set_to_false, code, 3 ); +} + +/** + * @brief Create three dynamic extensions. Call the system termination + * procedure. Delete one dynamic extension during the fatal extension + * invocation. Delete the two remaining dynamic extensions. + */ +static void ScoreInterrValTerminate_Action_0( void ) +{ + rtems_status_code sc; + rtems_extensions_table table; + rtems_id id_2; + rtems_id id_3; + bool shutdown_ok; + + #if defined(RTEMS_SMP) + shutdown_ok = ( _Per_CPU_Get_state( _Per_CPU_Get() ) == PER_CPU_STATE_UP ); + #else + shutdown_ok = true; + #endif + + memset( &table, 0, sizeof( table ) ); + + table.fatal = FatalExtension2; + sc = rtems_extension_create( + rtems_build_name( ' ', ' ', ' ', '2' ), + &table, + &id_2 + ); + T_step_rsc_success( 0, sc ); + + table.fatal = FatalExtension3; + sc = rtems_extension_create( + rtems_build_name( ' ', ' ', ' ', '3' ), + &table, + &id_3 + ); + T_step_rsc_success( 1, sc ); + + table.fatal = FatalExtension4; + sc = rtems_extension_create( + rtems_build_name( ' ', ' ', ' ', '4' ), + &table, + &extension_id_4 + ); + T_step_rsc_success( 2, sc ); + + test_case_active = true; + + if ( setjmp( before_terminate ) == 0 ) { + _Terminate( RTEMS_FATAL_SOURCE_APPLICATION, 123456 ); + } + + test_case_active = false; + + sc = rtems_extension_delete( id_2 ); + T_step_rsc_success( 3, sc ); + + sc = rtems_extension_delete( id_3 ); + T_step_rsc_success( 4, sc ); + + /* + * Check that the fatal extensions were invoked with the expected source. + */ + T_step_eq_int( + 5, + info[ 0 ].source, + RTEMS_FATAL_SOURCE_APPLICATION + ); + T_step_eq_int( + 6, + info[ 1 ].source, + RTEMS_FATAL_SOURCE_APPLICATION + ); + T_step_eq_int( + 7, + info[ 2 ].source, + RTEMS_FATAL_SOURCE_APPLICATION + ); + T_step_eq_int( + 8, + info[ 3 ].source, + RTEMS_FATAL_SOURCE_APPLICATION + ); + + /* + * Check that the fatal extensions were invoked with the expected always set + * to false argument. + */ + T_step_false( 9, info[ 0 ].always_set_to_false ); + T_step_false( 10, info[ 1 ].always_set_to_false ); + T_step_false( 11, info[ 2 ].always_set_to_false ); + T_step_false( 12, info[ 3 ].always_set_to_false ); + + /* + * Check that the fatal extensions were invoked with the expected code. + */ + T_step_eq_ulong( 13, info[ 0 ].code, 123456 ); + T_step_eq_ulong( 14, info[ 1 ].code, 123456 ); + T_step_eq_ulong( 15, info[ 2 ].code, 123456 ); + T_step_eq_ulong( 16, info[ 3 ].code, 123456 ); + + /* + * Check that the fatal extensions were invoked in forward order. + */ + T_step_eq_uint( 17, info[ 0 ].counter, 1 ); + T_step_eq_uint( 18, info[ 1 ].counter, 2 ); + T_step_eq_uint( 19, info[ 2 ].counter, 3 ); + T_step_eq_uint( 20, info[ 3 ].counter, 4 ); + + /* + * Check that the fatal extension in the deleted extension set was not + * invoked. + */ + T_step_eq_int( 21, info[ 4 ].source, 0 ); + T_step_false( 22, info[ 4 ].always_set_to_false ); + T_step_eq_ulong( 23, info[ 4 ].code, 0 ); + T_step_eq_uint( 24, info[ 4 ].counter, 0 ); + + /* + * Check that the system state is terminated. + */ + T_step_eq_int( 25, _System_state_Get(), SYSTEM_STATE_TERMINATED ); + + /* + * Where the system was built with SMP support enabled, check that a shutdown + * request was issued. + */ + #if defined(RTEMS_SMP) + shutdown_ok = ( shutdown_ok && _ISR_Get_level() != 0 && + _Per_CPU_Get_state( _Per_CPU_Get() ) == PER_CPU_STATE_SHUTDOWN ); + _ISR_Set_level( 0 ); + #endif + T_step_true( 26, shutdown_ok ); + + /* + * Check that the system was halted with the expected fatal source. + */ + T_step_eq_int( 27, halt_source, RTEMS_FATAL_SOURCE_APPLICATION ); + + /* + * Check that the system was halted with the expected fatal code. + */ + T_step_eq_ulong( 28, halt_code, 123456 ); + + /* + * Check that the system was finally halted. + */ + T_step_eq_uint( 29, counter, 5 ); +} + +/** + * @fn void T_case_body_ScoreInterrValTerminate( void ) + */ +T_TEST_CASE( ScoreInterrValTerminate ) +{ + T_plan( 30 ); + + ScoreInterrValTerminate_Action_0(); +} + +/** @} */ diff --git a/testsuites/validation/tc-terminate.h b/testsuites/validation/tc-terminate.h new file mode 100644 index 0000000000..e46c8b0b16 --- /dev/null +++ b/testsuites/validation/tc-terminate.h @@ -0,0 +1,61 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup RTEMSTestCaseScoreInterrValTerminate + * + * @brief This header file provides functions used by corresponding test suite. + */ + +/* + * Copyright (C) 2021 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. + */ + +#ifndef _TC_TERMINATE_H +#define _TC_TERMINATE_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +void FatalExtension0( + rtems_fatal_source source, + bool always_set_to_false, + rtems_fatal_code code +); + +void FatalExtension1( + rtems_fatal_source source, + bool always_set_to_false, + rtems_fatal_code code +); + +#ifdef __cplusplus +} +#endif + +#endif /* _TC_TERMINATE_H */ diff --git a/testsuites/validation/ts-default.h b/testsuites/validation/ts-default.h index 40704141f3..f608811319 100644 --- a/testsuites/validation/ts-default.h +++ b/testsuites/validation/ts-default.h @@ -185,7 +185,9 @@ static void task_stack_deallocate( void *stack ) #define CONFIGURE_INIT_TASK_CONSTRUCT_STORAGE_SIZE TASK_STORAGE_SIZE +#if !defined( CONFIGURE_INITIAL_EXTENSIONS ) #define CONFIGURE_INITIAL_EXTENSIONS { .fatal = FatalInitialExtension } +#endif #if defined( RTEMS_SMP ) && \ ( CONFIGURE_MAXIMUM_PROCESSORS == 4 || CONFIGURE_MAXIMUM_PROCESSORS == 5 ) diff --git a/testsuites/validation/ts-terminate.c b/testsuites/validation/ts-terminate.c new file mode 100644 index 0000000000..491444a029 --- /dev/null +++ b/testsuites/validation/ts-terminate.c @@ -0,0 +1,82 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup RTEMSTestSuiteTestsuitesTerminate + */ + +/* + * Copyright (C) 2021 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. + */ + +/* + * This file is part of the RTEMS quality process and was automatically + * generated. If you find something that needs to be fixed or + * worded better please post a report or patch to an RTEMS mailing list + * or raise a bug report: + * + * https://www.rtems.org/bugs.html + * + * For information on updating and regenerating please refer to the How-To + * section in the Software Requirements Engineering chapter of the + * RTEMS Software Engineering manual. The manual is provided as a part of + * a release. For development sources please refer to the online + * documentation at: + * + * https://docs.rtems.org + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "tc-terminate.h" + +#include + +/** + * @defgroup RTEMSTestSuiteTestsuitesTerminate spec:/testsuites/terminate + * + * @ingroup RTEMSTestSuites + * + * @brief This validation test suite contains a test case for the system + * termination procedure. + * + * @{ + */ + +const char rtems_test_name[] = "Fatal"; + +#define CONFIGURE_MAXIMUM_PROCESSORS 2 + +#define CONFIGURE_INITIAL_EXTENSIONS \ + { .fatal = FatalExtension0 }, \ + { .fatal = FatalExtension1 } + +#define CONFIGURE_DISABLE_BSP_SETTINGS + +#include "ts-default.h" + +/** @} */ -- cgit v1.2.3