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 #include "system.h"
0048 #include "tmacros.h"
0049 
0050 void test3()
0051 {
0052   rtems_status_code   result;
0053   uint32_t      remove_task;
0054   uint32_t      block;
0055   uint32_t      task_count = 0;
0056 
0057   char               c1 = 'a';
0058   char               c2 = 'a';
0059   char               c3 = '0';
0060   char               c4 = '0';
0061 
0062   printf( "\n TEST3 : free more than 3 x allocation size, but not the same block,\n"
0063             "         then free a block\n");
0064 
0065   /*
0066    *  Check the value of the allocation unit
0067    */
0068 
0069   if (TASK_ALLOCATION_SIZE < 4)
0070   {
0071     printf( " FAIL3 : task allocation size must be greater than 4.\n");
0072     exit( 1 );
0073   }
0074 
0075    /*
0076    *  Allocate as many tasks as possible.
0077    */
0078 
0079   while (task_count < MAX_TASKS)
0080   {
0081     rtems_name name;
0082 
0083     printf(" TEST3 : creating task '%c%c%c%c', ", c1, c2, c3, c4);
0084 
0085     name = rtems_build_name(c1, c2, c3, c4);
0086 
0087     result = rtems_task_create(name,
0088                                10,
0089                                RTEMS_MINIMUM_STACK_SIZE,
0090                                RTEMS_DEFAULT_ATTRIBUTES,
0091                                RTEMS_LOCAL,
0092                                &task_id[task_count]);
0093 
0094     if (status_code_bad(result))
0095       break;
0096 
0097     printf("number = %3" PRIi32 ", id = %08" PRIxrtems_id ", starting, ", task_count, task_id[task_count]);
0098     fflush(stdout);
0099 
0100     result = rtems_task_start(task_id[task_count],
0101                               test_task,
0102                               (rtems_task_argument) task_count);
0103 
0104     if (status_code_bad(result))
0105       break;
0106 
0107     /*
0108      *  Update the name.
0109      */
0110 
0111     NEXT_TASK_NAME(c1, c2, c3, c4);
0112 
0113     task_count++;
0114   }
0115 
0116   /*
0117    *  Take out 3 tasks from each block of allocated tasks. Do this for
0118    *  allocation size number of blocks.
0119    */
0120 
0121   if (task_count < (TASK_ALLOCATION_SIZE * 11))
0122   {
0123     printf( " FAIL3 : not enough tasks created -\n"
0124             "         task created = %" PRIi32 ", required number = %i\n",
0125             task_count, (TASK_ALLOCATION_SIZE * 11));
0126     exit( 1 );
0127   }
0128 
0129   for (block = 0; block < TASK_ALLOCATION_SIZE; block++)
0130   {
0131     for (remove_task = ((block * TASK_ALLOCATION_SIZE) - TASK_INDEX_OFFSET);
0132          remove_task < (((block * TASK_ALLOCATION_SIZE) + 3) - TASK_INDEX_OFFSET);
0133          remove_task++)
0134     {
0135       if (!task_id[remove_task])
0136       {
0137         printf( " FAIL3 : remove task has a 0 id -\n"
0138                 "         task number = %" PRIi32 "\n",
0139                 remove_task);
0140         exit( 1 );
0141       }
0142 
0143       printf(" TEST3 : remove, signal task %08" PRIxrtems_id ", ", task_id[remove_task]);
0144       rtems_event_send(task_id[remove_task], 1);
0145       task_id[remove_task] = 0;
0146     }
0147   }
0148 
0149   /*
0150    *  Remove a complete block, not the first, forces a scan of the blocks in the
0151    *  allocator's free routine
0152    */
0153 
0154   for (remove_task = (TASK_ALLOCATION_SIZE - TASK_INDEX_OFFSET);
0155        remove_task < ((TASK_ALLOCATION_SIZE * 2) - - TASK_INDEX_OFFSET);
0156        remove_task++)
0157   {
0158     if (task_id[remove_task])
0159     {
0160       printf(" TEST3 : remove, signal task %08" PRIxrtems_id ", ", task_id[remove_task]);
0161       rtems_event_send(task_id[remove_task], 1);
0162       task_id[remove_task] = 0;
0163     }
0164   }
0165 
0166   destroy_all_tasks("TEST3");
0167 
0168   printf( " TEST3 : completed\n" );
0169 }