maint-xml-dump.exp revision 1.1.1.2 1 1.1.1.2 christos # Copyright 2020-2023 Free Software Foundation, Inc.
2 1.1 christos
3 1.1 christos # This program is free software; you can redistribute it and/or modify
4 1.1 christos # it under the terms of the GNU General Public License as published by
5 1.1 christos # the Free Software Foundation; either version 3 of the License, or
6 1.1 christos # (at your option) any later version.
7 1.1 christos #
8 1.1 christos # This program is distributed in the hope that it will be useful,
9 1.1 christos # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 1.1 christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 1.1 christos # GNU General Public License for more details.
12 1.1 christos #
13 1.1 christos # You should have received a copy of the GNU General Public License
14 1.1 christos # along with this program. If not, see <http://www.gnu.org/licenses/>.
15 1.1 christos
16 1.1 christos # Test the 'maint print xml-tdesc' command. This file picks up every
17 1.1 christos # XML file matching the pattern maint-xml-dump-*.xml (in the same
18 1.1 christos # directory as this script) and passes each in turn to the command
19 1.1 christos # 'maint print xml-tdesc'.
20 1.1 christos #
21 1.1 christos # The expected output is generated by parsing the input XML file. The
22 1.1 christos # rules for changing an XML file into the expected output are:
23 1.1 christos #
24 1.1 christos # 1. Blank lines, and lines starting with a comment are stripped from
25 1.1 christos # the expected output.
26 1.1 christos #
27 1.1 christos # 2. The <?xml ... ?> and <!DOCTYPE ...> entities are optional,
28 1.1 christos # suitable defaults will be added if these lines are missing from
29 1.1 christos # the input file.
30 1.1 christos #
31 1.1 christos # 3. A trailing comment on a line will replace the expected output for
32 1.1 christos # that line but with the indentation of the line preserved. So
33 1.1 christos # this (The '|' marks the start of the line):
34 1.1 christos # | <reg name="r1" bitsize="32"/> <!-- <reg name="r1" bitsize="32" type="int" regnum="0"/> -->
35 1.1 christos # Will actually look for the following output:
36 1.1 christos # | <reg name="r1" bitsize="32" type="int" regnum="0"/>
37 1.1 christos #
38 1.1 christos # 4. Indentation of lines will be preserved so your input file needs
39 1.1 christos # to follow the expected indentation.
40 1.1 christos if {[gdb_skip_xml_test]} {
41 1.1 christos unsupported "xml tests not being run"
42 1.1 christos return -1
43 1.1 christos }
44 1.1 christos
45 1.1 christos gdb_start
46 1.1 christos
47 1.1 christos # Read the XML file FILENAME and produce an output pattern that should
48 1.1 christos # match what GDB produces with the 'maint print xml-desc' command.
49 1.1 christos proc build_pattern { filename } {
50 1.1 christos set pattern {}
51 1.1 christos
52 1.1 christos set xml_version_line {<?xml version="1.0"?>}
53 1.1 christos set doc_type_line {<!DOCTYPE target SYSTEM "gdb-target.dtd">}
54 1.1 christos
55 1.1 christos set linenum 0
56 1.1 christos set ifd [open "$filename" r]
57 1.1 christos while {[gets $ifd line] >= 0} {
58 1.1 christos incr linenum
59 1.1 christos
60 1.1 christos # The <?xml .... ?> tag can only appear as the first line in
61 1.1 christos # the file. If it is not present then add one to the expected
62 1.1 christos # output now.
63 1.1 christos if {$linenum == 1} {
64 1.1 christos if {![regexp {^<\?xml} $line]} {
65 1.1 christos set pattern [string_to_regexp $xml_version_line]
66 1.1 christos set xml_version_line ""
67 1.1 christos }
68 1.1 christos }
69 1.1 christos
70 1.1 christos # If we have not yet seen a DOCTYPE line, then maybe we should
71 1.1 christos # be adding one? If we find <target> then add a default
72 1.1 christos # DOCTYPE line, otherwise, if the XML file includes a DOCTYPE
73 1.1 christos # line, use that.
74 1.1 christos if {$doc_type_line != "" } {
75 1.1 christos if {[regexp {^[ \t]*<target>} $line]} {
76 1.1 christos set pattern [multi_line $pattern \
77 1.1 christos [string_to_regexp $doc_type_line]]
78 1.1 christos set doc_type_line ""
79 1.1 christos } elseif {[regexp {^[ \t]*<!DOCTYPE } $line]} {
80 1.1 christos set doc_type_line ""
81 1.1 christos }
82 1.1 christos }
83 1.1 christos
84 1.1 christos if {[regexp {^[ \t]*<!--} $line]} {
85 1.1 christos # Comment line, ignore it.
86 1.1 christos } elseif {[regexp {^[ \t]+$} $line]} {
87 1.1 christos # Blank line, ignore it.
88 1.1 christos } elseif {[regexp {^([ \t]*).*<!-- (.*) -->$} $line \
89 1.1 christos matches grp1 grp2]} {
90 1.1 christos set pattern [multi_line \
91 1.1 christos $pattern \
92 1.1 christos [string_to_regexp "$grp1$grp2"]]
93 1.1 christos } else {
94 1.1 christos set pattern [multi_line \
95 1.1 christos $pattern \
96 1.1 christos [string_to_regexp $line]]
97 1.1 christos }
98 1.1 christos }
99 1.1 christos close $ifd
100 1.1 christos
101 1.1 christos # Due to handling the <?xml ...?> tags we can end up with a stray
102 1.1 christos # '\r\n' at the start of the output pattern. Remove it here.
103 1.1 christos if {[string range $pattern 0 1] == "\r\n"} {
104 1.1 christos set pattern [string range $pattern 2 end]
105 1.1 christos }
106 1.1 christos
107 1.1 christos return $pattern
108 1.1 christos }
109 1.1 christos
110 1.1 christos # Run over every test XML file and check the output.
111 1.1 christos foreach filename [lsort [glob $srcdir/$subdir/maint-xml-dump-*.xml]] {
112 1.1 christos set pattern [build_pattern $filename]
113 1.1 christos
114 1.1 christos if {[is_remote host]} {
115 1.1 christos set test_path [remote_download host $filename]
116 1.1 christos } else {
117 1.1 christos set test_path $filename
118 1.1 christos }
119 1.1 christos
120 1.1 christos verbose -log "Looking for:\n$pattern"
121 1.1 christos
122 1.1 christos gdb_test "maint print xml-tdesc $test_path" \
123 1.1 christos "$pattern" "check [file tail $filename]"
124 1.1 christos }
125