1 1.1.1.3 christos # Copyright 2020-2024 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.1.3 christos require allow_xml_test 41 1.1 christos 42 1.1 christos gdb_start 43 1.1 christos 44 1.1 christos # Read the XML file FILENAME and produce an output pattern that should 45 1.1 christos # match what GDB produces with the 'maint print xml-desc' command. 46 1.1 christos proc build_pattern { filename } { 47 1.1 christos set pattern {} 48 1.1 christos 49 1.1 christos set xml_version_line {<?xml version="1.0"?>} 50 1.1 christos set doc_type_line {<!DOCTYPE target SYSTEM "gdb-target.dtd">} 51 1.1 christos 52 1.1 christos set linenum 0 53 1.1 christos set ifd [open "$filename" r] 54 1.1 christos while {[gets $ifd line] >= 0} { 55 1.1 christos incr linenum 56 1.1 christos 57 1.1 christos # The <?xml .... ?> tag can only appear as the first line in 58 1.1 christos # the file. If it is not present then add one to the expected 59 1.1 christos # output now. 60 1.1 christos if {$linenum == 1} { 61 1.1 christos if {![regexp {^<\?xml} $line]} { 62 1.1 christos set pattern [string_to_regexp $xml_version_line] 63 1.1 christos set xml_version_line "" 64 1.1 christos } 65 1.1 christos } 66 1.1 christos 67 1.1 christos # If we have not yet seen a DOCTYPE line, then maybe we should 68 1.1 christos # be adding one? If we find <target> then add a default 69 1.1 christos # DOCTYPE line, otherwise, if the XML file includes a DOCTYPE 70 1.1 christos # line, use that. 71 1.1 christos if {$doc_type_line != "" } { 72 1.1 christos if {[regexp {^[ \t]*<target>} $line]} { 73 1.1 christos set pattern [multi_line $pattern \ 74 1.1 christos [string_to_regexp $doc_type_line]] 75 1.1 christos set doc_type_line "" 76 1.1 christos } elseif {[regexp {^[ \t]*<!DOCTYPE } $line]} { 77 1.1 christos set doc_type_line "" 78 1.1 christos } 79 1.1 christos } 80 1.1 christos 81 1.1 christos if {[regexp {^[ \t]*<!--} $line]} { 82 1.1 christos # Comment line, ignore it. 83 1.1 christos } elseif {[regexp {^[ \t]+$} $line]} { 84 1.1 christos # Blank line, ignore it. 85 1.1 christos } elseif {[regexp {^([ \t]*).*<!-- (.*) -->$} $line \ 86 1.1 christos matches grp1 grp2]} { 87 1.1 christos set pattern [multi_line \ 88 1.1 christos $pattern \ 89 1.1 christos [string_to_regexp "$grp1$grp2"]] 90 1.1 christos } else { 91 1.1 christos set pattern [multi_line \ 92 1.1 christos $pattern \ 93 1.1 christos [string_to_regexp $line]] 94 1.1 christos } 95 1.1 christos } 96 1.1 christos close $ifd 97 1.1 christos 98 1.1 christos # Due to handling the <?xml ...?> tags we can end up with a stray 99 1.1 christos # '\r\n' at the start of the output pattern. Remove it here. 100 1.1 christos if {[string range $pattern 0 1] == "\r\n"} { 101 1.1 christos set pattern [string range $pattern 2 end] 102 1.1 christos } 103 1.1 christos 104 1.1 christos return $pattern 105 1.1 christos } 106 1.1 christos 107 1.1 christos # Run over every test XML file and check the output. 108 1.1 christos foreach filename [lsort [glob $srcdir/$subdir/maint-xml-dump-*.xml]] { 109 1.1 christos set pattern [build_pattern $filename] 110 1.1 christos 111 1.1 christos if {[is_remote host]} { 112 1.1 christos set test_path [remote_download host $filename] 113 1.1 christos } else { 114 1.1 christos set test_path $filename 115 1.1 christos } 116 1.1 christos 117 1.1 christos verbose -log "Looking for:\n$pattern" 118 1.1 christos 119 1.1 christos gdb_test "maint print xml-tdesc $test_path" \ 120 1.1 christos "$pattern" "check [file tail $filename]" 121 1.1 christos } 122