diff options
Diffstat (limited to 'testsuites/sptests/sptimecounter02/init.c')
-rw-r--r-- | testsuites/sptests/sptimecounter02/init.c | 107 |
1 files changed, 69 insertions, 38 deletions
diff --git a/testsuites/sptests/sptimecounter02/init.c b/testsuites/sptests/sptimecounter02/init.c index ffa53edfd8..ff05f147de 100644 --- a/testsuites/sptests/sptimecounter02/init.c +++ b/testsuites/sptests/sptimecounter02/init.c @@ -1,15 +1,28 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + /* - * Copyright (c) 2015 embedded brains GmbH. All rights reserved. + * Copyright (C) 2015, 2024 embedded brains GmbH & Co. KG * - * embedded brains GmbH - * Dornierstr. 4 - * 82178 Puchheim - * Germany - * <rtems@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. * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. + * 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. */ #ifdef HAVE_CONFIG_H @@ -48,6 +61,8 @@ const char rtems_test_name[] = "SPTIMECOUNTER 2"; typedef struct { rtems_test_parallel_context base; + const char *test_sep; + const char *counter_sep; struct timecounter tc_null; uint32_t binuptime_per_job[CPU_COUNT]; sbintime_t duration_per_job[CPU_COUNT]; @@ -77,6 +92,45 @@ static void install_tc_null(timecounter_context *ctx) rtems_timecounter_install(tc_cpu); } +static void test_print_results( + const char *driver, + timecounter_context *ctx, + size_t active_workers +) +{ + const char *value_sep; + size_t i; + + if (active_workers == 1) { + printf( + "%s{\n" + " \"timecounter\": \"%s\",\n" + " \"counter\": [", + ctx->test_sep, + driver + ); + ctx->test_sep = ", "; + ctx->counter_sep = "\n "; + } + + printf("%s[", ctx->counter_sep); + ctx->counter_sep = "],\n "; + value_sep = ""; + + for (i = 0; i < active_workers; ++i) { + printf( + "%s%" PRIu32, + value_sep, + ctx->binuptime_per_job[i] + ); + value_sep = ", "; + } + + if (active_workers == rtems_scheduler_get_processor_maximum()) { + printf("]\n ]\n }"); + } +} + static rtems_interval test_bintime_init( rtems_test_parallel_context *base, void *arg, @@ -120,25 +174,14 @@ static void test_bintime_fini( timecounter_context *ctx = (timecounter_context *) base; size_t i; - printf(" <BinuptimeTest activeWorker=\"%zu\">\n", active_workers); - for (i = 0; i < active_workers; ++i) { sbintime_t error; - printf( - " <Counter worker=\"%zu\">%" PRIu32 "</Counter>\n" - " <Duration worker=\"%zu\" unit=\"sbintime\">%" PRId64 "</Duration>\n", - i + 1, - ctx->binuptime_per_job[i], - i + 1, - ctx->duration_per_job[i] - ); - error = DURATION_IN_SECONDS * SBT_1S - ctx->duration_per_job[i]; rtems_test_assert(error * error < SBT_1MS * SBT_1MS); } - printf(" </BinuptimeTest>\n"); + test_print_results("Clock Driver", ctx, active_workers); } static rtems_interval test_bintime_null_init( @@ -179,20 +222,7 @@ static void test_bintime_null_fini( size_t active_workers ) { - timecounter_context *ctx = (timecounter_context *) base; - size_t i; - - printf(" <BinuptimeNullTest activeWorker=\"%zu\">\n", active_workers); - - for (i = 0; i < active_workers; ++i) { - printf( - " <Counter worker=\"%zu\">%" PRIu32 "</Counter>\n", - i + 1, - ctx->binuptime_per_job[i] - ); - } - - printf(" </BinuptimeNullTest>\n"); + test_print_results("Null", (timecounter_context *) base, active_workers); } static const rtems_test_parallel_job timecounter_jobs[] = { @@ -218,8 +248,9 @@ static void Init(rtems_task_argument arg) TEST_BEGIN(); - printf("<SPTimecounter01>\n"); + printf("*** BEGIN OF JSON DATA ***\n[\n "); + ctx->test_sep = ""; rtems_test_parallel( &ctx->base, NULL, @@ -227,6 +258,8 @@ static void Init(rtems_task_argument arg) RTEMS_ARRAY_SIZE(timecounter_jobs) ); + printf("\n]\n*** END OF JSON DATA ***\n"); + /* Check for all functions available in the bsd.h user space */ rtems_bsd_bintime(&bt); @@ -242,8 +275,6 @@ static void Init(rtems_task_argument arg) rtems_bsd_getmicrouptime(&tv); rtems_bsd_getnanouptime(&ts); - printf("</SPTimecounter01>\n"); - TEST_END(); rtems_test_exit(0); } |