Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup RTEMSTestFrameworkImpl
0007  *
0008  * @brief This source file contains the implementation of
0009  *   T_check_task_context().
0010  */
0011 
0012 /*
0013  * Copyright (C) 2019 embedded brains GmbH & Co. KG
0014  *
0015  * Redistribution and use in source and binary forms, with or without
0016  * modification, are permitted provided that the following conditions
0017  * are met:
0018  * 1. Redistributions of source code must retain the above copyright
0019  *    notice, this list of conditions and the following disclaimer.
0020  * 2. Redistributions in binary form must reproduce the above copyright
0021  *    notice, this list of conditions and the following disclaimer in the
0022  *    documentation and/or other materials provided with the distribution.
0023  *
0024  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0025  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0026  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0027  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0028  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0029  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0030  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0031  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0032  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0033  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0034  * POSSIBILITY OF SUCH DAMAGE.
0035  */
0036 
0037 #undef __STRICT_ANSI__
0038 
0039 #include <rtems/test.h>
0040 
0041 #include <rtems.h>
0042 #include <rtems/score/isrlevel.h>
0043 #include <rtems/score/percpu.h>
0044 #include <rtems/score/threaddispatch.h>
0045 
0046 #include <inttypes.h>
0047 
0048 #ifdef RTEMS_SMP
0049 static rtems_id T_runner_scheduler;
0050 #endif
0051 
0052 static rtems_task_priority T_runner_priority;
0053 
0054 static void
0055 T_initialize_runner_properties(void)
0056 {
0057     rtems_status_code sc;
0058 
0059 #ifdef RTEMS_SMP
0060     sc = rtems_task_get_scheduler(RTEMS_SELF, &T_runner_scheduler);
0061     T_quiet_rsc_success(sc);
0062 #endif
0063 
0064     sc = rtems_task_set_priority(RTEMS_SELF, RTEMS_CURRENT_PRIORITY,
0065         &T_runner_priority);
0066     T_quiet_rsc_success(sc);
0067 }
0068 
0069 static void
0070 T_do_check_task_context(void)
0071 {
0072     rtems_task_priority prio;
0073     rtems_status_code sc;
0074     uint32_t v;
0075     rtems_event_set events;
0076 #ifdef RTEMS_SMP
0077     rtems_id id;
0078 #endif
0079 
0080     v = _Per_CPU_Get_snapshot()->thread_dispatch_disable_level;
0081     T_check(&T_special, v == 0,
0082         "Wrong thread dispatch disabled level (%" PRIu32 ")", v);
0083 
0084     v = _Per_CPU_Get_snapshot()->isr_nest_level;
0085     T_check(&T_special, v == 0,
0086         "Wrong ISR nest level (%" PRIu32 ")", v);
0087 
0088     v = _ISR_Get_level();
0089     T_check(&T_special, v == 0,
0090         "Wrong ISR level (%" PRIu32 ")", v);
0091 
0092 #ifdef RTEMS_SMP
0093     id = 0;
0094     sc = rtems_task_get_scheduler(RTEMS_SELF, &id);
0095     T_quiet_rsc_success(sc);
0096     T_check(&T_special, id == T_runner_scheduler,
0097         "Wrong runner scheduler, expected ID %08" PRIx32 ", actual ID %08"
0098         PRIx32, T_runner_scheduler, id);
0099 #endif
0100 
0101     prio = 0;
0102     sc = rtems_task_set_priority(RTEMS_SELF, RTEMS_CURRENT_PRIORITY,
0103         &prio);
0104     T_quiet_rsc_success(sc);
0105     T_check(&T_special, prio == T_runner_priority,
0106         "Wrong runner priority, expected %" PRIu32 ", actual %"
0107         PRIu32, T_runner_priority, prio);
0108 
0109     sc = rtems_event_receive(RTEMS_ALL_EVENTS,
0110         RTEMS_NO_WAIT | RTEMS_EVENT_ANY, 0, &events);
0111     T_quiet_rsc( sc, RTEMS_UNSATISFIED );
0112 
0113     sc = rtems_event_system_receive(RTEMS_ALL_EVENTS,
0114         RTEMS_NO_WAIT | RTEMS_EVENT_ANY, 0, &events);
0115     T_quiet_rsc( sc, RTEMS_UNSATISFIED );
0116 }
0117 
0118 void
0119 T_check_task_context(T_event event, const char *name)
0120 {
0121     (void)name;
0122 
0123     switch (event) {
0124     case T_EVENT_RUN_INITIALIZE_LATE:
0125         T_initialize_runner_properties();
0126         /* Fall through */
0127     case T_EVENT_CASE_END:
0128         T_do_check_task_context();
0129         break;
0130     default:
0131         break;
0132     };
0133 }