maint-xml-dump.exp 4.1 KB

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