[PATCH 8/8] smpopenmp01: Convert to JSON data

Sebastian Huber sebastian.huber at embedded-brains.de
Tue Jan 9 09:36:57 UTC 2024


This avoids a dependency on the non-standard libxml2 module.
---
 testsuites/smptests/smpopenmp01/init.c        |  36 +++--
 .../smptests/smpopenmp01/smpopenmp01.py       |  71 +++++----
 .../smptests/smpopenmp01/smpopenmp01.scn      | 137 ++++++++----------
 3 files changed, 118 insertions(+), 126 deletions(-)

diff --git a/testsuites/smptests/smpopenmp01/init.c b/testsuites/smptests/smpopenmp01/init.c
index 46577ff4b2..d37fe852cf 100644
--- a/testsuites/smptests/smpopenmp01/init.c
+++ b/testsuites/smptests/smpopenmp01/init.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017 embedded brains GmbH & Co. KG
+ * Copyright (C) 2017, 2024 embedded brains GmbH & Co. KG
  *
  * The license and distribution terms for this file may be
  * found in the file LICENSE in this distribution or at
@@ -143,21 +143,31 @@ static void do_bench(const char *name, void (*bench)(void), int n)
     (*bench)();
   }
   delta = omp_get_wtime() - start;
-  printf("\t\t<%sBench unit=\"s\">%f</%sBench>\n", name, delta, name);
+  printf(",\n    \"%s-bench\": %f", name, delta);
 }
 
+static const char *test_sep = "";
+
 static void microbench(int num_threads, int n)
 {
-  printf("\t<Microbench numThreads=\"%i\" majorLoopCount=\"%i\">\n", num_threads, n);
   omp_set_num_threads(num_threads);
-  do_bench("Barrier", barrier_bench, n);
-  do_bench("Parallel", parallel_bench, n);
-  do_bench("Static", static_bench, n);
-  do_bench("Dynamic", dynamic_bench, n);
-  do_bench("Guided", guided_bench, n);
-  do_bench("Runtime", runtime_bench, n);
-  do_bench("Single", single_bench, n);
-  printf("\t</Microbench>\n");
+  printf(
+    "%s{\n"
+    "    \"num-threads\": %i,\n"
+    "    \"major-loop-count\": %i",
+    test_sep,
+    num_threads,
+    n
+  );
+  test_sep = ", ";
+  do_bench("barrier", barrier_bench, n);
+  do_bench("parallel", parallel_bench, n);
+  do_bench("static", static_bench, n);
+  do_bench("dynamic", dynamic_bench, n);
+  do_bench("guided", guided_bench, n);
+  do_bench("runtime", runtime_bench, n);
+  do_bench("single", single_bench, n);
+  printf("\n  }");
 }
 
 static int estimate_3s_runtime_with_one_proc(void)
@@ -186,7 +196,7 @@ static void test(void)
   int num_procs;
   int n;
 
-  printf("<SMPOpenMP01>\n");
+  printf("*** BEGIN OF JSON DATA ***\n[\n  ");
 
   n = estimate_3s_runtime_with_one_proc();
   num_procs = omp_get_num_procs();
@@ -196,7 +206,7 @@ static void test(void)
     microbench(i, n);
   }
 
-  printf("</SMPOpenMP01>\n");
+  printf("\n]\n*** END OF JSON DATA ***\n");
 }
 
 #ifdef __rtems__
diff --git a/testsuites/smptests/smpopenmp01/smpopenmp01.py b/testsuites/smptests/smpopenmp01/smpopenmp01.py
index 8545d2d91f..227b089926 100644
--- a/testsuites/smptests/smpopenmp01/smpopenmp01.py
+++ b/testsuites/smptests/smpopenmp01/smpopenmp01.py
@@ -1,9 +1,6 @@
-#!/usr/bin/env python
-
 # SPDX-License-Identifier: BSD-2-Clause
 
-#
-# Copyright (c) 2017 embedded brains GmbH & Co. KG
+# Copyright (C) 2017, 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
@@ -25,37 +22,39 @@
 # 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 json
 import re
