Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  COPYRIGHT (c) 1989-2012.
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 #ifdef HAVE_CONFIG_H
0030 #include "config.h"
0031 #endif
0032 
0033 #define CONFIGURE_INIT
0034 
0035 #include "system.h"
0036 #include "tmacros.h"
0037 #include <stdio.h>
0038 #include <stdlib.h>
0039 
0040 const char rtems_test_name[] = "UNLIMITED TASK";
0041 
0042 rtems_id task_id[MAX_TASKS];
0043 
0044 rtems_task Init(
0045   rtems_task_argument ignored
0046 )
0047 {
0048   rtems_task_priority old_priority;
0049   rtems_mode          old_mode;
0050   uint32_t            task;
0051 
0052   TEST_BEGIN();
0053 
0054   /* lower the task priority to allow created tasks to execute */
0055 
0056   rtems_task_set_priority(
0057     RTEMS_SELF, RTEMS_MAXIMUM_PRIORITY - 1, &old_priority);
0058   rtems_task_mode(RTEMS_PREEMPT,  RTEMS_PREEMPT_MASK, &old_mode);
0059 
0060   /*
0061    * Invalid state if the task id is 0
0062    */
0063 
0064   for (task = 0; task < MAX_TASKS; task++)
0065     task_id[task] = 0;
0066 
0067   test1();
0068   test2();
0069   test3();
0070 
0071   TEST_END();
0072   exit( 0 );
0073 }
0074 
0075 rtems_task test_task(
0076   rtems_task_argument my_number
0077 )
0078 {
0079   rtems_event_set out;
0080   unsigned int    my_n = (unsigned int) my_number;
0081 
0082   printf( "task %u has started.\n",  my_n);
0083 
0084   rtems_event_receive(1, RTEMS_WAIT | RTEMS_EVENT_ANY, 0, &out);
0085 
0086   printf( "task %u ending.\n",  my_n);
0087 
0088   rtems_task_exit();
0089 }
0090 
0091 void destroy_all_tasks(
0092   const char *who
0093 )
0094 {
0095   uint32_t   task;
0096 
0097   /*
0098    *  If the id is not zero, signal the task to delete.
0099    */
0100 
0101   for (task = 0; task < MAX_TASKS; task++) {
0102     if (task_id[task]) {
0103       printf(
0104         " %s : signal task %08" PRIxrtems_id " to delete, ",
0105          who,
0106          task_id[task]
0107       );
0108       fflush(stdout);
0109       rtems_event_send(task_id[task], 1);
0110       task_id[task] = 0;
0111     }
0112   }
0113 }
0114 
0115 bool status_code_bad(
0116   rtems_status_code status_code
0117 )
0118 {
0119   if (status_code != RTEMS_SUCCESSFUL)
0120   {
0121     printf("failure, ");
0122 
0123     if (status_code == RTEMS_TOO_MANY)
0124     {
0125       printf("too many.\n");
0126       return TRUE;
0127     }
0128     if (status_code == RTEMS_UNSATISFIED)
0129     {
0130       printf("unsatisfied.\n");
0131       return TRUE;
0132     }
0133 
0134     printf("error code = %i\n", status_code);
0135     exit( 1 );
0136   }
0137   return FALSE;
0138 }