Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  * Copyright (c) 2018 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 "tmacros.h"
0033 
0034 #include <rtems.h>
0035 
0036 const char rtems_test_name[] = "SMPSCHEDEDF 4";
0037 
0038 #define CPU_COUNT 4
0039 
0040 #define TASK_COUNT 2
0041 
0042 #define MAIN rtems_build_name('M', 'A', 'I', 'N')
0043 
0044 #define OTHER rtems_build_name('O', 'T', 'H', 'R')
0045 
0046 typedef struct {
0047   rtems_id other_scheduler_id;
0048   rtems_id task_ids[TASK_COUNT];
0049 } test_context;
0050 
0051 static test_context test_instance;
0052 
0053 static void do_nothing_task(rtems_task_argument arg)
0054 {
0055   (void) arg;
0056 
0057   _CPU_Thread_Idle_body(0);
0058 }
0059 
0060 static void test(void)
0061 {
0062   test_context *ctx;
0063   rtems_status_code sc;
0064   size_t i;
0065 
0066   ctx = &test_instance;
0067 
0068   for (i = 0; i < TASK_COUNT; ++i) {
0069     sc = rtems_task_create(
0070       rtems_build_name('N', 'B', 'D', 'Y'),
0071       2,
0072       RTEMS_MINIMUM_STACK_SIZE,
0073       RTEMS_DEFAULT_MODES,
0074       RTEMS_DEFAULT_ATTRIBUTES,
0075       &ctx->task_ids[i]
0076     );
0077     rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0078 
0079     sc = rtems_task_start(ctx->task_ids[i], do_nothing_task, 0);
0080     rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0081   }
0082 
0083   sc = rtems_scheduler_ident(OTHER, &ctx->other_scheduler_id);
0084   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0085 
0086   for (i = 0; i < TASK_COUNT; ++i) {
0087     const Per_CPU_Control *cpu;
0088 
0089     sc = rtems_task_set_scheduler(ctx->task_ids[i], ctx->other_scheduler_id, 2);
0090     rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0091 
0092     cpu = _Per_CPU_Get_by_index(CPU_COUNT - 1 - i);
0093     rtems_test_assert(cpu->heir->Object.id == ctx->task_ids[i]);
0094   }
0095 
0096   for (i = 0; i < TASK_COUNT; ++i) {
0097     sc = rtems_task_delete(ctx->task_ids[i]);
0098     rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0099   }
0100 }
0101 
0102 static void Init(rtems_task_argument arg)
0103 {
0104   TEST_BEGIN();
0105 
0106   if (rtems_scheduler_get_processor_maximum() == CPU_COUNT) {
0107     test();
0108   } else {
0109     puts("warning: wrong processor count to run the test");
0110   }
0111 
0112   TEST_END();
0113   rtems_test_exit(0);
0114 }
0115 
0116 #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
0117 
0118 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0119 
0120 #define CONFIGURE_MAXIMUM_TASKS (1 + TASK_COUNT)
0121 
0122 #define CONFIGURE_MAXIMUM_PROCESSORS CPU_COUNT
0123 
0124 #define CONFIGURE_SCHEDULER_EDF_SMP
0125 
0126 #include <rtems/scheduler.h>
0127 
0128 RTEMS_SCHEDULER_EDF_SMP(a);
0129 
0130 RTEMS_SCHEDULER_EDF_SMP(b);
0131 
0132 #define CONFIGURE_SCHEDULER_TABLE_ENTRIES \
0133   RTEMS_SCHEDULER_TABLE_EDF_SMP(a, MAIN), \
0134   RTEMS_SCHEDULER_TABLE_EDF_SMP(b, OTHER)
0135 
0136 #define CONFIGURE_SCHEDULER_ASSIGNMENTS \
0137   RTEMS_SCHEDULER_ASSIGN(0, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_MANDATORY), \
0138   RTEMS_SCHEDULER_ASSIGN_NO_SCHEDULER, \
0139   RTEMS_SCHEDULER_ASSIGN(1, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL), \
0140   RTEMS_SCHEDULER_ASSIGN(1, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_OPTIONAL)
0141 
0142 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0143 
0144 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0145 
0146 #define CONFIGURE_INIT
0147 
0148 #include <rtems/confdefs.h>