-import libxml2
-from libxml2 import xmlNode
-import matplotlib.pyplot as plt
-data = open('smpopenmp01.scn').read()
-data = re.sub(r'\*\*\*.*', '', data)
-doc = libxml2.parseDoc(data)
-ctx = doc.xpathNewContext()
-
-plt.title('OpenMP Microbench')
-plt.xlabel('Number of Threads')
-plt.ylabel('Relative Duration')
-
-def m(n):
-	return float(n.getContent())
-
-def p(bench):
-	d = map(m, ctx.xpathEval('/SMPOpenMP01/Microbench/' + bench))
-	y = [x / d[0] for x in d]
-	x = range(1, len(y) + 1)
-	plt.xticks(x)
-	plt.plot(x, y, label = bench, marker = 'o')
-
-p('BarrierBench')
-p('ParallelBench')
-p('StaticBench')
-p('DynamicBench')
-p('GuidedBench')
-p('RuntimeBench')
-p('SingleBench')
-plt.legend(loc = 'best')
-plt.show()
+import matplotlib.pyplot as plt  # type: ignore
+from matplotlib import ticker  # type: ignore
+
+
+def _plot(data: dict) -> None:
+    _, axes = plt.subplots()
+    axes.set_title("OpenMP Microbench")
+    axes.set_xlabel("Number of Threads")
+    axes.set_ylabel("Relative Duration")
+    x = list(range(1, len(data) + 1))
+    axes.xaxis.set_major_locator(ticker.FixedLocator(x))
+    for key in [
+            "barrier-bench", "dynamic-bench", "guided-bench", "parallel-bench",
+            "runtime-bench", "single-bench", "static-bench"
+    ]:
+        d = [results[key] for results in data]
+        y = [x / d[0] for x in d]
+        axes.plot(x, y, label=key.replace("-bench", ""), marker="o")
+    axes.legend(loc="best")
+    plt.savefig("smpopenmp01.png")
+    plt.savefig("smpopenmp01.pdf")
+    plt.close()
+
+
+_JSON_DATA = re.compile(
+    r"\*\*\* BEGIN OF JSON DATA \*\*\*(.*)"
+    r"\*\*\* END OF JSON DATA \*\*\*", re.DOTALL)
+
+with open("smpopenmp01.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/smptests/smpopenmp01/smpopenmp01.scn b/testsuites/smptests/smpopenmp01/smpopenmp01.scn
index 6f63ddca1d..2d6c944d3f 100644
--- a/testsuites/smptests/smpopenmp01/smpopenmp01.scn
+++ b/testsuites/smptests/smpopenmp01/smpopenmp01.scn
@@ -1,81 +1,64 @@
+
+ SIS - SPARC/RISCV instruction simulator 2.30,  copyright Jiri Gaisler 2020
+ Bug-reports to jiri at gaisler.se
+
+ GR740/LEON4 emulation enabled, 4 cpus online, delta 50 clocks
+
+ Loaded build/sparc/gr740/testsuites/smptests/smpopenmp01.exe, entry 0x00000000
+
+
 *** BEGIN OF TEST SMPOPENMP 1 ***
-*** TEST VERSION: 5.0.0.4c8cffc19865eaa3b033ce2776bcce9992f24b18
+*** TEST VERSION: 6.0.0.43eecff0b1b2915b87d5324ae562888851cabdaf
 *** TEST STATE: EXPECTED_PASS
-*** TEST BUILD: RTEMS_POSIX_API RTEMS_SMP
-*** TEST TOOLS: 7.3.0 20180125 (RTEMS 5, RSB 6d9c77c77d271d1fc2dfe8493d6713930b52a6dd, Newlib 3.0.0)
-<SMPOpenMP01>
-        <Microbench numThreads="1" majorLoopCount="20">
-                <BarrierBench unit="s">0.720318</BarrierBench>
-                <ParallelBench unit="s">1.121403</ParallelBench>
-                <StaticBench unit="s">0.059288</StaticBench>
-                <DynamicBench unit="s">0.440113</DynamicBench>
-                <GuidedBench unit="s">0.003230</GuidedBench>
-                <RuntimeBench unit="s">0.440121</RuntimeBench>
-                <SingleBench unit="s">0.116486</SingleBench>
-        </Microbench>
-        <Microbench numThreads="2" majorLoopCount="20">
-                <BarrierBench unit="s">0.416734</BarrierBench>
-                <ParallelBench unit="s">0.259013</ParallelBench>
-                <StaticBench unit="s">0.015311</StaticBench>
-                <DynamicBench unit="s">0.196751</DynamicBench>
-                <GuidedBench unit="s">0.002367</GuidedBench>
-                <RuntimeBench unit="s">0.199640</RuntimeBench>
-                <SingleBench unit="s">0.077629</SingleBench>
-        </Microbench>
-        <Microbench numThreads="3" majorLoopCount="20">
-                <BarrierBench unit="s">0.748332</BarrierBench>
-                <ParallelBench unit="s">0.387318</ParallelBench>
-                <StaticBench unit="s">0.021244</StaticBench>
-                <DynamicBench unit="s">0.141558</DynamicBench>
-                <GuidedBench unit="s">0.001544</GuidedBench>
-                <RuntimeBench unit="s">0.142693</RuntimeBench>
-                <SingleBench unit="s">0.117683</SingleBench>
-        </Microbench>
-        <Microbench numThreads="4" majorLoopCount="20">
-                <BarrierBench unit="s">0.552830</BarrierBench>
-                <ParallelBench unit="s">0.323241</ParallelBench>
-                <StaticBench unit="s">0.017796</StaticBench>
-                <DynamicBench unit="s">0.099475</DynamicBench>
-                <GuidedBench unit="s">0.001259</GuidedBench>
-                <RuntimeBench unit="s">0.100053</RuntimeBench>
-                <SingleBench unit="s">0.091069</SingleBench>
-        </Microbench>
-        <Microbench numThreads="5" majorLoopCount="20">
-                <BarrierBench unit="s">0.882791</BarrierBench>
-                <ParallelBench unit="s">0.452561</ParallelBench>
-                <StaticBench unit="s">0.023620</StaticBench>
-                <DynamicBench unit="s">0.094107</DynamicBench>
-                <GuidedBench unit="s">0.000989</GuidedBench>
-                <RuntimeBench unit="s">0.093911</RuntimeBench>
-                <SingleBench unit="s">0.130070</SingleBench>
-        </Microbench>
-        <Microbench numThreads="6" majorLoopCount="20">
-                <BarrierBench unit="s">0.670385</BarrierBench>
-                <ParallelBench unit="s">0.393587</ParallelBench>
-                <StaticBench unit="s">0.021141</StaticBench>
-                <DynamicBench unit="s">0.072322</DynamicBench>
-                <GuidedBench unit="s">0.000937</GuidedBench>
-                <RuntimeBench unit="s">0.069804</RuntimeBench>
-                <SingleBench unit="s">0.104107</SingleBench>
-        </Microbench>
-        <Microbench numThreads="7" majorLoopCount="20">
-                <BarrierBench unit="s">1.031511</BarrierBench>
-                <ParallelBench unit="s">0.466571</ParallelBench>
-                <StaticBench unit="s">0.024944</StaticBench>
-                <DynamicBench unit="s">0.069194</DynamicBench>
-                <GuidedBench unit="s">0.000814</GuidedBench>
-                <RuntimeBench unit="s">0.069596</RuntimeBench>
-                <SingleBench unit="s">0.133137</SingleBench>
-        </Microbench>
-        <Microbench numThreads="8" majorLoopCount="20">
-                <BarrierBench unit="s">0.761015</BarrierBench>
-                <ParallelBench unit="s">0.452577</ParallelBench>
-                <StaticBench unit="s">0.023979</StaticBench>
-                <DynamicBench unit="s">0.061193</DynamicBench>
-                <GuidedBench unit="s">0.000799</GuidedBench>
-                <RuntimeBench unit="s">0.061519</RuntimeBench>
-                <SingleBench unit="s">0.114285</SingleBench>
-        </Microbench>
-</SMPOpenMP01>
+*** TEST BUILD: RTEMS_SMP
+*** TEST TOOLS: 13.2.0 20230727 (RTEMS 6, RSB d3d738c35a71ca05f675b188539225099401ac79, Newlib a021448)
+*** BEGIN OF JSON DATA ***
+[
+  {
+    "num-threads": 1,
+    "major-loop-count": 1,
+    "barrier-bench": 0.269517,
+    "parallel-bench": 1.277477,
+    "static-bench": 0.073541,
+    "dynamic-bench": 0.118271,
+    "guided-bench": 0.008089,
+    "runtime-bench": 0.142307,
+    "single-bench": 0.034294
+  }, {
+    "num-threads": 2,
+    "major-loop-count": 1,
+    "barrier-bench": 0.269345,
+    "parallel-bench": 0.557423,
+    "static-bench": 0.033622,
+    "dynamic-bench": 0.059762,
+    "guided-bench": 0.004065,
+    "runtime-bench": 0.072107,
+    "single-bench": 0.033129
+  }, {
+    "num-threads": 3,
+    "major-loop-count": 1,
+    "barrier-bench": 0.271522,
+    "parallel-bench": 0.631576,
+    "static-bench": 0.036074,
+    "dynamic-bench": 0.039981,
+    "guided-bench": 0.002757,
+    "runtime-bench": 0.049072,
+    "single-bench": 0.033129
+  }, {
+    "num-threads": 4,
+    "major-loop-count": 1,
+    "barrier-bench": 0.272048,
+    "parallel-bench": 0.705746,
+    "static-bench": 0.039061,
+    "dynamic-bench": 0.030069,
+    "guided-bench": 0.002095,
+    "runtime-bench": 0.037570,
+    "single-bench": 0.033176
+  }
+]
+*** END OF JSON DATA ***
 
 *** END OF TEST SMPOPENMP 1 ***
+
+cpu 0 in error mode (tt = 0x80)
+ 706370700  0000cac0:  91d02000   ta  0x0
-- 
2.35.3



More information about the devel mailing list