Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

gmtest.in 6.1 KB

You have to be logged in to leave a comment. Sign In
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
  1. #!/usr/bin/env bash
  2. #
  3. #
  4. # Functions to be used with test scripts
  5. test -z "$1" && exit 1
  6. # Where the current script resides (need absolute path)
  7. script_name="$1"
  8. script="@GMT_SOURCE_DIR@/doc/scripts/${script_name}"
  9. local_script=$(basename "${script_name}")
  10. src="@GMT_SOURCE_DIR@/doc/scripts"
  11. # Is it a modern mode script?
  12. modern=$(grep "gmt begin" "$script" -c)
  13. # Is it a script that is known to fail?
  14. known2fail=$(grep "GMT_KNOWN_FAILURE" "$script" -c)
  15. # Any script override of GRAPHICSMAGICK_RMS? Must be a comment line of the format
  16. # GRAPHICSMAGICK_RMS = <custom-limit>
  17. GRAPHICSMAGICK_RMS=$(grep "GRAPHICSMAGICK_RMS" "$script" | awk '{print $4}')
  18. if ! [ -x "${script}" ]; then
  19. echo "error: cannot execute script ${script}." >&2
  20. exit 1
  21. fi
  22. shift
  23. # choose awk
  24. if command -v gawk >/dev/null 2>&1 ; then
  25. export AWK=gawk
  26. elif command -v nawk >/dev/null 2>&1 ; then
  27. export AWK=nawk
  28. else
  29. export AWK=awk
  30. fi
  31. # Temporary change LANG to C
  32. LANG=C
  33. # Additional variables needed in gmtest
  34. GRAPHICSMAGICK="@GRAPHICSMAGICK@"
  35. # If no script-specific rms we use the system default
  36. if [ -z "$GRAPHICSMAGICK_RMS" ]; then
  37. GRAPHICSMAGICK_RMS="@GRAPHICSMAGICK_RMS@"
  38. fi
  39. # Reset error count
  40. ERROR=0
  41. # valgrind gmt wrapper
  42. function gmt()
  43. {
  44. if [ -n "${VALGRIND_ARGS}" ]; then
  45. valgrind ${VALGRIND_ARGS} --log-file=valgrind_%p.log \
  46. --dsymutil=yes @GMT_BINARY_DIR@/src/gmt "$@"
  47. else
  48. "@GMT_BINARY_DIR@/src/gmt" "$@"
  49. fi
  50. }
  51. # export function definitions to subshells
  52. export -f gmt
  53. # invalidate module calls without "gmt" prefix, which would bypass gmt from build dir
  54. . "@GMT_SOURCE_DIR@/test/invalidate_modules.sh"
  55. # Convert PS to PDF
  56. function make_pdf()
  57. {
  58. pdf="${ps%.ps}.pdf"
  59. test -f "$ps" || return 1
  60. gmt psconvert -Tf -A -P "$ps" || ((++ERROR))
  61. test -f "$pdf" || ((++ERROR))
  62. }
  63. # Compare the ps file with its original.
  64. pscmp () {
  65. test -f "$ps" || return 1
  66. if ! [ -x "$GRAPHICSMAGICK" ]; then
  67. echo "[PASS] (without comparison)"
  68. return
  69. fi
  70. if [ ${known2fail} -eq 1 ]; then # No point running the comparison since we know it fails
  71. echo "${ps}: RMS Error = N/A [FAIL] (known failure)"
  72. now=$(date "+%F %T")
  73. echo "$now ${ps}: RMS Error = N/A Limit = $GRAPHICSMAGICK_RMS Failure = known" >> "@CMAKE_CURRENT_BINARY_DIR@/fail_count.txt"
  74. else
  75. # syntax: gm compare [ options ... ] reference-image [ options ... ] compare-image [ options ... ]
  76. rms=$("${GRAPHICSMAGICK}" compare -density 200 -maximum-error $GRAPHICSMAGICK_RMS -highlight-color magenta -highlight-style assign -metric rmse -file "${ps%.ps}.png" "$ps" "${src}/${ps}") || pscmpfailed="yes"
  77. rms=$(perl -ne 'print $1 if /Total: ([0-9.]+)/' <<< "$rms")
  78. if [ -z "$rms" ]; then
  79. rms="NA"
  80. else
  81. rms=$(printf "%.4f\n" $rms)
  82. fi
  83. if [ "$pscmpfailed" ]; then
  84. now=$(date "+%F %T")
  85. echo "${ps}: RMS Error = $rms [FAIL]"
  86. echo "$now ${ps}: RMS Error = $rms Limit = $GRAPHICSMAGICK_RMS Failure = new" >> "@CMAKE_CURRENT_BINARY_DIR@/fail_count.txt"
  87. make_pdf "$ps" # try to make pdf file
  88. ((++ERROR))
  89. else
  90. test -z "$rms" && rms=N/A
  91. echo "${ps}: RMS Error = $rms [PASS]"
  92. fi
  93. fi
  94. }
  95. # Make sure to cleanup at end
  96. function cleanup()
  97. {
  98. memtrack_err=0
  99. for log_file in gmt_memtrack_*.log; do
  100. test -f ${log_file} || continue
  101. n_err=$(perl -lne '$a++ if /(Memory not freed|^!)/; END {print $a+0}' ${log_file})
  102. (( memtrack_err += n_err )) || : # second assignment in case return code != 0
  103. test ${n_err} -eq 0 && rm -f ${log_file} # remove logs w/o errors
  104. done
  105. echo "memtrack errors: $memtrack_err" >&2
  106. valgrind_err=0
  107. if [ -n "${VALGRIND_ARGS}" ]; then
  108. for log_file in valgrind_*.log; do
  109. test -f ${log_file} || continue
  110. n_err=$(perl -ne 'print $1 if /ERROR SUMMARY: ([0-9]+)/' ${log_file})
  111. n_err=${n_err:-1} # if valgrind crashes itself, there is no ERROR SUMMARY
  112. (( valgrind_err += n_err )) || : # second assignment in case return code != 0
  113. test ${n_err} -eq 0 && rm -f ${log_file} # remove logs w/o errors
  114. done
  115. echo "valgrind errors: $valgrind_err" >&2
  116. fi
  117. cd "@CMAKE_CURRENT_BINARY_DIR@" # get out of exec_dir before removing it
  118. test "$ERROR" -eq 0 -a "$memtrack_err" -eq 0 -a "$valgrind_err" -eq 0 && rm -rf "$exec_dir"
  119. echo "exit status: $ERROR" >&2
  120. exit $ERROR
  121. }
  122. # Test the output image before exiting
  123. function on_exit()
  124. {
  125. trap - EXIT # Restore EXIT trap
  126. pscmp
  127. cleanup
  128. }
  129. trap on_exit EXIT
  130. set -E # Shell functions and subshells need to inherit ERR trap
  131. function on_err()
  132. {
  133. trap - EXIT ERR SIGSEGV SIGTRAP SIGBUS # Restore trap
  134. ((++ERROR))
  135. echo "ERROR: ${1}:${2}" >&2 # Report error line
  136. cleanup
  137. }
  138. trap 'on_err "${BASH_SOURCE}" "${LINENO}"' ERR SIGSEGV SIGTRAP SIGBUS
  139. # Create a temporary directory exec_dir in the build dir
  140. # Then copy all of its contents (except *.ps files)
  141. # Run remainder of this GMT script there
  142. exec_dir="@CMAKE_CURRENT_BINARY_DIR@/${script_name%.sh}"
  143. rm -rf "$exec_dir"
  144. mkdir -p "$exec_dir"
  145. cd "$exec_dir"
  146. # Run the original script via link from current directory
  147. ln -sf "$script" .
  148. # Make a script to capture everything that can be run again
  149. cat > gmtest.sh << EOF
  150. LANG=C
  151. # Define variables that are needed *within* test scripts
  152. export PATH="@GMT_BINARY_DIR@/src:\$PATH"
  153. unset GMT5_SHAREDIR
  154. export GMT_SHAREDIR="@GMT_SOURCE_DIR@/share"
  155. export GMT_DATADIR="$src"
  156. export GMT_SRCDIR="$src"
  157. export GSHHG_DIR="@GSHHG_PATH@"
  158. export DCW_DIR="@DCW_PATH@"
  159. export GMT_BINARY_DIR="@GMT_BINARY_DIR@"
  160. export GMT_SOURCE_DIR="@GMT_SOURCE_DIR@"
  161. export GMT_VERSION="@GMT_PACKAGE_VERSION_WITH_GIT_REVISION@"
  162. # Disable gmt end show from displaying plots
  163. export GMT_END_SHOW=off
  164. # Start with proper GMT defaults
  165. gmt set -Du PS_CHAR_ENCODING ISOLatin1+ GMT_GRAPHICS_FORMAT ps
  166. # Tentative PS file name
  167. ps="${script_name%.sh}.ps"
  168. # Modern mode needs a stable PPID but ctest messes that up when pipes are used
  169. if [ ${modern} -gt 0 ]; then
  170. export GMT_SESSION_NAME=\$\$
  171. echo "Set GMT_SESSION_NAME = \$GMT_SESSION_NAME"
  172. script_mode=M
  173. fi
  174. # Now run the script
  175. . "${local_script}"
  176. EOF
  177. chmod 755 gmtest.sh
  178. . ./gmtest.sh
  179. # Modern mode needs to reestablish the $ps variable before exit
  180. if [ "X$script_mode" = "XM" ] && [ ! "X$ps" = "X" ]; then
  181. ps="${local_script%.sh}.ps"
  182. fi
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...