mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 4/6] test: py: add test for valid JSON output from iomem/clk_dump
Date: Thu, 11 Dec 2025 21:50:06 +0100	[thread overview]
Message-ID: <20251211205240.2836186-5-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20251211205240.2836186-1-a.fatoum@pengutronix.de>

Both iomem and clk_dump support a -j parameter for JSON output that's
easier to consume from test suites. Add a simple test that verifies the
JSON can actually be parsed.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 test/py/test_shell.py | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/test/py/test_shell.py b/test/py/test_shell.py
index 3d2d85d80594..ac240636714d 100644
--- a/test/py/test_shell.py
+++ b/test/py/test_shell.py
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0-only
 
 from .helper import skip_disabled
+import json
 
 
 def test_barebox_true(barebox, barebox_config):
@@ -39,3 +40,43 @@ def test_barebox_no_err(barebox, barebox_config):
     # TODO extend by err once all qemu platforms conform
     stdout, _, _ = barebox.run('dmesg -l crit,alert,emerg')
     assert stdout == []
+
+
+def count_dicts_in_command_output(barebox, cmd):
+    def count_dicts(obj):
+        count = 0
+        if isinstance(obj, dict):
+            count += 1  # count this dict itself
+            for value in obj.values():
+                count += count_dicts(value)
+        elif isinstance(obj, list):
+            for item in obj:
+                count += count_dicts(item)
+        return count
+
+    stdout = "\n".join(barebox.run_check(cmd))
+    return count_dicts(json.loads(stdout))
+
+
+def test_cmd_iomem(barebox, barebox_config):
+    skip_disabled(barebox_config, "CONFIG_CMD_IOMEM")
+
+    regions = count_dicts_in_command_output(barebox, 'iomem -j')
+    assert regions > 0
+
+    assert count_dicts_in_command_output(barebox, 'iomem -jv') == regions
+    if regions > 1:
+        assert count_dicts_in_command_output(barebox, 'iomem -jg') > regions
+        assert count_dicts_in_command_output(barebox, 'iomem -vjg') > regions
+    else:
+        assert count_dicts_in_command_output(barebox, 'iomem -jg') >= regions
+        assert count_dicts_in_command_output(barebox, 'iomem -vjg') >= regions
+
+
+def test_cmd_clk(barebox, barebox_config):
+    skip_disabled(barebox_config, "CONFIG_CMD_CLK")
+
+    regions = count_dicts_in_command_output(barebox, 'clk_dump -j')
+    assert regions >= 0
+
+    assert count_dicts_in_command_output(barebox, 'clk_dump -vj') == regions
-- 
2.47.3




  parent reply	other threads:[~2025-12-11 20:53 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-11 20:50 [PATCH 0/6] resource: add support for walking resource gaps Ahmad Fatoum
2025-12-11 20:50 ` [PATCH 1/6] resource: implement resource walker Ahmad Fatoum
2025-12-11 20:50 ` [PATCH 2/6] test: self: implement resource walker selftest Ahmad Fatoum
2025-12-11 20:50 ` [PATCH 3/6] commands: iomem: add support for printing gaps Ahmad Fatoum
2025-12-11 20:50 ` Ahmad Fatoum [this message]
2025-12-11 20:50 ` [PATCH 5/6] memory: add helpers for iterating over memory regions Ahmad Fatoum
2025-12-11 20:50 ` [PATCH 6/6] resource: implement release_region_range Ahmad Fatoum
2025-12-15  9:29 ` [PATCH 0/6] resource: add support for walking resource gaps Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251211205240.2836186-5-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox