From 70023777ebaad47c734412f3c0e74de561e9cbb5 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Wed, 28 Sep 2022 12:22:33 +0200 Subject: score: INTERNAL_ERROR_IDLE_THREAD_CREATE_FAILED Add the INTERNAL_ERROR_IDLE_THREAD_CREATE_FAILED fatal error in case the creation of an idle thread fails. This may happen due to a failing create extension provided by the application. --- cpukit/include/rtems/score/interr.h | 1 + cpukit/sapi/src/interrtext.c | 3 +- cpukit/score/src/threadcreateidle.c | 5 +- .../validation/fatal-idle-thread-create-failed.yml | 20 +++ spec/build/testsuites/validation/grp.yml | 2 + testsuites/sptests/spinternalerror02/init.c | 2 +- .../tr-fatal-idle-thread-create-failed.c | 158 +++++++++++++++++++++ .../tr-fatal-idle-thread-create-failed.h | 84 +++++++++++ .../ts-fatal-idle-thread-create-failed.c | 90 ++++++++++++ testsuites/validation/ts-fatal-sysinit.h | 7 + 10 files changed, 369 insertions(+), 3 deletions(-) create mode 100644 spec/build/testsuites/validation/fatal-idle-thread-create-failed.yml create mode 100644 testsuites/validation/tr-fatal-idle-thread-create-failed.c create mode 100644 testsuites/validation/tr-fatal-idle-thread-create-failed.h create mode 100644 testsuites/validation/ts-fatal-idle-thread-create-failed.c diff --git a/cpukit/include/rtems/score/interr.h b/cpukit/include/rtems/score/interr.h index ae4966d6d8..d0ecf0f5c8 100644 --- a/cpukit/include/rtems/score/interr.h +++ b/cpukit/include/rtems/score/interr.h @@ -229,6 +229,7 @@ typedef enum { INTERNAL_ERROR_NO_MEMORY_FOR_PER_CPU_DATA = 40, INTERNAL_ERROR_TOO_LARGE_TLS_SIZE = 41, INTERNAL_ERROR_RTEMS_INIT_TASK_CONSTRUCT_FAILED = 42, + INTERNAL_ERROR_IDLE_THREAD_CREATE_FAILED = 43 } Internal_errors_Core_list; typedef CPU_Uint32ptr Internal_errors_t; diff --git a/cpukit/sapi/src/interrtext.c b/cpukit/sapi/src/interrtext.c index 383cc5bc0a..6ed115f430 100644 --- a/cpukit/sapi/src/interrtext.c +++ b/cpukit/sapi/src/interrtext.c @@ -83,7 +83,8 @@ static const char *const internal_error_text[] = { "INTERNAL_ERROR_ARC4RANDOM_GETENTROPY_FAIL", "INTERNAL_ERROR_NO_MEMORY_FOR_PER_CPU_DATA", "INTERNAL_ERROR_TOO_LARGE_TLS_SIZE", - "INTERNAL_ERROR_RTEMS_INIT_TASK_CONSTRUCT_FAILED" + "INTERNAL_ERROR_RTEMS_INIT_TASK_CONSTRUCT_FAILED", + "INTERNAL_ERROR_IDLE_THREAD_CREATE_FAILED" }; const char *rtems_internal_error_text( rtems_fatal_code error ) diff --git a/cpukit/score/src/threadcreateidle.c b/cpukit/score/src/threadcreateidle.c index b5e0cfdc9b..e7eb9899c0 100644 --- a/cpukit/score/src/threadcreateidle.c +++ b/cpukit/score/src/threadcreateidle.c @@ -66,6 +66,7 @@ static void _Thread_Create_idle_for_CPU( Per_CPU_Control *cpu ) config.name = _Objects_Build_name( 'I', 'D', 'L', 'E' ); config.is_fp = CPU_IDLE_TASK_IS_FP; config.is_preemptible = true; + config.stack_free = _Objects_Free_nothing; config.stack_size = _Thread_Idle_stack_size + CPU_IDLE_TASK_IS_FP * CONTEXT_FP_SIZE; @@ -87,7 +88,9 @@ static void _Thread_Create_idle_for_CPU( Per_CPU_Control *cpu ) _Assert( idle != NULL ); status = _Thread_Initialize( &_Thread_Information, idle, &config ); - _Assert_Unused_variable_equals( status, STATUS_SUCCESSFUL ); + if ( status != STATUS_SUCCESSFUL ) { + _Internal_error( INTERNAL_ERROR_IDLE_THREAD_CREATE_FAILED ); + } /* * WARNING!!! This is necessary to "kick" start the system and diff --git a/spec/build/testsuites/validation/fatal-idle-thread-create-failed.yml b/spec/build/testsuites/validation/fatal-idle-thread-create-failed.yml new file mode 100644 index 0000000000..49af89452a --- /dev/null +++ b/spec/build/testsuites/validation/fatal-idle-thread-create-failed.yml @@ -0,0 +1,20 @@ +SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause +build-type: test-program +cflags: [] +copyrights: +- Copyright (C) 2022 embedded brains GmbH (http://www.embedded-brains.de) +cppflags: [] +cxxflags: [] +enabled-by: true +features: c cprogram +includes: [] +ldflags: [] +links: [] +source: +- testsuites/validation/tr-fatal-idle-thread-create-failed.c +- testsuites/validation/ts-fatal-idle-thread-create-failed.c +stlib: [] +target: testsuites/validation/ts-fatal-idle-thread-create-failed.exe +type: build +use-after: [] +use-before: [] diff --git a/spec/build/testsuites/validation/grp.yml b/spec/build/testsuites/validation/grp.yml index ab9813ec78..73d4204721 100644 --- a/spec/build/testsuites/validation/grp.yml +++ b/spec/build/testsuites/validation/grp.yml @@ -27,6 +27,8 @@ links: uid: fatal-bsp-sparc-leon3-clock-initialization - role: build-dependency uid: fatal-bsp-sparc-leon3-shutdown +- role: build-dependency + uid: fatal-idle-thread-create-failed - role: build-dependency uid: fatal-init-task-construct-failed - role: build-dependency diff --git a/testsuites/sptests/spinternalerror02/init.c b/testsuites/sptests/spinternalerror02/init.c index 08aeabd3a7..f94759a99b 100644 --- a/testsuites/sptests/spinternalerror02/init.c +++ b/testsuites/sptests/spinternalerror02/init.c @@ -49,7 +49,7 @@ static void test_internal_error_text(void) } while ( text != text_last ); rtems_test_assert( - error - 3 == INTERNAL_ERROR_RTEMS_INIT_TASK_CONSTRUCT_FAILED + error - 3 == INTERNAL_ERROR_IDLE_THREAD_CREATE_FAILED ); } diff --git a/testsuites/validation/tr-fatal-idle-thread-create-failed.c b/testsuites/validation/tr-fatal-idle-thread-create-failed.c new file mode 100644 index 0000000000..8c66f01c82 --- /dev/null +++ b/testsuites/validation/tr-fatal-idle-thread-create-failed.c @@ -0,0 +1,158 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup RTEMSTestCaseScoreThreadValFatalIdleThreadCreateFailed + */ + +/* + * Copyright (C) 2022 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 "tr-fatal-idle-thread-create-failed.h" + +#include + +/** + * @defgroup RTEMSTestCaseScoreThreadValFatalIdleThreadCreateFailed \ + * spec:/score/thread/val/fatal-idle-thread-create-failed + * + * @ingroup RTEMSTestSuiteTestsuitesFatalIdleThreadCreateFailed + * + * @brief Tests a fatal error caused by a failing task create extension. + * + * This test case performs the following actions: + * + * - The test action is carried out by configuring a task create extension + * which always fails. + * + * - Check that the expected fatal source is present. + * + * - Check that the expected fatal code is present. + * + * @{ + */ + +/** + * @brief Test context for + * spec:/score/thread/val/fatal-idle-thread-create-failed test case. + */ +typedef struct { + /** + * @brief This member contains a copy of the corresponding + * ScoreThreadValFatalIdleThreadCreateFailed_Run() parameter. + */ + rtems_fatal_source source; + + /** + * @brief This member contains a copy of the corresponding + * ScoreThreadValFatalIdleThreadCreateFailed_Run() parameter. + */ + rtems_fatal_code code; +} ScoreThreadValFatalIdleThreadCreateFailed_Context; + +static ScoreThreadValFatalIdleThreadCreateFailed_Context + ScoreThreadValFatalIdleThreadCreateFailed_Instance; + +static T_fixture ScoreThreadValFatalIdleThreadCreateFailed_Fixture = { + .setup = NULL, + .stop = NULL, + .teardown = NULL, + .scope = NULL, + .initial_context = &ScoreThreadValFatalIdleThreadCreateFailed_Instance +}; + +/** + * @brief The test action is carried out by configuring a task create extension + * which always fails. + */ +static void ScoreThreadValFatalIdleThreadCreateFailed_Action_0( + ScoreThreadValFatalIdleThreadCreateFailed_Context *ctx +) +{ + /* Nothing to do */ + + /* + * Check that the expected fatal source is present. + */ + T_step_eq_int( 0, ctx->source, INTERNAL_ERROR_CORE ); + + /* + * Check that the expected fatal code is present. + */ + T_step_eq_ulong( + 1, + ctx->code, + INTERNAL_ERROR_IDLE_THREAD_CREATE_FAILED + ); +} + +void ScoreThreadValFatalIdleThreadCreateFailed_Run( + rtems_fatal_source source, + rtems_fatal_code code +) +{ + ScoreThreadValFatalIdleThreadCreateFailed_Context *ctx; + + ctx = &ScoreThreadValFatalIdleThreadCreateFailed_Instance; + ctx->source = source; + ctx->code = code; + + ctx = T_case_begin( + "ScoreThreadValFatalIdleThreadCreateFailed", + &ScoreThreadValFatalIdleThreadCreateFailed_Fixture + ); + + T_plan( 2 ); + + ScoreThreadValFatalIdleThreadCreateFailed_Action_0( ctx ); + + T_case_end(); +} + +/** @} */ diff --git a/testsuites/validation/tr-fatal-idle-thread-create-failed.h b/testsuites/validation/tr-fatal-idle-thread-create-failed.h new file mode 100644 index 0000000000..15d4c9a086 --- /dev/null +++ b/testsuites/validation/tr-fatal-idle-thread-create-failed.h @@ -0,0 +1,84 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup RTEMSTestCaseScoreThreadValFatalIdleThreadCreateFailed + */ + +/* + * Copyright (C) 2022 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 + */ + +#ifndef _TR_FATAL_IDLE_THREAD_CREATE_FAILED_H +#define _TR_FATAL_IDLE_THREAD_CREATE_FAILED_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @addtogroup RTEMSTestCaseScoreThreadValFatalIdleThreadCreateFailed + * + * @{ + */ + +/** + * @brief Runs the parameterized test case. + * + * @param source is the fatal source. + * + * @param code is the fatal code. + */ +void ScoreThreadValFatalIdleThreadCreateFailed_Run( + rtems_fatal_source source, + rtems_fatal_code code +); + +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* _TR_FATAL_IDLE_THREAD_CREATE_FAILED_H */ diff --git a/testsuites/validation/ts-fatal-idle-thread-create-failed.c b/testsuites/validation/ts-fatal-idle-thread-create-failed.c new file mode 100644 index 0000000000..55173f21d1 --- /dev/null +++ b/testsuites/validation/ts-fatal-idle-thread-create-failed.c @@ -0,0 +1,90 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup RTEMSTestSuiteTestsuitesFatalIdleThreadCreateFailed + */ + +/* + * Copyright (C) 2022 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 "tr-fatal-idle-thread-create-failed.h" + +#include + +/** + * @defgroup RTEMSTestSuiteTestsuitesFatalIdleThreadCreateFailed \ + * spec:/testsuites/fatal-idle-thread-create-failed + * + * @ingroup RTEMSTestSuites + * + * @brief This validation test suite contains a test case which is triggered by + * a fatal error during system initialization. + * + * @{ + */ + +const char rtems_test_name[] = "FatalIdleThreadCreateFailed"; + +static bool CreateTask( rtems_tcb *executing, rtems_tcb *created ) +{ + (void) executing; + (void) created; + return false; +} + +#define FATAL_SYSINIT_RUN ScoreThreadValFatalIdleThreadCreateFailed_Run + +#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER + +#define CONFIGURE_IDLE_TASK_INITIALIZES_APPLICATION + +#define FATAL_SYSINIT_INITIAL_EXTENSION { .thread_create = CreateTask } + +#include "ts-fatal-sysinit.h" + +/** @} */ diff --git a/testsuites/validation/ts-fatal-sysinit.h b/testsuites/validation/ts-fatal-sysinit.h index 5744bc6fea..09d86d02ea 100644 --- a/testsuites/validation/ts-fatal-sysinit.h +++ b/testsuites/validation/ts-fatal-sysinit.h @@ -122,7 +122,14 @@ RTEMS_SYSINIT_ITEM( #define CONFIGURE_APPLICATION_DISABLE_FILESYSTEM +#ifdef FATAL_SYSINIT_INITIAL_EXTENSION +#define OPTIONAL_FATAL_SYSINIT_INITIAL_EXTENSION FATAL_SYSINIT_INITIAL_EXTENSION, +#else +#define OPTIONAL_FATAL_SYSINIT_INITIAL_EXTENSION +#endif + #define CONFIGURE_INITIAL_EXTENSIONS \ + OPTIONAL_FATAL_SYSINIT_INITIAL_EXTENSION \ { .fatal = FatalInitialExtension }, \ { .fatal = TestSuiteFatalExtension } -- cgit v1.2.3