forked from Imagelibrary/rtems
validation: Test C libary functions
The test source code is generated from specification items by the "./spec2modules.py" script contained in the git://git.rtems.org/rtems-central.git Git repository. Please read the "How-To" section in the "Software Requirements Engineering" chapter of the RTEMS Software Engineering manual to get more information about the process. Update #3716.
This commit is contained in:
@@ -20,6 +20,7 @@ source:
|
||||
- testsuites/validation/tc-barrier-wait.c
|
||||
- testsuites/validation/tc-basedefs.c
|
||||
- testsuites/validation/tc-basedefs-pendant.c
|
||||
- testsuites/validation/tc-c.c
|
||||
- testsuites/validation/tc-clock.c
|
||||
- testsuites/validation/tc-clock-get-tod.c
|
||||
- testsuites/validation/tc-clock-get-uptime.c
|
||||
@@ -27,6 +28,7 @@ source:
|
||||
- testsuites/validation/tc-clock-set.c
|
||||
- testsuites/validation/tc-cpuuse.c
|
||||
- testsuites/validation/tc-events.c
|
||||
- testsuites/validation/tc-flsl.c
|
||||
- testsuites/validation/tc-futex-wait.c
|
||||
- testsuites/validation/tc-futex-wake.c
|
||||
- testsuites/validation/tc-intr.c
|
||||
|
||||
189
testsuites/validation/tc-c.c
Normal file
189
testsuites/validation/tc-c.c
Normal file
@@ -0,0 +1,189 @@
|
||||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @ingroup RTEMSTestCaseCValC
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2021 embedded brains GmbH (http://www.embedded-brains.de)
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file is part of the RTEMS quality process and was automatically
|
||||
* generated. If you find something that needs to be fixed or
|
||||
* worded better please post a report or patch to an RTEMS mailing list
|
||||
* or raise a bug report:
|
||||
*
|
||||
* https://www.rtems.org/bugs.html
|
||||
*
|
||||
* For information on updating and regenerating please refer to the How-To
|
||||
* section in the Software Requirements Engineering chapter of the
|
||||
* RTEMS Software Engineering manual. The manual is provided as a part of
|
||||
* a release. For development sources please refer to the online
|
||||
* documentation at:
|
||||
*
|
||||
* https://docs.rtems.org
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <rtems.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <rtems/test.h>
|
||||
|
||||
/**
|
||||
* @defgroup RTEMSTestCaseCValC spec:/c/val/c
|
||||
*
|
||||
* @ingroup RTEMSTestSuiteTestsuitesValidationNoClock0
|
||||
*
|
||||
* @brief Tests C library functions.
|
||||
*
|
||||
* This test case performs the following actions:
|
||||
*
|
||||
* - Call memcpy() for a sample set of buffers.
|
||||
*
|
||||
* - Call memset() for a sample set of buffers.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
static void Clear( volatile uint8_t *b, const volatile uint8_t *e )
|
||||
{
|
||||
while ( b != e ) {
|
||||
*b = 0;
|
||||
++b;
|
||||
}
|
||||
}
|
||||
|
||||
static bool Compare(
|
||||
volatile uint8_t *b,
|
||||
const volatile uint8_t *e,
|
||||
uint8_t expected
|
||||
)
|
||||
{
|
||||
bool result;
|
||||
|
||||
result = true;
|
||||
|
||||
while ( b != e ) {
|
||||
result = result && *b == expected;
|
||||
++b;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Call memcpy() for a sample set of buffers.
|
||||
*/
|
||||
static void CValC_Action_0( void )
|
||||
{
|
||||
uint8_t src[sizeof( long ) * 10];
|
||||
uint8_t dst[sizeof( long ) * 10];
|
||||
uint8_t *begin;
|
||||
uint8_t *end;
|
||||
uint8_t *aligned_src;
|
||||
uint8_t *aligned_dst;
|
||||
size_t offset_src;
|
||||
|
||||
memset( src, 0x85, sizeof( src ) );
|
||||
begin = dst;
|
||||
end = begin + sizeof( dst );
|
||||
aligned_src = (uint8_t *) RTEMS_ALIGN_UP( (uintptr_t) src, sizeof( long ) );
|
||||
aligned_dst = (uint8_t *) RTEMS_ALIGN_UP( (uintptr_t) dst, sizeof( long ) );
|
||||
|
||||
for ( offset_src = 0; offset_src < sizeof( long ); ++offset_src ) {
|
||||
size_t offset_dst;
|
||||
|
||||
for ( offset_dst = 0; offset_dst < sizeof( long ); ++offset_dst ) {
|
||||
size_t size;
|
||||
|
||||
for ( size = 0; size < sizeof( long ) * 8; ++size ) {
|
||||
uint8_t *s;
|
||||
uint8_t *p;
|
||||
uint8_t *q;
|
||||
|
||||
s = aligned_src + offset_src;
|
||||
p = aligned_dst + offset_dst;
|
||||
q = p + size;
|
||||
|
||||
Clear( begin, end );
|
||||
memcpy( p, s, size );
|
||||
T_true( Compare( begin, p, 0 ) );
|
||||
T_true( Compare( p, q, 0x85 ) );
|
||||
T_true( Compare( q, end, 0 ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Call memset() for a sample set of buffers.
|
||||
*/
|
||||
static void CValC_Action_1( void )
|
||||
{
|
||||
uint8_t dst[sizeof( long ) * 10];
|
||||
uint8_t *begin;
|
||||
uint8_t *end;
|
||||
uint8_t *aligned;
|
||||
size_t offset;
|
||||
|
||||
begin = dst;
|
||||
end = begin + sizeof( dst );
|
||||
aligned = (uint8_t *) RTEMS_ALIGN_UP( (uintptr_t) dst, sizeof( long ) );
|
||||
|
||||
for ( offset = 0; offset < sizeof( long ); ++offset ) {
|
||||
size_t size;
|
||||
|
||||
for ( size = 0; size < sizeof( long ) * 8; ++size ) {
|
||||
uint8_t *p;
|
||||
uint8_t *q;
|
||||
|
||||
p = aligned + offset;
|
||||
q = p + size;
|
||||
|
||||
Clear( begin, end );
|
||||
memset( p, 0x85, size );
|
||||
T_true( Compare( begin, p, 0 ) );
|
||||
T_true( Compare( p, q, 0x85 ) );
|
||||
T_true( Compare( q, end, 0 ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @fn void T_case_body_CValC( void )
|
||||
*/
|
||||
T_TEST_CASE( CValC )
|
||||
{
|
||||
CValC_Action_0();
|
||||
CValC_Action_1();
|
||||
}
|
||||
|
||||
/** @} */
|
||||
275
testsuites/validation/tc-flsl.c
Normal file
275
testsuites/validation/tc-flsl.c
Normal file
@@ -0,0 +1,275 @@
|
||||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @ingroup RTEMSTestCaseCReqFlsl
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2021 embedded brains GmbH (http://www.embedded-brains.de)
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file is part of the RTEMS quality process and was automatically
|
||||
* generated. If you find something that needs to be fixed or
|
||||
* worded better please post a report or patch to an RTEMS mailing list
|
||||
* or raise a bug report:
|
||||
*
|
||||
* https://www.rtems.org/bugs.html
|
||||
*
|
||||
* For information on updating and regenerating please refer to the How-To
|
||||
* section in the Software Requirements Engineering chapter of the
|
||||
* RTEMS Software Engineering manual. The manual is provided as a part of
|
||||
* a release. For development sources please refer to the online
|
||||
* documentation at:
|
||||
*
|
||||
* https://docs.rtems.org
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <limits.h>
|
||||
#include <strings.h>
|
||||
|
||||
#include <rtems/test.h>
|
||||
|
||||
/**
|
||||
* @defgroup RTEMSTestCaseCReqFlsl spec:/c/req/flsl
|
||||
*
|
||||
* @ingroup RTEMSTestSuiteTestsuitesValidationNoClock0
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
typedef enum {
|
||||
CReqFlsl_Pre_Value_Zero,
|
||||
CReqFlsl_Pre_Value_NonZero,
|
||||
CReqFlsl_Pre_Value_NA
|
||||
} CReqFlsl_Pre_Value;
|
||||
|
||||
typedef enum {
|
||||
CReqFlsl_Post_Result_Zero,
|
||||
CReqFlsl_Post_Result_LastBitSet,
|
||||
CReqFlsl_Post_Result_NA
|
||||
} CReqFlsl_Post_Result;
|
||||
|
||||
typedef struct {
|
||||
uint8_t Skip : 1;
|
||||
uint8_t Pre_Value_NA : 1;
|
||||
uint8_t Post_Result : 2;
|
||||
} CReqFlsl_Entry;
|
||||
|
||||
/**
|
||||
* @brief Test context for spec:/c/req/flsl test case.
|
||||
*/
|
||||
typedef struct {
|
||||
struct {
|
||||
/**
|
||||
* @brief This member defines the pre-condition states for the next action.
|
||||
*/
|
||||
size_t pcs[ 1 ];
|
||||
|
||||
/**
|
||||
* @brief If this member is true, then the test action loop is executed.
|
||||
*/
|
||||
bool in_action_loop;
|
||||
|
||||
/**
|
||||
* @brief This member contains the next transition map index.
|
||||
*/
|
||||
size_t index;
|
||||
|
||||
/**
|
||||
* @brief This member contains the current transition map entry.
|
||||
*/
|
||||
CReqFlsl_Entry entry;
|
||||
|
||||
/**
|
||||
* @brief If this member is true, then the current transition variant
|
||||
* should be skipped.
|
||||
*/
|
||||
bool skip;
|
||||
} Map;
|
||||
} CReqFlsl_Context;
|
||||
|
||||
static CReqFlsl_Context
|
||||
CReqFlsl_Instance;
|
||||
|
||||
static const char * const CReqFlsl_PreDesc_Value[] = {
|
||||
"Zero",
|
||||
"NonZero",
|
||||
"NA"
|
||||
};
|
||||
|
||||
static const char * const * const CReqFlsl_PreDesc[] = {
|
||||
CReqFlsl_PreDesc_Value,
|
||||
NULL
|
||||
};
|
||||
|
||||
static void CReqFlsl_Pre_Value_Prepare(
|
||||
CReqFlsl_Context *ctx,
|
||||
CReqFlsl_Pre_Value state
|
||||
)
|
||||
{
|
||||
switch ( state ) {
|
||||
case CReqFlsl_Pre_Value_Zero: {
|
||||
/*
|
||||
* While the parameter value is equal to zero.
|
||||
*/
|
||||
/* Nothing to prepare */
|
||||
break;
|
||||
}
|
||||
|
||||
case CReqFlsl_Pre_Value_NonZero: {
|
||||
/*
|
||||
* While the parameter value is not equal to zero.
|
||||
*/
|
||||
/* Nothing to prepare */
|
||||
break;
|
||||
}
|
||||
|
||||
case CReqFlsl_Pre_Value_NA:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void CReqFlsl_Post_Result_Check(
|
||||
CReqFlsl_Context *ctx,
|
||||
CReqFlsl_Post_Result state
|
||||
)
|
||||
{
|
||||
int expected_result;
|
||||
long value;
|
||||
size_t i;
|
||||
|
||||
switch ( state ) {
|
||||
case CReqFlsl_Post_Result_Zero: {
|
||||
/*
|
||||
* The return value of flsl() shall be equal to zero.
|
||||
*/
|
||||
T_eq_int( flsl( 0 ), 0 );
|
||||
break;
|
||||
}
|
||||
|
||||
case CReqFlsl_Post_Result_LastBitSet: {
|
||||
/*
|
||||
* The return value of flsl() shall be equal to the index of the
|
||||
* most-significant bit set in the parameter value.
|
||||
*/
|
||||
expected_result = 1;
|
||||
value = 1;
|
||||
|
||||
for ( i = 0; i < sizeof( long ) * CHAR_BIT; ++i ) {
|
||||
T_eq_int( flsl( value ), expected_result );
|
||||
++expected_result;
|
||||
value <<= 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case CReqFlsl_Post_Result_NA:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void CReqFlsl_Action( CReqFlsl_Context *ctx )
|
||||
{
|
||||
/* The action is performed in the post-condition states */
|
||||
}
|
||||
|
||||
static const CReqFlsl_Entry
|
||||
CReqFlsl_Entries[] = {
|
||||
{ 0, 0, CReqFlsl_Post_Result_Zero },
|
||||
{ 0, 0, CReqFlsl_Post_Result_LastBitSet }
|
||||
};
|
||||
|
||||
static const uint8_t
|
||||
CReqFlsl_Map[] = {
|
||||
0, 1
|
||||
};
|
||||
|
||||
static size_t CReqFlsl_Scope( void *arg, char *buf, size_t n )
|
||||
{
|
||||
CReqFlsl_Context *ctx;
|
||||
|
||||
ctx = arg;
|
||||
|
||||
if ( ctx->Map.in_action_loop ) {
|
||||
return T_get_scope( CReqFlsl_PreDesc, buf, n, ctx->Map.pcs );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static T_fixture CReqFlsl_Fixture = {
|
||||
.setup = NULL,
|
||||
.stop = NULL,
|
||||
.teardown = NULL,
|
||||
.scope = CReqFlsl_Scope,
|
||||
.initial_context = &CReqFlsl_Instance
|
||||
};
|
||||
|
||||
static inline CReqFlsl_Entry CReqFlsl_PopEntry( CReqFlsl_Context *ctx )
|
||||
{
|
||||
size_t index;
|
||||
|
||||
index = ctx->Map.index;
|
||||
ctx->Map.index = index + 1;
|
||||
return CReqFlsl_Entries[
|
||||
CReqFlsl_Map[ index ]
|
||||
];
|
||||
}
|
||||
|
||||
static void CReqFlsl_TestVariant( CReqFlsl_Context *ctx )
|
||||
{
|
||||
CReqFlsl_Pre_Value_Prepare( ctx, ctx->Map.pcs[ 0 ] );
|
||||
CReqFlsl_Action( ctx );
|
||||
CReqFlsl_Post_Result_Check( ctx, ctx->Map.entry.Post_Result );
|
||||
}
|
||||
|
||||
/**
|
||||
* @fn void T_case_body_CReqFlsl( void )
|
||||
*/
|
||||
T_TEST_CASE_FIXTURE( CReqFlsl, &CReqFlsl_Fixture )
|
||||
{
|
||||
CReqFlsl_Context *ctx;
|
||||
|
||||
ctx = T_fixture_context();
|
||||
ctx->Map.in_action_loop = true;
|
||||
ctx->Map.index = 0;
|
||||
|
||||
for (
|
||||
ctx->Map.pcs[ 0 ] = CReqFlsl_Pre_Value_Zero;
|
||||
ctx->Map.pcs[ 0 ] < CReqFlsl_Pre_Value_NA;
|
||||
++ctx->Map.pcs[ 0 ]
|
||||
) {
|
||||
ctx->Map.entry = CReqFlsl_PopEntry( ctx );
|
||||
CReqFlsl_TestVariant( ctx );
|
||||
}
|
||||
}
|
||||
|
||||
/** @} */
|
||||
Reference in New Issue
Block a user