source: rtems/testsuites/validation/tc-barrier-delete.c @ 34f279aa

Last change on this file since 34f279aa was 34f279aa, checked in by Sebastian Huber <sebastian.huber@…>, on Feb 24, 2021 at 4:59:32 PM

validation: Add comments to barrier tests

Unify code sections across tests.

  • Property mode set to 100644
File size: 11.4 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/**
4 * @file
5 *
6 * @ingroup RTEMSTestCaseRtemsBarrierReqDelete
7 */
8
9/*
10 * Copyright (C) 2021 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 * This file is part of the RTEMS quality process and was automatically
36 * generated.  If you find something that needs to be fixed or
37 * worded better please post a report or patch to an RTEMS mailing list
38 * or raise a bug report:
39 *
40 * https://www.rtems.org/bugs.html
41 *
42 * For information on updating and regenerating please refer to the How-To
43 * section in the Software Requirements Engineering chapter of the
44 * RTEMS Software Engineering manual.  The manual is provided as a part of
45 * a release.  For development sources please refer to the online
46 * documentation at:
47 *
48 * https://docs.rtems.org
49 */
50
51#ifdef HAVE_CONFIG_H
52#include "config.h"
53#endif
54
55#include <rtems.h>
56#include <string.h>
57
58#include <rtems/test.h>
59
60/**
61 * @defgroup RTEMSTestCaseRtemsBarrierReqDelete spec:/rtems/barrier/req/delete
62 *
63 * @ingroup RTEMSTestSuiteTestsuitesValidation0
64 *
65 * @{
66 */
67
68typedef enum {
69  RtemsBarrierReqDelete_Pre_Id_Valid,
70  RtemsBarrierReqDelete_Pre_Id_Invalid,
71  RtemsBarrierReqDelete_Pre_Id_NA
72} RtemsBarrierReqDelete_Pre_Id;
73
74typedef enum {
75  RtemsBarrierReqDelete_Post_Status_Ok,
76  RtemsBarrierReqDelete_Post_Status_InvId,
77  RtemsBarrierReqDelete_Post_Status_NA
78} RtemsBarrierReqDelete_Post_Status;
79
80typedef enum {
81  RtemsBarrierReqDelete_Post_Id_Valid,
82  RtemsBarrierReqDelete_Post_Id_Invalid,
83  RtemsBarrierReqDelete_Post_Id_NA
84} RtemsBarrierReqDelete_Post_Id;
85
86typedef enum {
87  RtemsBarrierReqDelete_Post_Flush_Yes,
88  RtemsBarrierReqDelete_Post_Flush_No,
89  RtemsBarrierReqDelete_Post_Flush_NA
90} RtemsBarrierReqDelete_Post_Flush;
91
92/**
93 * @brief Test context for spec:/rtems/barrier/req/delete test case.
94 */
95typedef struct {
96  rtems_id worker_id;
97
98  rtems_id barrier_id;
99
100  uint32_t wait_done;
101
102  uint32_t wait_expected;
103
104  rtems_id id;
105
106  rtems_status_code status;
107
108  /**
109   * @brief This member defines the pre-condition states for the next action.
110   */
111  size_t pcs[ 1 ];
112
113  /**
114   * @brief This member indicates if the test action loop is currently
115   *   executed.
116   */
117  bool in_action_loop;
118} RtemsBarrierReqDelete_Context;
119
120static RtemsBarrierReqDelete_Context
121  RtemsBarrierReqDelete_Instance;
122
123static const char * const RtemsBarrierReqDelete_PreDesc_Id[] = {
124  "Valid",
125  "Invalid",
126  "NA"
127};
128
129static const char * const * const RtemsBarrierReqDelete_PreDesc[] = {
130  RtemsBarrierReqDelete_PreDesc_Id,
131  NULL
132};
133
134#define NAME rtems_build_name( 'T', 'E', 'S', 'T' )
135
136typedef RtemsBarrierReqDelete_Context Context;
137
138typedef enum {
139  PRIO_HIGH = 1,
140  PRIO_NORMAL,
141  PRIO_LOW
142} Priorities;
143
144static void Worker( rtems_task_argument arg )
145{
146  Context *ctx;
147
148  ctx = (Context *) arg;
149
150  while ( true ) {
151    rtems_status_code   sc;
152    rtems_task_priority prio;
153
154    T_eq_u32( ctx->barrier_id, 0 );
155
156    sc = rtems_barrier_create(
157      NAME,
158      RTEMS_DEFAULT_ATTRIBUTES,
159      0,
160      &ctx->barrier_id
161    );
162    T_rsc_success( sc );
163
164    sc = rtems_barrier_wait(
165      ctx->barrier_id,
166      RTEMS_NO_TIMEOUT
167    );
168    T_rsc( sc, RTEMS_OBJECT_WAS_DELETED );
169
170    ++ctx->wait_done;
171
172    prio = 0;
173    sc = rtems_task_set_priority( RTEMS_SELF, PRIO_LOW, &prio );
174    T_rsc_success( sc );
175    T_eq_u32( prio, PRIO_HIGH );
176  }
177}
178
179static void RtemsBarrierReqDelete_Pre_Id_Prepare(
180  RtemsBarrierReqDelete_Context *ctx,
181  RtemsBarrierReqDelete_Pre_Id   state
182)
183{
184  switch ( state ) {
185    case RtemsBarrierReqDelete_Pre_Id_Valid: {
186      /*
187       * The ``id`` parameter shall be associated with
188       * the barrier.
189       */
190      ctx->id = ctx->barrier_id;
191      break;
192    }
193
194    case RtemsBarrierReqDelete_Pre_Id_Invalid: {
195      /*
196       * The ``id`` parameter shall be invalid.
197       */
198      ctx->id = 0;
199      break;
200    }
201
202    case RtemsBarrierReqDelete_Pre_Id_NA:
203      break;
204  }
205}
206
207static void RtemsBarrierReqDelete_Post_Status_Check(
208  RtemsBarrierReqDelete_Context    *ctx,
209  RtemsBarrierReqDelete_Post_Status state
210)
211{
212  switch ( state ) {
213    case RtemsBarrierReqDelete_Post_Status_Ok: {
214      /*
215       * The return status of rtems_barrier_delete() shall be
216       * RTEMS_SUCCESSFUL.
217       */
218      ctx->barrier_id = 0;
219      T_rsc_success( ctx->status );
220      break;
221    }
222
223    case RtemsBarrierReqDelete_Post_Status_InvId: {
224      /*
225       * The return status of rtems_barrier_delete() shall be
226       * RTEMS_INVALID_ID.
227       */
228      T_rsc( ctx->status, RTEMS_INVALID_ID );
229      break;
230    }
231
232    case RtemsBarrierReqDelete_Post_Status_NA:
233      break;
234  }
235}
236
237static void RtemsBarrierReqDelete_Post_Id_Check(
238  RtemsBarrierReqDelete_Context *ctx,
239  RtemsBarrierReqDelete_Post_Id  state
240)
241{
242  rtems_status_code sc;
243  rtems_id          id;
244
245  switch ( state ) {
246    case RtemsBarrierReqDelete_Post_Id_Valid: {
247      /*
248       * The unique object name shall identify the barrier.
249       */
250      id = 0;
251      sc = rtems_barrier_ident( NAME, &id );
252      T_rsc_success( sc );
253      T_eq_u32( id, ctx->barrier_id );
254      break;
255    }
256
257    case RtemsBarrierReqDelete_Post_Id_Invalid: {
258      /*
259       * The unique object name shall not identify the barrier.
260       */
261      sc = rtems_barrier_ident( NAME, &id );
262      T_rsc( sc, RTEMS_INVALID_NAME );
263      break;
264    }
265
266    case RtemsBarrierReqDelete_Post_Id_NA:
267      break;
268  }
269}
270
271static void RtemsBarrierReqDelete_Post_Flush_Check(
272  RtemsBarrierReqDelete_Context   *ctx,
273  RtemsBarrierReqDelete_Post_Flush state
274)
275{
276  switch ( state ) {
277    case RtemsBarrierReqDelete_Post_Flush_Yes: {
278      /*
279       * Tasks waiting at the barrier shall be unblocked.
280       */
281      ++ctx->wait_expected;
282      T_eq_u32( ctx->wait_done, ctx->wait_expected );
283      break;
284    }
285
286    case RtemsBarrierReqDelete_Post_Flush_No: {
287      /*
288       * Tasks waiting at the barrier shall remain blocked.
289       */
290      T_eq_u32( ctx->wait_done, ctx->wait_expected );
291      break;
292    }
293
294    case RtemsBarrierReqDelete_Post_Flush_NA:
295      break;
296  }
297}
298
299static void RtemsBarrierReqDelete_Setup( RtemsBarrierReqDelete_Context *ctx )
300{
301  rtems_status_code   sc;
302  rtems_task_priority prio;
303
304  memset( ctx, 0, sizeof( *ctx ) );
305
306  prio = 0;
307  sc = rtems_task_set_priority( RTEMS_SELF, PRIO_NORMAL, &prio );
308  T_rsc_success( sc );
309  T_eq_u32( prio, PRIO_HIGH );
310
311  sc = rtems_task_create(
312    rtems_build_name( 'W', 'O', 'R', 'K' ),
313    PRIO_LOW,
314    RTEMS_MINIMUM_STACK_SIZE,
315    RTEMS_DEFAULT_MODES,
316    RTEMS_DEFAULT_ATTRIBUTES,
317    &ctx->worker_id
318  );
319  T_assert_rsc_success( sc );
320
321  sc = rtems_task_start( ctx->worker_id, Worker, (rtems_task_argument) ctx );
322  T_assert_rsc_success( sc );
323}
324
325static void RtemsBarrierReqDelete_Setup_Wrap( void *arg )
326{
327  RtemsBarrierReqDelete_Context *ctx;
328
329  ctx = arg;
330  ctx->in_action_loop = false;
331  RtemsBarrierReqDelete_Setup( ctx );
332}
333
334static void RtemsBarrierReqDelete_Teardown(
335  RtemsBarrierReqDelete_Context *ctx
336)
337{
338  rtems_status_code   sc;
339  rtems_task_priority prio;
340
341  prio = 0;
342  sc = rtems_task_set_priority( RTEMS_SELF, PRIO_HIGH, &prio );
343  T_rsc_success( sc );
344  T_eq_u32( prio, PRIO_NORMAL );
345
346  if ( ctx->worker_id != 0 ) {
347    sc = rtems_task_delete( ctx->worker_id );
348    T_rsc_success( sc );
349  }
350}
351
352static void RtemsBarrierReqDelete_Teardown_Wrap( void *arg )
353{
354  RtemsBarrierReqDelete_Context *ctx;
355
356  ctx = arg;
357  ctx->in_action_loop = false;
358  RtemsBarrierReqDelete_Teardown( ctx );
359}
360
361static size_t RtemsBarrierReqDelete_Scope( void *arg, char *buf, size_t n )
362{
363  RtemsBarrierReqDelete_Context *ctx;
364
365  ctx = arg;
366
367  if ( ctx->in_action_loop ) {
368    return T_get_scope( RtemsBarrierReqDelete_PreDesc, buf, n, ctx->pcs );
369  }
370
371  return 0;
372}
373
374static T_fixture RtemsBarrierReqDelete_Fixture = {
375  .setup = RtemsBarrierReqDelete_Setup_Wrap,
376  .stop = NULL,
377  .teardown = RtemsBarrierReqDelete_Teardown_Wrap,
378  .scope = RtemsBarrierReqDelete_Scope,
379  .initial_context = &RtemsBarrierReqDelete_Instance
380};
381
382static const uint8_t RtemsBarrierReqDelete_TransitionMap[][ 3 ] = {
383  {
384    RtemsBarrierReqDelete_Post_Status_Ok,
385    RtemsBarrierReqDelete_Post_Id_Invalid,
386    RtemsBarrierReqDelete_Post_Flush_Yes
387  }, {
388    RtemsBarrierReqDelete_Post_Status_InvId,
389    RtemsBarrierReqDelete_Post_Id_Valid,
390    RtemsBarrierReqDelete_Post_Flush_No
391  }
392};
393
394static const struct {
395  uint8_t Skip : 1;
396  uint8_t Pre_Id_NA : 1;
397} RtemsBarrierReqDelete_TransitionInfo[] = {
398  {
399    0, 0
400  }, {
401    0, 0
402  }
403};
404
405static void RtemsBarrierReqDelete_Prepare( RtemsBarrierReqDelete_Context *ctx )
406{
407  rtems_status_code   sc;
408  rtems_task_priority prio;
409
410  prio = 0;
411  sc = rtems_task_set_priority( ctx->worker_id, PRIO_HIGH, &prio );
412  T_rsc_success( sc );
413  T_true( prio == PRIO_LOW || prio == PRIO_HIGH );
414}
415
416static void RtemsBarrierReqDelete_Action( RtemsBarrierReqDelete_Context *ctx )
417{
418  ctx->status = rtems_barrier_delete( ctx->id );
419}
420
421static void RtemsBarrierReqDelete_Cleanup( RtemsBarrierReqDelete_Context *ctx )
422{
423  if ( ctx->barrier_id != 0 ) {
424    rtems_status_code sc;
425
426    sc = rtems_barrier_delete( ctx->barrier_id );
427    T_rsc_success( sc );
428  }
429}
430
431/**
432 * @fn void T_case_body_RtemsBarrierReqDelete( void )
433 */
434T_TEST_CASE_FIXTURE( RtemsBarrierReqDelete, &RtemsBarrierReqDelete_Fixture )
435{
436  RtemsBarrierReqDelete_Context *ctx;
437  size_t index;
438
439  ctx = T_fixture_context();
440  ctx->in_action_loop = true;
441  index = 0;
442
443  for (
444    ctx->pcs[ 0 ] = RtemsBarrierReqDelete_Pre_Id_Valid;
445    ctx->pcs[ 0 ] < RtemsBarrierReqDelete_Pre_Id_NA;
446    ++ctx->pcs[ 0 ]
447  ) {
448    if ( RtemsBarrierReqDelete_TransitionInfo[ index ].Pre_Id_NA ) {
449      ctx->pcs[ 0 ] = RtemsBarrierReqDelete_Pre_Id_NA;
450      index += ( RtemsBarrierReqDelete_Pre_Id_NA - 1 );
451    }
452
453    if ( RtemsBarrierReqDelete_TransitionInfo[ index ].Skip ) {
454      ++index;
455      continue;
456    }
457
458    RtemsBarrierReqDelete_Prepare( ctx );
459    RtemsBarrierReqDelete_Pre_Id_Prepare( ctx, ctx->pcs[ 0 ] );
460    RtemsBarrierReqDelete_Action( ctx );
461    RtemsBarrierReqDelete_Post_Status_Check(
462      ctx,
463      RtemsBarrierReqDelete_TransitionMap[ index ][ 0 ]
464    );
465    RtemsBarrierReqDelete_Post_Id_Check(
466      ctx,
467      RtemsBarrierReqDelete_TransitionMap[ index ][ 1 ]
468    );
469    RtemsBarrierReqDelete_Post_Flush_Check(
470      ctx,
471      RtemsBarrierReqDelete_TransitionMap[ index ][ 2 ]
472    );
473    RtemsBarrierReqDelete_Cleanup( ctx );
474    ++index;
475  }
476}
477
478/** @} */
Note: See TracBrowser for help on using the repository browser.