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 RtemsCacheValCache
0007  */
0008 
0009 /*
0010  * Copyright (C) 2021 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 RtemsCacheValCache spec:/rtems/cache/val/cache
0061  *
0062  * @ingroup TestsuitesValidationCache
0063  *
0064  * @brief Tests some @ref RTEMSAPIClassicCache directives.
0065  *
0066  * This test case performs the following actions:
0067  *
0068  * - Call the rtems_cache_enable_data() directive.
0069  *
0070  * - Call the rtems_cache_enable_data() directive with maskable interrupts
0071  *   disabled.
0072  *
0073  * - Call the rtems_cache_disable_instruction() and
0074  *   rtems_cache_enable_instruction() directives.
0075  *
0076  * - Call the rtems_cache_disable_instruction() and
0077  *   rtems_cache_enable_instruction() directives with maskable interrupts
0078  *   disabled.
0079  *
0080  * - Call the rtems_cache_freeze_data() and rtems_cache_unfreeze_data()
0081  *   directives.
0082  *
0083  * - Call the rtems_cache_freeze_data() and rtems_cache_unfreeze_data()
0084  *   directives with maskable interrupts disabled.
0085  *
0086  * - Call the rtems_cache_freeze_instruction() and
0087  *   rtems_cache_unfreeze_instruction() directives.
0088  *
0089  * - Call the rtems_cache_freeze_instruction() and
0090  *   rtems_cache_unfreeze_instruction() directives with maskable interrupts
0091  *   disabled.
0092  *
0093  * - Call the rtems_cache_invalidate_entire_instruction() directive.
0094  *
0095  * - Call the rtems_cache_invalidate_entire_instruction() directive with
0096  *   maskable interrupts disabled.
0097  *
0098  * - Call the rtems_cache_flush_entire_data() directive.
0099  *
0100  * - Call the rtems_cache_flush_entire_data() directive with maskable
0101  *   interrupts disabled.
0102  *
0103  * - Call the rtems_cache_flush_multiple_data_lines() directive with a sample
0104  *   set of memory areas.
0105  *
0106  * - Call the rtems_cache_flush_multiple_data_lines() directive with a sample
0107  *   set of memory areas with maskable interrupts disabled.
0108  *
0109  * - Call the rtems_cache_invalidate_multiple_data_lines() directive with a
0110  *   sample set of memory areas.
0111  *
0112  * - Call the rtems_cache_invalidate_multiple_data_lines() directive with a
0113  *   sample set of memory areas with maskable interrupts disabled.
0114  *
0115  * - Call the rtems_cache_invalidate_multiple_instruction_lines() directive
0116  *   with a sample set of memory areas.
0117  *
0118  * - Call the rtems_cache_invalidate_multiple_instruction_lines() directive
0119  *   with a sample set of memory areas with maskable interrupts disabled.
0120  *
0121  * - Call the rtems_cache_instruction_sync_after_code_change() directive with a
0122  *   sample set of memory areas.
0123  *
0124  * - Call the rtems_cache_instruction_sync_after_code_change() directive with a
0125  *   sample set of memory areas with maskable interrupts disabled.
0126  *
0127  * - Call the rtems_cache_get_data_line_size(),
0128  *   rtems_cache_get_instruction_line_size(), and the
0129  *   rtems_cache_get_maximal_line_size() directives.
0130  *
0131  *   - Check that the maximal cache line size is greater than or equal to the
0132  *     data cache line size.
0133  *
0134  *   - Check that the maximal cache line size is greater than or equal to the
0135  *     instruction cache line size.
0136  *
0137  * - Call the rtems_cache_get_data_line_size(),
0138  *   rtems_cache_get_instruction_line_size(), and the
0139  *   rtems_cache_get_maximal_line_size() directives with maskable interrupts
0140  *   disabled.
0141  *
0142  *   - Check that the maximal cache line size is greater than or equal to the
0143  *     data cache line size.
0144  *
0145  *   - Check that the maximal cache line size is greater than or equal to the
0146  *     instruction cache line size.
0147  *
0148  * - Call the rtems_cache_get_data_cache_size() directive with increasing level
0149  *   starting with zero until it returns zero.
0150  *
0151  * - Call the rtems_cache_get_data_cache_size() directive with increasing level
0152  *   starting with zero until it returns zero with maskable interrupts
0153  *   disabled.
0154  *
0155  * - Call the rtems_cache_get_instruction_cache_size() directive with
0156  *   increasing level starting with zero until it returns zero.
0157  *
0158  * - Call the rtems_cache_get_instruction_cache_size() directive with
0159  *   increasing level starting with zero until it returns zero with maskable
0160  *   interrupts disabled.
0161  *
0162  * @{
0163  */
0164 
0165 static void CallFlushMultipleDataLines( void )
0166 {
0167   uint8_t buf[ 256 ];
0168   uintptr_t data;
0169   uintptr_t n;
0170   uintptr_t i;
0171 
0172   rtems_cache_flush_multiple_data_lines( NULL, 0 );
0173   data = RTEMS_ALIGN_UP( (uintptr_t) &buf[ 1 ], 128 );
0174 
0175   for ( n = 16; n <= 128 ; n *= 2 ) {
0176     for ( i = 0; i < 3; ++i ) {
0177       uintptr_t j;
0178 
0179       for ( j = 0; j < 3; ++j ) {
0180         rtems_cache_flush_multiple_data_lines(
0181           (const void *) ( data + 1 - i ),
0182           n + 1 - j
0183         );
0184       }
0185     }
0186   }
0187 }
0188 
0189 static void CallInvalidateMultipleDataLines( void )
0190 {
0191   uint8_t buf[ 384 ];
0192   uintptr_t data;
0193   uintptr_t n;
0194   uintptr_t i;
0195 
0196   rtems_cache_invalidate_multiple_data_lines( NULL, 0 );
0197   data = RTEMS_ALIGN_UP( (uintptr_t) &buf[ 128 ], 128 );
0198 
0199   for ( n = 16; n <= 128 ; n *= 2 ) {
0200     for ( i = 0; i < 3; ++i ) {
0201       uintptr_t j;
0202 
0203       for ( j = 0; j < 3; ++j ) {
0204         rtems_cache_invalidate_multiple_data_lines(
0205           (const void *) ( data + 1 - i ),
0206           n + 1 - j
0207         );
0208       }
0209     }
0210   }
0211 }
0212 
0213 static void CallInvalidateMultipleInstructionLines( void )
0214 {
0215   uintptr_t data;
0216   uintptr_t n;
0217   uintptr_t i;
0218 
0219   rtems_cache_invalidate_multiple_instruction_lines( NULL, 0 );
0220   data = (uintptr_t) rtems_cache_invalidate_multiple_instruction_lines;
0221 
0222   for ( n = 16; n <= 128 ; n *= 2 ) {
0223     for ( i = 0; i < 3; ++i ) {
0224       uintptr_t j;
0225 
0226       for ( j = 0; j < 3; ++j ) {
0227         rtems_cache_invalidate_multiple_instruction_lines(
0228           (const void *) ( data + 1 - i ),
0229           n + 1 - j
0230         );
0231       }
0232     }
0233   }
0234 }
0235 
0236 static void CallInstructionSyncAfterCodeChange( void )
0237 {
0238   uintptr_t data;
0239   uintptr_t n;
0240   uintptr_t i;
0241 
0242   rtems_cache_instruction_sync_after_code_change( NULL, 0 );
0243   data = (uintptr_t) rtems_cache_instruction_sync_after_code_change;
0244 
0245   for ( n = 16; n <= 128 ; n *= 2 ) {
0246     for ( i = 0; i < 3; ++i ) {
0247       uintptr_t j;
0248 
0249       for ( j = 0; j < 3; ++j ) {
0250         rtems_cache_instruction_sync_after_code_change(
0251           (const void *) ( data + 1 - i ),
0252           n + 1 - j
0253         );
0254       }
0255     }
0256   }
0257 }
0258 
0259 static void CallGetDataSize( void )
0260 {
0261   uint32_t level;
0262   size_t   n;
0263 
0264   level = 0;
0265 
0266   do {
0267     n = rtems_cache_get_data_cache_size( level );
0268     ++level;
0269   } while (n != 0 );
0270 }
0271 
0272 static void CallGetInstructionSize( void )
0273 {
0274   uint32_t level;
0275   size_t   n;
0276 
0277   level = 0;
0278 
0279   do {
0280     n = rtems_cache_get_instruction_cache_size( level );
0281     ++level;
0282   } while (n != 0 );
0283 }
0284 
0285 /**
0286  * @brief Call the rtems_cache_enable_data() directive.
0287  */
0288 static void RtemsCacheValCache_Action_0( void )
0289 {
0290   rtems_cache_enable_data();
0291 }
0292 
0293 /**
0294  * @brief Call the rtems_cache_enable_data() directive with maskable interrupts
0295  *   disabled.
0296  */
0297 static void RtemsCacheValCache_Action_1( void )
0298 {
0299   rtems_interrupt_level level;
0300 
0301   rtems_interrupt_local_disable(level);
0302   rtems_cache_enable_data();
0303   rtems_interrupt_local_enable(level);
0304 }
0305 
0306 /**
0307  * @brief Call the rtems_cache_disable_instruction() and
0308  *   rtems_cache_enable_instruction() directives.
0309  */
0310 static void RtemsCacheValCache_Action_2( void )
0311 {
0312   rtems_cache_disable_instruction();
0313   rtems_cache_enable_instruction();
0314 }
0315 
0316 /**
0317  * @brief Call the rtems_cache_disable_instruction() and
0318  *   rtems_cache_enable_instruction() directives with maskable interrupts
0319  *   disabled.
0320  */
0321 static void RtemsCacheValCache_Action_3( void )
0322 {
0323   rtems_interrupt_level level;
0324 
0325   rtems_interrupt_local_disable(level);
0326   rtems_cache_disable_instruction();
0327   rtems_cache_enable_instruction();
0328   rtems_interrupt_local_enable(level);
0329 }
0330 
0331 /**
0332  * @brief Call the rtems_cache_freeze_data() and rtems_cache_unfreeze_data()
0333  *   directives.
0334  */
0335 static void RtemsCacheValCache_Action_4( void )
0336 {
0337   rtems_cache_freeze_data();
0338   rtems_cache_unfreeze_data();
0339 }
0340 
0341 /**
0342  * @brief Call the rtems_cache_freeze_data() and rtems_cache_unfreeze_data()
0343  *   directives with maskable interrupts disabled.
0344  */
0345 static void RtemsCacheValCache_Action_5( void )
0346 {
0347   rtems_interrupt_level level;
0348 
0349   rtems_interrupt_local_disable(level);
0350   rtems_cache_freeze_data();
0351   rtems_cache_unfreeze_data();
0352   rtems_interrupt_local_enable(level);
0353 }
0354 
0355 /**
0356  * @brief Call the rtems_cache_freeze_instruction() and
0357  *   rtems_cache_unfreeze_instruction() directives.
0358  */
0359 static void RtemsCacheValCache_Action_6( void )
0360 {
0361   rtems_cache_freeze_instruction();
0362   rtems_cache_unfreeze_instruction();
0363 }
0364 
0365 /**
0366  * @brief Call the rtems_cache_freeze_instruction() and
0367  *   rtems_cache_unfreeze_instruction() directives with maskable interrupts
0368  *   disabled.
0369  */
0370 static void RtemsCacheValCache_Action_7( void )
0371 {
0372   rtems_interrupt_level level;
0373 
0374   rtems_interrupt_local_disable(level);
0375   rtems_cache_freeze_instruction();
0376   rtems_cache_unfreeze_instruction();
0377   rtems_interrupt_local_enable(level);
0378 }
0379 
0380 /**
0381  * @brief Call the rtems_cache_invalidate_entire_instruction() directive.
0382  */
0383 static void RtemsCacheValCache_Action_8( void )
0384 {
0385   rtems_cache_invalidate_entire_instruction();
0386 }
0387 
0388 /**
0389  * @brief Call the rtems_cache_invalidate_entire_instruction() directive with
0390  *   maskable interrupts disabled.
0391  */
0392 static void RtemsCacheValCache_Action_9( void )
0393 {
0394   rtems_interrupt_level level;
0395 
0396   rtems_interrupt_local_disable(level);
0397   rtems_cache_invalidate_entire_instruction();
0398   rtems_interrupt_local_enable(level);
0399 }
0400 
0401 /**
0402  * @brief Call the rtems_cache_flush_entire_data() directive.
0403  */
0404 static void RtemsCacheValCache_Action_10( void )
0405 {
0406   rtems_cache_flush_entire_data();
0407 }
0408 
0409 /**
0410  * @brief Call the rtems_cache_flush_entire_data() directive with maskable
0411  *   interrupts disabled.
0412  */
0413 static void RtemsCacheValCache_Action_11( void )
0414 {
0415   rtems_interrupt_level level;
0416 
0417   rtems_interrupt_local_disable(level);
0418   rtems_cache_flush_entire_data();
0419   rtems_interrupt_local_enable(level);
0420 }
0421 
0422 /**
0423  * @brief Call the rtems_cache_flush_multiple_data_lines() directive with a
0424  *   sample set of memory areas.
0425  */
0426 static void RtemsCacheValCache_Action_12( void )
0427 {
0428   CallFlushMultipleDataLines();
0429 }
0430 
0431 /**
0432  * @brief Call the rtems_cache_flush_multiple_data_lines() directive with a
0433  *   sample set of memory areas with maskable interrupts disabled.
0434  */
0435 static void RtemsCacheValCache_Action_13( void )
0436 {
0437   rtems_interrupt_level level;
0438 
0439   rtems_interrupt_local_disable(level);
0440   CallFlushMultipleDataLines();
0441   rtems_interrupt_local_enable(level);
0442 }
0443 
0444 /**
0445  * @brief Call the rtems_cache_invalidate_multiple_data_lines() directive with
0446  *   a sample set of memory areas.
0447  */
0448 static void RtemsCacheValCache_Action_14( void )
0449 {
0450   CallInvalidateMultipleDataLines();
0451 }
0452 
0453 /**
0454  * @brief Call the rtems_cache_invalidate_multiple_data_lines() directive with
0455  *   a sample set of memory areas with maskable interrupts disabled.
0456  */
0457 static void RtemsCacheValCache_Action_15( void )
0458 {
0459   rtems_interrupt_level level;
0460 
0461   rtems_interrupt_local_disable(level);
0462   CallInvalidateMultipleDataLines();
0463   rtems_interrupt_local_enable(level);
0464 }
0465 
0466 /**
0467  * @brief Call the rtems_cache_invalidate_multiple_instruction_lines()
0468  *   directive with a sample set of memory areas.
0469  */
0470 static void RtemsCacheValCache_Action_16( void )
0471 {
0472   CallInvalidateMultipleInstructionLines();
0473 }
0474 
0475 /**
0476  * @brief Call the rtems_cache_invalidate_multiple_instruction_lines()
0477  *   directive with a sample set of memory areas with maskable interrupts
0478  *   disabled.
0479  */
0480 static void RtemsCacheValCache_Action_17( void )
0481 {
0482   rtems_interrupt_level level;
0483 
0484   rtems_interrupt_local_disable(level);
0485   CallInvalidateMultipleInstructionLines();
0486   rtems_interrupt_local_enable(level);
0487 }
0488 
0489 /**
0490  * @brief Call the rtems_cache_instruction_sync_after_code_change() directive
0491  *   with a sample set of memory areas.
0492  */
0493 static void RtemsCacheValCache_Action_18( void )
0494 {
0495   CallInstructionSyncAfterCodeChange();
0496 }
0497 
0498 /**
0499  * @brief Call the rtems_cache_instruction_sync_after_code_change() directive
0500  *   with a sample set of memory areas with maskable interrupts disabled.
0501  */
0502 static void RtemsCacheValCache_Action_19( void )
0503 {
0504   rtems_interrupt_level level;
0505 
0506   rtems_interrupt_local_disable(level);
0507   CallInstructionSyncAfterCodeChange();
0508   rtems_interrupt_local_enable(level);
0509 }
0510 
0511 /**
0512  * @brief Call the rtems_cache_get_data_line_size(),
0513  *   rtems_cache_get_instruction_line_size(), and the
0514  *   rtems_cache_get_maximal_line_size() directives.
0515  */
0516 static void RtemsCacheValCache_Action_20( void )
0517 {
0518   size_t data_line_size;
0519   size_t instruction_line_size;
0520   size_t maximal_line_size;
0521 
0522   data_line_size = rtems_cache_get_data_line_size();
0523   instruction_line_size = rtems_cache_get_instruction_line_size();
0524   maximal_line_size = rtems_cache_get_maximal_line_size();
0525 
0526   /*
0527    * Check that the maximal cache line size is greater than or equal to the
0528    * data cache line size.
0529    */
0530   T_step_ge_sz( 0, maximal_line_size, data_line_size );
0531 
0532   /*
0533    * Check that the maximal cache line size is greater than or equal to the
0534    * instruction cache line size.
0535    */
0536   T_step_ge_sz( 1, maximal_line_size, instruction_line_size );
0537 }
0538 
0539 /**
0540  * @brief Call the rtems_cache_get_data_line_size(),
0541  *   rtems_cache_get_instruction_line_size(), and the
0542  *   rtems_cache_get_maximal_line_size() directives with maskable interrupts
0543  *   disabled.
0544  */
0545 static void RtemsCacheValCache_Action_21( void )
0546 {
0547   size_t data_line_size;
0548   size_t instruction_line_size;
0549   size_t maximal_line_size;
0550   rtems_interrupt_level level;
0551 
0552   rtems_interrupt_local_disable(level);
0553   data_line_size = rtems_cache_get_data_line_size();
0554   instruction_line_size = rtems_cache_get_instruction_line_size();
0555   maximal_line_size = rtems_cache_get_maximal_line_size();
0556   rtems_interrupt_local_enable(level);
0557 
0558   /*
0559    * Check that the maximal cache line size is greater than or equal to the
0560    * data cache line size.
0561    */
0562   T_step_ge_sz( 2, maximal_line_size, data_line_size );
0563 
0564   /*
0565    * Check that the maximal cache line size is greater than or equal to the
0566    * instruction cache line size.
0567    */
0568   T_step_ge_sz( 3, maximal_line_size, instruction_line_size );
0569 }
0570 
0571 /**
0572  * @brief Call the rtems_cache_get_data_cache_size() directive with increasing
0573  *   level starting with zero until it returns zero.
0574  */
0575 static void RtemsCacheValCache_Action_22( void )
0576 {
0577   CallGetDataSize();
0578 }
0579 
0580 /**
0581  * @brief Call the rtems_cache_get_data_cache_size() directive with increasing
0582  *   level starting with zero until it returns zero with maskable interrupts
0583  *   disabled.
0584  */
0585 static void RtemsCacheValCache_Action_23( void )
0586 {
0587   rtems_interrupt_level level;
0588 
0589   rtems_interrupt_local_disable(level);
0590   CallGetDataSize();
0591   rtems_interrupt_local_enable(level);
0592 }
0593 
0594 /**
0595  * @brief Call the rtems_cache_get_instruction_cache_size() directive with
0596  *   increasing level starting with zero until it returns zero.
0597  */
0598 static void RtemsCacheValCache_Action_24( void )
0599 {
0600   CallGetInstructionSize();
0601 }
0602 
0603 /**
0604  * @brief Call the rtems_cache_get_instruction_cache_size() directive with
0605  *   increasing level starting with zero until it returns zero with maskable
0606  *   interrupts disabled.
0607  */
0608 static void RtemsCacheValCache_Action_25( void )
0609 {
0610   rtems_interrupt_level level;
0611 
0612   rtems_interrupt_local_disable(level);
0613   CallGetInstructionSize();
0614   rtems_interrupt_local_enable(level);
0615 }
0616 
0617 /**
0618  * @fn void T_case_body_RtemsCacheValCache( void )
0619  */
0620 T_TEST_CASE( RtemsCacheValCache )
0621 {
0622   T_plan( 4 );
0623 
0624   RtemsCacheValCache_Action_0();
0625   RtemsCacheValCache_Action_1();
0626   RtemsCacheValCache_Action_2();
0627   RtemsCacheValCache_Action_3();
0628   RtemsCacheValCache_Action_4();
0629   RtemsCacheValCache_Action_5();
0630   RtemsCacheValCache_Action_6();
0631   RtemsCacheValCache_Action_7();
0632   RtemsCacheValCache_Action_8();
0633   RtemsCacheValCache_Action_9();
0634   RtemsCacheValCache_Action_10();
0635   RtemsCacheValCache_Action_11();
0636   RtemsCacheValCache_Action_12();
0637   RtemsCacheValCache_Action_13();
0638   RtemsCacheValCache_Action_14();
0639   RtemsCacheValCache_Action_15();
0640   RtemsCacheValCache_Action_16();
0641   RtemsCacheValCache_Action_17();
0642   RtemsCacheValCache_Action_18();
0643   RtemsCacheValCache_Action_19();
0644   RtemsCacheValCache_Action_20();
0645   RtemsCacheValCache_Action_21();
0646   RtemsCacheValCache_Action_22();
0647   RtemsCacheValCache_Action_23();
0648   RtemsCacheValCache_Action_24();
0649   RtemsCacheValCache_Action_25();
0650 }
0651 
0652 /** @} */