From bb901ead0aea0fecad53e661ed79067faa4149c8 Mon Sep 17 00:00:00 2001 From: Jonathan Rajotte Date: Wed, 26 May 2021 17:17:02 -0400 Subject: [PATCH] Add pretty_xml utils MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This util reads on stdin and outputs an indented/formatted xml. It is equivalent to "xmllint --format -". It will be used for MI trigger testing. For testing we will essentially diff the output of the command against the expected output. While a nicely formatted multi-line output is not necessary for a machine to do the diff, the human that will have to debug it will surely appreciate it. Signed-off-by: Jonathan Rajotte Signed-off-by: Jérémie Galarneau Change-Id: Ie1597644941c55ce3e59f7ff16f196ac36325179 --- .gitignore | 1 + tests/utils/xml-utils/Makefile.am | 6 ++++- tests/utils/xml-utils/pretty_xml.c | 37 ++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 tests/utils/xml-utils/pretty_xml.c diff --git a/.gitignore b/.gitignore index d9ecbd3d3..d8c51e53e 100644 --- a/.gitignore +++ b/.gitignore @@ -141,6 +141,7 @@ compile_commands.json /tests/utils/testapp/gen-kernel-test-events/gen-kernel-test-events /tests/utils/xml-utils/extract_xml /tests/utils/xml-utils/validate_xml +/tests/utils/xml-utils/pretty_xml /tests/regression/tools/live/live_test /tests/unit/ini_config/ini_config /tests/perf/find_event diff --git a/tests/utils/xml-utils/Makefile.am b/tests/utils/xml-utils/Makefile.am index 9b00f7027..7fac12728 100644 --- a/tests/utils/xml-utils/Makefile.am +++ b/tests/utils/xml-utils/Makefile.am @@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only -noinst_PROGRAMS = validate_xml extract_xml +noinst_PROGRAMS = validate_xml extract_xml pretty_xml validate_xml_SOURCES = validate_xml.c validate_xml_CPPFLAGS = $(libxml2_CFLAGS) $(AM_CPPFLAGS) validate_xml_LDADD = $(libxml2_LIBS) @@ -9,6 +9,10 @@ extract_xml_SOURCES = extract_xml.c extract_xml_CPPFLAGS = $(libxml2_CFLAGS) $(AM_CPPFLAGS) extract_xml_LDADD = $(libxml2_LIBS) +pretty_xml_SOURCES = pretty_xml.c +pretty_xml_CPPFLAGS = $(libxml2_CFLAGS) $(AM_CPPFLAGS) +pretty_xml_LDADD = $(libxml2_LIBS) + all-local: @if [ x"$(srcdir)" != x"$(builddir)" ]; then \ for script in $(EXTRA_DIST); do \ diff --git a/tests/utils/xml-utils/pretty_xml.c b/tests/utils/xml-utils/pretty_xml.c new file mode 100644 index 000000000..ccc1b23f3 --- /dev/null +++ b/tests/utils/xml-utils/pretty_xml.c @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2021 Jonathan Rajotte + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +/* + * Prettyfi a xml input from stdin to stddout. + * This allows a more human friendly format for xml testing when problems occur. + */ + +#include + +int main(int argc, char **argv) +{ + xmlDocPtr doc = NULL; + + /* Init libxml. */ + xmlInitParser(); + xmlKeepBlanksDefault(0); + + /* Parse the XML document from stdin. */ + doc = xmlParseFile("-"); + if (!doc) { + fprintf(stderr, "ERR parsing: xml input invalid"); + return -1; + } + + xmlDocFormatDump(stdout, doc, 1); + + xmlFreeDoc(doc); + /* Shutdown libxml. */ + xmlCleanupParser(); + + return 0; +} -- 2.34.1