From: Mauro Carvalho Chehab <mauro.chehab@linux.intel.com>
To: igt-dev@lists.freedesktop.org
Subject: [igt-dev] [PATCH i-g-t 2/7] scripts/igt_doc.py: add JSON file output
Date: Tue, 21 Feb 2023 09:35:36 +0100 [thread overview]
Message-ID: <20230221083541.1079643-3-mauro.chehab@linux.intel.com> (raw)
In-Reply-To: <20230221083541.1079643-1-mauro.chehab@linux.intel.com>
From: Mauro Carvalho Chehab <mchehab@kernel.org>
At least for debugging purposes, it is interesting to see how the
script is parsing the input files and expanding wildcards on a more
condensed way. So, add support to output the dictionary contents
into a json file.
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
Reviewed-by: Zbigniew Kempczyński <zbigniew.kempczynski@intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
---
scripts/igt_doc.py | 51 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 51 insertions(+)
diff --git a/scripts/igt_doc.py b/scripts/igt_doc.py
index c8bd4054f638..d21f87dc7183 100644
--- a/scripts/igt_doc.py
+++ b/scripts/igt_doc.py
@@ -11,6 +11,7 @@
"""Maintain test plan and test implementation documentation on IGT."""
import argparse
+import json
import re
import subprocess
import sys
@@ -231,6 +232,42 @@ class TestList:
return subtest_array
+ def expand_dictionary(self):
+
+ """ prepares a dictonary with subtest arguments expanded """
+
+ test_dict = {}
+
+ for test in self.doc: # pylint: disable=C0206
+ fname = self.doc[test]["File"]
+
+ name = re.sub(r'.*tests/', '', fname)
+ name = re.sub(r'\.[ch]', '', name)
+ name = "igt@" + name
+
+ test_dict[name] = {}
+
+ for field in self.doc[test]:
+ if field == "subtest":
+ continue
+ if field == "arg":
+ continue
+
+ test_dict[name][field] = self.doc[test][field]
+
+ subtest_array = self.expand_subtest(fname, name, test)
+ for subtest in subtest_array:
+ summary = subtest["Summary"]
+ test_dict[name][summary] = {}
+ for field in sorted(subtest.keys()):
+ if field == 'Summary':
+ continue
+ if field == 'arg':
+ continue
+ test_dict[name][summary][field] = subtest[field]
+
+ return test_dict
+
#
# Output methods
#
@@ -280,6 +317,14 @@ class TestList:
print()
print()
+ def print_json(self, out_fname):
+
+ """Adds the contents of test/subtest documentation form a file"""
+ test_dict = self.expand_dictionary()
+
+ with open(out_fname, "w", encoding='utf8') as write_file:
+ json.dump(test_dict, write_file, indent=4)
+
#
# Subtest list methods
#
@@ -541,6 +586,8 @@ parser = argparse.ArgumentParser(description = "Print formatted kernel documenta
epilog = 'If no action specified, assume --rest.')
parser.add_argument("--rest", action="store_true",
help="Generate documentation from the source files, in ReST file format.")
+parser.add_argument("--to-json",
+ help="Output test documentation in JSON format as TO_JSON file")
parser.add_argument("--show-subtests", action="store_true",
help="Shows the name of the documented subtests in alphabetical order.")
parser.add_argument("--check-testlist", action="store_true",
@@ -570,5 +617,9 @@ if parse_args.check_testlist:
RUN = 1
tests.check_tests()
+if parse_args.to_json:
+ RUN = 1
+ tests.print_json(parse_args.to_json)
+
if not RUN or parse_args.rest:
tests.print_test()
--
2.39.2
next prev parent reply other threads:[~2023-02-21 8:36 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-21 8:35 [igt-dev] [PATCH i-g-t 0/7] Improve scripts/igt_doc.py script Mauro Carvalho Chehab
2023-02-21 8:35 ` [igt-dev] [PATCH i-g-t 1/7] scripts/igt_doc.py: beautify its code Mauro Carvalho Chehab
2023-02-21 8:35 ` Mauro Carvalho Chehab [this message]
2023-02-21 8:35 ` [igt-dev] [PATCH i-g-t 3/7] scripts/igt_doc.py: dynamically create fields array from a JSON file Mauro Carvalho Chehab
2023-02-21 8:35 ` [igt-dev] [PATCH i-g-t 4/7] scripts/igt_doc.py: add support to specify numeric values Mauro Carvalho Chehab
2023-02-21 8:35 ` [igt-dev] [PATCH i-g-t 5/7] scripts/igt_doc.py: add support to produce hierarchical output Mauro Carvalho Chehab
2023-02-21 8:35 ` [igt-dev] [PATCH i-g-t 6/7] scripts/igt_doc.py: improve --show-subtests logic Mauro Carvalho Chehab
2023-02-21 8:35 ` [igt-dev] [PATCH i-g-t 7/7] scripts/igt_doc.py: add error handler for subprocess Mauro Carvalho Chehab
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=20230221083541.1079643-3-mauro.chehab@linux.intel.com \
--to=mauro.chehab@linux.intel.com \
--cc=igt-dev@lists.freedesktop.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