Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:47

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  COPYRIGHT (c) 1989-2011.
0005  *  On-Line Applications Research Corporation (OAR).
0006  *
0007  * Redistribution and use in source and binary forms, with or without
0008  * modification, are permitted provided that the following conditions
0009  * are met:
0010  * 1. Redistributions of source code must retain the above copyright
0011  *    notice, this list of conditions and the following disclaimer.
0012  * 2. Redistributions in binary form must reproduce the above copyright
0013  *    notice, this list of conditions and the following disclaimer in the
0014  *    documentation and/or other materials provided with the distribution.
0015  *
0016  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0017  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0018  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0019  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0020  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0021  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0022  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0023  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0024  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0025  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0026  * POSSIBILITY OF SUCH DAMAGE.
0027  */
0028 
0029 #include <rtems/bspIo.h>
0030 
0031 #include <tmacros.h>
0032 
0033 rtems_task Init( rtems_task_argument argument );
0034 
0035 const char rtems_test_name[] = "SPFATAL " FATAL_ERROR_TEST_NAME;
0036 
0037 static void print_test_begin_message(void)
0038 {
0039   static bool done = false;
0040 
0041   if (!done) {
0042     done = true;
0043     TEST_BEGIN();
0044   }
0045 }
0046 
0047 rtems_task Init(
0048   rtems_task_argument argument
0049 )
0050 {
0051   print_test_begin_message();
0052   force_error();
0053   printk( "Fatal error (%s) NOT hit\n", FATAL_ERROR_DESCRIPTION );
0054   rtems_test_exit(0);
0055 }
0056 
0057 #ifdef FATAL_ERROR_EXPECTED_ERROR
0058 static void Put_Error( uint32_t source, uint32_t error )
0059 {
0060   if ( source == INTERNAL_ERROR_CORE ) {
0061     printk( rtems_internal_error_text( error ) );
0062   }
0063   else if (source == INTERNAL_ERROR_RTEMS_API ){
0064     if (error >  RTEMS_NOT_IMPLEMENTED )
0065       printk("Unknown Internal RTEMS Error (0x%08" PRIx32 ")", error);
0066     else
0067       printk( "%s", rtems_status_text( error ) );
0068   }
0069 }
0070 #endif
0071 
0072 static void Put_Source( rtems_fatal_source source )
0073 {
0074   printk( "%s", rtems_fatal_source_text( source ) );
0075 }
0076 
0077 static bool is_expected_error( rtems_fatal_code error )
0078 {
0079 #ifdef FATAL_ERROR_EXPECTED_ERROR
0080   return error == FATAL_ERROR_EXPECTED_ERROR;
0081 #else /* FATAL_ERROR_EXPECTED_ERROR */
0082   return FATAL_ERROR_EXPECTED_ERROR_CHECK( error );
0083 #endif /* FATAL_ERROR_EXPECTED_ERROR */
0084 }
0085 
0086 static void Fatal_extension(
0087   rtems_fatal_source source,
0088   bool               always_set_to_false,
0089   rtems_fatal_code   error
0090 )
0091 {
0092   print_test_begin_message();
0093   printk( "Fatal error (%s) hit\n", FATAL_ERROR_DESCRIPTION );
0094 
0095   if ( source != FATAL_ERROR_EXPECTED_SOURCE ){
0096     printk( "ERROR==> Fatal Extension source Expected (");
0097     Put_Source( FATAL_ERROR_EXPECTED_SOURCE );
0098     printk( ") received (");
0099     Put_Source( source );
0100     printk( ")\n" );
0101   }
0102 
0103   if ( always_set_to_false )
0104     printk(
0105       "ERROR==> Fatal Extension is internal set to true expected false\n"
0106     );
0107 
0108 #ifdef FATAL_ERROR_EXPECTED_ERROR
0109   if ( error !=  FATAL_ERROR_EXPECTED_ERROR ) {
0110     printk( "ERROR==> Fatal Error Expected (");
0111     Put_Error( source, FATAL_ERROR_EXPECTED_ERROR );
0112     printk( ") received (");
0113     Put_Error( source, error );
0114     printk( ")\n" );
0115   }
0116 #endif /* FATAL_ERROR_EXPECTED_ERROR */
0117 
0118   if (
0119     source == FATAL_ERROR_EXPECTED_SOURCE
0120       && !always_set_to_false
0121       && is_expected_error( error )
0122   ) {
0123     TEST_END();
0124   }
0125 }
0126 
0127 #define CONFIGURE_INIT
0128 
0129 #define CONFIGURE_INITIAL_EXTENSIONS \
0130   { \
0131     NULL,                    /* create  */ \
0132     NULL,                    /* start   */ \
0133     NULL,                    /* restart */ \
0134     NULL,                    /* delete  */ \
0135     NULL,                    /* switch  */ \
0136     NULL,                    /* begin   */ \
0137     NULL,                    /* exitted */ \
0138     Fatal_extension          /* fatal   */ \
0139   }, \
0140   RTEMS_TEST_INITIAL_EXTENSION
0141 
0142 /* extra parameters may be in testcase.h */
0143 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0144 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0145 
0146 /* always need an Init task, some cases need more tasks */
0147 #ifndef SPFATAL_TEST_CASE_EXTRA_TASKS
0148 #define SPFATAL_TEST_CASE_EXTRA_TASKS 0
0149 #endif
0150 #define CONFIGURE_MAXIMUM_TASKS \
0151   (SPFATAL_TEST_CASE_EXTRA_TASKS + 1)
0152 
0153 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0154 
0155 #include <rtems/confdefs.h>