RTEMS
tc-task-ident.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 
9 /*
10  * Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  * notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  * notice, this list of conditions and the following disclaimer in the
19  * documentation and/or other materials provided with the distribution.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 /*
35  * Do not manually edit this file. It is part of the RTEMS quality process
36  * and was automatically generated.
37  *
38  * If you find something that needs to be fixed or worded better please
39  * post a report to an RTEMS mailing list or raise a bug report:
40  *
41  * https://docs.rtems.org/branches/master/user/support/bugs.html
42  *
43  * For information on updating and regenerating please refer to:
44  *
45  * https://docs.rtems.org/branches/master/eng/req/howto.html
46  */
47 
48 #ifdef HAVE_CONFIG_H
49 #include "config.h"
50 #endif
51 
52 #include "tr-object-ident.h"
53 
54 #include <rtems/test.h>
55 
64 typedef enum {
65  RtemsTaskReqIdent_Pre_Pre_Self,
66  RtemsTaskReqIdent_Pre_Pre_Generic,
67  RtemsTaskReqIdent_Pre_Pre_NA
68 } RtemsTaskReqIdent_Pre_Pre;
69 
70 typedef enum {
71  RtemsTaskReqIdent_Post_Post_OkAndSelfId,
72  RtemsTaskReqIdent_Post_Post_Generic,
73  RtemsTaskReqIdent_Post_Post_NA
74 } RtemsTaskReqIdent_Post_Post;
75 
79 typedef struct {
80  rtems_status_code status;
81 
82  rtems_id *id;
83 
84  rtems_id id_value;
85 
86  rtems_id id_local_object;
87 
91  size_t pcs[ 1 ];
92 
99 
101  RtemsTaskReqIdent_Instance;
102 
103 static const char * const RtemsTaskReqIdent_PreDesc_Pre[] = {
104  "Self",
105  "Generic",
106  "NA"
107 };
108 
109 static const char * const * const RtemsTaskReqIdent_PreDesc[] = {
110  RtemsTaskReqIdent_PreDesc_Pre,
111  NULL
112 };
113 
114 static rtems_status_code ClassicTaskIdentAction(
115  rtems_name name,
116  uint32_t node,
117  rtems_id *id
118 )
119 {
120  return rtems_task_ident( name, node, id );
121 }
122 
123 #define TASK_ATTRIBUTES RTEMS_DEFAULT_ATTRIBUTES
124 
125 #define MAX_TLS_SIZE RTEMS_ALIGN_UP( 64, RTEMS_TASK_STORAGE_ALIGNMENT )
126 
128 static char ClassicTaskIdentStorage[
130  MAX_TLS_SIZE + RTEMS_MINIMUM_STACK_SIZE,
131  TASK_ATTRIBUTES
132  )
133 ];
134 
135 static const rtems_task_config ClassicTaskIdentConfig = {
136  .name = ClassicObjectIdentName,
137  .initial_priority = 1,
138  .storage_area = ClassicTaskIdentStorage,
139  .storage_size = sizeof( ClassicTaskIdentStorage ),
140  .maximum_thread_local_storage_size = MAX_TLS_SIZE,
141  .initial_modes = RTEMS_DEFAULT_MODES,
142  .attributes = TASK_ATTRIBUTES
143 };
144 
145 static void RtemsTaskReqIdent_Pre_Pre_Prepare(
147  RtemsTaskReqIdent_Pre_Pre state
148 )
149 {
150  switch ( state ) {
151  case RtemsTaskReqIdent_Pre_Pre_Self: {
152  ctx->id_value = 0xffffffff;
153  ctx->id = &ctx->id_value;
154  break;
155  }
156 
157  case RtemsTaskReqIdent_Pre_Pre_Generic: {
158  ctx->id = NULL;
159  /* Preparation performed by RtemsReqIdent_Run() */
160  break;
161  }
162 
163  case RtemsTaskReqIdent_Pre_Pre_NA:
164  break;
165  }
166 }
167 
168 static void RtemsTaskReqIdent_Post_Post_Check(
170  RtemsTaskReqIdent_Post_Post state
171 )
172 {
173  switch ( state ) {
174  case RtemsTaskReqIdent_Post_Post_OkAndSelfId: {
175  T_rsc(ctx->status, RTEMS_SUCCESSFUL);
176  T_eq_ptr(ctx->id, &ctx->id_value);
177  T_eq_u32(ctx->id_value, rtems_task_self());
178  break;
179  }
180 
181  case RtemsTaskReqIdent_Post_Post_Generic: {
182  /* Checks performed by RtemsReqIdent_Run() */
183  break;
184  }
185 
186  case RtemsTaskReqIdent_Post_Post_NA:
187  break;
188  }
189 }
190 
191 static void RtemsTaskReqIdent_Setup( RtemsTaskReqIdent_Context *ctx )
192 {
194 
196  &ClassicTaskIdentConfig,
197  &ctx->id_local_object
198  );
199  T_assert_rsc_success( sc );
200 }
201 
202 static void RtemsTaskReqIdent_Setup_Wrap( void *arg )
203 {
205 
206  ctx = arg;
207  ctx->in_action_loop = false;
208  RtemsTaskReqIdent_Setup( ctx );
209 }
210 
211 static void RtemsTaskReqIdent_Teardown( RtemsTaskReqIdent_Context *ctx )
212 {
213  if ( ctx->id_local_object != 0 ) {
215 
216  sc = rtems_task_delete( ctx->id_local_object );
217  T_rsc_success( sc );
218  }
219 }
220 
221 static void RtemsTaskReqIdent_Teardown_Wrap( void *arg )
222 {
224 
225  ctx = arg;
226  ctx->in_action_loop = false;
227  RtemsTaskReqIdent_Teardown( ctx );
228 }
229 
230 static size_t RtemsTaskReqIdent_Scope( void *arg, char *buf, size_t n )
231 {
233 
234  ctx = arg;
235 
236  if ( ctx->in_action_loop ) {
237  return T_get_scope( RtemsTaskReqIdent_PreDesc, buf, n, ctx->pcs );
238  }
239 
240  return 0;
241 }
242 
243 static T_fixture RtemsTaskReqIdent_Fixture = {
244  .setup = RtemsTaskReqIdent_Setup_Wrap,
245  .stop = NULL,
246  .teardown = RtemsTaskReqIdent_Teardown_Wrap,
247  .scope = RtemsTaskReqIdent_Scope,
248  .initial_context = &RtemsTaskReqIdent_Instance
249 };
250 
251 static const uint8_t RtemsTaskReqIdent_TransitionMap[][ 1 ] = {
252  {
253  RtemsTaskReqIdent_Post_Post_OkAndSelfId
254  }, {
255  RtemsTaskReqIdent_Post_Post_Generic
256  }
257 };
258 
259 static const struct {
260  uint8_t Skip : 1;
261  uint8_t Pre_Pre_NA : 1;
262 } RtemsTaskReqIdent_TransitionInfo[] = {
263  {
264  0, 0
265  }, {
266  0, 0
267  }
268 };
269 
270 static void RtemsTaskReqIdent_Action( RtemsTaskReqIdent_Context *ctx )
271 {
272  if ( ctx->id != NULL ) {
273  ctx->status = rtems_task_ident( RTEMS_SELF, 0xdeadbeef, ctx->id );
274  } else {
276  ctx->id_local_object,
277  ClassicTaskIdentAction
278  );
279  }
280 }
281 
285 T_TEST_CASE_FIXTURE( RtemsTaskReqIdent, &RtemsTaskReqIdent_Fixture )
286 {
288  size_t index;
289 
290  ctx = T_fixture_context();
291  ctx->in_action_loop = true;
292  index = 0;
293 
294  for (
295  ctx->pcs[ 0 ] = RtemsTaskReqIdent_Pre_Pre_Self;
296  ctx->pcs[ 0 ] < RtemsTaskReqIdent_Pre_Pre_NA;
297  ++ctx->pcs[ 0 ]
298  ) {
299  if ( RtemsTaskReqIdent_TransitionInfo[ index ].Pre_Pre_NA ) {
300  ctx->pcs[ 0 ] = RtemsTaskReqIdent_Pre_Pre_NA;
301  index += ( RtemsTaskReqIdent_Pre_Pre_NA - 1 );
302  }
303 
304  if ( RtemsTaskReqIdent_TransitionInfo[ index ].Skip ) {
305  ++index;
306  continue;
307  }
308 
309  RtemsTaskReqIdent_Pre_Pre_Prepare( ctx, ctx->pcs[ 0 ] );
310  RtemsTaskReqIdent_Action( ctx );
311  RtemsTaskReqIdent_Post_Post_Check(
312  ctx,
313  RtemsTaskReqIdent_TransitionMap[ index ][ 0 ]
314  );
315  ++index;
316  }
317 }
318 
uint32_t rtems_name
This type is used to represent a Classic API object name.
Definition: types.h:227
rtems_status_code rtems_task_ident(rtems_name name, uint32_t node, rtems_id *id)
Identifies a task object by the specified object name.
Definition: taskident.c:45
bool in_action_loop
This member indicates if the test action loop is currently executed.
Definition: tc-task-ident.c:97
rtems_name name
This member defines the name of the task.
Definition: tasks.h:138
rtems_status_code rtems_task_delete(rtems_id id)
%
Definition: taskdelete.c:24
This structure defines the configuration of a task constructed by rtems_task_construct().
Definition: tasks.h:134
rtems_id rtems_task_self(void)
%
Definition: taskself.c:23
size_t pcs[1]
This member defines the pre-condition states for the next action.
Definition: tc-task-ident.c:91
This status code indicates successful completion.
Definition: status.h:86
#define RTEMS_SELF
%
Definition: tasks.h:1046
void RtemsReqIdent_Run(rtems_id id_local_object, rtems_status_code(*action)(rtems_name, uint32_t, rtems_id *))
Runs the parameterized test case.
rtems_status_code
This enumeration provides status codes for directives of the Classic API.
Definition: status.h:82
#define RTEMS_ALIGNED(_alignment)
Instructs the compiler in a declaration or definition to enforce the specified alignment.
Definition: basedefs.h:389
#define RTEMS_MINIMUM_STACK_SIZE
%
Definition: tasks.h:973
Test context for spec:/rtems/task/req/ident test case.
Definition: tc-task-ident.c:79
Definition: test.h:61
#define RTEMS_TASK_STORAGE_SIZE(_size, _attributes)
Returns the recommended task storage area size for the specified size and task attributes.
Definition: tasks.h:1157
Objects_Id rtems_id
Values of this type identify an RTEMS object.
Definition: types.h:99
#define RTEMS_DEFAULT_MODES
This task mode constant represents the default mode set.
Definition: modes.h:137
rtems_status_code rtems_task_construct(const rtems_task_config *config, rtems_id *id)
Constructs a task from the specified the task configuration.
Definition: taskconstruct.c:73
#define RTEMS_TASK_STORAGE_ALIGNMENT
This constant defines the recommended alignment of a task storage area in bytes.
Definition: tasks.h:1135