gfortran-dg.exp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. # Copyright (C) 2004-2015 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 GCC; see the file COPYING3. If not see
  14. # <http://www.gnu.org/licenses/>.
  15. load_lib gcc-dg.exp
  16. load_lib torture-options.exp
  17. # Define gfortran callbacks for dg.exp.
  18. proc gfortran-dg-test { prog do_what extra_tool_flags } {
  19. set result \
  20. [gcc-dg-test-1 gfortran_target_compile $prog $do_what $extra_tool_flags]
  21. set comp_output [lindex $result 0]
  22. set output_file [lindex $result 1]
  23. # gfortran error messages look like this:
  24. # [name]:[locus]:
  25. #
  26. # some code
  27. # 1
  28. # Error: Some error at (1)
  29. # or
  30. # [name]:[locus]:
  31. #
  32. # some code
  33. # 1
  34. # [name]:[locus2]:
  35. #
  36. # some other code
  37. # 2
  38. # Error: Some error at (1) and (2)
  39. # or
  40. # [name]:[locus]:
  41. #
  42. # some code and some more code
  43. # 1 2
  44. # Error: Some error at (1) and (2)
  45. #
  46. # or
  47. # [name]:[locus]: Error: Some error
  48. #
  49. # Where [locus] is either [line] or [line].[column] or
  50. # [line].[column]-[column] .
  51. #
  52. # We collapse these to look like:
  53. # [name]:[line]:[column]: Error: Some error at (1) and (2)
  54. # or
  55. # [name]:[line]:[column]: Error: Some error at (1) and (2)
  56. # [name]:[line2]:[column]: Error: Some error at (1) and (2)
  57. #
  58. # Note that these regexps only make sense in the combinations used below.
  59. # Note also that is imperative that we first deal with the form with
  60. # two loci.
  61. set locus_regexp "(\[^\n\]+:\[0-9\]+)\[\.:\](\[0-9\]+)(-\[0-9\]+)?:\n\n\[^\n\]+\n\[^\n\]+\n"
  62. set diag_regexp "(\[^\n\]+)\n"
  63. # We proceed in steps:
  64. # 1. We add first a column number if none exists.
  65. # (Some Fortran diagnostics have the locus after Warning|Error)
  66. set colnum_regexp "(^|\n)(Warning: |Error: )?(\[^:\n\]+:\[0-9\]+):(\[ \n\])"
  67. regsub -all $colnum_regexp $comp_output "\\1\\3:0:\\4\\2" comp_output
  68. verbose "comput_output0:\n$comp_output"
  69. # 2. We deal with the form with two different locus lines,
  70. set two_loci "(^|\n)$locus_regexp$locus_regexp$diag_regexp"
  71. regsub -all $two_loci $comp_output "\\1\\2:\\3: \\8\n\\5\:\\6: \\8\n" comp_output
  72. verbose "comput_output1:\n$comp_output"
  73. # 3. then with the form with only one locus line.
  74. set single_locus "(^|\n)$locus_regexp$diag_regexp"
  75. regsub -all $single_locus $comp_output "\\1\\2:\\3: \\5\n" comp_output
  76. verbose "comput_output2:\n$comp_output"
  77. # 4. Add a line number if none exists
  78. regsub -all "(^|\n)(Warning: |Error: )" $comp_output "\\1:0:0: \\2" comp_output
  79. verbose "comput_output3:\n$comp_output"
  80. return [list $comp_output $output_file]
  81. }
  82. proc gfortran-dg-prune { system text } {
  83. return [gcc-dg-prune $system $text]
  84. }
  85. # Utility routines.
  86. # Modified dg-runtest that can cycle through a list of optimization options
  87. # as c-torture does.
  88. proc gfortran-dg-runtest { testcases flags default-extra-flags } {
  89. global runtests
  90. global DG_TORTURE_OPTIONS torture_with_loops
  91. torture-init
  92. set-torture-options $DG_TORTURE_OPTIONS
  93. foreach test $testcases {
  94. # If we're only testing specific files and this isn't one of
  95. # them, skip it.
  96. if ![runtest_file_p $runtests $test] {
  97. continue
  98. }
  99. # look if this is dg-do-run test, in which case
  100. # we cycle through the option list, otherwise we don't
  101. if [expr [search_for $test "dg-do run"]] {
  102. set option_list $torture_with_loops
  103. } else {
  104. set option_list [list { -O } ]
  105. }
  106. set nshort [file tail [file dirname $test]]/[file tail $test]
  107. list-module-names $test
  108. foreach flags_t $option_list {
  109. verbose "Testing $nshort, $flags $flags_t" 1
  110. dg-test $test "$flags $flags_t" ${default-extra-flags}
  111. cleanup-modules ""
  112. }
  113. }
  114. torture-finish
  115. }
  116. proc gfortran-dg-debug-runtest { target_compile trivial opt_opts testcases } {
  117. global srcdir subdir DEBUG_TORTURE_OPTIONS
  118. if ![info exists DEBUG_TORTURE_OPTIONS] {
  119. set DEBUG_TORTURE_OPTIONS ""
  120. set type_list [list "-gstabs" "-gstabs+" "-gxcoff" "-gxcoff+" "-gcoff" "-gdwarf-2" ]
  121. foreach type $type_list {
  122. set comp_output [$target_compile \
  123. "$srcdir/$subdir/$trivial" "trivial.S" assembly \
  124. "additional_flags=$type"]
  125. if { [string match "exit status *" $comp_output] } {
  126. continue
  127. }
  128. if { [string match \
  129. "* target system does not support the * debug format*" \
  130. $comp_output]
  131. } {
  132. continue
  133. }
  134. remove-build-file "trivial.S"
  135. foreach level {1 "" 3} {
  136. if { ($type == "-gdwarf-2") && ($level != "") } {
  137. lappend DEBUG_TORTURE_OPTIONS [list "${type}" "-g${level}"]
  138. foreach opt $opt_opts {
  139. lappend DEBUG_TORTURE_OPTIONS \
  140. [list "${type}" "-g${level}" "$opt" ]
  141. }
  142. } else {
  143. lappend DEBUG_TORTURE_OPTIONS [list "${type}${level}"]
  144. foreach opt $opt_opts {
  145. lappend DEBUG_TORTURE_OPTIONS \
  146. [list "${type}${level}" "$opt" ]
  147. }
  148. }
  149. }
  150. }
  151. }
  152. verbose -log "Using options $DEBUG_TORTURE_OPTIONS"
  153. global runtests
  154. foreach test $testcases {
  155. # If we're only testing specific files and this isn't one of
  156. # them, skip it.
  157. if ![runtest_file_p $runtests $test] {
  158. continue
  159. }
  160. set nshort [file tail [file dirname $test]]/[file tail $test]
  161. list-module-names $test
  162. foreach flags $DEBUG_TORTURE_OPTIONS {
  163. set doit 1
  164. # gcc-specific checking removed here
  165. if { $doit } {
  166. verbose -log "Testing $nshort, $flags" 1
  167. dg-test $test $flags ""
  168. cleanup-modules ""
  169. }
  170. }
  171. }
  172. }