Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:51

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup RtemsPartValPerf
0007  */
0008 
0009 /*
0010  * Copyright (C) 2020 embedded brains GmbH & Co. KG
0011  *
0012  * Redistribution and use in source and binary forms, with or without
0013  * modification, are permitted provided that the following conditions
0014  * are met:
0015  * 1. Redistributions of source code must retain the above copyright
0016  *    notice, this list of conditions and the following disclaimer.
0017  * 2. Redistributions in binary form must reproduce the above copyright
0018  *    notice, this list of conditions and the following disclaimer in the
0019  *    documentation and/or other materials provided with the distribution.
0020  *
0021  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0022  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0023  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0024  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0025  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0026  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0027  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0028  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0029  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0030  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0031  * POSSIBILITY OF SUCH DAMAGE.
0032  */
0033 
0034 /*
0035  * This file is part of the RTEMS quality process and was automatically
0036  * generated.  If you find something that needs to be fixed or
0037  * worded better please post a report or patch to an RTEMS mailing list
0038  * or raise a bug report:
0039  *
0040  * https://www.rtems.org/bugs.html
0041  *
0042  * For information on updating and regenerating please refer to the How-To
0043  * section in the Software Requirements Engineering chapter of the
0044  * RTEMS Software Engineering manual.  The manual is provided as a part of
0045  * a release.  For development sources please refer to the online
0046  * documentation at:
0047  *
0048  * https://docs.rtems.org
0049  */
0050 
0051 #ifdef HAVE_CONFIG_H
0052 #include "config.h"
0053 #endif
0054 
0055 #include <rtems.h>
0056 
0057 #include <rtems/test.h>
0058 
0059 /**
0060  * @defgroup RtemsPartValPerf spec:/rtems/part/val/perf
0061  *
0062  * @ingroup TestsuitesPerformanceNoClock0
0063  *
0064  * @brief This test case provides a context to run @ref RTEMSAPIClassicPart
0065  *   performance tests.
0066  *
0067  * @{
0068  */
0069 
0070 /**
0071  * @brief Test context for spec:/rtems/part/val/perf test case.
0072  */
0073 typedef struct {
0074   /**
0075    * @brief This member provides a partition with exactly one free buffer.
0076    */
0077   rtems_id part_one;
0078 
0079   /**
0080    * @brief This member provides a partition with exactly 100 free buffers.
0081    */
0082   rtems_id part_many;
0083 
0084   /**
0085    * @brief This member provides a status code.
0086    */
0087   rtems_status_code status;
0088 
0089   /**
0090    * @brief This member provides a buffer pointer.
0091    */
0092   void *buffer;
0093 
0094   /**
0095    * @brief This member provides a second buffer pointer.
0096    */
0097   void *buffer_2;
0098 
0099   /**
0100    * @brief This member references the measure runtime context.
0101    */
0102   T_measure_runtime_context *context;
0103 
0104   /**
0105    * @brief This member provides the measure runtime request.
0106    */
0107   T_measure_runtime_request request;
0108 
0109   /**
0110    * @brief This member provides an optional measurement begin time point.
0111    */
0112   T_ticks begin;
0113 
0114   /**
0115    * @brief This member provides an optional measurement end time point.
0116    */
0117   T_ticks end;
0118 } RtemsPartValPerf_Context;
0119 
0120 static RtemsPartValPerf_Context
0121   RtemsPartValPerf_Instance;
0122 
0123 static void RtemsPartValPerf_Setup_Context( RtemsPartValPerf_Context *ctx )
0124 {
0125   T_measure_runtime_config config;
0126 
0127   memset( &config, 0, sizeof( config ) );
0128   config.sample_count = 100;
0129   ctx->request.arg = ctx;
0130   ctx->request.flags = T_MEASURE_RUNTIME_REPORT_SAMPLES;
0131   ctx->context = T_measure_runtime_create( &config );
0132   T_assert_not_null( ctx->context );
0133 }
0134 
0135 /**
0136  * @brief Creates the test partition.
0137  */
0138 static void RtemsPartValPerf_Setup( RtemsPartValPerf_Context *ctx )
0139 {
0140   rtems_status_code sc;
0141   size_t            size;
0142   void             *area;
0143   uintptr_t         length;
0144 
0145   size = 2 * sizeof( uintptr_t );
0146 
0147   area = T_malloc( size );
0148   sc = rtems_partition_create(
0149     rtems_build_name( ' ', 'O', 'N', 'E' ),
0150     area,
0151     size,
0152     size,
0153     RTEMS_DEFAULT_ATTRIBUTES,
0154     &ctx->part_one
0155   );
0156   T_assert_rsc_success( sc );
0157 
0158   length = 100 * size;
0159   area = T_malloc( length );
0160   sc = rtems_partition_create(
0161     rtems_build_name( 'M', 'A', 'N', 'Y' ),
0162     area,
0163     length,
0164     size,
0165     RTEMS_DEFAULT_ATTRIBUTES,
0166     &ctx->part_many
0167   );
0168   T_assert_rsc_success( sc );
0169 }
0170 
0171 static void RtemsPartValPerf_Setup_Wrap( void *arg )
0172 {
0173   RtemsPartValPerf_Context *ctx;
0174 
0175   ctx = arg;
0176   RtemsPartValPerf_Setup_Context( ctx );
0177   RtemsPartValPerf_Setup( ctx );
0178 }
0179 
0180 /**
0181  * @brief Deletes the test partition.
0182  */
0183 static void RtemsPartValPerf_Teardown( RtemsPartValPerf_Context *ctx )
0184 {
0185   rtems_status_code sc;
0186 
0187   if ( ctx->part_one != 0 ) {
0188     sc = rtems_partition_delete( ctx->part_one );
0189     T_rsc_success( sc );
0190   }
0191 
0192   if ( ctx->part_many != 0 ) {
0193     sc = rtems_partition_delete( ctx->part_many );
0194     T_rsc_success( sc );
0195   }
0196 }
0197 
0198 static void RtemsPartValPerf_Teardown_Wrap( void *arg )
0199 {
0200   RtemsPartValPerf_Context *ctx;
0201 
0202   ctx = arg;
0203   RtemsPartValPerf_Teardown( ctx );
0204 }
0205 
0206 static T_fixture RtemsPartValPerf_Fixture = {
0207   .setup = RtemsPartValPerf_Setup_Wrap,
0208   .stop = NULL,
0209   .teardown = RtemsPartValPerf_Teardown_Wrap,
0210   .scope = NULL,
0211   .initial_context = &RtemsPartValPerf_Instance
0212 };
0213 
0214 /**
0215  * @defgroup RtemsPartReqPerfGetBuffer spec:/rtems/part/req/perf-get-buffer
0216  *
0217  * @{
0218  */
0219 
0220 /**
0221  * @brief Get a buffer.
0222  */
0223 static void RtemsPartReqPerfGetBuffer_Body( RtemsPartValPerf_Context *ctx )
0224 {
0225   ctx->status = rtems_partition_get_buffer( ctx->part_many, &ctx->buffer );
0226 }
0227 
0228 static void RtemsPartReqPerfGetBuffer_Body_Wrap( void *arg )
0229 {
0230   RtemsPartValPerf_Context *ctx;
0231 
0232   ctx = arg;
0233   RtemsPartReqPerfGetBuffer_Body( ctx );
0234 }
0235 
0236 /**
0237  * @brief Return the buffer.
0238  */
0239 static bool RtemsPartReqPerfGetBuffer_Teardown(
0240   RtemsPartValPerf_Context *ctx,
0241   T_ticks                  *delta,
0242   uint32_t                  tic,
0243   uint32_t                  toc,
0244   unsigned int              retry
0245 )
0246 {
0247   rtems_status_code sc;
0248 
0249   T_quiet_rsc_success( ctx->status );
0250 
0251   sc = rtems_partition_return_buffer( ctx->part_many, ctx->buffer );
0252   T_quiet_rsc_success( sc );
0253 
0254   return tic == toc;
0255 }
0256 
0257 static bool RtemsPartReqPerfGetBuffer_Teardown_Wrap(
0258   void        *arg,
0259   T_ticks     *delta,
0260   uint32_t     tic,
0261   uint32_t     toc,
0262   unsigned int retry
0263 )
0264 {
0265   RtemsPartValPerf_Context *ctx;
0266 
0267   ctx = arg;
0268   return RtemsPartReqPerfGetBuffer_Teardown( ctx, delta, tic, toc, retry );
0269 }
0270 
0271 /** @} */
0272 
0273 /**
0274  * @defgroup RtemsPartReqPerfGetNoBuffer \
0275  *   spec:/rtems/part/req/perf-get-no-buffer
0276  *
0277  * @{
0278  */
0279 
0280 /**
0281  * @brief Get the buffer.
0282  */
0283 static void RtemsPartReqPerfGetNoBuffer_Prepare(
0284   RtemsPartValPerf_Context *ctx
0285 )
0286 {
0287   rtems_status_code sc;
0288 
0289   sc = rtems_partition_get_buffer( ctx->part_one, &ctx->buffer_2 );
0290   T_rsc_success( sc );
0291 }
0292 
0293 /**
0294  * @brief Try to get a buffer.
0295  */
0296 static void RtemsPartReqPerfGetNoBuffer_Body( RtemsPartValPerf_Context *ctx )
0297 {
0298   ctx->status = rtems_partition_get_buffer( ctx->part_one, &ctx->buffer );
0299 }
0300 
0301 static void RtemsPartReqPerfGetNoBuffer_Body_Wrap( void *arg )
0302 {
0303   RtemsPartValPerf_Context *ctx;
0304 
0305   ctx = arg;
0306   RtemsPartReqPerfGetNoBuffer_Body( ctx );
0307 }
0308 
0309 /**
0310  * @brief Check the status code.
0311  */
0312 static bool RtemsPartReqPerfGetNoBuffer_Teardown(
0313   RtemsPartValPerf_Context *ctx,
0314   T_ticks                  *delta,
0315   uint32_t                  tic,
0316   uint32_t                  toc,
0317   unsigned int              retry
0318 )
0319 {
0320   T_quiet_rsc( ctx->status, RTEMS_UNSATISFIED );
0321 
0322   return tic == toc;
0323 }
0324 
0325 static bool RtemsPartReqPerfGetNoBuffer_Teardown_Wrap(
0326   void        *arg,
0327   T_ticks     *delta,
0328   uint32_t     tic,
0329   uint32_t     toc,
0330   unsigned int retry
0331 )
0332 {
0333   RtemsPartValPerf_Context *ctx;
0334 
0335   ctx = arg;
0336   return RtemsPartReqPerfGetNoBuffer_Teardown( ctx, delta, tic, toc, retry );
0337 }
0338 
0339 /**
0340  * @brief Return the buffer.
0341  */
0342 static void RtemsPartReqPerfGetNoBuffer_Cleanup(
0343   RtemsPartValPerf_Context *ctx
0344 )
0345 {
0346   rtems_status_code sc;
0347 
0348   sc = rtems_partition_return_buffer( ctx->part_one, ctx->buffer_2 );
0349   T_rsc_success( sc );
0350 }
0351 
0352 /** @} */
0353 
0354 /**
0355  * @defgroup RtemsPartReqPerfReturnBuffer \
0356  *   spec:/rtems/part/req/perf-return-buffer
0357  *
0358  * @{
0359  */
0360 
0361 /**
0362  * @brief Get the buffer.
0363  */
0364 static void RtemsPartReqPerfReturnBuffer_Setup( RtemsPartValPerf_Context *ctx )
0365 {
0366   rtems_status_code sc;
0367 
0368   sc = rtems_partition_get_buffer( ctx->part_many, &ctx->buffer );
0369   T_quiet_rsc_success( sc );
0370 }
0371 
0372 static void RtemsPartReqPerfReturnBuffer_Setup_Wrap( void *arg )
0373 {
0374   RtemsPartValPerf_Context *ctx;
0375 
0376   ctx = arg;
0377   RtemsPartReqPerfReturnBuffer_Setup( ctx );
0378 }
0379 
0380 /**
0381  * @brief Return the buffer.
0382  */
0383 static void RtemsPartReqPerfReturnBuffer_Body( RtemsPartValPerf_Context *ctx )
0384 {
0385   ctx->status = rtems_partition_return_buffer( ctx->part_many, ctx->buffer );
0386 }
0387 
0388 static void RtemsPartReqPerfReturnBuffer_Body_Wrap( void *arg )
0389 {
0390   RtemsPartValPerf_Context *ctx;
0391 
0392   ctx = arg;
0393   RtemsPartReqPerfReturnBuffer_Body( ctx );
0394 }
0395 
0396 /**
0397  * @brief Check the status code.
0398  */
0399 static bool RtemsPartReqPerfReturnBuffer_Teardown(
0400   RtemsPartValPerf_Context *ctx,
0401   T_ticks                  *delta,
0402   uint32_t                  tic,
0403   uint32_t                  toc,
0404   unsigned int              retry
0405 )
0406 {
0407   T_quiet_rsc( ctx->status, RTEMS_SUCCESSFUL );
0408 
0409   return tic == toc;
0410 }
0411 
0412 static bool RtemsPartReqPerfReturnBuffer_Teardown_Wrap(
0413   void        *arg,
0414   T_ticks     *delta,
0415   uint32_t     tic,
0416   uint32_t     toc,
0417   unsigned int retry
0418 )
0419 {
0420   RtemsPartValPerf_Context *ctx;
0421 
0422   ctx = arg;
0423   return RtemsPartReqPerfReturnBuffer_Teardown( ctx, delta, tic, toc, retry );
0424 }
0425 
0426 /** @} */
0427 
0428 /**
0429  * @fn void T_case_body_RtemsPartValPerf( void )
0430  */
0431 T_TEST_CASE_FIXTURE( RtemsPartValPerf, &RtemsPartValPerf_Fixture )
0432 {
0433   RtemsPartValPerf_Context *ctx;
0434 
0435   ctx = T_fixture_context();
0436 
0437   ctx->request.name = "RtemsPartReqPerfGetBuffer";
0438   ctx->request.setup = NULL;
0439   ctx->request.body = RtemsPartReqPerfGetBuffer_Body_Wrap;
0440   ctx->request.teardown = RtemsPartReqPerfGetBuffer_Teardown_Wrap;
0441   T_measure_runtime( ctx->context, &ctx->request );
0442 
0443   RtemsPartReqPerfGetNoBuffer_Prepare( ctx );
0444   ctx->request.name = "RtemsPartReqPerfGetNoBuffer";
0445   ctx->request.setup = NULL;
0446   ctx->request.body = RtemsPartReqPerfGetNoBuffer_Body_Wrap;
0447   ctx->request.teardown = RtemsPartReqPerfGetNoBuffer_Teardown_Wrap;
0448   T_measure_runtime( ctx->context, &ctx->request );
0449   RtemsPartReqPerfGetNoBuffer_Cleanup( ctx );
0450 
0451   ctx->request.name = "RtemsPartReqPerfReturnBuffer";
0452   ctx->request.setup = RtemsPartReqPerfReturnBuffer_Setup_Wrap;
0453   ctx->request.body = RtemsPartReqPerfReturnBuffer_Body_Wrap;
0454   ctx->request.teardown = RtemsPartReqPerfReturnBuffer_Teardown_Wrap;
0455   T_measure_runtime( ctx->context, &ctx->request );
0456 }
0457 
0458 /** @} */