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

Last change on this file since a26a326 was e76470df, checked in by Sebastian Huber <sebastian.huber@…>, on 03/08/21 at 09:49:51

validation: Use common wording

  • Property mode set to 100644
File size: 11.5 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_NoObj,
70  RtemsBarrierReqDelete_Pre_Id_Barrier,
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_Name_Valid,
82  RtemsBarrierReqDelete_Post_Name_Invalid,
83  RtemsBarrierReqDelete_Post_Name_NA
84} RtemsBarrierReqDelete_Post_Name;
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  "NoObj",
125  "Barrier",
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_NoObj: {
186      /*
187       * The ``id`` parameter shall not be associated with a barrier.
188       */
189      ctx->id = 0;
190      break;
191    }
192
193    case RtemsBarrierReqDelete_Pre_Id_Barrier: {
194      /*
195       * The ``id`` parameter shall be associated with a barrier.
196       */
197      ctx->id = ctx->barrier_id;
198      break;
199    }
200
201    case RtemsBarrierReqDelete_Pre_Id_NA:
202      break;
203  }
204}
205
206static void RtemsBarrierReqDelete_Post_Status_Check(
207  RtemsBarrierReqDelete_Context    *ctx,
208  RtemsBarrierReqDelete_Post_Status state
209)
210{
211  switch ( state ) {
212    case RtemsBarrierReqDelete_Post_Status_Ok: {
213      /*
214       * The return status of rtems_barrier_delete() shall be RTEMS_SUCCESSFUL.
215       */
216      ctx->barrier_id = 0;
217      T_rsc_success( ctx->status );
218      break;
219    }
220
221    case RtemsBarrierReqDelete_Post_Status_InvId: {
222      /*
223       * The return status of rtems_barrier_delete() shall be RTEMS_INVALID_ID.
224       */
225      T_rsc( ctx->status, RTEMS_INVALID_ID );
226      break;
227    }
228
229    case RtemsBarrierReqDelete_Post_Status_NA:
230      break;
231  }
232}
233
234static void RtemsBarrierReqDelete_Post_Name_Check(
235  RtemsBarrierReqDelete_Context  *ctx,
236  RtemsBarrierReqDelete_Post_Name state
237)
238{
239  rtems_status_code sc;
240  rtems_id          id;
241
242  switch ( state ) {
243    case RtemsBarrierReqDelete_Post_Name_Valid: {
244      /*
245       * The unique object name shall identify the barrier.
246       */
247      id = 0;
248      sc = rtems_barrier_ident( NAME, &id );
249      T_rsc_success( sc );
250      T_eq_u32( id, ctx->barrier_id );
251      break;
252    }
253
254    case RtemsBarrierReqDelete_Post_Name_Invalid: {
255      /*
256       * The unique object name shall not identify the barrier.
257       */
258      sc = rtems_barrier_ident( NAME, &id );
259      T_rsc( sc, RTEMS_INVALID_NAME );
260      break;
261    }
262
263    case RtemsBarrierReqDelete_Post_Name_NA:
264      break;
265  }
266}
267
268static void RtemsBarrierReqDelete_Post_Flush_Check(
269  RtemsBarrierReqDelete_Context   *ctx,
270  RtemsBarrierReqDelete_Post_Flush state
271)
272{
273  switch ( state ) {
274    case RtemsBarrierReqDelete_Post_Flush_Yes: {
275      /*
276       * Tasks waiting at the barrier shall be unblocked.
277       */
278      ++ctx->wait_expected;
279      T_eq_u32( ctx->wait_done, ctx->wait_expected );
280      break;
281    }
282
283    case RtemsBarrierReqDelete_Post_Flush_No: {
284      /*
285       * Tasks waiting at the barrier shall remain blocked.
286       */
287      T_eq_u32( ctx->wait_done, ctx->wait_expected );
288      break;
289    }
290
291    case RtemsBarrierReqDelete_Post_Flush_NA:
292      break;
293  }
294}
295
296static void RtemsBarrierReqDelete_Setup( RtemsBarrierReqDelete_Context *ctx )
297{
298  rtems_status_code   sc;
299  rtems_task_priority prio;
300
301  memset( ctx, 0, sizeof( *ctx ) );
302
303  prio = 0;
304  sc = rtems_task_set_priority( RTEMS_SELF, PRIO_NORMAL, &prio );
305  T_rsc_success( sc );
306  T_eq_u32( prio, PRIO_HIGH );
307
308  sc = rtems_task_create(
309    rtems_build_name( 'W', 'O', 'R', 'K' ),
310    PRIO_LOW,
311    RTEMS_MINIMUM_STACK_SIZE,
312    RTEMS_DEFAULT_MODES,
313    RTEMS_DEFAULT_ATTRIBUTES,
314    &ctx->worker_id
315  );
316  T_assert_rsc_success( sc );
317
318  sc = rtems_task_start( ctx->worker_id, Worker, (rtems_task_argument) ctx );
319  T_assert_rsc_success( sc );
320}
321
322static void RtemsBarrierReqDelete_Setup_Wrap( void *arg )
323{
324  RtemsBarrierReqDelete_Context *ctx;
325
326  ctx = arg;
327  ctx->in_action_loop = false;
328  RtemsBarrierReqDelete_Setup( ctx );
329}
330
331static void RtemsBarrierReqDelete_Teardown(
332  RtemsBarrierReqDelete_Context *ctx
333)
334{
335  rtems_status_code   sc;
336  rtems_task_priority prio;
337
338  prio = 0;
339  sc = rtems_task_set_priority( RTEMS_SELF, PRIO_HIGH, &prio );
340  T_rsc_success( sc );
341  T_eq_u32( prio, PRIO_NORMAL );
342
343  if ( ctx->worker_id != 0 ) {
344    sc = rtems_task_delete( ctx->worker_id );
345    T_rsc_success( sc );
346  }
347}
348
349static void RtemsBarrierReqDelete_Teardown_Wrap( void *arg )
350{
351  RtemsBarrierReqDelete_Context *ctx;
352
353  ctx = arg;
354  ctx->in_action_loop = false;
355  RtemsBarrierReqDelete_Teardown( ctx );
356}
357
358static size_t RtemsBarrierReqDelete_Scope( void *arg, char *buf, size_t n )
359{
360  RtemsBarrierReqDelete_Context *ctx;
361
362  ctx = arg;
363
364  if ( ctx->in_action_loop ) {
365    return T_get_scope( RtemsBarrierReqDelete_PreDesc, buf, n, ctx->pcs );
366  }
367
368  return 0;
369}
370
371static T_fixture RtemsBarrierReqDelete_Fixture = {
372  .setup = RtemsBarrierReqDelete_Setup_Wrap,
373  .stop = NULL,
374  .teardown = RtemsBarrierReqDelete_Teardown_Wrap,
375  .scope = RtemsBarrierReqDelete_Scope,
376  .initial_context = &RtemsBarrierReqDelete_Instance
377};
378
379static const uint8_t RtemsBarrierReqDelete_TransitionMap[][ 3 ] = {
380  {
381    RtemsBarrierReqDelete_Post_Status_InvId,
382    RtemsBarrierReqDelete_Post_Name_Valid,
383    RtemsBarrierReqDelete_Post_Flush_No
384  }, {
385    RtemsBarrierReqDelete_Post_Status_Ok,
386    RtemsBarrierReqDelete_Post_Name_Invalid,
387    RtemsBarrierReqDelete_Post_Flush_Yes
388  }
389};
390
391static const struct {
392  uint8_t Skip : 1;
393  uint8_t Pre_Id_NA : 1;
394} RtemsBarrierReqDelete_TransitionInfo[] = {
395  {
396    0, 0
397  }, {
398    0, 0
399  }
400};
401
402static void RtemsBarrierReqDelete_Prepare( RtemsBarrierReqDelete_Context *ctx )
403{
404  rtems_status_code   sc;
405  rtems_task_priority prio;
406
407  prio = 0;
408  sc = rtems_task_set_priority( ctx->worker_id, PRIO_HIGH, &prio );
409  T_rsc_success( sc );
410  T_true( prio == PRIO_LOW || prio == PRIO_HIGH );
411}
412
413static void RtemsBarrierReqDelete_Action( RtemsBarrierReqDelete_Context *ctx )
414{
415  ctx->status = rtems_barrier_delete( ctx->id );
416}
417
418static void RtemsBarrierReqDelete_Cleanup( RtemsBarrierReqDelete_Context *ctx )
419{
420  if ( ctx->barrier_id != 0 ) {
421    rtems_status_code sc;
422
423    sc = rtems_barrier_delete( ctx->barrier_id );
424    T_rsc_success( sc );
425
426    ++ctx->wait_expected;
427    T_eq_u32( ctx->wait_done, ctx->wait_expected );
428
429    ctx->barrier_id = 0;
430  }
431}
432
433/**
434 * @fn void T_case_body_RtemsBarrierReqDelete( void )
435 */
436T_TEST_CASE_FIXTURE( RtemsBarrierReqDelete, &RtemsBarrierReqDelete_Fixture )
437{
438  RtemsBarrierReqDelete_Context *ctx;
439  size_t index;
440
441  ctx = T_fixture_context();
442  ctx->in_action_loop = true;
443  index = 0;
444
445  for (
446    ctx->pcs[ 0 ] = RtemsBarrierReqDelete_Pre_Id_NoObj;
447    ctx->pcs[ 0 ] < RtemsBarrierReqDelete_Pre_Id_NA;
448    ++ctx->pcs[ 0 ]
449  ) {
450    if ( RtemsBarrierReqDelete_TransitionInfo[ index ].Pre_Id_NA ) {
451      ctx->pcs[ 0 ] = RtemsBarrierReqDelete_Pre_Id_NA;
452      index += ( RtemsBarrierReqDelete_Pre_Id_NA - 1 );
453    }
454
455    if ( RtemsBarrierReqDelete_TransitionInfo[ index ].Skip ) {
456      ++index;
457      continue;
458    }
459
460    RtemsBarrierReqDelete_Prepare( ctx );
461    RtemsBarrierReqDelete_Pre_Id_Prepare( ctx, ctx->pcs[ 0 ] );
462    RtemsBarrierReqDelete_Action( ctx );
463    RtemsBarrierReqDelete_Post_Status_Check(
464      ctx,
465      RtemsBarrierReqDelete_TransitionMap[ index ][ 0 ]
466    );
467    RtemsBarrierReqDelete_Post_Name_Check(
468      ctx,
469      RtemsBarrierReqDelete_TransitionMap[ index ][ 1 ]
470    );
471    RtemsBarrierReqDelete_Post_Flush_Check(
472      ctx,
473      RtemsBarrierReqDelete_TransitionMap[ index ][ 2 ]
474    );
475    RtemsBarrierReqDelete_Cleanup( ctx );
476    ++index;
477  }
478}
479
480/** @} */
Note: See TracBrowser for help on using the repository browser.