source: rtems/testsuites/validation/tc-sem-performance.c @ 9bfe5f5

Last change on this file since 9bfe5f5 was 9bfe5f5, checked in by Sebastian Huber <sebastian.huber@…>, on 02/14/23 at 14:59:22

validation: Derive names from item UIDs

Use the item UID converted to CamelCase for Doxygen group names and
testsuite names.

Update #3716.

  • Property mode set to 100644
File size: 20.6 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/**
4 * @file
5 *
6 * @ingroup RtemsSemValPerf
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
57#include "tx-support.h"
58
59#include <rtems/test.h>
60
61/**
62 * @defgroup RtemsSemValPerf spec:/rtems/sem/val/perf
63 *
64 * @ingroup TestsuitesPerformanceNoClock0
65 *
66 * @brief This test case provides a context to run @ref RTEMSAPIClassicSem
67 *   performance tests.
68 *
69 * @{
70 */
71
72/**
73 * @brief Test context for spec:/rtems/sem/val/perf test case.
74 */
75typedef struct {
76  /**
77   * @brief This member provides a mutex identifier.
78   */
79  rtems_id mutex_id;
80
81  /**
82   * @brief This member provides a worker identifier.
83   */
84  rtems_id worker_id;
85
86  /**
87   * @brief This member provides a status code.
88   */
89  rtems_status_code status;
90
91  /**
92   * @brief This member references the measure runtime context.
93   */
94  T_measure_runtime_context *context;
95
96  /**
97   * @brief This member provides the measure runtime request.
98   */
99  T_measure_runtime_request request;
100
101  /**
102   * @brief This member provides an optional measurement begin time point.
103   */
104  T_ticks begin;
105
106  /**
107   * @brief This member provides an optional measurement end time point.
108   */
109  T_ticks end;
110} RtemsSemValPerf_Context;
111
112static RtemsSemValPerf_Context
113  RtemsSemValPerf_Instance;
114
115typedef RtemsSemValPerf_Context Context;
116
117typedef enum {
118  EVENT_END = RTEMS_EVENT_0,
119  EVENT_OBTAIN = RTEMS_EVENT_1,
120  EVENT_OBTAIN_END = RTEMS_EVENT_2,
121  EVENT_RELEASE = RTEMS_EVENT_3,
122  EVENT_RELEASE_END = RTEMS_EVENT_4
123} Event;
124
125static void Send( const Context *ctx, rtems_event_set events )
126{
127  SendEvents( ctx->worker_id, events );
128}
129
130static void Worker( rtems_task_argument arg )
131{
132  Context *ctx;
133
134  ctx = (Context *) arg;
135
136  while ( true ) {
137    rtems_event_set   events;
138    rtems_status_code sc;
139    T_ticks           ticks;
140
141    sc = rtems_event_receive(
142      RTEMS_ALL_EVENTS,
143      RTEMS_EVENT_ANY | RTEMS_WAIT,
144      RTEMS_NO_TIMEOUT,
145      &events
146    );
147    ticks = T_tick();
148    T_quiet_rsc_success( sc );
149
150    if ( ( events & EVENT_END ) != 0 ) {
151      ctx->end = ticks;
152    }
153
154    if ( ( events & EVENT_OBTAIN ) != 0 ) {
155      sc = rtems_semaphore_obtain(
156        ctx->mutex_id,
157        RTEMS_WAIT,
158        RTEMS_NO_TIMEOUT
159      );
160      ticks = T_tick();
161      T_quiet_rsc_success( sc );
162
163      if ( ( events & EVENT_OBTAIN_END ) != 0 ) {
164        ctx->end = ticks;
165      }
166    }
167
168    if ( ( events & EVENT_RELEASE ) != 0 ) {
169      sc = rtems_semaphore_release( ctx->mutex_id );
170      ticks = T_tick();
171      T_quiet_rsc_success( sc );
172
173      if ( ( events & EVENT_RELEASE_END ) != 0 ) {
174        ctx->end = ticks;
175      }
176    }
177  }
178}
179
180static void RtemsSemValPerf_Setup_Context( RtemsSemValPerf_Context *ctx )
181{
182  T_measure_runtime_config config;
183
184  memset( &config, 0, sizeof( config ) );
185  config.sample_count = 100;
186  ctx->request.arg = ctx;
187  ctx->request.flags = T_MEASURE_RUNTIME_REPORT_SAMPLES;
188  ctx->context = T_measure_runtime_create( &config );
189  T_assert_not_null( ctx->context );
190}
191
192/**
193 * @brief Create a mutex and a worker task.
194 */
195static void RtemsSemValPerf_Setup( RtemsSemValPerf_Context *ctx )
196{
197  SetSelfPriority( PRIO_NORMAL );
198  ctx->mutex_id = CreateMutex();
199  ctx->worker_id = CreateTask( "WORK", PRIO_HIGH );
200  StartTask( ctx->worker_id, Worker, ctx );
201}
202
203static void RtemsSemValPerf_Setup_Wrap( void *arg )
204{
205  RtemsSemValPerf_Context *ctx;
206
207  ctx = arg;
208  RtemsSemValPerf_Setup_Context( ctx );
209  RtemsSemValPerf_Setup( ctx );
210}
211
212/**
213 * @brief Delete the worker task and the mutex.
214 */
215static void RtemsSemValPerf_Teardown( RtemsSemValPerf_Context *ctx )
216{
217  DeleteTask( ctx->worker_id );
218  DeleteMutex( ctx->mutex_id );
219  RestoreRunnerPriority();
220}
221
222static void RtemsSemValPerf_Teardown_Wrap( void *arg )
223{
224  RtemsSemValPerf_Context *ctx;
225
226  ctx = arg;
227  RtemsSemValPerf_Teardown( ctx );
228}
229
230static T_fixture RtemsSemValPerf_Fixture = {
231  .setup = RtemsSemValPerf_Setup_Wrap,
232  .stop = NULL,
233  .teardown = RtemsSemValPerf_Teardown_Wrap,
234  .scope = NULL,
235  .initial_context = &RtemsSemValPerf_Instance
236};
237
238/**
239 * @brief Obtain the available mutex.
240 */
241static void RtemsSemReqPerfMtxPiObtain_Body( RtemsSemValPerf_Context *ctx )
242{
243  ctx->status = rtems_semaphore_obtain(
244    ctx->mutex_id,
245    RTEMS_WAIT,
246    RTEMS_NO_TIMEOUT
247  );
248}
249
250static void RtemsSemReqPerfMtxPiObtain_Body_Wrap( void *arg )
251{
252  RtemsSemValPerf_Context *ctx;
253
254  ctx = arg;
255  RtemsSemReqPerfMtxPiObtain_Body( ctx );
256}
257
258/**
259 * @brief Release the mutex.  Discard samples interrupted by a clock tick.
260 */
261static bool RtemsSemReqPerfMtxPiObtain_Teardown(
262  RtemsSemValPerf_Context *ctx,
263  T_ticks                 *delta,
264  uint32_t                 tic,
265  uint32_t                 toc,
266  unsigned int             retry
267)
268{
269  T_quiet_rsc_success( ctx->status );
270
271  ReleaseMutex( ctx->mutex_id );
272
273  return tic == toc;
274}
275
276static bool RtemsSemReqPerfMtxPiObtain_Teardown_Wrap(
277  void        *arg,
278  T_ticks     *delta,
279  uint32_t     tic,
280  uint32_t     toc,
281  unsigned int retry
282)
283{
284  RtemsSemValPerf_Context *ctx;
285
286  ctx = arg;
287  return RtemsSemReqPerfMtxPiObtain_Teardown( ctx, delta, tic, toc, retry );
288}
289
290/**
291 * @brief Obtain the mutex.
292 */
293static void RtemsSemReqPerfMtxPiRelease_Setup( RtemsSemValPerf_Context *ctx )
294{
295  ObtainMutex( ctx->mutex_id );
296}
297
298static void RtemsSemReqPerfMtxPiRelease_Setup_Wrap( void *arg )
299{
300  RtemsSemValPerf_Context *ctx;
301
302  ctx = arg;
303  RtemsSemReqPerfMtxPiRelease_Setup( ctx );
304}
305
306/**
307 * @brief Release the mutex.
308 */
309static void RtemsSemReqPerfMtxPiRelease_Body( RtemsSemValPerf_Context *ctx )
310{
311  ctx->status = rtems_semaphore_release( ctx->mutex_id );
312}
313
314static void RtemsSemReqPerfMtxPiRelease_Body_Wrap( void *arg )
315{
316  RtemsSemValPerf_Context *ctx;
317
318  ctx = arg;
319  RtemsSemReqPerfMtxPiRelease_Body( ctx );
320}
321
322/**
323 * @brief Discard samples interrupted by a clock tick.
324 */
325static bool RtemsSemReqPerfMtxPiRelease_Teardown(
326  RtemsSemValPerf_Context *ctx,
327  T_ticks                 *delta,
328  uint32_t                 tic,
329  uint32_t                 toc,
330  unsigned int             retry
331)
332{
333  T_quiet_rsc_success( ctx->status );
334
335  return tic == toc;
336}
337
338static bool RtemsSemReqPerfMtxPiRelease_Teardown_Wrap(
339  void        *arg,
340  T_ticks     *delta,
341  uint32_t     tic,
342  uint32_t     toc,
343  unsigned int retry
344)
345{
346  RtemsSemValPerf_Context *ctx;
347
348  ctx = arg;
349  return RtemsSemReqPerfMtxPiRelease_Teardown( ctx, delta, tic, toc, retry );
350}
351
352/**
353 * @brief Let one task wait on the mutex.
354 */
355static void RtemsSemReqPerfMtxPiReleaseOne_Setup(
356  RtemsSemValPerf_Context *ctx
357)
358{
359  ObtainMutex( ctx->mutex_id );
360  Send( ctx, EVENT_OBTAIN );
361  SetPriority( ctx->worker_id, PRIO_LOW );
362  Send( ctx, EVENT_RELEASE );
363}
364
365static void RtemsSemReqPerfMtxPiReleaseOne_Setup_Wrap( void *arg )
366{
367  RtemsSemValPerf_Context *ctx;
368
369  ctx = arg;
370  RtemsSemReqPerfMtxPiReleaseOne_Setup( ctx );
371}
372
373/**
374 * @brief Release the mutex.
375 */
376static void RtemsSemReqPerfMtxPiReleaseOne_Body( RtemsSemValPerf_Context *ctx )
377{
378  ctx->status = rtems_semaphore_release( ctx->mutex_id );
379}
380
381static void RtemsSemReqPerfMtxPiReleaseOne_Body_Wrap( void *arg )
382{
383  RtemsSemValPerf_Context *ctx;
384
385  ctx = arg;
386  RtemsSemReqPerfMtxPiReleaseOne_Body( ctx );
387}
388
389/**
390 * @brief Restore the worker priority.  Discard samples interrupted by a clock
391 *   tick.
392 */
393static bool RtemsSemReqPerfMtxPiReleaseOne_Teardown(
394  RtemsSemValPerf_Context *ctx,
395  T_ticks                 *delta,
396  uint32_t                 tic,
397  uint32_t                 toc,
398  unsigned int             retry
399)
400{
401  T_quiet_rsc( ctx->status, RTEMS_SUCCESSFUL );
402
403  SetPriority( ctx->worker_id, PRIO_HIGH );
404
405  return tic == toc;
406}
407
408static bool RtemsSemReqPerfMtxPiReleaseOne_Teardown_Wrap(
409  void        *arg,
410  T_ticks     *delta,
411  uint32_t     tic,
412  uint32_t     toc,
413  unsigned int retry
414)
415{
416  RtemsSemValPerf_Context *ctx;
417
418  ctx = arg;
419  return RtemsSemReqPerfMtxPiReleaseOne_Teardown(
420    ctx,
421    delta,
422    tic,
423    toc,
424    retry
425  );
426}
427
428#if defined(RTEMS_SMP)
429/**
430 * @brief Move worker to scheduler B.
431 */
432static void RtemsSemReqPerfMtxPiReleaseOtherCpu_Prepare(
433  RtemsSemValPerf_Context *ctx
434)
435{
436  SetScheduler( ctx->worker_id, SCHEDULER_B_ID, PRIO_NORMAL );
437}
438
439/**
440 * @brief Let one task wait on the mutex.
441 */
442static void RtemsSemReqPerfMtxPiReleaseOtherCpu_Setup(
443  RtemsSemValPerf_Context *ctx
444)
445{
446  ObtainMutex( ctx->mutex_id );
447  Send( ctx, EVENT_OBTAIN | EVENT_OBTAIN_END | EVENT_RELEASE );
448  WaitForNextTask( 1, ctx->worker_id );
449}
450
451static void RtemsSemReqPerfMtxPiReleaseOtherCpu_Setup_Wrap( void *arg )
452{
453  RtemsSemValPerf_Context *ctx;
454
455  ctx = arg;
456  RtemsSemReqPerfMtxPiReleaseOtherCpu_Setup( ctx );
457}
458
459/**
460 * @brief Release the mutex.
461 */
462static void RtemsSemReqPerfMtxPiReleaseOtherCpu_Body(
463  RtemsSemValPerf_Context *ctx
464)
465{
466  ctx->begin = T_tick();
467  ctx->status = rtems_semaphore_release( ctx->mutex_id );
468}
469
470static void RtemsSemReqPerfMtxPiReleaseOtherCpu_Body_Wrap( void *arg )
471{
472  RtemsSemValPerf_Context *ctx;
473
474  ctx = arg;
475  RtemsSemReqPerfMtxPiReleaseOtherCpu_Body( ctx );
476}
477
478/**
479 * @brief Make sure the worker waits for the next event.  Set the measured
480 *   runtime. Discard samples interrupted by a clock tick.
481 */
482static bool RtemsSemReqPerfMtxPiReleaseOtherCpu_Teardown(
483  RtemsSemValPerf_Context *ctx,
484  T_ticks                 *delta,
485  uint32_t                 tic,
486  uint32_t                 toc,
487  unsigned int             retry
488)
489{
490  T_quiet_rsc( ctx->status, RTEMS_SUCCESSFUL );
491
492  WaitForNextTask( 1, ctx->worker_id );
493  *delta = ctx->end - ctx->begin;
494
495  return tic == toc;
496}
497
498static bool RtemsSemReqPerfMtxPiReleaseOtherCpu_Teardown_Wrap(
499  void        *arg,
500  T_ticks     *delta,
501  uint32_t     tic,
502  uint32_t     toc,
503  unsigned int retry
504)
505{
506  RtemsSemValPerf_Context *ctx;
507
508  ctx = arg;
509  return RtemsSemReqPerfMtxPiReleaseOtherCpu_Teardown(
510    ctx,
511    delta,
512    tic,
513    toc,
514    retry
515  );
516}
517
518/**
519 * @brief Move worker to scheduler A.
520 */
521static void RtemsSemReqPerfMtxPiReleaseOtherCpu_Cleanup(
522  RtemsSemValPerf_Context *ctx
523)
524{
525  SetScheduler( ctx->worker_id, SCHEDULER_A_ID, PRIO_HIGH );
526}
527#endif
528
529/**
530 * @brief Let one task wait on the mutex.
531 */
532static void RtemsSemReqPerfMtxPiReleasePreempt_Setup(
533  RtemsSemValPerf_Context *ctx
534)
535{
536  ObtainMutex( ctx->mutex_id );
537  Send( ctx, EVENT_OBTAIN | EVENT_OBTAIN_END | EVENT_RELEASE );
538}
539
540static void RtemsSemReqPerfMtxPiReleasePreempt_Setup_Wrap( void *arg )
541{
542  RtemsSemValPerf_Context *ctx;
543
544  ctx = arg;
545  RtemsSemReqPerfMtxPiReleasePreempt_Setup( ctx );
546}
547
548/**
549 * @brief Release the mutex.
550 */
551static void RtemsSemReqPerfMtxPiReleasePreempt_Body(
552  RtemsSemValPerf_Context *ctx
553)
554{
555  ctx->begin = T_tick();
556  ctx->status = rtems_semaphore_release( ctx->mutex_id );
557}
558
559static void RtemsSemReqPerfMtxPiReleasePreempt_Body_Wrap( void *arg )
560{
561  RtemsSemValPerf_Context *ctx;
562
563  ctx = arg;
564  RtemsSemReqPerfMtxPiReleasePreempt_Body( ctx );
565}
566
567/**
568 * @brief Set the measured runtime.  Discard samples interrupted by a clock
569 *   tick.
570 */
571static bool RtemsSemReqPerfMtxPiReleasePreempt_Teardown(
572  RtemsSemValPerf_Context *ctx,
573  T_ticks                 *delta,
574  uint32_t                 tic,
575  uint32_t                 toc,
576  unsigned int             retry
577)
578{
579  T_quiet_rsc( ctx->status, RTEMS_SUCCESSFUL );
580
581  *delta = ctx->end - ctx->begin;
582
583  return tic == toc;
584}
585
586static bool RtemsSemReqPerfMtxPiReleasePreempt_Teardown_Wrap(
587  void        *arg,
588  T_ticks     *delta,
589  uint32_t     tic,
590  uint32_t     toc,
591  unsigned int retry
592)
593{
594  RtemsSemValPerf_Context *ctx;
595
596  ctx = arg;
597  return RtemsSemReqPerfMtxPiReleasePreempt_Teardown(
598    ctx,
599    delta,
600    tic,
601    toc,
602    retry
603  );
604}
605
606/**
607 * @brief Make the mutex unavailable.
608 */
609static void RtemsSemReqPerfMtxPiTry_Prepare( RtemsSemValPerf_Context *ctx )
610{
611  Send( ctx, EVENT_OBTAIN );
612}
613
614/**
615 * @brief Try to obtain the unavailable mutex.
616 */
617static void RtemsSemReqPerfMtxPiTry_Body( RtemsSemValPerf_Context *ctx )
618{
619  ctx->status = rtems_semaphore_obtain( ctx->mutex_id, RTEMS_NO_WAIT, 0 );
620}
621
622static void RtemsSemReqPerfMtxPiTry_Body_Wrap( void *arg )
623{
624  RtemsSemValPerf_Context *ctx;
625
626  ctx = arg;
627  RtemsSemReqPerfMtxPiTry_Body( ctx );
628}
629
630/**
631 * @brief Discard samples interrupted by a clock tick.
632 */
633static bool RtemsSemReqPerfMtxPiTry_Teardown(
634  RtemsSemValPerf_Context *ctx,
635  T_ticks                 *delta,
636  uint32_t                 tic,
637  uint32_t                 toc,
638  unsigned int             retry
639)
640{
641  T_quiet_rsc( ctx->status, RTEMS_UNSATISFIED );
642
643  return tic == toc;
644}
645
646static bool RtemsSemReqPerfMtxPiTry_Teardown_Wrap(
647  void        *arg,
648  T_ticks     *delta,
649  uint32_t     tic,
650  uint32_t     toc,
651  unsigned int retry
652)
653{
654  RtemsSemValPerf_Context *ctx;
655
656  ctx = arg;
657  return RtemsSemReqPerfMtxPiTry_Teardown( ctx, delta, tic, toc, retry );
658}
659
660/**
661 * @brief Make the mutex available.
662 */
663static void RtemsSemReqPerfMtxPiTry_Cleanup( RtemsSemValPerf_Context *ctx )
664{
665  Send( ctx, EVENT_RELEASE );
666}
667
668/**
669 * @brief Make the mutex unavailable.
670 */
671static void RtemsSemReqPerfMtxPiWaitForever_Setup(
672  RtemsSemValPerf_Context *ctx
673)
674{
675  Send( ctx, EVENT_OBTAIN );
676  SetPriority( ctx->worker_id, PRIO_LOW );
677  Send( ctx, EVENT_END | EVENT_RELEASE );
678}
679
680static void RtemsSemReqPerfMtxPiWaitForever_Setup_Wrap( void *arg )
681{
682  RtemsSemValPerf_Context *ctx;
683
684  ctx = arg;
685  RtemsSemReqPerfMtxPiWaitForever_Setup( ctx );
686}
687
688/**
689 * @brief Obtain the unavailable mutex and wait forever.
690 */
691static void RtemsSemReqPerfMtxPiWaitForever_Body(
692  RtemsSemValPerf_Context *ctx
693)
694{
695  ctx->begin = T_tick();
696  ctx->status = rtems_semaphore_obtain(
697    ctx->mutex_id,
698    RTEMS_WAIT,
699    RTEMS_NO_TIMEOUT
700  );
701}
702
703static void RtemsSemReqPerfMtxPiWaitForever_Body_Wrap( void *arg )
704{
705  RtemsSemValPerf_Context *ctx;
706
707  ctx = arg;
708  RtemsSemReqPerfMtxPiWaitForever_Body( ctx );
709}
710
711/**
712 * @brief Set the measured runtime.  Restore the worker priority.  Release the
713 *   mutex. Discard samples interrupted by a clock tick.
714 */
715static bool RtemsSemReqPerfMtxPiWaitForever_Teardown(
716  RtemsSemValPerf_Context *ctx,
717  T_ticks                 *delta,
718  uint32_t                 tic,
719  uint32_t                 toc,
720  unsigned int             retry
721)
722{
723  T_quiet_rsc( ctx->status, RTEMS_SUCCESSFUL );
724
725  *delta = ctx->end - ctx->begin;
726  SetPriority( ctx->worker_id, PRIO_HIGH );
727  ReleaseMutex( ctx->mutex_id );
728
729  return tic == toc;
730}
731
732static bool RtemsSemReqPerfMtxPiWaitForever_Teardown_Wrap(
733  void        *arg,
734  T_ticks     *delta,
735  uint32_t     tic,
736  uint32_t     toc,
737  unsigned int retry
738)
739{
740  RtemsSemValPerf_Context *ctx;
741
742  ctx = arg;
743  return RtemsSemReqPerfMtxPiWaitForever_Teardown(
744    ctx,
745    delta,
746    tic,
747    toc,
748    retry
749  );
750}
751
752/**
753 * @brief Make the mutex unavailable.
754 */
755static void RtemsSemReqPerfMtxPiWaitTimed_Setup( RtemsSemValPerf_Context *ctx )
756{
757  Send( ctx, EVENT_OBTAIN );
758  SetPriority( ctx->worker_id, PRIO_LOW );
759  Send( ctx, EVENT_END | EVENT_RELEASE );
760}
761
762static void RtemsSemReqPerfMtxPiWaitTimed_Setup_Wrap( void *arg )
763{
764  RtemsSemValPerf_Context *ctx;
765
766  ctx = arg;
767  RtemsSemReqPerfMtxPiWaitTimed_Setup( ctx );
768}
769
770/**
771 * @brief Obtain the unavailable mutex and wait forever.
772 */
773static void RtemsSemReqPerfMtxPiWaitTimed_Body( RtemsSemValPerf_Context *ctx )
774{
775  ctx->begin = T_tick();
776  ctx->status = rtems_semaphore_obtain(
777    ctx->mutex_id,
778    RTEMS_WAIT,
779    UINT32_MAX
780  );
781}
782
783static void RtemsSemReqPerfMtxPiWaitTimed_Body_Wrap( void *arg )
784{
785  RtemsSemValPerf_Context *ctx;
786
787  ctx = arg;
788  RtemsSemReqPerfMtxPiWaitTimed_Body( ctx );
789}
790
791/**
792 * @brief Set the measured runtime.  Restore the worker priority.  Release the
793 *   mutex. Discard samples interrupted by a clock tick.
794 */
795static bool RtemsSemReqPerfMtxPiWaitTimed_Teardown(
796  RtemsSemValPerf_Context *ctx,
797  T_ticks                 *delta,
798  uint32_t                 tic,
799  uint32_t                 toc,
800  unsigned int             retry
801)
802{
803  T_quiet_rsc( ctx->status, RTEMS_SUCCESSFUL );
804
805  *delta = ctx->end - ctx->begin;
806  SetPriority( ctx->worker_id, PRIO_HIGH );
807  ReleaseMutex( ctx->mutex_id );
808
809  return tic == toc;
810}
811
812static bool RtemsSemReqPerfMtxPiWaitTimed_Teardown_Wrap(
813  void        *arg,
814  T_ticks     *delta,
815  uint32_t     tic,
816  uint32_t     toc,
817  unsigned int retry
818)
819{
820  RtemsSemValPerf_Context *ctx;
821
822  ctx = arg;
823  return RtemsSemReqPerfMtxPiWaitTimed_Teardown( ctx, delta, tic, toc, retry );
824}
825
826/**
827 * @fn void T_case_body_RtemsSemValPerf( void )
828 */
829T_TEST_CASE_FIXTURE( RtemsSemValPerf, &RtemsSemValPerf_Fixture )
830{
831  RtemsSemValPerf_Context *ctx;
832
833  ctx = T_fixture_context();
834
835  ctx->request.name = "RtemsSemReqPerfMtxPiObtain";
836  ctx->request.setup = NULL;
837  ctx->request.body = RtemsSemReqPerfMtxPiObtain_Body_Wrap;
838  ctx->request.teardown = RtemsSemReqPerfMtxPiObtain_Teardown_Wrap;
839  T_measure_runtime( ctx->context, &ctx->request );
840
841  ctx->request.name = "RtemsSemReqPerfMtxPiRelease";
842  ctx->request.setup = RtemsSemReqPerfMtxPiRelease_Setup_Wrap;
843  ctx->request.body = RtemsSemReqPerfMtxPiRelease_Body_Wrap;
844  ctx->request.teardown = RtemsSemReqPerfMtxPiRelease_Teardown_Wrap;
845  T_measure_runtime( ctx->context, &ctx->request );
846
847  ctx->request.name = "RtemsSemReqPerfMtxPiReleaseOne";
848  ctx->request.setup = RtemsSemReqPerfMtxPiReleaseOne_Setup_Wrap;
849  ctx->request.body = RtemsSemReqPerfMtxPiReleaseOne_Body_Wrap;
850  ctx->request.teardown = RtemsSemReqPerfMtxPiReleaseOne_Teardown_Wrap;
851  T_measure_runtime( ctx->context, &ctx->request );
852
853  #if defined(RTEMS_SMP)
854  RtemsSemReqPerfMtxPiReleaseOtherCpu_Prepare( ctx );
855  ctx->request.name = "RtemsSemReqPerfMtxPiReleaseOtherCpu";
856  ctx->request.setup = RtemsSemReqPerfMtxPiReleaseOtherCpu_Setup_Wrap;
857  ctx->request.body = RtemsSemReqPerfMtxPiReleaseOtherCpu_Body_Wrap;
858  ctx->request.teardown = RtemsSemReqPerfMtxPiReleaseOtherCpu_Teardown_Wrap;
859  T_measure_runtime( ctx->context, &ctx->request );
860  RtemsSemReqPerfMtxPiReleaseOtherCpu_Cleanup( ctx );
861  #endif
862
863  ctx->request.name = "RtemsSemReqPerfMtxPiReleasePreempt";
864  ctx->request.setup = RtemsSemReqPerfMtxPiReleasePreempt_Setup_Wrap;
865  ctx->request.body = RtemsSemReqPerfMtxPiReleasePreempt_Body_Wrap;
866  ctx->request.teardown = RtemsSemReqPerfMtxPiReleasePreempt_Teardown_Wrap;
867  T_measure_runtime( ctx->context, &ctx->request );
868
869  RtemsSemReqPerfMtxPiTry_Prepare( ctx );
870  ctx->request.name = "RtemsSemReqPerfMtxPiTry";
871  ctx->request.setup = NULL;
872  ctx->request.body = RtemsSemReqPerfMtxPiTry_Body_Wrap;
873  ctx->request.teardown = RtemsSemReqPerfMtxPiTry_Teardown_Wrap;
874  T_measure_runtime( ctx->context, &ctx->request );
875  RtemsSemReqPerfMtxPiTry_Cleanup( ctx );
876
877  ctx->request.name = "RtemsSemReqPerfMtxPiWaitForever";
878  ctx->request.setup = RtemsSemReqPerfMtxPiWaitForever_Setup_Wrap;
879  ctx->request.body = RtemsSemReqPerfMtxPiWaitForever_Body_Wrap;
880  ctx->request.teardown = RtemsSemReqPerfMtxPiWaitForever_Teardown_Wrap;
881  T_measure_runtime( ctx->context, &ctx->request );
882
883  ctx->request.name = "RtemsSemReqPerfMtxPiWaitTimed";
884  ctx->request.setup = RtemsSemReqPerfMtxPiWaitTimed_Setup_Wrap;
885  ctx->request.body = RtemsSemReqPerfMtxPiWaitTimed_Body_Wrap;
886  ctx->request.teardown = RtemsSemReqPerfMtxPiWaitTimed_Teardown_Wrap;
887  T_measure_runtime( ctx->context, &ctx->request );
888}
889
890/** @} */
Note: See TracBrowser for help on using the repository browser.