diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2024-01-09 10:27:39 +0100 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2024-01-15 07:26:05 +0100 |
commit | 8e26f7ef024d880bf9ccfbe147b541b24b873911 (patch) | |
tree | 733d1d3c4a65988479aaedad2dfd5647c9618abe /testsuites/sptests/sptimecounter02/init.c | |
parent | tmtimer01: Convert to JSON data (diff) | |
download | rtems-8e26f7ef024d880bf9ccfbe147b541b24b873911.tar.bz2 |
sptimecounter02: Convert to JSON data
This avoids a dependency on the non-standard libxml2 module.
Diffstat (limited to '')
-rw-r--r-- | testsuites/sptests/sptimecounter02/init.c | 78 |
1 files changed, 48 insertions, 30 deletions
diff --git a/testsuites/sptests/sptimecounter02/init.c b/testsuites/sptests/sptimecounter02/init.c index 95b6292359..ff05f147de 100644 --- a/testsuites/sptests/sptimecounter02/init.c +++ b/testsuites/sptests/sptimecounter02/init.c @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* - * Copyright (c) 2015 embedded brains GmbH & Co. KG + * Copyright (C) 2015, 2024 embedded brains GmbH & Co. KG * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -61,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]; @@ -90,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, @@ -133,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( @@ -192,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[] = { @@ -231,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, @@ -240,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); @@ -255,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); } |