summaryrefslogtreecommitdiffstats
path: root/testsuites/validation/tc-task.c
blob: 5ab96445edd849c0f06d890517959ff6cc048671 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
/* SPDX-License-Identifier: BSD-2-Clause */

/**
 * @file
 *
 * @ingroup RtemsTaskValTask
 */

/*
 * Copyright (C) 2021, 2022 embedded brains GmbH & Co. KG
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * This file is part of the RTEMS quality process and was automatically
 * generated.  If you find something that needs to be fixed or
 * worded better please post a report or patch to an RTEMS mailing list
 * or raise a bug report:
 *
 * https://www.rtems.org/bugs.html
 *
 * For information on updating and regenerating please refer to the How-To
 * section in the Software Requirements Engineering chapter of the
 * RTEMS Software Engineering manual.  The manual is provided as a part of
 * a release.  For development sources please refer to the online
 * documentation at:
 *
 * https://docs.rtems.org
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <rtems.h>
#include <string.h>
#include <rtems/score/apimutex.h>

#include "ts-config.h"
#include "tx-support.h"

#include <rtems/test.h>

/**
 * @defgroup RtemsTaskValTask spec:/rtems/task/val/task
 *
 * @ingroup TestsuitesValidationNoClock0
 *
 * @brief This test case collection provides validation test cases for
 *   requirements of the @ref RTEMSAPIClassicTasks.
 *
 * This test case performs the following actions:
 *
 * - Call rtems_task_self() check the returned value.
 *
 *   - Check that the returned value is equal to the object identifier of the
 *     calling task.
 *
 * - Call rtems_task_iterate() with a visitor which always returns false.
 *
 *   - Check that the all counter is equal to the count of tasks.  Check that
 *     the calling task was visited exacly once.  Firstly, this shows that
 *     rtems_task_iterate() used the parameters specified by ``visitor`` and
 *     ``arg``. Secondly, this shows that the iteration was done over all
 *     tasks.
 *
 *   - Check that the object alloctor mutex was not owned before and after the
 *     call.  Check that the object alloctor mutex was owned during the
 *     iteration.
 *
 * - Call rtems_task_iterate() with a visitor which returns true.
 *
 *   - Check that the all counter is equal to one.  This shows that the
 *     iteration stops when the visitor returns true.
 *
 * - Assert that RTEMS_TASK_STORAGE_ALIGNMENT is a constant expression which
 *   evaluates to the expected value.
 *
 * - Assert that RTEMS_NO_PRIORITY is a constant expression which evaluates to
 *   the expected value.
 *
 * - Assert that RTEMS_MINIMUM_STACK_SIZE is a constant expression which
 *   evaluates to the expected value.
 *
 * - Assert that RTEMS_CONFIGURED_MINIMUM_STACK_SIZE is a constant expression
 *   which evaluates to the expected value.
 *
 * - Assert that RTEMS_MINIMUM_PRIORITY is a constant expression which
 *   evaluates to the expected value.
 *
 * - Validate RTEMS_SELF using a sample directive call.
 *
 *   - Check that rtems_task_is_suspended() returns the expected status if
 *     called with a task identifier parameter of RTEMS_SELF.
 *
 * - Validate the home scheduler of tasks created by rtems_task_create() and
 *   constructed by rtems_task_construct().
 *
 *   - Create a task.  Check that the home scheduler of the created task is
 *     scheduler A.
 *
 *   - Construct a task.  Check that the home scheduler of the constructed task
 *     is scheduler A.
 *
 * @{
 */

typedef struct {
  bool     owner_before;
  bool     owner_in_visitor;
  bool     owner_after;
  uint32_t counter_all;
  uint32_t counter_self;
  bool     done;
} TaskIterateContext;

static bool TaskVisitor( rtems_tcb *tcb, void *arg )
{
  TaskIterateContext *ctx;

  ctx = arg;
  ++ctx->counter_all;

  if ( rtems_task_self() == tcb->Object.id ) {
    ++ctx->counter_self;
  }

  ctx->owner_in_visitor = _RTEMS_Allocator_is_owner();

  return ctx->done;
}

/**
 * @brief Call rtems_task_self() check the returned value.
 */
static void RtemsTaskValTask_Action_0( void )
{
  rtems_id id;

  id = rtems_task_self();

  /*
   * Check that the returned value is equal to the object identifier of the
   * calling task.
   */
  T_step_eq_u32( 0, id, 0x0a010001 );
}

/**
 * @brief Call rtems_task_iterate() with a visitor which always returns false.
 */
static void RtemsTaskValTask_Action_1( void )
{
  TaskIterateContext ctx;
  uint32_t           task_count;

  task_count = rtems_scheduler_get_processor_maximum();

  if ( task_count > 4 ) {
    task_count = 4;
  }

  ++task_count;

  memset( &ctx, 0, sizeof( ctx ) );
  ctx.owner_before = _RTEMS_Allocator_is_owner();
  rtems_task_iterate( TaskVisitor, &ctx );
  ctx.owner_after = _RTEMS_Allocator_is_owner();

  /*
   * Check that the all counter is equal to the count of tasks.  Check that the
   * calling task was visited exacly once.  Firstly, this shows that
   * rtems_task_iterate() used the parameters specified by ``visitor`` and
   * ``arg``. Secondly, this shows that the iteration was done over all tasks.
   */
  T_step_eq_u32( 1, ctx.counter_all, task_count );
  T_step_eq_u32( 2, ctx.counter_self, 1 );

  /*
   * Check that the object alloctor mutex was not owned before and after the
   * call.  Check that the object alloctor mutex was owned during the
   * iteration.
   */
  T_step_false( 3, ctx.owner_before );
  T_step_true( 4, ctx.owner_in_visitor );
  T_step_false( 5, ctx.owner_after );
}

