libtest: Use test configuration in T_now()

Use the user provided now handler of the test configuration to get the
time in T_now().
This commit is contained in:
Sebastian Huber
2019-12-20 10:55:36 +01:00
parent 8c3b0d7445
commit 77ac1519e8
5 changed files with 32 additions and 47 deletions

View File

@@ -2146,29 +2146,23 @@ T_time T_seconds_and_nanoseconds_to_time(uint32_t, uint32_t);
void T_time_to_seconds_and_nanoseconds(T_time, uint32_t *, uint32_t *);
T_time T_now(void);
#ifdef __rtems__
int64_t _Timecounter_Sbinuptime(void);
static inline T_time
T_now(void)
{
return (T_time)_Timecounter_Sbinuptime();
}
static inline T_ticks
T_tick(void)
{
return _CPU_Counter_read();
}
#else
T_time T_now(void);
T_ticks T_tick(void);
#endif
T_time T_now_clock(void);
T_time T_now_dummy(void);
T_time T_now_via_tick(void);
T_time T_now_tick(void);
T_time T_case_begin_time(void);

View File

@@ -201,16 +201,20 @@ T_time_to_seconds_and_nanoseconds(T_time time, uint32_t *s, uint32_t *ns)
#endif
}
#ifndef __rtems__
T_time
T_now(void)
T_now_clock(void)
{
#ifndef __rtems__
struct timespec tp;
(void)clock_gettime(CLOCK_MONOTONIC, &tp);
return (T_time)tp.tv_sec * (T_time)1000000000 + (T_time)tp.tv_nsec;
#else /* __rtems__ */
return (T_time)_Timecounter_Sbinuptime();
#endif /* __rtems__ */
}
#ifndef __rtems__
T_ticks
T_tick(void)
{
@@ -218,16 +222,17 @@ T_tick(void)
}
#endif
static atomic_uint dummy_time;
static atomic_uint T_dummy_time;
T_time
T_now_dummy(void)
{
return atomic_fetch_add_explicit(&dummy_time, 1, memory_order_relaxed);
return atomic_fetch_add_explicit(&T_dummy_time, 1,
memory_order_relaxed);
}
T_time
T_now_via_tick(void)
T_now_tick(void)
{
return T_ticks_to_time(T_tick());
}

View File

@@ -994,3 +994,14 @@ T_set_putchar(T_putchar new_putchar, void *new_arg, T_putchar *old_putchar,
ctx->putchar = new_putchar;
ctx->putchar_arg = new_arg;
}
T_time
T_now(void)
{
T_context *ctx;
const T_config *config;
ctx = &T_instance;
config = ctx->config;
return (*config->now)();
}

View File

@@ -32,8 +32,6 @@
#include <rtems.h>
#include <rtems/bspIo.h>
#include <rtems/timecounter.h>
#include <rtems/sysinit.h>
#include "t-self-test.h"
@@ -54,7 +52,6 @@ typedef struct {
const char *c;
size_t case_begin_count;
size_t case_end_count;
struct timecounter tc;
T_putchar putchar;
void *putchar_arg;
const char *censor_c;
@@ -180,8 +177,8 @@ run_initialize(void)
T_set_putchar(censor_putchar, ctx, &ctx->putchar, &ctx->putchar_arg);
}
static const char expected_final[] = "Z:ttest01:C:341:N:1316:F:790:D:0.682999\n"
"Y:ReportHash:SHA256:62d6f3b37299137932ea2c2f0505c8b8f12b95749c81d5af19570e9470203475\n";
static const char expected_final[] = "Z:ttest01:C:341:N:1316:F:790:D:0.685999\n"
"Y:ReportHash:SHA256:cb5ba027ade5b907d9e988776e393835f34a76cc2381d67bb9db44d986a3fecf\n";
static void
run_finalize(void)
@@ -226,28 +223,6 @@ now(void)
return t * SBT_1MS;
}
static uint32_t
get_timecount(struct timecounter *tc)
{
return 0;
}
static void
install_timecounter(void)
{
test_context *ctx;
ctx = &test_instance;
ctx->tc.tc_get_timecount = get_timecount;
ctx->tc.tc_counter_mask = 0xffffffff;
ctx->tc.tc_frequency = 1000000000;
ctx->tc.tc_quality = RTEMS_TIMECOUNTER_QUALITY_CLOCK_DRIVER + 1;
rtems_timecounter_install(&ctx->tc);
}
RTEMS_SYSINIT_ITEM(install_timecounter, RTEMS_SYSINIT_DEVICE_DRIVERS,
RTEMS_SYSINIT_ORDER_FIRST);
static char buffer[512];
static const T_action actions[] = {

View File

@@ -203,8 +203,8 @@ T_TEST_OUTPUT(time_to_string,
T_TEST_OUTPUT(now,
"B:now\n"
"L:0.000000000\n"
"E:now:N:0:F:0:D:0.001000\n");
"L:0.001000000\n"
"E:now:N:0:F:0:D:0.003000\n");
T_TEST_OUTPUT(tick,
"B:tick\n"
@@ -268,8 +268,8 @@ T_TEST_OUTPUT(ticks,
T_TEST_OUTPUT(begin_time,
"B:begin_time\n"
"L:time at test case begin 0.325000046\n"
"E:begin_time:N:0:F:0:D:0.001000\n");
"L:time at test case begin 0.001000000\n"
"E:begin_time:N:0:F:0:D:0.002000\n");
/*
* The license is at the end of the file to be able to use the test code and