abg-reader: handle empty corpus nodes in xml representation
authorMatthias Maennich <maennich@google.com>
Mon, 13 Jan 2020 10:42:14 +0000 (10:42 +0000)
committerMatthias Maennich <maennich@google.com>
Mon, 20 Jan 2020 12:20:09 +0000 (12:20 +0000)
commit53d10a789db27f984a6d73d0fe514404ff08ac50
treeeb0fc7950c4146c94f7e116bb4d1674ee096ef17
parentaa15698aaf8cc354c09dee0b1a0d6a631ee4a403
abg-reader: handle empty corpus nodes in xml representation

An abi-corpus might be part of the representation, but might (due to
filters like whitelisting) not contain actual symbols to be considered.
In that case, `abidw` produces an empty abi-corpus node.

Valid ways of representing this in XML are

 -  <abi-corpus path='vmlinux' architecture='elf-arm-aarch64'/>

 -  <abi-corpus path='vmlinux' architecture='elf-arm-aarch64'></abi-corpus>

 -  <abi-corpus path='vmlinux' architecture='elf-arm-aarch64'>
    </abi-corpus>

abg-reader could currently only handle the last format and crashed upon
processing the first two ones. The crash happened due to the XMLNode
having no children, but that was assumed. The last case succeeded so
far as this form actually contains a text node (with the newline
character) as a child.

Fix this by handling the case of a node not having children by exiting
early with an empty node.

* src/abg-reader.cc (read_corpus_from_input): when assigning a
corpus node, assure the node actually has children.
* tests/test-abidiff.cc (main): Add test for variants of empty
xml nodes to the test harness.
* tests/data/test-abidiff/test-empty-corpus-0.xml: Test input
containing an empty xml node that closes immediately.
* tests/data/test-abidiff/test-empty-corpus-0.xml: Test input
containing an empty xml node that closes immediately with a tag.
* tests/data/test-abidiff/test-empty-corpus-0.xml: Test input
containing an empty xml node that closes with a tag on a new line.
* tests/data/test-abidiff/test-empty-corpus-report.txt:
Expected test output (empty abidiff) for diffing xml with itself.
* tests/data/Makefile.am: Add the new test input material above
to source distribution.

Reviewed-by: Dodji Seketeli <dodji@seketeli.org>
Signed-off-by: Matthias Maennich <maennich@google.com>
src/abg-reader.cc
tests/data/Makefile.am
tests/data/test-abidiff/test-empty-corpus-0.xml [new file with mode: 0644]
tests/data/test-abidiff/test-empty-corpus-1.xml [new file with mode: 0644]
tests/data/test-abidiff/test-empty-corpus-2.xml [new file with mode: 0644]
tests/data/test-abidiff/test-empty-corpus-report.txt [new file with mode: 0644]
tests/test-abidiff.cc