aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.xml/maint-xml-dump.exp
blob: 692491b7de853c4afdef5681aed3f8d9818bc9f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# Copyright 2020-2021 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Test the 'maint print xml-tdesc' command.  This file picks up every
# XML file matching the pattern maint-xml-dump-*.xml (in the same
# directory as this script) and passes each in turn to the command
# 'maint print xml-tdesc'.
#
# The expected output is generated by parsing the input XML file.  The
# rules for changing an XML file into the expected output are:
#
# 1. Blank lines, and lines starting with a comment are stripped from
#    the expected output.
#
# 2. The <?xml ... ?> and <!DOCTYPE ...> entities are optional,
#    suitable defaults will be added if these lines are missing from
#    the input file.
#
# 3. A trailing comment on a line will replace the expected output for
#    that line but with the indentation of the line preserved.  So
#    this (The '|' marks the start of the line):
#    |    <reg name="r1" bitsize="32"/>  <!-- <reg name="r1" bitsize="32" type="int" regnum="0"/> -->
#    Will actually look for the following output:
#    |    <reg name="r1" bitsize="32" type="int" regnum="0"/>
#
# 4. Indentation of lines will be preserved so your input file needs
#    to follow the expected indentation.
if {[gdb_skip_xml_test]} {
    unsupported "xml tests not being run"
    return -1
}

gdb_start

# Read the XML file FILENAME and produce an output pattern that should
# match what GDB produces with the 'maint print xml-desc' command.
proc build_pattern { filename } {
    set pattern {}

    set xml_version_line {<?xml version="1.0"?>}
    set doc_type_line {<!DOCTYPE target SYSTEM "gdb-target.dtd">}

    set linenum 0
    set ifd [open "$filename" r]
    while {[gets $ifd line] >= 0} {
	incr linenum

	# The <?xml .... ?> tag can only appear as the first line in
	# the file.  If it is not present then add one to the expected
	# output now.
	if {$linenum == 1} {
	    if {![regexp {^<\?xml} $line]} {
		set pattern [string_to_regexp $xml_version_line]
		set xml_version_line ""
	    }
	}

	# If we have not yet seen a DOCTYPE line, then maybe we should
	# be adding one?  If we find <target> then add a default
	# DOCTYPE line, otherwise, if the XML file includes a DOCTYPE
	# line, use that.
	if {$doc_type_line != "" } {
	    if {[regexp {^[ \t]*<target>} $line]} {
		set pattern [multi_line $pattern \
				 [string_to_regexp $doc_type_line]]
		set doc_type_line ""
	    } elseif {[regexp {^[ \t]*<!DOCTYPE } $line]} {
		set doc_type_line ""
	    }
	}

	if {[regexp {^[ \t]*<!--} $line]} {
	    # Comment line, ignore it.
	} elseif {[regexp {^[ \t]+$} $line]} {
	    # Blank line, ignore it.
	} elseif {[regexp {^([ \t]*).*<!-- (.*) -->$} $line \
		       matches grp1 grp2]} {
	    set pattern [multi_line \
			     $pattern \
			     [string_to_regexp "$grp1$grp2"]]
	} else {
	    set pattern [multi_line \
			     $pattern \
			     [string_to_regexp $line]]
	}
    }
    close $ifd

    # Due to handling the <?xml ...?> tags we can end up with a stray
    # '\r\n' at the start of the output pattern.  Remove it here.
    if {[string range $pattern 0 1] == "\r\n"} {
	set pattern [string range $pattern 2 end]
    }

    return $pattern
}

# Run over every test XML file and check the output.
foreach filename [lsort [glob $srcdir/$subdir/maint-xml-dump-*.xml]] {
    set pattern [build_pattern $filename]

    if {[is_remote host]} {
	set test_path [remote_download host $filename]
    } else {
	set test_path $filename
    }

    verbose -log "Looking for:\n$pattern"

    gdb_test "maint print xml-tdesc $test_path" \
	"$pattern" "check [file tail $filename]"
}