Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*  Init
0004  *
0005  *  This routine is the initialization task for this test program.
0006  *  It is called from init_exec and has the responsibility for creating
0007  *  and starting the tasks that make up the test.  If the time of day
0008  *  clock is required for the test, it should also be set to a known
0009  *  value by this function.
0010  *
0011  *  Input parameters:  NONE
0012  *
0013  *  Output parameters:  NONE
0014  *
0015  *  COPYRIGHT (c) 1989-1997.
0016  *  On-Line Applications Research Corporation (OAR).
0017  *
0018  * Redistribution and use in source and binary forms, with or without
0019  * modification, are permitted provided that the following conditions
0020  * are met:
0021  * 1. Redistributions of source code must retain the above copyright
0022  *    notice, this list of conditions and the following disclaimer.
0023  * 2. Redistributions in binary form must reproduce the above copyright
0024  *    notice, this list of conditions and the following disclaimer in the
0025  *    documentation and/or other materials provided with the distribution.
0026  *
0027  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0028  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0029  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0030  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0031  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0032  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0033  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0034  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0035  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0036  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0037  * POSSIBILITY OF SUCH DAMAGE.
0038  */
0039 
0040 #ifdef HAVE_CONFIG_H
0041 #include "config.h"
0042 #endif
0043 
0044 #include <inttypes.h>
0045 #include <stdio.h>
0046 #include <stdlib.h>
0047 
0048 #include "system.h"
0049 #include "tmacros.h"
0050 
0051 void test2()
0052 {
0053   rtems_status_code   result;
0054   uint32_t      remove_task;
0055   uint32_t      task;
0056   uint32_t      block;
0057   uint32_t      task_count = 0;
0058   rtems_id      removed_ids[TASK_ALLOCATION_SIZE * 2];
0059 
0060   char               c1 = 'a';
0061   char               c2 = 'a';
0062   char               c3 = '0';
0063   char               c4 = '0';
0064 
0065   printf( "\n TEST2 : re-allocate of index numbers, and a block free'ed and one inactive\n" );
0066 
0067   /*
0068    *  Allocate enought tasks so the Inactive list is empty. Remember
0069    *  to count the Init task, ie ... - 1.
0070    */
0071 
0072   while (task_count < ((TASK_ALLOCATION_SIZE * 5) - TASK_INDEX_OFFSET))
0073   {
0074     rtems_name name;
0075 
0076     printf(" TEST2 : creating task '%c%c%c%c', ", c1, c2, c3, c4);
0077 
0078     name = rtems_build_name(c1, c2, c3, c4);
0079 
0080     result = rtems_task_create(name,
0081                                10,
0082                                RTEMS_MINIMUM_STACK_SIZE,
0083                                RTEMS_DEFAULT_ATTRIBUTES,
0084                                RTEMS_LOCAL,
0085                                &task_id[task_count]);
0086 
0087     if (status_code_bad(result))
0088       break;
0089 
0090     printf("number = %3" PRIi32 ", id = %08" PRIxrtems_id ", starting, ", task_count, task_id[task_count]);
0091     fflush(stdout);
0092 
0093     result = rtems_task_start(task_id[task_count],
0094                               test_task,
0095                               (rtems_task_argument) task_count);
0096 
0097     if (status_code_bad(result))
0098       break;
0099 
0100     /*
0101      *  Update the name.
0102      */
0103 
0104     NEXT_TASK_NAME(c1, c2, c3, c4);
0105 
0106     task_count++;
0107   }
0108 
0109   /*
0110    *  Take out the second and fourth allocation size block of tasks
0111    */
0112 
0113   if (task_count != ((TASK_ALLOCATION_SIZE * 5) - TASK_INDEX_OFFSET)) {
0114     printf( " FAIL2 : not enough tasks created -\n"
0115             "         task created = %" PRIi32 ", required number = %i\n",
0116             task_count, (TASK_ALLOCATION_SIZE * 5) - TASK_INDEX_OFFSET);
0117     destroy_all_tasks("TEST2");
0118     exit( 1 );
0119   }
0120 
0121   task = 0;
0122 
0123   for (block = 1; block < 4; block += 2)
0124   {
0125     for (remove_task = (block * TASK_ALLOCATION_SIZE) - TASK_INDEX_OFFSET;
0126          remove_task < (((block + 1) * TASK_ALLOCATION_SIZE) - TASK_INDEX_OFFSET);
0127          remove_task++)
0128     {
0129       if (!task_id[remove_task])
0130       {
0131         printf( " FAIL2 : remove task has a 0 id -\n"
0132                 "         task number = %" PRIi32 "\n",
0133                 remove_task);
0134         destroy_all_tasks("TEST2");
0135         exit( 1 );
0136       }
0137 
0138       /*
0139        * Save the id's to match them against the reallocated ids
0140        */
0141 
0142       removed_ids[task++] = task_id[remove_task];
0143 
0144       printf(" TEST2 : block %" PRIi32 " remove, signal task %08"
0145                PRIxrtems_id ", ", block, task_id[remove_task]);
0146       rtems_event_send(task_id[remove_task], 1);
0147       task_id[remove_task] = 0;
0148     }
0149   }
0150 
0151   for (task = 0; task < (TASK_ALLOCATION_SIZE * 2); task++)
0152   {
0153     rtems_name       name;
0154     uint32_t   id_slot;
0155 
0156     /*
0157      *  Find a free slot in the task id table.
0158      */
0159 
0160     for (id_slot = 0; id_slot < MAX_TASKS; id_slot++)
0161       if (!task_id[id_slot])
0162         break;
0163 
0164     if (id_slot == MAX_TASKS)
0165     {
0166       printf( " FAIL2 : no free task id slot.\n");
0167       destroy_all_tasks("TEST2");
0168       exit( 1 );
0169     }
0170 
0171     printf(" TEST2 : creating task '%c%c%c%c', ", c1, c2, c3, c4);
0172 
0173     name = rtems_build_name(c1, c2, c3, c4);
0174 
0175     result = rtems_task_create(name,
0176                                10,
0177                                RTEMS_MINIMUM_STACK_SIZE,
0178                                RTEMS_DEFAULT_ATTRIBUTES,
0179                                RTEMS_LOCAL,
0180                                &task_id[id_slot]);
0181 
0182     if (status_code_bad(result))
0183     {
0184       printf( " FAIL2 : re-creating a task -\n"
0185               "         task number = %" PRIi32 "\n",
0186               id_slot);
0187       destroy_all_tasks("TEST2");
0188       exit( 1 );
0189     }
0190 
0191     printf("number = %3" PRIi32 ", id = %08" PRIxrtems_id ", starting, ",
0192            task_count, task_id[id_slot]);
0193 
0194     result = rtems_task_start(task_id[id_slot],
0195                               test_task,
0196                               (rtems_task_argument) task_count);
0197 
0198     if (status_code_bad(result))
0199     {
0200       printf( " FAIL : re-starting a task -\n"
0201               "        task number = %" PRIi32 "\n",
0202               id_slot);
0203       destroy_all_tasks("TEST2");
0204       exit( 1 );
0205     }
0206 
0207     /*
0208      *  Update the name.
0209      */
0210 
0211     NEXT_TASK_NAME(c1, c2, c3, c4);
0212 
0213     /*
0214      *  Search the removed ids to see if it existed, clear the removed id
0215      *  when found
0216      */
0217 
0218     for (remove_task = 0; remove_task < (TASK_ALLOCATION_SIZE * 2); remove_task++)
0219       if (removed_ids[remove_task] == task_id[id_slot])
0220       {
0221         removed_ids[remove_task] = 0;
0222         break;
0223       }
0224 
0225     /*
0226      *  If not located in the removed id table, check and make sure it is not
0227      *  already allocated
0228      */
0229 
0230     if (remove_task == (TASK_ALLOCATION_SIZE * 2))
0231     {
0232       uint32_t   allocated_id;
0233 
0234       for (allocated_id = 0; allocated_id < MAX_TASKS; allocated_id++)
0235         if ((task_id[id_slot] == task_id[allocated_id]) && (id_slot != allocated_id))
0236         {
0237           printf(
0238             " FAIL2 : the new id is the same as an id already allocated -\n"
0239             "         task id = %08" PRIxrtems_id "\n",
0240             task_id[id_slot]);
0241           exit( 1 );
0242         }
0243 
0244       printf( " FAIL2 : could not find the task id in the removed table -\n"
0245               "         task id = %08" PRIxrtems_id "\n",
0246               task_id[id_slot]);
0247       exit( 1 );
0248     }
0249 
0250     task_count++;
0251   }
0252 
0253   destroy_all_tasks("TEST2");
0254 
0255   printf( " TEST2 : completed\n" );
0256 }