Add pretty_xml utils
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Wed, 26 May 2021 21:17:02 +0000 (17:17 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 7 Jul 2021 21:31:33 +0000 (17:31 -0400)
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 <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Ie1597644941c55ce3e59f7ff16f196ac36325179

.gitignore
tests/utils/xml-utils/Makefile.am
tests/utils/xml-utils/pretty_xml.c [new file with mode: 0644]

index d9ecbd3d3797d88f6f51a2b3e5a36f8c43660146..d8c51e53eaa7c7a172513cd3b6bcd96470005958 100644 (file)
@@ -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
index 9b00f7027591c415a6b813257db51026fde0e75f..7fac127281f1075438b6044857d6e2e68c89a598 100644 (file)
@@ -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 (file)
index 0000000..ccc1b23
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2021 Jonathan Rajotte <jonathan.r.julien@gmail.com>
+ *
+ * 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 <libxml/parser.h>
+
+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;
+}
This page took 0.026749 seconds and 4 git commands to generate.