diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2019-10-01 13:48:27 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2019-10-02 07:01:36 +0200 |
commit | 8d989c56ff0c65beb7ec3390aebef6ea52840fab (patch) | |
tree | b63e2df686da87a30a79f9a6643ff3c7e81219a0 /testsuites | |
parent | score: Remove strange timecounter init step (diff) | |
download | rtems-8d989c56ff0c65beb7ec3390aebef6ea52840fab.tar.bz2 |
score: Install timecounter according to quality
This makes it possible to install higher quality timecounter in
plug-and-play systems and helps to override the clock driver provided
timecounter in some test scenarios.
Diffstat (limited to 'testsuites')
-rw-r--r-- | testsuites/sptests/sptimecounter01/init.c | 101 |
1 files changed, 79 insertions, 22 deletions
diff --git a/testsuites/sptests/sptimecounter01/init.c b/testsuites/sptests/sptimecounter01/init.c index 8928c5e051..c949244dc4 100644 --- a/testsuites/sptests/sptimecounter01/init.c +++ b/testsuites/sptests/sptimecounter01/init.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 embedded brains GmbH. All rights reserved. + * Copyright (c) 2015, 2019 embedded brains GmbH. All rights reserved. * * embedded brains GmbH * Dornierstr. 4 @@ -29,32 +29,87 @@ const char rtems_test_name[] = "SPTIMECOUNTER 1"; +#define TEST_QUAL 1234 + +#define TEST_FREQ 1000000 + typedef struct { - struct timecounter tc_soft; - u_int tc_soft_counter; + struct timecounter tc; + uint32_t counter; + struct timecounter tc_2; + uint32_t counter_2; } test_context; static test_context test_instance; -static uint32_t test_get_timecount_soft(struct timecounter *tc) +static uint32_t test_get_timecount(struct timecounter *tc) +{ + test_context *ctx; + + ctx = RTEMS_CONTAINER_OF(tc, test_context, tc); + ++ctx->counter; + + return ctx->counter; +} + +static uint32_t test_get_timecount_2(struct timecounter *tc) { test_context *ctx; - ctx = RTEMS_CONTAINER_OF(tc, test_context, tc_soft); - ++ctx->tc_soft_counter; + ctx = RTEMS_CONTAINER_OF(tc, test_context, tc_2); + ++ctx->counter_2; + + return ctx->counter_2; +} - return ctx->tc_soft_counter; +static void test_install(test_context *ctx) +{ + struct timecounter *tc; + struct timecounter *tc_2; + uint32_t c; + uint32_t c_2; + + tc = &ctx->tc; + tc_2 = &ctx->tc_2; + c = ctx->counter; + c_2 = ctx->counter_2; + + tc_2->tc_get_timecount = test_get_timecount_2; + tc_2->tc_counter_mask = 0x0fffffff; + tc_2->tc_frequency = TEST_FREQ - 1; + tc_2->tc_quality = TEST_QUAL; + _Timecounter_Install(tc_2); + assert(ctx->counter == c); + assert(ctx->counter_2 == c_2); + + tc_2->tc_get_timecount = test_get_timecount_2; + tc_2->tc_counter_mask = 0x0fffffff; + tc_2->tc_frequency = TEST_FREQ - 1; + tc_2->tc_quality = TEST_QUAL + 1; + _Timecounter_Install(tc_2); + assert(ctx->counter == c + 1); + assert(ctx->counter_2 == c_2 + 1); + + tc->tc_get_timecount = test_get_timecount; + tc->tc_counter_mask = 0x0fffffff; + tc->tc_frequency = TEST_FREQ; + tc->tc_quality = TEST_QUAL + 1; + _Timecounter_Install(tc); + assert(ctx->counter == c + 2); + assert(ctx->counter_2 == c_2 + 2); } void boot_card(const char *cmdline) { - test_context *ctx = &test_instance; - struct timecounter *tc_soft = &ctx->tc_soft; - uint64_t soft_freq = 1000000; + test_context *ctx; + struct timecounter *tc; struct bintime bt; struct timeval tv; struct timespec ts; + ctx = &test_instance; + tc = &ctx->tc; + TEST_BEGIN(); assert(time(NULL) == TOD_SECONDS_1970_THROUGH_1988); @@ -120,34 +175,36 @@ void boot_card(const char *cmdline) assert(bt.sec == 1); assert(bt.frac == 0); - ctx->tc_soft_counter = 0; - tc_soft->tc_get_timecount = test_get_timecount_soft; - tc_soft->tc_counter_mask = 0x0fffffff; - tc_soft->tc_frequency = soft_freq; - tc_soft->tc_quality = 1234; - _Timecounter_Install(tc_soft); - assert(ctx->tc_soft_counter == 1); + ctx->counter = 0; + tc->tc_get_timecount = test_get_timecount; + tc->tc_counter_mask = 0x0fffffff; + tc->tc_frequency = TEST_FREQ; + tc->tc_quality = TEST_QUAL; + _Timecounter_Install(tc); + assert(ctx->counter == 1); rtems_bsd_binuptime(&bt); - assert(ctx->tc_soft_counter == 2); + assert(ctx->counter == 2); assert(bt.sec == 1); assert(bt.frac == 18446744073708); - ctx->tc_soft_counter = 0xf0000000 | 1; + ctx->counter = 0xf0000000 | 1; rtems_bsd_binuptime(&bt); - assert(ctx->tc_soft_counter == (0xf0000000 | 2)); + assert(ctx->counter == (0xf0000000 | 2)); assert(bt.sec == 1); assert(bt.frac == 18446744073708); /* Ensure that the fraction overflows and the second remains constant */ - ctx->tc_soft_counter = (0xf0000000 | 1) + soft_freq; + ctx->counter = (0xf0000000 | 1) + TEST_FREQ; rtems_bsd_binuptime(&bt); - assert(ctx->tc_soft_counter == (0xf0000000 | 2) + soft_freq); + assert(ctx->counter == (0xf0000000 | 2) + TEST_FREQ); assert(bt.sec == 1); assert(bt.frac == 18446742522092); + test_install(ctx); + TEST_END(); _Terminate(RTEMS_FATAL_SOURCE_EXIT, 0); |