Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  * Copyright (c) 2010 embedded brains GmbH & Co. KG
0005  *
0006  * Redistribution and use in source and binary forms, with or without
0007  * modification, are permitted provided that the following conditions
0008  * are met:
0009  * 1. Redistributions of source code must retain the above copyright
0010  *    notice, this list of conditions and the following disclaimer.
0011  * 2. Redistributions in binary form must reproduce the above copyright
0012  *    notice, this list of conditions and the following disclaimer in the
0013  *    documentation and/or other materials provided with the distribution.
0014  *
0015  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0016  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0017  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0018  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0019  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0020  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0021  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0022  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0023  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0024  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0025  * POSSIBILITY OF SUCH DAMAGE.
0026  */
0027 
0028 #ifdef HAVE_CONFIG_H
0029 #include "config.h"
0030 #endif
0031 
0032 #include <stdio.h>
0033 #include <inttypes.h>
0034 
0035 #include <rtems.h>
0036 
0037 #include "tmacros.h"
0038 
0039 const char rtems_test_name[] = "PSX 15";
0040 
0041 /* forward declarations to avoid warnings */
0042 rtems_task Init(rtems_task_argument argument);
0043 
0044 /*
0045  * This test case shows that post switch extension handlers must cope with
0046  * already deleted resources (e.g. _POSIX_signals_Post_switch_extension()).
0047  * The thread delete extensions run with thread dispatching enabled.  Only the
0048  * allocation mutex is locked.
0049  */
0050 
0051 static rtems_id task_0 = RTEMS_ID_NONE;
0052 
0053 static rtems_id task_1 = RTEMS_ID_NONE;
0054 
0055 static void thread_delete_hook(
0056   Thread_Control *executing,
0057   Thread_Control *deleted
0058 )
0059 {
0060   rtems_status_code sc = RTEMS_SUCCESSFUL;
0061 
0062   if (deleted->Object.id == task_0) {
0063     rtems_task_priority old = 0;
0064 
0065     sc = rtems_task_set_priority(task_1, 2, &old);
0066     rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0067   }
0068 }
0069 
0070 static void suicide_task(rtems_task_argument arg)
0071 {
0072   int me = (int) arg;
0073 
0074   printf("suicide task %d\n", me);
0075 
0076   rtems_task_exit();
0077   rtems_test_assert(false);
0078 }
0079 
0080 void Init(rtems_task_argument arg)
0081 {
0082   rtems_status_code sc = RTEMS_SUCCESSFUL;
0083 
0084   TEST_BEGIN();
0085 
0086   sc = rtems_task_create(
0087     rtems_build_name('T', 'S', 'K', '1'),
0088     5,
0089     RTEMS_MINIMUM_STACK_SIZE,
0090     RTEMS_DEFAULT_MODES,
0091     RTEMS_DEFAULT_ATTRIBUTES,
0092     &task_1
0093   );
0094   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0095 
0096   sc = rtems_task_start(task_1, suicide_task, 1);
0097   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0098 
0099   sc = rtems_task_create(
0100     rtems_build_name('T', 'S', 'K', '0'),
0101     3,
0102     RTEMS_MINIMUM_STACK_SIZE,
0103     RTEMS_DEFAULT_MODES,
0104     RTEMS_DEFAULT_ATTRIBUTES,
0105     &task_0
0106   );
0107   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0108 
0109   sc = rtems_task_start(task_0, suicide_task, 0);
0110   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0111 
0112   TEST_END();
0113 
0114   rtems_test_exit(0);
0115   rtems_test_assert(false);
0116 }
0117 
0118 #define CONFIGURE_INIT
0119 
0120 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0121 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0122 
0123 #define CONFIGURE_MAXIMUM_TASKS 3
0124 #define CONFIGURE_MAXIMUM_USER_EXTENSIONS 1
0125 
0126 #define CONFIGURE_INITIAL_EXTENSIONS \
0127   { .thread_delete = thread_delete_hook }, \
0128   RTEMS_TEST_INITIAL_EXTENSION
0129 
0130 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0131 
0132 #define CONFIGURE_INIT_TASK_INITIAL_MODES RTEMS_PREEMPT
0133 #define CONFIGURE_INIT_TASK_PRIORITY 4
0134 
0135 #include <rtems/confdefs.h>