/**
 * @brief Call rtems_task_iterate() with a visitor which returns true.
 */
static void RtemsTaskValTask_Action_2( void )
{
  TaskIterateContext ctx;

  memset( &ctx, 0, sizeof( ctx ) );
  ctx.done = true;
  rtems_task_iterate( TaskVisitor, &ctx );

  /*
   * Check that the all counter is equal to one.  This shows that the iteration
   * stops when the visitor returns true.
   */
  T_step_eq_u32( 6, ctx.counter_all, 1 );
}

/**
 * @brief Assert that RTEMS_TASK_STORAGE_ALIGNMENT is a constant expression
 *   which evaluates to the expected value.
 */
static void RtemsTaskValTask_Action_3( void )
{
  RTEMS_STATIC_ASSERT(
    RTEMS_TASK_STORAGE_ALIGNMENT == CPU_STACK_ALIGNMENT,
    STORAGE_ALIGNMENT
  );
}

/**
 * @brief Assert that RTEMS_NO_PRIORITY is a constant expression which
 *   evaluates to the expected value.
 */
static void RtemsTaskValTask_Action_4( void )
{
  RTEMS_STATIC_ASSERT(
    RTEMS_NO_PRIORITY == RTEMS_CURRENT_PRIORITY,
    NO_PRIORITY
  );
}

/**
 * @brief Assert that RTEMS_MINIMUM_STACK_SIZE is a constant expression which
 *   evaluates to the expected value.
 */
static void RtemsTaskValTask_Action_5( void )
{
  RTEMS_STATIC_ASSERT(
    RTEMS_MINIMUM_STACK_SIZE == STACK_MINIMUM_SIZE,
    MINIMUM_STACK_SIZE
  );
}

/**
 * @brief Assert that RTEMS_CONFIGURED_MINIMUM_STACK_SIZE is a constant
 *   expression which evaluates to the expected value.
 */
static void RtemsTaskValTask_Action_6( void )
{
  RTEMS_STATIC_ASSERT(
    RTEMS_CONFIGURED_MINIMUM_STACK_SIZE == 0,
    CONFIGURED_MINIMUM_STACK_SIZE
  );
}

/**
 * @brief Assert that RTEMS_MINIMUM_PRIORITY is a constant expression which
 *   evaluates to the expected value.
 */
static void RtemsTaskValTask_Action_7( void )
{
  RTEMS_STATIC_ASSERT( RTEMS_MINIMUM_PRIORITY == 1, MINIMUM_PRIORITY );
}

/**
 * @brief Validate RTEMS_SELF using a sample directive call.
 */
static void RtemsTaskValTask_Action_8( void )
{
  rtems_status_code sc;

  /*
   * Check that rtems_task_is_suspended() returns the expected status if called
   * with a task identifier parameter of RTEMS_SELF.
   */
  sc = rtems_task_is_suspended( RTEMS_SELF );
  T_step_rsc_success( 7, sc );
}

/**
 * @brief Validate the home scheduler of tasks created by rtems_task_create()
 *   and constructed by rtems_task_construct().
 */
static void RtemsTaskValTask_Action_9( void )
{
  rtems_status_code sc;
  rtems_id          id;

  /*
   * Create a task.  Check that the home scheduler of the created task is
   * scheduler A.
   */
  sc = rtems_task_create(
    OBJECT_NAME,
    1,
    TEST_MINIMUM_STACK_SIZE,
    RTEMS_DEFAULT_MODES,
    RTEMS_DEFAULT_ATTRIBUTES,
    &id
  );
  T_step_rsc_success( 8, sc );

  T_step_eq_u32( 9, GetScheduler( id ), SCHEDULER_A_ID );
  DeleteTask( id );

  /*
   * Construct a task.  Check that the home scheduler of the constructed task
   * is scheduler A.
   */
  sc = rtems_task_construct( &DefaultTaskConfig, &id );
  T_step_rsc_success( 10, sc );

  T_step_eq_u32( 11, GetScheduler( id ), SCHEDULER_A_ID );
  DeleteTask( id );
}

/**
 * @fn void T_case_body_RtemsTaskValTask( void )
 */
T_TEST_CASE( RtemsTaskValTask )
{
  T_plan( 12 );

  RtemsTaskValTask_Action_0();
  RtemsTaskValTask_Action_1();
  RtemsTaskValTask_Action_2();
  RtemsTaskValTask_Action_3();
  RtemsTaskValTask_Action_4();
  RtemsTaskValTask_Action_5();
  RtemsTaskValTask_Action_6();
  RtemsTaskValTask_Action_7();
  RtemsTaskValTask_Action_8();
  RtemsTaskValTask_Action_9();
}

/** @} */