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

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

Comments

Loading...