forked from Imagelibrary/rtems
validation: Test timecounter
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:
@@ -60,6 +60,12 @@ links:
|
||||
uid: validation-smp-only-1
|
||||
- role: build-dependency
|
||||
uid: validation-smp-only-2
|
||||
- role: build-dependency
|
||||
uid: validation-timecounter-0
|
||||
- role: build-dependency
|
||||
uid: validation-timecounter-1
|
||||
- role: build-dependency
|
||||
uid: validation-timecounter-smp-0
|
||||
type: build
|
||||
use-after:
|
||||
- validation
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
|
||||
build-type: test-program
|
||||
cflags: []
|
||||
copyrights:
|
||||
- Copyright (C) 2021 embedded brains GmbH (http://www.embedded-brains.de)
|
||||
cppflags: []
|
||||
cxxflags: []
|
||||
enabled-by: true
|
||||
features: c cprogram
|
||||
includes: []
|
||||
ldflags: []
|
||||
links: []
|
||||
source:
|
||||
- testsuites/validation/tc-timecounter-install.c
|
||||
- testsuites/validation/ts-validation-timecounter-0.c
|
||||
stlib: []
|
||||
target: testsuites/validation/ts-validation-timecounter-0.exe
|
||||
type: build
|
||||
use-after: []
|
||||
use-before: []
|
||||
@@ -0,0 +1,20 @@
|
||||
SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
|
||||
build-type: test-program
|
||||
cflags: []
|
||||
copyrights:
|
||||
- Copyright (C) 2021 embedded brains GmbH (http://www.embedded-brains.de)
|
||||
cppflags: []
|
||||
cxxflags: []
|
||||
enabled-by: true
|
||||
features: c cprogram
|
||||
includes: []
|
||||
ldflags: []
|
||||
links: []
|
||||
source:
|
||||
- testsuites/validation/tc-timecounter-get.c
|
||||
- testsuites/validation/ts-validation-timecounter-1.c
|
||||
stlib: []
|
||||
target: testsuites/validation/ts-validation-timecounter-1.exe
|
||||
type: build
|
||||
use-after: []
|
||||
use-before: []
|
||||
@@ -0,0 +1,20 @@
|
||||
SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
|
||||
build-type: test-program
|
||||
cflags: []
|
||||
copyrights:
|
||||
- Copyright (C) 2021 embedded brains GmbH (http://www.embedded-brains.de)
|
||||
cppflags: []
|
||||
cxxflags: []
|
||||
enabled-by: RTEMS_SMP
|
||||
features: c cprogram
|
||||
includes: []
|
||||
ldflags: []
|
||||
links: []
|
||||
source:
|
||||
- testsuites/validation/tc-timecounter-get-smp.c
|
||||
- testsuites/validation/ts-validation-timecounter-smp-0.c
|
||||
stlib: []
|
||||
target: testsuites/validation/ts-validation-timecounter-smp-0.exe
|
||||
type: build
|
||||
use-after: []
|
||||
use-before: []
|
||||
741
testsuites/validation/tc-timecounter-get-smp.c
Normal file
741
testsuites/validation/tc-timecounter-get-smp.c
Normal file
@@ -0,0 +1,741 @@
|
||||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @ingroup RTEMSTestCaseScoreTimecounterValGetSmp
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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 <rtems/counter.h>
|
||||
#include <rtems/timecounter.h>
|
||||
#include <rtems/score/smpbarrier.h>
|
||||
#include <rtems/score/threaddispatch.h>
|
||||
|
||||
#include "tx-support.h"
|
||||
|
||||
#include <rtems/test.h>
|
||||
|
||||
/**
|
||||
* @defgroup RTEMSTestCaseScoreTimecounterValGetSmp \
|
||||
* spec:/score/timecounter/val/get-smp
|
||||
*
|
||||
* @ingroup RTEMSTestSuiteTestsuitesValidationTimecounterSmp0
|
||||
*
|
||||
* @brief Tests directives to get a time value.
|
||||
*
|
||||
* This test case performs the following actions:
|
||||
*
|
||||
* - Install timecounter of different quality levels and frequencies.
|
||||
*
|
||||
* - Call the rtems_clock_get_realtime() directive and let it observe a
|
||||
* generation number of zero as well as a generation number change.
|
||||
*
|
||||
* - Call the rtems_clock_get_realtime_bintime() directive and let it observe
|
||||
* a generation number of zero as well as a generation number change.
|
||||
*
|
||||
* - Call the rtems_clock_get_realtime_timeval() directive and let it observe
|
||||
* a generation number of zero as well as a generation number change.
|
||||
*
|
||||
* - Call the rtems_clock_get_monotonic() directive and let it observe a
|
||||
* generation number of zero as well as a generation number change.
|
||||
*
|
||||
* - Call the rtems_clock_get_monotonic_bintime() directive and let it
|
||||
* observe a generation number of zero as well as a generation number
|
||||
* change.
|
||||
*
|
||||
* - Call the rtems_clock_get_monotonic_sbintime() directive and let it
|
||||
* observe a generation number of zero as well as a generation number
|
||||
* change.
|
||||
*
|
||||
* - Call the rtems_clock_get_monotonic_timeval() directive and let it
|
||||
* observe a generation number of zero as well as a generation number
|
||||
* change.
|
||||
*
|
||||
* - Delete the synchronous worker task. Reinitialize the barrier and
|
||||
* barrier states. Start the zero worker task.
|
||||
*
|
||||
* - Call the rtems_clock_get_realtime_coarse() directive and try to let it
|
||||
* observe a generation number of zero.
|
||||
*
|
||||
* - Call the rtems_clock_get_realtime_coarse_bintime() directive and try to
|
||||
* let it observe a generation number of zero.
|
||||
*
|
||||
* - Call the rtems_clock_get_realtime_coarse_timeval() directive and try to
|
||||
* let it observe a generation number of zero.
|
||||
*
|
||||
* - Call the rtems_clock_get_monotonic_coarse() directive and try to let it
|
||||
* observe a generation number of zero.
|
||||
*
|
||||
* - Call the rtems_clock_get_monotonic_coarse_bintime() directive and try to
|
||||
* let it observe a generation number of zero.
|
||||
*
|
||||
* - Call the rtems_clock_get_monotonic_coarse_timeval() directive and try to
|
||||
* let it observe a generation number of zero.
|
||||
*
|
||||
* - Call the rtems_clock_get_boot_time() directive and try to let it observe
|
||||
* a generation number of zero.
|
||||
*
|
||||
* - Call the rtems_clock_get_boot_time_bintime() directive and try to let it
|
||||
* observe a generation number of zero.
|
||||
*
|
||||
* - Call the rtems_clock_get_boot_time_timeval() directive and try to let it
|
||||
* observe a generation number of zero.
|
||||
*
|
||||
* - Delete the zero worker task. Reinitialize the barrier and barrier
|
||||
* states. Start the change worker task.
|
||||
*
|
||||
* - Call the rtems_clock_get_realtime_coarse() directive and try to let it
|
||||
* observe a changing generation number.
|
||||
*
|
||||
* - Call the rtems_clock_get_realtime_coarse_bintime() directive and try to
|
||||
* let it observe a changing generation number.
|
||||
*
|
||||
* - Call the rtems_clock_get_realtime_coarse_timeval() directive and try to
|
||||
* let it observe a changing generation number.
|
||||
*
|
||||
* - Call the rtems_clock_get_monotonic_coarse() directive and try to let it
|
||||
* observe a changing generation number.
|
||||
*
|
||||
* - Call the rtems_clock_get_monotonic_coarse_bintime() directive and try to
|
||||
* let it observe a changing generation number.
|
||||
*
|
||||
* - Call the rtems_clock_get_monotonic_coarse_timeval() directive and try to
|
||||
* let it observe a changing generation number.
|
||||
*
|
||||
* - Call the rtems_clock_get_boot_time() directive and try to let it observe
|
||||
* a changing generation number.
|
||||
*
|
||||
* - Call the rtems_clock_get_boot_time_bintime() directive and try to let it
|
||||
* observe a changing generation number.
|
||||
*
|
||||
* - Call the rtems_clock_get_boot_time_timeval() directive and try to let it
|
||||
* observe a changing generation number.
|
||||
*
|
||||
* - Delete the change worker task.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
struct timecounter base;
|
||||
Atomic_Ulong counter;
|
||||
Atomic_Uint *generation_0;
|
||||
Atomic_Uint *generation_1;
|
||||
SMP_barrier_Control barrier;
|
||||
SMP_barrier_State barrier_state[ 2 ];
|
||||
} Timecounter;
|
||||
|
||||
static Timecounter test_timecounter;
|
||||
|
||||
static uint32_t GetTimecount( struct timecounter *base )
|
||||
{
|
||||
Timecounter *tc;
|
||||
|
||||
tc = (Timecounter *) base;
|
||||
|
||||
return (uint32_t) _Atomic_Fetch_add_ulong(
|
||||
&tc->counter,
|
||||
1,
|
||||
ATOMIC_ORDER_RELAXED
|
||||
);
|
||||
}
|
||||
|
||||
static uint32_t GetTimecountBarrier( struct timecounter *base )
|
||||
{
|
||||
Timecounter *tc;
|
||||
|
||||
tc = (Timecounter *) base;
|
||||
|
||||
/* C0, C1, C2 */
|
||||
_SMP_barrier_Wait( &tc->barrier, &tc->barrier_state[ 0 ], 2 );
|
||||
|
||||
/* D0, D1, D2 */
|
||||
_SMP_barrier_Wait( &tc->barrier, &tc->barrier_state[ 0 ], 2 );
|
||||
|
||||
return GetTimecount( &tc->base );
|
||||
}
|
||||
|
||||
static uint32_t GetCounter( const Timecounter *tc )
|
||||
{
|
||||
return (uint32_t) _Atomic_Load_ulong(
|
||||
&tc->counter,
|
||||
ATOMIC_ORDER_RELAXED
|
||||
);
|
||||
}
|
||||
|
||||
static void SetCounter( Timecounter *tc, uint32_t counter )
|
||||
{
|
||||
_Atomic_Store_ulong(
|
||||
&tc->counter,
|
||||
counter,
|
||||
ATOMIC_ORDER_RELAXED
|
||||
);
|
||||
}
|
||||
|
||||
static void CallTimecounterTick( void )
|
||||
{
|
||||
Per_CPU_Control *cpu_self;
|
||||
|
||||
cpu_self = _Thread_Dispatch_disable();
|
||||
rtems_timecounter_tick();
|
||||
_Thread_Dispatch_enable( cpu_self );
|
||||
}
|
||||
|
||||
static void SetGeneration( Timecounter *tc, unsigned int generation )
|
||||
{
|
||||
_Atomic_Store_uint( tc->generation_0, generation, ATOMIC_ORDER_RELAXED );
|
||||
_Atomic_Store_uint( tc->generation_1, generation, ATOMIC_ORDER_RELAXED );
|
||||
}
|
||||
|
||||
static void PrepareSynchronousWork( Timecounter *tc )
|
||||
{
|
||||
/* A */
|
||||
_SMP_barrier_Wait( &tc->barrier, &tc->barrier_state[ 0 ], 2 );
|
||||
|
||||
SetCounter( tc, 0 );
|
||||
|
||||
/* B */
|
||||
_SMP_barrier_Wait( &tc->barrier, &tc->barrier_state[ 0 ], 2 );
|
||||
}
|
||||
|
||||
static void CleanupSynchronousWork( Timecounter *tc )
|
||||
{
|
||||
/* E */
|
||||
_SMP_barrier_Wait( &tc->barrier, &tc->barrier_state[ 0 ], 2 );
|
||||
|
||||
T_eq_u32( GetCounter( tc ), 3 );
|
||||
}
|
||||
|
||||
static void SynchronousWorker( rtems_task_argument arg )
|
||||
{
|
||||
Timecounter *tc;
|
||||
|
||||
tc = (Timecounter *) arg;
|
||||
|
||||
while ( true ) {
|
||||
/* A */
|
||||
_SMP_barrier_Wait( &tc->barrier, &tc->barrier_state[ 1 ], 2 );
|
||||
|
||||
SetGeneration( tc, 0 );
|
||||
|
||||
/* B */
|
||||
_SMP_barrier_Wait( &tc->barrier, &tc->barrier_state[ 1 ], 2 );
|
||||
|
||||
/* C0 */
|
||||
_SMP_barrier_Wait( &tc->barrier, &tc->barrier_state[ 1 ], 2 );
|
||||
|
||||
SetGeneration( tc, 1 );
|
||||
|
||||
/* D0 */
|
||||
_SMP_barrier_Wait( &tc->barrier, &tc->barrier_state[ 1 ], 2 );
|
||||
|
||||
/* C1 */
|
||||
_SMP_barrier_Wait( &tc->barrier, &tc->barrier_state[ 1 ], 2 );
|
||||
|
||||
SetGeneration( tc, 2 );
|
||||
|
||||
/* D1 */
|
||||
_SMP_barrier_Wait( &tc->barrier, &tc->barrier_state[ 1 ], 2 );
|
||||
|
||||
/* C2 */
|
||||
_SMP_barrier_Wait( &tc->barrier, &tc->barrier_state[ 1 ], 2 );
|
||||
|
||||
/* D2 */
|
||||
_SMP_barrier_Wait( &tc->barrier, &tc->barrier_state[ 1 ], 2 );
|
||||
|
||||
/* E */
|
||||
_SMP_barrier_Wait( &tc->barrier, &tc->barrier_state[ 1 ], 2 );
|
||||
}
|
||||
}
|
||||
|
||||
static void PrepareZeroWork( Timecounter *tc )
|
||||
{
|
||||
/* F */
|
||||
_SMP_barrier_Wait( &tc->barrier, &tc->barrier_state[ 0 ], 2 );
|
||||
|
||||
SetCounter( tc, 0 );
|
||||
|
||||
/* G */
|
||||
_SMP_barrier_Wait( &tc->barrier, &tc->barrier_state[ 0 ], 2 );
|
||||
}
|
||||
|
||||
static void CleanupZeroWork( Timecounter *tc )
|
||||
{
|
||||
/* H */
|
||||
_SMP_barrier_Wait( &tc->barrier, &tc->barrier_state[ 0 ], 2 );
|
||||
|
||||
T_eq_u32( GetCounter( tc ), 0 );
|
||||
}
|
||||
|
||||
static void ZeroWorker( rtems_task_argument arg )
|
||||
{
|
||||
Timecounter *tc;
|
||||
|
||||
tc = (Timecounter *) arg;
|
||||
|
||||
while ( true ) {
|
||||
/* F */
|
||||
_SMP_barrier_Wait( &tc->barrier, &tc->barrier_state[ 1 ], 2 );
|
||||
|
||||
SetGeneration( tc, 0 );
|
||||
|
||||
/* G */
|
||||
_SMP_barrier_Wait( &tc->barrier, &tc->barrier_state[ 1 ], 2 );
|
||||
|
||||
rtems_counter_delay_nanoseconds( 10000000 );
|
||||
SetGeneration( tc, 1 );
|
||||
|
||||
/* H */
|
||||
_SMP_barrier_Wait( &tc->barrier, &tc->barrier_state[ 1 ], 2 );
|
||||
}
|
||||
}
|
||||
|
||||
static void PrepareChangeWork( Timecounter *tc )
|
||||
{
|
||||
/* F */
|
||||
_SMP_barrier_Wait( &tc->barrier, &tc->barrier_state[ 0 ], 2 );
|
||||
|
||||
SetCounter( tc, 0 );
|
||||
|
||||
/* G */
|
||||
_SMP_barrier_Wait( &tc->barrier, &tc->barrier_state[ 0 ], 2 );
|
||||
}
|
||||
|
||||
static void CleanupChangeWork( Timecounter *tc )
|
||||
{
|
||||
/* H */
|
||||
_SMP_barrier_Wait( &tc->barrier, &tc->barrier_state[ 0 ], 2 );
|
||||
|
||||
T_eq_u32( GetCounter( tc ), 0 );
|
||||
}
|
||||
|
||||
static void ChangeWorker( rtems_task_argument arg )
|
||||
{
|
||||
Timecounter *tc;
|
||||
|
||||
tc = (Timecounter *) arg;
|
||||
|
||||
while ( true ) {
|
||||
unsigned int i;
|
||||
|
||||
/* F */
|
||||
_SMP_barrier_Wait( &tc->barrier, &tc->barrier_state[ 1 ], 2 );
|
||||
|
||||
/* G */
|
||||
_SMP_barrier_Wait( &tc->barrier, &tc->barrier_state[ 1 ], 2 );
|
||||
|
||||
for ( i = 1; i < 1000; ++i ) {
|
||||
SetGeneration( tc, i );
|
||||
}
|
||||
|
||||
/* H */
|
||||
_SMP_barrier_Wait( &tc->barrier, &tc->barrier_state[ 1 ], 2 );
|
||||
}
|
||||
}
|
||||
|
||||
/* This definition must be identical to the one in kern_tc.c */
|
||||
struct timehands {
|
||||
struct timecounter *th_counter;
|
||||
int64_t th_adjustment;
|
||||
uint64_t th_scale;
|
||||
uint32_t th_large_delta;
|
||||
uint32_t th_offset_count;
|
||||
struct bintime th_offset;
|
||||
struct bintime th_bintime;
|
||||
struct timeval th_microtime;
|
||||
struct timespec th_nanotime;
|
||||
struct bintime th_boottime;
|
||||
Atomic_Uint th_generation;
|
||||
struct timehands *th_next;
|
||||
};
|
||||
|
||||
static void NtpUpdateSecond( int64_t *adjustment, time_t *newsec )
|
||||
{
|
||||
Timecounter *tc;
|
||||
struct timehands *th;
|
||||
|
||||
tc = &test_timecounter;
|
||||
th = RTEMS_CONTAINER_OF( adjustment, struct timehands, th_adjustment );
|
||||
T_assert_eq_ptr( th, th->th_next->th_next );
|
||||
tc->generation_0 = &th->th_generation;
|
||||
tc->generation_1 = &th->th_next->th_generation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Install timecounter of different quality levels and frequencies.
|
||||
*/
|
||||
static void ScoreTimecounterValGetSmp_Action_0( void )
|
||||
{
|
||||
Timecounter *tc;
|
||||
rtems_id worker_id;
|
||||
struct bintime bt;
|
||||
sbintime_t sbt;
|
||||
struct timespec ts;
|
||||
struct timeval tv;
|
||||
unsigned int i;
|
||||
|
||||
tc = &test_timecounter;
|
||||
tc->base.tc_get_timecount = GetTimecount;
|
||||
tc->base.tc_counter_mask = 0xffffffff;
|
||||
tc->base.tc_frequency = 0x10000000;
|
||||
tc->base.tc_quality = RTEMS_TIMECOUNTER_QUALITY_CLOCK_DRIVER;
|
||||
rtems_timecounter_install( &tc->base );
|
||||
|
||||
SetCounter( tc, tc->base.tc_frequency );
|
||||
_Timecounter_Set_NTP_update_second( NtpUpdateSecond );
|
||||
CallTimecounterTick();
|
||||
_Timecounter_Set_NTP_update_second( NULL );
|
||||
|
||||
T_assert_not_null( tc->generation_0 );
|
||||
T_assert_not_null( tc->generation_1 );
|
||||
|
||||
_SMP_barrier_Control_initialize( &tc->barrier );
|
||||
_SMP_barrier_State_initialize( &tc->barrier_state[ 0 ] );
|
||||
_SMP_barrier_State_initialize( &tc->barrier_state[ 1 ] );
|
||||
|
||||
worker_id = CreateTask( "WORK", PRIO_NORMAL );
|
||||
SetScheduler( worker_id, SCHEDULER_B_ID, PRIO_NORMAL );
|
||||
StartTask( worker_id, SynchronousWorker, tc );
|
||||
|
||||
tc->base.tc_get_timecount = GetTimecountBarrier;
|
||||
|
||||
/*
|
||||
* Call the rtems_clock_get_realtime() directive and let it observe a
|
||||
* generation number of zero as well as a generation number change.
|
||||
*/
|
||||
PrepareSynchronousWork( tc );
|
||||
rtems_clock_get_realtime( &ts );
|
||||
T_eq_i64( ts.tv_sec, 567993616 );
|
||||
T_eq_long( ts.tv_nsec, 7 );
|
||||
CleanupSynchronousWork( tc );
|
||||
|
||||
/*
|
||||
* Call the rtems_clock_get_realtime_bintime() directive and let it observe a
|
||||
* generation number of zero as well as a generation number change.
|
||||
*/
|
||||
PrepareSynchronousWork( tc );
|
||||
rtems_clock_get_realtime_bintime( &bt );
|
||||
T_eq_i64( bt.sec, 567993616 );
|
||||
T_eq_u64( bt.frac, 137438953472 );
|
||||
CleanupSynchronousWork( tc );
|
||||
|
||||
/*
|
||||
* Call the rtems_clock_get_realtime_timeval() directive and let it observe a
|
||||
* generation number of zero as well as a generation number change.
|
||||
*/
|
||||
PrepareSynchronousWork( tc );
|
||||
rtems_clock_get_realtime_timeval( &tv );
|
||||
T_eq_i64( tv.tv_sec, 567993616 );
|
||||
T_eq_long( tv.tv_usec, 0 );
|
||||
CleanupSynchronousWork( tc );
|
||||
|
||||
/*
|
||||
* Call the rtems_clock_get_monotonic() directive and let it observe a
|
||||
* generation number of zero as well as a generation number change.
|
||||
*/
|
||||
PrepareSynchronousWork( tc );
|
||||
rtems_clock_get_monotonic( &ts );
|
||||
T_eq_i64( ts.tv_sec, 17 );
|
||||
T_eq_long( ts.tv_nsec, 7 );
|
||||
CleanupSynchronousWork( tc );
|
||||
|
||||
/*
|
||||
* Call the rtems_clock_get_monotonic_bintime() directive and let it observe
|
||||
* a generation number of zero as well as a generation number change.
|
||||
*/
|
||||
PrepareSynchronousWork( tc );
|
||||
rtems_clock_get_monotonic_bintime( &bt );
|
||||
T_eq_i64( bt.sec, 17 );
|
||||
T_eq_u64( bt.frac, 137438953472 );
|
||||
CleanupSynchronousWork( tc );
|
||||
|
||||
/*
|
||||
* Call the rtems_clock_get_monotonic_sbintime() directive and let it observe
|
||||
* a generation number of zero as well as a generation number change.
|
||||
*/
|
||||
PrepareSynchronousWork( tc );
|
||||
sbt = rtems_clock_get_monotonic_sbintime();
|
||||
T_eq_i64( sbt, 73014444064 );
|
||||
CleanupSynchronousWork( tc );
|
||||
|
||||
/*
|
||||
* Call the rtems_clock_get_monotonic_timeval() directive and let it observe
|
||||
* a generation number of zero as well as a generation number change.
|
||||
*/
|
||||
PrepareSynchronousWork( tc );
|
||||
rtems_clock_get_monotonic_timeval( &tv );
|
||||
T_eq_i64( tv.tv_sec, 17 );
|
||||
T_eq_long( tv.tv_usec, 0 );
|
||||
CleanupSynchronousWork( tc );
|
||||
|
||||
/*
|
||||
* Delete the synchronous worker task. Reinitialize the barrier and barrier
|
||||
* states. Start the zero worker task.
|
||||
*/
|
||||
tc->base.tc_get_timecount = GetTimecount;
|
||||
DeleteTask( worker_id );
|
||||
|
||||
_SMP_barrier_Control_initialize( &tc->barrier );
|
||||
_SMP_barrier_State_initialize( &tc->barrier_state[ 0 ] );
|
||||
_SMP_barrier_State_initialize( &tc->barrier_state[ 1 ] );
|
||||
|
||||
worker_id = CreateTask( "WORK", PRIO_NORMAL );
|
||||
SetScheduler( worker_id, SCHEDULER_B_ID, PRIO_NORMAL );
|
||||
StartTask( worker_id, ZeroWorker, tc );
|
||||
|
||||
/*
|
||||
* Call the rtems_clock_get_realtime_coarse() directive and try to let it
|
||||
* observe a generation number of zero.
|
||||
*/
|
||||
PrepareZeroWork( tc );
|
||||
rtems_clock_get_realtime_coarse( &ts );
|
||||
CleanupZeroWork( tc );
|
||||
|
||||
/*
|
||||
* Call the rtems_clock_get_realtime_coarse_bintime() directive and try to
|
||||
* let it observe a generation number of zero.
|
||||
*/
|
||||
PrepareZeroWork( tc );
|
||||
rtems_clock_get_realtime_coarse_bintime( &bt );
|
||||
CleanupZeroWork( tc );
|
||||
|
||||
/*
|
||||
* Call the rtems_clock_get_realtime_coarse_timeval() directive and try to
|
||||
* let it observe a generation number of zero.
|
||||
*/
|
||||
PrepareZeroWork( tc );
|
||||
rtems_clock_get_realtime_coarse_timeval( &tv );
|
||||
CleanupZeroWork( tc );
|
||||
|
||||
/*
|
||||
* Call the rtems_clock_get_monotonic_coarse() directive and try to let it
|
||||
* observe a generation number of zero.
|
||||
*/
|
||||
PrepareZeroWork( tc );
|
||||
rtems_clock_get_monotonic_coarse( &ts );
|
||||
CleanupZeroWork( tc );
|
||||
|
||||
/*
|
||||
* Call the rtems_clock_get_monotonic_coarse_bintime() directive and try to
|
||||
* let it observe a generation number of zero.
|
||||
*/
|
||||
PrepareZeroWork( tc );
|
||||
rtems_clock_get_monotonic_coarse_bintime( &bt );
|
||||
CleanupZeroWork( tc );
|
||||
|
||||
/*
|
||||
* Call the rtems_clock_get_monotonic_coarse_timeval() directive and try to
|
||||
* let it observe a generation number of zero.
|
||||
*/
|
||||
PrepareZeroWork( tc );
|
||||
rtems_clock_get_monotonic_coarse_timeval( &tv );
|
||||
CleanupZeroWork( tc );
|
||||
|
||||
/*
|
||||
* Call the rtems_clock_get_boot_time() directive and try to let it observe a
|
||||
* generation number of zero.
|
||||
*/
|
||||
PrepareZeroWork( tc );
|
||||
rtems_clock_get_boot_time( &ts );
|
||||
CleanupZeroWork( tc );
|
||||
|
||||
/*
|
||||
* Call the rtems_clock_get_boot_time_bintime() directive and try to let it
|
||||
* observe a generation number of zero.
|
||||
*/
|
||||
PrepareZeroWork( tc );
|
||||
rtems_clock_get_boot_time_bintime( &bt );
|
||||
CleanupZeroWork( tc );
|
||||
|
||||
/*
|
||||
* Call the rtems_clock_get_boot_time_timeval() directive and try to let it
|
||||
* observe a generation number of zero.
|
||||
*/
|
||||
PrepareZeroWork( tc );
|
||||
rtems_clock_get_boot_time_timeval( &tv );
|
||||
CleanupZeroWork( tc );
|
||||
|
||||
/*
|
||||
* Delete the zero worker task. Reinitialize the barrier and barrier states.
|
||||
* Start the change worker task.
|
||||
*/
|
||||
DeleteTask( worker_id );
|
||||
|
||||
_SMP_barrier_Control_initialize( &tc->barrier );
|
||||
_SMP_barrier_State_initialize( &tc->barrier_state[ 0 ] );
|
||||
_SMP_barrier_State_initialize( &tc->barrier_state[ 1 ] );
|
||||
|
||||
worker_id = CreateTask( "WORK", PRIO_NORMAL );
|
||||
SetScheduler( worker_id, SCHEDULER_B_ID, PRIO_NORMAL );
|
||||
StartTask( worker_id, ChangeWorker, tc );
|
||||
|
||||
/*
|
||||
* Call the rtems_clock_get_realtime_coarse() directive and try to let it
|
||||
* observe a changing generation number.
|
||||
*/
|
||||
PrepareChangeWork( tc );
|
||||
|
||||
for ( i = 0; i < 100; ++i ) {
|
||||
rtems_clock_get_realtime_coarse( &ts );
|
||||
}
|
||||
|
||||
CleanupChangeWork( tc );
|
||||
|
||||
/*
|
||||
* Call the rtems_clock_get_realtime_coarse_bintime() directive and try to
|
||||
* let it observe a changing generation number.
|
||||
*/
|
||||
PrepareChangeWork( tc );
|
||||
|
||||
for ( i = 0; i < 100; ++i ) {
|
||||
rtems_clock_get_realtime_coarse_bintime( &bt );
|
||||
}
|
||||
|
||||
CleanupChangeWork( tc );
|
||||
|
||||
/*
|
||||
* Call the rtems_clock_get_realtime_coarse_timeval() directive and try to
|
||||
* let it observe a changing generation number.
|
||||
*/
|
||||
PrepareChangeWork( tc );
|
||||
|
||||
for ( i = 0; i < 100; ++i ) {
|
||||
rtems_clock_get_realtime_coarse_timeval( &tv );
|
||||
}
|
||||
|
||||
CleanupChangeWork( tc );
|
||||
|
||||
/*
|
||||
* Call the rtems_clock_get_monotonic_coarse() directive and try to let it
|
||||
* observe a changing generation number.
|
||||
*/
|
||||
PrepareChangeWork( tc );
|
||||
|
||||
for ( i = 0; i < 100; ++i ) {
|
||||
rtems_clock_get_monotonic_coarse( &ts );
|
||||
}
|
||||
|
||||
CleanupChangeWork( tc );
|
||||
|
||||
/*
|
||||
* Call the rtems_clock_get_monotonic_coarse_bintime() directive and try to
|
||||
* let it observe a changing generation number.
|
||||
*/
|
||||
PrepareChangeWork( tc );
|
||||
|
||||
for ( i = 0; i < 100; ++i ) {
|
||||
rtems_clock_get_monotonic_coarse_bintime( &bt );
|
||||
}
|
||||
|
||||
CleanupChangeWork( tc );
|
||||
|
||||
/*
|
||||
* Call the rtems_clock_get_monotonic_coarse_timeval() directive and try to
|
||||
* let it observe a changing generation number.
|
||||
*/
|
||||
PrepareChangeWork( tc );
|
||||
|
||||
for ( i = 0; i < 100; ++i ) {
|
||||
rtems_clock_get_monotonic_coarse_timeval( &tv );
|
||||
}
|
||||
|
||||
CleanupChangeWork( tc );
|
||||
|
||||
/*
|
||||
* Call the rtems_clock_get_boot_time() directive and try to let it observe a
|
||||
* changing generation number.
|
||||
*/
|
||||
PrepareChangeWork( tc );
|
||||
|
||||
for ( i = 0; i < 100; ++i ) {
|
||||
rtems_clock_get_boot_time( &ts );
|
||||
}
|
||||
|
||||
CleanupChangeWork( tc );
|
||||
|
||||
/*
|
||||
* Call the rtems_clock_get_boot_time_bintime() directive and try to let it
|
||||
* observe a changing generation number.
|
||||
*/
|
||||
PrepareChangeWork( tc );
|
||||
|
||||
for ( i = 0; i < 100; ++i ) {
|
||||
rtems_clock_get_boot_time_bintime( &bt );
|
||||
}
|
||||
|
||||
CleanupChangeWork( tc );
|
||||
|
||||
/*
|
||||
* Call the rtems_clock_get_boot_time_timeval() directive and try to let it
|
||||
* observe a changing generation number.
|
||||
*/
|
||||
PrepareChangeWork( tc );
|
||||
|
||||
for ( i = 0; i < 100; ++i ) {
|
||||
rtems_clock_get_boot_time_timeval( &tv );
|
||||
}
|
||||
|
||||
CleanupChangeWork( tc );
|
||||
|
||||
/*
|
||||
* Delete the change worker task.
|
||||
*/
|
||||
DeleteTask( worker_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* @fn void T_case_body_ScoreTimecounterValGetSmp( void )
|
||||
*/
|
||||
T_TEST_CASE( ScoreTimecounterValGetSmp )
|
||||
{
|
||||
ScoreTimecounterValGetSmp_Action_0();
|
||||
}
|
||||
|
||||
/** @} */
|
||||
575
testsuites/validation/tc-timecounter-get.c
Normal file
575
testsuites/validation/tc-timecounter-get.c
Normal file
@@ -0,0 +1,575 @@
|
||||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @ingroup RTEMSTestCaseScoreTimecounterValGet
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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 <rtems/counter.h>
|
||||
#include <rtems/timecounter.h>
|
||||
#include <rtems/score/timecounterimpl.h>
|
||||
|
||||
#include "tx-support.h"
|
||||
|
||||
#include <rtems/test.h>
|
||||
|
||||
/**
|
||||
* @defgroup RTEMSTestCaseScoreTimecounterValGet \
|
||||
* spec:/score/timecounter/val/get
|
||||
*
|
||||
* @ingroup RTEMSTestSuiteTestsuitesValidationTimecounter1
|
||||
*
|
||||
* @brief Tests directives to get a time value.
|
||||
*
|
||||
* This test case performs the following actions:
|
||||
*
|
||||
* - Install a timecounter which can be used to perform interrut tests for the
|
||||
* get time directives.
|
||||
*
|
||||
* - Try to interrupt the rtems_clock_get_realtime() directive to provoke a
|
||||
* change in the timehand generation number.
|
||||
*
|
||||
* - Try to interrupt the rtems_clock_get_realtime_bintime() directive to
|
||||
* provoke a change in the timehand generation number.
|
||||
*
|
||||
* - Try to interrupt the rtems_clock_get_realtime_timeval() directive to
|
||||
* provoke a change in the timehand generation number.
|
||||
*
|
||||
* - Try to interrupt the rtems_clock_get_monotonic() directive to provoke a
|
||||
* change in the timehand generation number.
|
||||
*
|
||||
* - Try to interrupt the rtems_clock_get_monotonic_bintime() directive to
|
||||
* provoke a change in the timehand generation number.
|
||||
*
|
||||
* - Try to interrupt the rtems_clock_get_monotonic_sbintime() directive to
|
||||
* provoke a change in the timehand generation number.
|
||||
*
|
||||
* - Try to interrupt the rtems_clock_get_monotonic_timeval() directive to
|
||||
* provoke a change in the timehand generation number.
|
||||
*
|
||||
* - Prepare for the coarse get time directives.
|
||||
*
|
||||
* - Try to interrupt the rtems_clock_get_realtime_coarse() directive to
|
||||
* provoke a change in the timehand generation number.
|
||||
*
|
||||
* - Try to interrupt the rtems_clock_get_realtime_coarse_bintime() directive
|
||||
* to provoke a change in the timehand generation number.
|
||||
*
|
||||
* - Try to interrupt the rtems_clock_get_realtime_coarse_timeval() directive
|
||||
* to provoke a change in the timehand generation number.
|
||||
*
|
||||
* - Try to interrupt the rtems_clock_get_monotonic_coarse() directive to
|
||||
* provoke a change in the timehand generation number.
|
||||
*
|
||||
* - Try to interrupt the rtems_clock_get_monotonic_coarse_bintime()
|
||||
* directive to provoke a change in the timehand generation number.
|
||||
*
|
||||
* - Try to interrupt the rtems_clock_get_monotonic_coarse_timeval()
|
||||
* directive to provoke a change in the timehand generation number.
|
||||
*
|
||||
* - Try to interrupt the rtems_clock_get_boot_time() directive to provoke a
|
||||
* change in the timehand generation number.
|
||||
*
|
||||
* - Try to interrupt the rtems_clock_get_boot_time_bintime() directive to
|
||||
* provoke a change in the timehand generation number.
|
||||
*
|
||||
* - Try to interrupt the rtems_clock_get_boot_time_timeval() directive to
|
||||
* provoke a change in the timehand generation number.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
typedef enum {
|
||||
STATE_EARLY,
|
||||
STATE_GET_TIMECOUNT_BEFORE,
|
||||
STATE_GET_TIMECOUNT_BUSY,
|
||||
STATE_GET_TIMECOUNT_DONE,
|
||||
STATE_GET_TIMECOUNT_AFTER
|
||||
} State;
|
||||
|
||||
typedef struct {
|
||||
struct timecounter base;
|
||||
State state;
|
||||
uint_fast32_t busy;
|
||||
struct bintime tod;
|
||||
} Timecounter;
|
||||
|
||||
static Timecounter test_timecounter;
|
||||
|
||||
static uint32_t GetTimecount( struct timecounter *base )
|
||||
{
|
||||
Timecounter *tc;
|
||||
|
||||
tc = (Timecounter *) base;
|
||||
|
||||
if (
|
||||
tc->state == STATE_GET_TIMECOUNT_BEFORE &&
|
||||
!rtems_interrupt_is_in_progress()
|
||||
) {
|
||||
tc->state = STATE_GET_TIMECOUNT_BUSY;
|
||||
T_busy( tc->busy );
|
||||
tc->state = STATE_GET_TIMECOUNT_DONE;
|
||||
}
|
||||
|
||||
return rtems_counter_read();
|
||||
}
|
||||
|
||||
static void InterruptPrepare( void *arg )
|
||||
{
|
||||
Timecounter *tc;
|
||||
|
||||
tc = (Timecounter *) arg;
|
||||
tc->state = STATE_EARLY;
|
||||
}
|
||||
|
||||
static void ActionRealtime( void *arg )
|
||||
{
|
||||
Timecounter *tc;
|
||||
struct timespec ts;
|
||||
|
||||
tc = (Timecounter *) arg;
|
||||
tc->state = STATE_GET_TIMECOUNT_BEFORE;
|
||||
rtems_clock_get_realtime( &ts );
|
||||
tc->state = STATE_GET_TIMECOUNT_AFTER;
|
||||
}
|
||||
|
||||
static void ActionRealtimeBintime( void *arg )
|
||||
{
|
||||
Timecounter *tc;
|
||||
struct bintime bt;
|
||||
|
||||
tc = (Timecounter *) arg;
|
||||
tc->state = STATE_GET_TIMECOUNT_BEFORE;
|
||||
rtems_clock_get_realtime_bintime( &bt );
|
||||
tc->state = STATE_GET_TIMECOUNT_AFTER;
|
||||
}
|
||||
|
||||
static void ActionRealtimeTimeval( void *arg )
|
||||
{
|
||||
Timecounter *tc;
|
||||
struct timeval tv;
|
||||
|
||||
tc = (Timecounter *) arg;
|
||||
tc->state = STATE_GET_TIMECOUNT_BEFORE;
|
||||
rtems_clock_get_realtime_timeval( &tv );
|
||||
tc->state = STATE_GET_TIMECOUNT_AFTER;
|
||||
}
|
||||
|
||||
static void ActionMonotonic( void *arg )
|
||||
{
|
||||
Timecounter *tc;
|
||||
struct timespec ts;
|
||||
|
||||
tc = (Timecounter *) arg;
|
||||
tc->state = STATE_GET_TIMECOUNT_BEFORE;
|
||||
rtems_clock_get_monotonic( &ts );
|
||||
tc->state = STATE_GET_TIMECOUNT_AFTER;
|
||||
}
|
||||
|
||||
static void ActionMonotonicBintime( void *arg )
|
||||
{
|
||||
Timecounter *tc;
|
||||
struct bintime bt;
|
||||
|
||||
tc = (Timecounter *) arg;
|
||||
tc->state = STATE_GET_TIMECOUNT_BEFORE;
|
||||
rtems_clock_get_monotonic_bintime( &bt );
|
||||
tc->state = STATE_GET_TIMECOUNT_AFTER;
|
||||
}
|
||||
|
||||
static void ActionMonotonicSbintime( void *arg )
|
||||
{
|
||||
Timecounter *tc;
|
||||
|
||||
tc = (Timecounter *) arg;
|
||||
tc->state = STATE_GET_TIMECOUNT_BEFORE;
|
||||
(void) rtems_clock_get_monotonic_sbintime();
|
||||
tc->state = STATE_GET_TIMECOUNT_AFTER;
|
||||
}
|
||||
|
||||
static void ActionMonotonicTimeval( void *arg )
|
||||
{
|
||||
Timecounter *tc;
|
||||
struct timeval tv;
|
||||
|
||||
tc = (Timecounter *) arg;
|
||||
tc->state = STATE_GET_TIMECOUNT_BEFORE;
|
||||
rtems_clock_get_monotonic_timeval( &tv );
|
||||
tc->state = STATE_GET_TIMECOUNT_AFTER;
|
||||
}
|
||||
|
||||
static void ActionCoarseRealtime( void *arg )
|
||||
{
|
||||
Timecounter *tc;
|
||||
struct timespec ts;
|
||||
|
||||
tc = (Timecounter *) arg;
|
||||
tc->state = STATE_GET_TIMECOUNT_BEFORE;
|
||||
rtems_clock_get_realtime_coarse( &ts );
|
||||
tc->state = STATE_GET_TIMECOUNT_AFTER;
|
||||
}
|
||||
|
||||
static void ActionCoarseRealtimeBintime( void *arg )
|
||||
{
|
||||
Timecounter *tc;
|
||||
struct bintime bt;
|
||||
|
||||
tc = (Timecounter *) arg;
|
||||
tc->state = STATE_GET_TIMECOUNT_BEFORE;
|
||||
rtems_clock_get_realtime_coarse_bintime( &bt );
|
||||
tc->state = STATE_GET_TIMECOUNT_AFTER;
|
||||
}
|
||||
|
||||
static void ActionCoarseRealtimeTimeval( void *arg )
|
||||
{
|
||||
Timecounter *tc;
|
||||
struct timeval tv;
|
||||
|
||||
tc = (Timecounter *) arg;
|
||||
tc->state = STATE_GET_TIMECOUNT_BEFORE;
|
||||
rtems_clock_get_realtime_coarse_timeval( &tv );
|
||||
tc->state = STATE_GET_TIMECOUNT_AFTER;
|
||||
}
|
||||
|
||||
static void ActionCoarseMonotonic( void *arg )
|
||||
{
|
||||
Timecounter *tc;
|
||||
struct timespec ts;
|
||||
|
||||
tc = (Timecounter *) arg;
|
||||
tc->state = STATE_GET_TIMECOUNT_BEFORE;
|
||||
rtems_clock_get_monotonic_coarse( &ts );
|
||||
tc->state = STATE_GET_TIMECOUNT_AFTER;
|
||||
}
|
||||
|
||||
static void ActionCoarseMonotonicBintime( void *arg )
|
||||
{
|
||||
Timecounter *tc;
|
||||
struct bintime bt;
|
||||
|
||||
tc = (Timecounter *) arg;
|
||||
tc->state = STATE_GET_TIMECOUNT_BEFORE;
|
||||
rtems_clock_get_monotonic_coarse_bintime( &bt );
|
||||
tc->state = STATE_GET_TIMECOUNT_AFTER;
|
||||
}
|
||||
|
||||
static void ActionCoarseMonotonicTimeval( void *arg )
|
||||
{
|
||||
Timecounter *tc;
|
||||
struct timeval tv;
|
||||
|
||||
tc = (Timecounter *) arg;
|
||||
tc->state = STATE_GET_TIMECOUNT_BEFORE;
|
||||
rtems_clock_get_monotonic_coarse_timeval( &tv );
|
||||
tc->state = STATE_GET_TIMECOUNT_AFTER;
|
||||
}
|
||||
|
||||
static void ActionBootTime( void *arg )
|
||||
{
|
||||
Timecounter *tc;
|
||||
struct timespec ts;
|
||||
|
||||
tc = (Timecounter *) arg;
|
||||
tc->state = STATE_GET_TIMECOUNT_BEFORE;
|
||||
rtems_clock_get_boot_time( &ts );
|
||||
tc->state = STATE_GET_TIMECOUNT_AFTER;
|
||||
}
|
||||
|
||||
static void ActionBootTimeBintime( void *arg )
|
||||
{
|
||||
Timecounter *tc;
|
||||
struct bintime bt;
|
||||
|
||||
tc = (Timecounter *) arg;
|
||||
tc->state = STATE_GET_TIMECOUNT_BEFORE;
|
||||
rtems_clock_get_boot_time_bintime( &bt );
|
||||
tc->state = STATE_GET_TIMECOUNT_AFTER;
|
||||
}
|
||||
|
||||
static void ActionBootTimeTimeval( void *arg )
|
||||
{
|
||||
Timecounter *tc;
|
||||
struct timeval tv;
|
||||
|
||||
tc = (Timecounter *) arg;
|
||||
tc->state = STATE_GET_TIMECOUNT_BEFORE;
|
||||
rtems_clock_get_boot_time_timeval( &tv );
|
||||
tc->state = STATE_GET_TIMECOUNT_AFTER;
|
||||
}
|
||||
|
||||
static void CallTimcounterWindupTwice( const Timecounter *tc )
|
||||
{
|
||||
ISR_lock_Context lock_context;
|
||||
|
||||
/*
|
||||
* Make sure that tc_windup() was called at least twice to increment the
|
||||
* generation number for * both timehands.
|
||||
*/
|
||||
|
||||
_Timecounter_Acquire( &lock_context );
|
||||
_Timecounter_Set_clock( &tc->tod, &lock_context );
|
||||
|
||||
_Timecounter_Acquire( &lock_context );
|
||||
_Timecounter_Set_clock( &tc->tod, &lock_context );
|
||||
}
|
||||
|
||||
static T_interrupt_test_state Interrupt( void *arg )
|
||||
{
|
||||
Timecounter *tc;
|
||||
State state;
|
||||
|
||||
tc = (Timecounter *) arg;
|
||||
state = tc->state;
|
||||
|
||||
if ( state == STATE_EARLY || state == STATE_GET_TIMECOUNT_BEFORE ) {
|
||||
return T_INTERRUPT_TEST_EARLY;
|
||||
}
|
||||
|
||||
if ( state == STATE_GET_TIMECOUNT_BUSY ) {
|
||||
CallTimcounterWindupTwice( tc );
|
||||
|
||||
return T_INTERRUPT_TEST_DONE;
|
||||
}
|
||||
|
||||
return T_INTERRUPT_TEST_LATE;
|
||||
}
|
||||
|
||||
static T_interrupt_test_state InterruptCoarse( void *arg )
|
||||
{
|
||||
Timecounter *tc;
|
||||
State state;
|
||||
|
||||
tc = (Timecounter *) arg;
|
||||
state = tc->state;
|
||||
|
||||
if ( state == STATE_EARLY ) {
|
||||
return T_INTERRUPT_TEST_EARLY;
|
||||
}
|
||||
|
||||
if ( state == STATE_GET_TIMECOUNT_BEFORE ) {
|
||||
CallTimcounterWindupTwice( tc );
|
||||
|
||||
return T_INTERRUPT_TEST_DONE;
|
||||
}
|
||||
|
||||
return T_INTERRUPT_TEST_LATE;
|
||||
}
|
||||
|
||||
static bool InterruptTest(
|
||||
const T_interrupt_test_config *config,
|
||||
void *arg,
|
||||
uint32_t iterations
|
||||
)
|
||||
{
|
||||
uint32_t i;
|
||||
bool ok;
|
||||
|
||||
ok = false;
|
||||
|
||||
for ( i = 0; i < iterations; ++i ) {
|
||||
T_interrupt_test_state test_state;
|
||||
|
||||
test_state = T_interrupt_test( config, arg );
|
||||
ok = ok || test_state == T_INTERRUPT_TEST_DONE;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Install a timecounter which can be used to perform interrut tests for
|
||||
* the get time directives.
|
||||
*/
|
||||
static void ScoreTimecounterValGet_Action_0( void )
|
||||
{
|
||||
T_interrupt_test_config config = {
|
||||
.prepare = InterruptPrepare,
|
||||
.interrupt = Interrupt,
|
||||
.max_iteration_count = 10000
|
||||
};
|
||||
Timecounter *tc;
|
||||
|
||||
tc = &test_timecounter;
|
||||
tc->base.tc_get_timecount = GetTimecount;
|
||||
tc->base.tc_counter_mask = 0xffffffff;
|
||||
tc->base.tc_frequency = rtems_counter_frequency();
|
||||
tc->base.tc_quality = RTEMS_TIMECOUNTER_QUALITY_CLOCK_DRIVER + 1;
|
||||
tc->busy = T_get_one_clock_tick_busy() / 10;
|
||||
rtems_clock_get_realtime_bintime( &tc->tod );
|
||||
rtems_timecounter_install( &tc->base );
|
||||
|
||||
/*
|
||||
* Try to interrupt the rtems_clock_get_realtime() directive to provoke a
|
||||
* change in the timehand generation number.
|
||||
*/
|
||||
config.action = ActionRealtime;
|
||||
T_true( InterruptTest( &config, tc, 1 ) );
|
||||
|
||||
/*
|
||||
* Try to interrupt the rtems_clock_get_realtime_bintime() directive to
|
||||
* provoke a change in the timehand generation number.
|
||||
*/
|
||||
config.action = ActionRealtimeBintime;
|
||||
T_true( InterruptTest( &config, tc, 1 ) );
|
||||
|
||||
/*
|
||||
* Try to interrupt the rtems_clock_get_realtime_timeval() directive to
|
||||
* provoke a change in the timehand generation number.
|
||||
*/
|
||||
config.action = ActionRealtimeTimeval;
|
||||
T_true( InterruptTest( &config, tc, 1 ) );
|
||||
|
||||
/*
|
||||
* Try to interrupt the rtems_clock_get_monotonic() directive to provoke a
|
||||
* change in the timehand generation number.
|
||||
*/
|
||||
config.action = ActionMonotonic;
|
||||
T_true( InterruptTest( &config, tc, 1 ) );
|
||||
|
||||
/*
|
||||
* Try to interrupt the rtems_clock_get_monotonic_bintime() directive to
|
||||
* provoke a change in the timehand generation number.
|
||||
*/
|
||||
config.action = ActionMonotonicBintime;
|
||||
T_true( InterruptTest( &config, tc, 1 ) );
|
||||
|
||||
/*
|
||||
* Try to interrupt the rtems_clock_get_monotonic_sbintime() directive to
|
||||
* provoke a change in the timehand generation number.
|
||||
*/
|
||||
config.action = ActionMonotonicSbintime;
|
||||
T_true( InterruptTest( &config, tc, 1 ) );
|
||||
|
||||
/*
|
||||
* Try to interrupt the rtems_clock_get_monotonic_timeval() directive to
|
||||
* provoke a change in the timehand generation number.
|
||||
*/
|
||||
config.action = ActionMonotonicTimeval;
|
||||
T_true( InterruptTest( &config, tc, 1 ) );
|
||||
|
||||
/*
|
||||
* Prepare for the coarse get time directives.
|
||||
*/
|
||||
config.interrupt = InterruptCoarse;
|
||||
|
||||
/*
|
||||
* Try to interrupt the rtems_clock_get_realtime_coarse() directive to
|
||||
* provoke a change in the timehand generation number.
|
||||
*/
|
||||
config.action = ActionCoarseRealtime;
|
||||
T_true( InterruptTest( &config, tc, 10 ) );
|
||||
|
||||
/*
|
||||
* Try to interrupt the rtems_clock_get_realtime_coarse_bintime() directive
|
||||
* to provoke a change in the timehand generation number.
|
||||
*/
|
||||
config.action = ActionCoarseRealtimeBintime;
|
||||
T_true( InterruptTest( &config, tc, 10 ) );
|
||||
|
||||
/*
|
||||
* Try to interrupt the rtems_clock_get_realtime_coarse_timeval() directive
|
||||
* to provoke a change in the timehand generation number.
|
||||
*/
|
||||
config.action = ActionCoarseRealtimeTimeval;
|
||||
T_true( InterruptTest( &config, tc, 10 ) );
|
||||
|
||||
/*
|
||||
* Try to interrupt the rtems_clock_get_monotonic_coarse() directive to
|
||||
* provoke a change in the timehand generation number.
|
||||
*/
|
||||
config.action = ActionCoarseMonotonic;
|
||||
T_true( InterruptTest( &config, tc, 10 ) );
|
||||
|
||||
/*
|
||||
* Try to interrupt the rtems_clock_get_monotonic_coarse_bintime() directive
|
||||
* to provoke a change in the timehand generation number.
|
||||
*/
|
||||
config.action = ActionCoarseMonotonicBintime;
|
||||
T_true( InterruptTest( &config, tc, 10 ) );
|
||||
|
||||
/*
|
||||
* Try to interrupt the rtems_clock_get_monotonic_coarse_timeval() directive
|
||||
* to provoke a change in the timehand generation number.
|
||||
*/
|
||||
config.action = ActionCoarseMonotonicTimeval;
|
||||
T_true( InterruptTest( &config, tc, 10 ) );
|
||||
|
||||
/*
|
||||
* Try to interrupt the rtems_clock_get_boot_time() directive to provoke a
|
||||
* change in the timehand generation number.
|
||||
*/
|
||||
config.action = ActionBootTime;
|
||||
T_true( InterruptTest( &config, tc, 10 ) );
|
||||
|
||||
/*
|
||||
* Try to interrupt the rtems_clock_get_boot_time_bintime() directive to
|
||||
* provoke a change in the timehand generation number.
|
||||
*/
|
||||
config.action = ActionBootTimeBintime;
|
||||
T_true( InterruptTest( &config, tc, 10 ) );
|
||||
|
||||
/*
|
||||
* Try to interrupt the rtems_clock_get_boot_time_timeval() directive to
|
||||
* provoke a change in the timehand generation number.
|
||||
*/
|
||||
config.action = ActionBootTimeTimeval;
|
||||
T_true( InterruptTest( &config, tc, 10 ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @fn void T_case_body_ScoreTimecounterValGet( void )
|
||||
*/
|
||||
T_TEST_CASE( ScoreTimecounterValGet )
|
||||
{
|
||||
ScoreTimecounterValGet_Action_0();
|
||||
}
|
||||
|
||||
/** @} */
|
||||
1134
testsuites/validation/tc-timecounter-install.c
Normal file
1134
testsuites/validation/tc-timecounter-install.c
Normal file
File diff suppressed because it is too large
Load Diff
77
testsuites/validation/ts-validation-timecounter-0.c
Normal file
77
testsuites/validation/ts-validation-timecounter-0.c
Normal file
@@ -0,0 +1,77 @@
|
||||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @ingroup RTEMSTestSuiteTestsuitesValidationTimecounter0
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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/test.h>
|
||||
|
||||
/**
|
||||
* @defgroup RTEMSTestSuiteTestsuitesValidationTimecounter0 \
|
||||
* spec:/testsuites/validation-timecounter-0
|
||||
*
|
||||
* @ingroup RTEMSTestSuites
|
||||
*
|
||||
* @brief This validation test suite is intended test cases related to the
|
||||
* installation of timecouters. The Clock Driver is disabled.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
const char rtems_test_name[] = "ValidationTimecounter0";
|
||||
|
||||
#define CONFIGURE_MAXIMUM_PROCESSORS 1
|
||||
|
||||
#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
|
||||
|
||||
#include "ts-default.h"
|
||||
|
||||
/** @} */
|
||||
75
testsuites/validation/ts-validation-timecounter-1.c
Normal file
75
testsuites/validation/ts-validation-timecounter-1.c
Normal file
@@ -0,0 +1,75 @@
|
||||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @ingroup RTEMSTestSuiteTestsuitesValidationTimecounter1
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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/test.h>
|
||||
|
||||
/**
|
||||
* @defgroup RTEMSTestSuiteTestsuitesValidationTimecounter1 \
|
||||
* spec:/testsuites/validation-timecounter-1
|
||||
*
|
||||
* @ingroup RTEMSTestSuites
|
||||
*
|
||||
* @brief This validation test suite is intended test cases related to the use
|
||||
* of timecouters. The Clock Driver is enabled.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
const char rtems_test_name[] = "ValidationTimecounter1";
|
||||
|
||||
#define CONFIGURE_MAXIMUM_PROCESSORS 4
|
||||
|
||||
#include "ts-default.h"
|
||||
|
||||
/** @} */
|
||||
77
testsuites/validation/ts-validation-timecounter-smp-0.c
Normal file
77
testsuites/validation/ts-validation-timecounter-smp-0.c
Normal file
@@ -0,0 +1,77 @@
|
||||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @ingroup RTEMSTestSuiteTestsuitesValidationTimecounterSmp0
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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/test.h>
|
||||
|
||||
/**
|
||||
* @defgroup RTEMSTestSuiteTestsuitesValidationTimecounterSmp0 \
|
||||
* spec:/testsuites/validation-timecounter-smp-0
|
||||
*
|
||||
* @ingroup RTEMSTestSuites
|
||||
*
|
||||
* @brief This validation test suite is intended test cases related to the use
|
||||
* of timecouters. The Clock Driver is disabled.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
const char rtems_test_name[] = "ValidationTimecounterSmp0";
|
||||
|
||||
#define CONFIGURE_MAXIMUM_PROCESSORS 4
|
||||
|
||||
#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
|
||||
|
||||
#include "ts-default.h"
|
||||
|
||||
/** @} */
|
||||
Reference in New Issue
Block a user