From 7cf8aa7f7215bbab420b348216cbffd202382c20 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Tue, 9 Jan 2024 10:27:39 +0100 Subject: [PATCH] tmtimer01: Convert to JSON data This avoids a dependency on the non-standard libxml2 module. --- testsuites/tmtests/tmfine01/init.c | 30 +- testsuites/tmtests/tmtimer01/init.c | 35 +- testsuites/tmtests/tmtimer01/plot.py | 48 ++- testsuites/tmtests/tmtimer01/tmtimer01.scn | 389 +++++++++++++-------- 4 files changed, 326 insertions(+), 176 deletions(-) diff --git a/testsuites/tmtests/tmfine01/init.c b/testsuites/tmtests/tmfine01/init.c index 0396a01054..c05894f6da 100644 --- a/testsuites/tmtests/tmfine01/init.c +++ b/testsuites/tmtests/tmfine01/init.c @@ -55,6 +55,8 @@ typedef struct { typedef struct { rtems_test_parallel_context base; + const char *test_sep; + const char *counter_sep; rtems_id master; rtems_id sema; rtems_id mq[CPU_COUNT]; @@ -88,11 +90,8 @@ static rtems_interval test_init( return test_duration(); } -static const char *test_sep = ""; - -static const char *counter_sep; - static void test_fini( + test_context *ctx, const char *type, const char *description, uint32_t *counters, @@ -108,16 +107,16 @@ static void test_fini( " \"type\": \"%s\",\n" " \"description\": \"%s\",\n" " \"counter\": [", - test_sep, + ctx->test_sep, type, description ); - test_sep = ", "; - counter_sep = "\n "; + ctx->test_sep = ", "; + ctx->counter_sep = "\n "; } - printf("%s[", counter_sep); - counter_sep = "],\n "; + printf("%s[", ctx->counter_sep); + ctx->counter_sep = "],\n "; value_sep = ""; for (i = 0; i < active_workers; ++i) { @@ -175,6 +174,7 @@ static void test_self_event_fini( test_context *ctx = (test_context *) base; test_fini( + ctx, "event", "Send Event to Self", &ctx->self_event_ops[active_workers - 1][0], @@ -227,6 +227,7 @@ static void test_all_to_one_event_fini( test_context *ctx = (test_context *) base; test_fini( + ctx, "event", "Send Event to One", &ctx->all_to_one_event_ops[active_workers - 1][0], @@ -269,6 +270,7 @@ static void test_one_mutex_fini( test_context *ctx = (test_context *) base; test_fini( + ctx, "contested-mutex", "Obtain/Release Contested Classic Inheritance Mutex", &ctx->one_mutex_ops[active_workers - 1][0], @@ -324,6 +326,7 @@ static void test_many_mutex_fini( test_context *ctx = (test_context *) base; test_fini( + ctx, "private-mutex", "Obtain/Release Private Classic Inheritance Mutex", &ctx->many_mutex_ops[active_workers - 1][0], @@ -376,6 +379,7 @@ static void test_self_msg_fini( test_context *ctx = (test_context *) base; test_fini( + ctx, "message", "Send Message to Self", &ctx->self_msg_ops[active_workers - 1][0], @@ -431,6 +435,7 @@ static void test_many_to_one_msg_fini( test_context *ctx = (test_context *) base; test_fini( + ctx, "message", "Send Message to One Receiver", &ctx->many_to_one_msg_ops[active_workers - 1][0], @@ -470,6 +475,7 @@ static void test_many_sys_lock_mutex_fini( test_context *ctx = (test_context *) base; test_fini( + ctx, "private-mutex", "Obtain/Release Private Mutex", &ctx->many_sys_lock_mutex_ops[active_workers - 1][0], @@ -525,6 +531,7 @@ static void test_many_classic_ceiling_fini( test_context *ctx = (test_context *) base; test_fini( + ctx, "private-mutex", "Obtain/Release Private Classic Ceiling Mutex", &ctx->many_classic_ceiling_ops[active_workers - 1][0], @@ -581,6 +588,7 @@ static void test_many_classic_mrsp_fini( test_context *ctx = (test_context *) base; test_fini( + ctx, "private-mutex", "Obtain/Release Private Classic MrsP Mutex", &ctx->many_classic_mrsp_ops[active_workers - 1][0], @@ -625,6 +633,7 @@ static void test_many_pthread_spinlock_fini( test_context *ctx = (test_context *) base; test_fini( + ctx, "private-mutex", "Obtain/Release Private Pthread Spinlock", &ctx->many_pthread_spinlock_ops[active_workers - 1][0], @@ -680,6 +689,7 @@ static void test_many_pthread_mutex_inherit_fini( test_context *ctx = (test_context *) base; test_fini( + ctx, "private-mutex", "Obtain/Release Private Pthread Inheritance Mutex", &ctx->many_pthread_mutex_inherit_ops[active_workers - 1][0], @@ -741,6 +751,7 @@ static void test_many_pthread_mutex_protect_fini( test_context *ctx = (test_context *) base; test_fini( + ctx, "private-mutex", "Obtain/Release Private Pthread Ceiling Mutex", &ctx->many_pthread_mutex_protect_ops[active_workers - 1][0], @@ -844,6 +855,7 @@ static void Init(rtems_task_argument arg) printf("*** BEGIN OF JSON DATA ***\n[\n "); + ctx->test_sep = ""; rtems_test_parallel( &ctx->base, NULL, diff --git a/testsuites/tmtests/tmtimer01/init.c b/testsuites/tmtests/tmtimer01/init.c index b905bb7ab4..1a37b5192c 100644 --- a/testsuites/tmtests/tmtimer01/init.c +++ b/testsuites/tmtests/tmtimer01/init.c @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* - * Copyright (c) 2016 embedded brains GmbH & Co. KG + * Copyright (C) 2016, 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 @@ -108,13 +108,14 @@ static void test_fire_and_cancel( rtems_test_assert(sc2 == RTEMS_SUCCESSFUL); printf( - "<%s unit=\"ns\">%" PRIu64 "", + ",\n \"%s\": %" PRIu64, name, - rtems_counter_ticks_to_nanoseconds(d), - name + rtems_counter_ticks_to_nanoseconds(d) ); } +static const char *sep = "\n "; + static void test_case(test_context *ctx, size_t j, size_t k) { rtems_status_code sc; @@ -130,13 +131,17 @@ static void test_case(test_context *ctx, size_t j, size_t k) rtems_test_assert(sc == RTEMS_SUCCESSFUL); } - printf(" \n %zu", j); + printf( + "%s{\n" + " \"active-timers\": %zu", + sep, + j + ); + sep = "\n }, "; - test_fire_and_cancel(ctx, j, 0, "First"); - test_fire_and_cancel(ctx, j, j / 2, "Middle"); - test_fire_and_cancel(ctx, j, j + 1, "Last"); - - printf("\n \n"); + test_fire_and_cancel(ctx, j, 0, "first"); + test_fire_and_cancel(ctx, j, j / 2, "middle"); + test_fire_and_cancel(ctx, j, j + 1, "last"); } static void test(void) @@ -181,7 +186,13 @@ static void test(void) timer_count = n; } - printf("\n", timer_count); + printf( + "*** BEGIN OF JSON DATA ***\n" + "{\n" + " \"timer-count\": %zu,\n" + " \"samples\": [", + timer_count + ); k = 0; j = 0; @@ -194,7 +205,7 @@ static void test(void) test_case(ctx, n - 2, k); - printf("\n"); + printf("\n }\n ]\n}\n*** END OF JSON DATA ***\n"); } static void Init(rtems_task_argument arg) diff --git a/testsuites/tmtests/tmtimer01/plot.py b/testsuites/tmtests/tmtimer01/plot.py index 0328062314..73654c5b9d 100644 --- a/testsuites/tmtests/tmtimer01/plot.py +++ b/testsuites/tmtests/tmtimer01/plot.py @@ -1,7 +1,6 @@ # SPDX-License-Identifier: BSD-2-Clause -# -# Copyright (c) 2016 embedded brains GmbH & Co. KG +# Copyright (C) 2016, 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 @@ -23,22 +22,35 @@ # 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. -# -import libxml2 -from libxml2 import xmlNode -import matplotlib.pyplot as plt -doc = libxml2.parseFile('tmtimer01.scn') -ctx = doc.xpathNewContext() +import json +import re +import matplotlib.pyplot as plt # type: ignore +from matplotlib import ticker # type: ignore -plt.title('timer test') -plt.xscale('log') -plt.xlabel('active timers') -plt.ylabel('timer fire and cancel [ns]') -x = map(xmlNode.getContent, ctx.xpathEval('/TMTimer01/Sample/ActiveTimers')) -for i in ['First', 'Middle', 'Last']: - y = map(xmlNode.getContent, ctx.xpathEval('/TMTimer01/Sample/' + i)) - plt.plot(x, y, label = i) -plt.legend(loc = 'best') -plt.show() +def _plot(data: dict) -> None: + _, axes = plt.subplots() + axes.set_title("Timer Fire and Cancel Timing Test") + axes.set_xlabel("Active Timers") + axes.set_xscale("log") + axes.set_ylabel("Timer Fire and Cancel Duration [μs]") + x = [sample["active-timers"] for sample in data["samples"]] + for key in ["first", "middle", "last"]: + y = [sample[key] / 1000.0 for sample in data["samples"]] + axes.plot(x, y, label=f"operate on {key} timer", marker='o') + axes.legend(loc='best') + plt.savefig("tmtimer01.png") + plt.savefig("tmtimer01.pdf") + plt.close() + + +_JSON_DATA = re.compile( + r"\*\*\* BEGIN OF JSON DATA \*\*\*(.*)" + r"\*\*\* END OF JSON DATA \*\*\*", re.DOTALL) + +with open("tmtimer01.scn", "r", encoding="utf-8") as src: + match = _JSON_DATA.search(src.read()) + data = json.loads(match.group(1)) + +_plot(data) diff --git a/testsuites/tmtests/tmtimer01/tmtimer01.scn b/testsuites/tmtests/tmtimer01/tmtimer01.scn index db3ca01d27..b278c75177 100644 --- a/testsuites/tmtests/tmtimer01/tmtimer01.scn +++ b/testsuites/tmtests/tmtimer01/tmtimer01.scn @@ -1,137 +1,252 @@ - - - 088121412917 - - - 2160210101367 - - - 4152410891086 - - - 7179111211838 - - - 10148810162134 - - - 14152716983186 - - - 19207816653397 - - - 25151923684464 - - - 32124326233549 - - - 41236825784105 - - - 52232225634126 - - - 66249918554919 - - - 83168931285894 - - - 104230126474595 - - - 130288031836222 - - - 162259723767118 - - - 201351934666673 - - - 249282931777784 - - - 308261433967338 - - - 381345448889114 - - - 470339724437689 - - - 580223344109355 - - - 715378758916833 - - - 881383950899232 - - - 10852838273911575 - - - 1336325650119684 - - - 16452293526210183 - - - 2025443659348804 - - - 24924506728410389 - - - 3067383249909536 - - - 3774508848889633 - - - 4644559057498975 - - - 57144854681311603 - - - 70306139613212630 - - - 86496877385210973 - - - 106406532609711725 - - - 130895284539213246 - - - 161017077757214820 - - - 198067132833511668 - - - 243638676791913937 - - - 2996859701097816035 - - - 368628804876713089 - - - 4534286081030515709 - - - 5577289491003116262 - - - 6550391991030919090 - - + + SIS - SPARC/RISCV instruction simulator 2.30, copyright Jiri Gaisler 2020 + Bug-reports to jiri@gaisler.se + + GR740/LEON4 emulation enabled, 4 cpus online, delta 50 clocks + + Loaded build/sparc/gr740/testsuites/tmtests/tmtimer01.exe, entry 0x00000000 + + +*** BEGIN OF TEST TMTIMER 1 *** +*** TEST VERSION: 6.0.0.76c91ee7793fc70b92e2f87e601c3fdc2d2b7f3f +*** TEST STATE: EXPECTED_PASS +*** TEST BUILD: RTEMS_SMP +*** TEST TOOLS: 13.2.0 20230727 (RTEMS 6, RSB d3d738c35a71ca05f675b188539225099401ac79, Newlib a021448) +*** BEGIN OF JSON DATA *** +{ + "timer-count": 61024, + "samples": [ + { + "active-timers": 0, + "first": 8560, + "middle": 8600, + "last": 8520 + }, { + "active-timers": 2, + "first": 9020, + "middle": 11680, + "last": 8860 + }, { + "active-timers": 4, + "first": 9480, + "middle": 9440, + "last": 11060 + }, { + "active-timers": 7, + "first": 9360, + "middle": 9820, + "last": 12300 + }, { + "active-timers": 10, + "first": 9860, + "middle": 9580, + "last": 11980 + }, { + "active-timers": 14, + "first": 9860, + "middle": 10040, + "last": 12280 + }, { + "active-timers": 19, + "first": 10360, + "middle": 10080, + "last": 13260 + }, { + "active-timers": 25, + "first": 10360, + "middle": 10500, + "last": 14460 + }, { + "active-timers": 32, + "first": 10240, + "middle": 10620, + "last": 13040 + }, { + "active-timers": 41, + "first": 10820, + "middle": 10540, + "last": 15000 + }, { + "active-timers": 52, + "first": 10740, + "middle": 10880, + "last": 13660 + }, { + "active-timers": 66, + "first": 10820, + "middle": 10880, + "last": 13960 + }, { + "active-timers": 83, + "first": 11160, + "middle": 11040, + "last": 14940 + }, { + "active-timers": 104, + "first": 11160, + "middle": 11420, + "last": 14340 + }, { + "active-timers": 130, + "first": 11160, + "middle": 11300, + "last": 14720 + }, { + "active-timers": 162, + "first": 11460, + "middle": 11380, + "last": 14880 + }, { + "active-timers": 201, + "first": 11500, + "middle": 11880, + "last": 17060 + }, { + "active-timers": 249, + "first": 11580, + "middle": 11800, + "last": 16900 + }, { + "active-timers": 308, + "first": 11380, + "middle": 12060, + "last": 15640 + }, { + "active-timers": 381, + "first": 11760, + "middle": 11840, + "last": 19800 + }, { + "active-timers": 470, + "first": 11880, + "middle": 12180, + "last": 16100 + }, { + "active-timers": 580, + "first": 11760, + "middle": 12600, + "last": 16560 + }, { + "active-timers": 715, + "first": 12140, + "middle": 12220, + "last": 17380 + }, { + "active-timers": 881, + "first": 12260, + "middle": 12640, + "last": 18740 + }, { + "active-timers": 1085, + "first": 12140, + "middle": 12560, + "last": 22320 + }, { + "active-timers": 1336, + "first": 12720, + "middle": 12600, + "last": 17240 + }, { + "active-timers": 1645, + "first": 12560, + "middle": 13020, + "last": 21140 + }, { + "active-timers": 2025, + "first": 12720, + "middle": 12980, + "last": 19500 + }, { + "active-timers": 2492, + "first": 12720, + "middle": 13400, + "last": 18160 + }, { + "active-timers": 3067, + "first": 13060, + "middle": 13060, + "last": 19220 + }, { + "active-timers": 3774, + "first": 12980, + "middle": 13560, + "last": 18620 + }, { + "active-timers": 4644, + "first": 13260, + "middle": 13860, + "last": 18920 + }, { + "active-timers": 5714, + "first": 13440, + "middle": 13520, + "last": 18920 + }, { + "active-timers": 7030, + "first": 13440, + "middle": 13900, + "last": 19380 + }, { + "active-timers": 8649, + "first": 13440, + "middle": 13820, + "last": 21640 + }, { + "active-timers": 10640, + "first": 14020, + "middle": 13940, + "last": 19760 + }, { + "active-timers": 13089, + "first": 13940, + "middle": 14160, + "last": 22100 + }, { + "active-timers": 16101, + "first": 13900, + "middle": 14320, + "last": 22680 + }, { + "active-timers": 19806, + "first": 13900, + "middle": 14700, + "last": 20840 + }, { + "active-timers": 24363, + "first": 14360, + "middle": 14320, + "last": 21660 + }, { + "active-timers": 29968, + "first": 14360, + "middle": 14540, + "last": 21300 + }, { + "active-timers": 36862, + "first": 14360, + "middle": 15320, + "last": 21440 + }, { + "active-timers": 45342, + "first": 14580, + "middle": 14700, + "last": 21600 + }, { + "active-timers": 55772, + "first": 14700, + "middle": 15040, + "last": 22060 + }, { + "active-timers": 61023, + "first": 14780, + "middle": 15080, + "last": 22960 + } + ] +} +*** END OF JSON DATA *** + +*** END OF TEST TMTIMER 1 *** + +cpu 0 in error mode (tt = 0x80) + 522750200 00009b40: 91d02000 ta 0x0