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 5.9 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
  1. #!/bin/bash
  2. #
  3. # $Id$
  4. #
  5. # Functions to be used with test scripts
  6. # Print the shell script name and purpose and fill out to 72 characters
  7. # and make sure to use US system defaults
  8. test -z "$1" && exit 1
  9. # Name of the script and the directory portion of it
  10. script_name="$1"
  11. script_dir=$(dirname "${script_name}")
  12. script="@GMT_SOURCE_DIR@/test/${script_name}"
  13. if ! [ -x "${script}" ]; then
  14. echo "error: cannot execute script ${script}." >&2
  15. exit 1
  16. fi
  17. shift
  18. # Temporary change LANG to C
  19. LANG=C
  20. # Define variables that are needed *within* test scripts
  21. GMT_BINARY_DIR="@GMT_BINARY_DIR@"
  22. GMT_SOURCE_DIR="@GMT_SOURCE_DIR@"
  23. GMT_VERSION="@GMT_PACKAGE_VERSION_WITH_SVN_REVISION@"
  24. GSHHG_DIR="@GSHHG_PATH@"
  25. HAVE_GMT_DEBUG_SYMBOLS="@HAVE_GMT_DEBUG_SYMBOLS@"
  26. HAVE_OPENMP="@HAVE_OPENMP@"
  27. GRAPHICSMAGICK="@GRAPHICSMAGICK@"
  28. src="@GMT_SOURCE_DIR@/test/${script_dir}"
  29. # choose awk
  30. if type gawk >/dev/null 2>&1 ; then
  31. export AWK=gawk
  32. elif type nawk >/dev/null 2>&1 ; then
  33. export AWK=nawk
  34. else
  35. export AWK=awk
  36. fi
  37. # Use executables from GMT_BINARY_DIR, fallback to CMAKE_INSTALL_PREFIX/GMT_BINDIR
  38. unset GMT5_SHAREDIR
  39. export GMT_SHAREDIR="@GMT_SOURCE_DIR@/share"
  40. export GMT_USERDIR="@GMT_BINARY_DIR@/share"
  41. export GMT_DATADIR="$src:@GMT_TEST_DATA@/"
  42. export GMT_SRCDIR="$src"
  43. # Reset error count
  44. ERROR=0
  45. # valgrind wrapper
  46. function valgrind_wrapper()
  47. {
  48. if [ -n "${VALGRIND_ARGS}" ]; then
  49. valgrind ${VALGRIND_ARGS} --log-file=valgrind_%p.log --dsymutil=yes "$@"
  50. else
  51. "$@"
  52. fi
  53. }
  54. # gmt wrapper
  55. function gmt()
  56. {
  57. valgrind_wrapper "@GMT_BINARY_DIR@/src/gmt" "$@"
  58. }
  59. # gmtlogo wrapper
  60. function gmtlogo()
  61. {
  62. "@GMT_SOURCE_DIR@/src/gmtlogo" "$@"
  63. }
  64. # psldemo wrapper
  65. function psldemo()
  66. {
  67. valgrind_wrapper "@GMT_BINARY_DIR@/src/psldemo" "$@"
  68. }
  69. # testapi wrapper
  70. function testapi()
  71. {
  72. valgrind_wrapper "@GMT_BINARY_DIR@/src/testapi" "$@"
  73. }
  74. # testgrdio wrapper
  75. function testgrdio()
  76. {
  77. valgrind_wrapper "@GMT_BINARY_DIR@/src/testgrdio" "$@"
  78. }
  79. # export function definitions to subshells
  80. export -f gmt gmtlogo psldemo valgrind_wrapper
  81. # invalidate module calls without "gmt" prefix, which would bypass gmt from build dir
  82. . "@GMT_SOURCE_DIR@/test/invalidate_modules.sh"
  83. # Convert PS to PDF
  84. function make_pdf()
  85. {
  86. pdf="${ps%.ps}.pdf"
  87. test -f "$ps" || return 1
  88. gmt ps2raster -Tf -A -P "$ps" || ((++ERROR))
  89. test -f "$pdf" || ((++ERROR))
  90. }
  91. # Compare the ps file with its original. Check $ps against original $ps or against $1.ps (if $1 given)
  92. pscmp () {
  93. test ${#ps} -gt 0 || return 0
  94. test -f "$ps" || return 1
  95. if ! [ -x "$GRAPHICSMAGICK" ]; then
  96. echo "[PASS] (without comparison)"
  97. return
  98. fi
  99. for ps in *.ps ; do
  100. # syntax: gm compare [ options ... ] reference-image [ options ... ] compare-image [ options ... ]
  101. rms=$("${GRAPHICSMAGICK}" compare -density 200 -maximum-error 0.001 -highlight-color magenta -highlight-style assign -metric rmse -file "${ps%.ps}.png" "$ps" "$src/${psref:-$ps}") || pscmpfailed="yes"
  102. rms=$(perl -ne 'print $1 if /Total: ([0-9.]+)/' <<< "$rms")
  103. if [ -z "$rms" ]; then
  104. rms="NA"
  105. else
  106. rms=$(printf "%.3f\n" $rms)
  107. fi
  108. if [ "$pscmpfailed" ]; then
  109. now=$(date "+%F %T")
  110. echo "${script_dir}/${ps}: RMS Error = $rms [FAIL]"
  111. echo "$now ${script_dir}/${ps}: RMS Error = $rms" >> "@CMAKE_CURRENT_BINARY_DIR@/fail_count.d"
  112. make_pdf "$ps" # try to make pdf file
  113. ((++ERROR))
  114. else
  115. test -z "$rms" && rms=NA
  116. echo "${script_dir}/${ps}: RMS Error = $rms [PASS]"
  117. fi
  118. done
  119. }
  120. passfail () {
  121. test -f fail || return 0
  122. if [ -s fail ]; then
  123. now=$(date "+%F %T")
  124. echo "[FAIL]"
  125. echo "$now ${script_name}: $(wc -l fail) failed lines" >> "@CMAKE_CURRENT_BINARY_DIR@/fail_count.d"
  126. mv -f fail $1.log
  127. ((++ERROR))
  128. else
  129. echo "[PASS]"
  130. fi
  131. }
  132. # Make sure to cleanup at end
  133. function cleanup()
  134. {
  135. memtrack_err=0
  136. for log_file in gmt_memtrack_*.log; do
  137. test -f ${log_file} || continue
  138. n_err=$(perl -lne '$a++ if /(Memory not freed|^!)/; END {print $a+0}' ${log_file})
  139. (( memtrack_err += n_err )) || : # second assignment in case return code != 0
  140. test ${n_err} -eq 0 && rm -f ${log_file} # remove logs w/o errors
  141. done
  142. echo "memtrack errors: $memtrack_err" >&2
  143. valgrind_err=0
  144. if [ -n "${VALGRIND_ARGS}" ]; then
  145. for log_file in valgrind_*.log; do
  146. test -f ${log_file} || continue
  147. n_err=$(perl -ne 'print $1 if /ERROR SUMMARY: ([0-9]+)/' ${log_file})
  148. n_err=${n_err:-1} # if valgrind crashes itself, there is no ERROR SUMMARY
  149. (( valgrind_err += n_err )) || : # second assignment in case return code != 0
  150. test ${n_err} -eq 0 && rm -f ${log_file} # remove logs w/o errors
  151. done
  152. echo "valgrind errors: $valgrind_err" >&2
  153. fi
  154. cd "@CMAKE_CURRENT_BINARY_DIR@" # get out of exec_dir before removing it
  155. test "$ERROR" -eq 0 -a "$memtrack_err" -eq 0 -a "$valgrind_err" -eq 0 && rm -rf "$exec_dir"
  156. echo "exit status: $ERROR" >&2
  157. exit $ERROR
  158. }
  159. # Test the output image(s) and/or fail file before exiting
  160. function on_exit()
  161. {
  162. trap - EXIT # Restore EXIT trap
  163. pscmp
  164. passfail
  165. cleanup
  166. }
  167. trap on_exit EXIT
  168. set -E # Shell functions and subshells need to inherit ERR trap
  169. function on_err()
  170. {
  171. trap - EXIT ERR SIGSEGV SIGTRAP SIGBUS # Restore trap
  172. ((++ERROR))
  173. echo "ERROR: ${1}:${2}" >&2 # Report error line
  174. cleanup
  175. }
  176. trap 'on_err "${BASH_SOURCE}" "${LINENO}"' ERR SIGSEGV SIGTRAP SIGBUS
  177. # Create a temporary directory exec_dir in the build dir
  178. # and run remainder of this GMT script there
  179. exec_dir="@CMAKE_CURRENT_BINARY_DIR@/${script_name%.sh}"
  180. rm -rf "$exec_dir"
  181. mkdir -p "$exec_dir"
  182. cd "$exec_dir"
  183. ln -sf "$script" .
  184. # Make a script to capture everything that can be run again
  185. cat > gmtest.sh << EOF
  186. export PATH="@GMT_BINARY_DIR@/src:\$PATH"
  187. unset GMT5_SHAREDIR
  188. export GMT_SHAREDIR="$GMT_SHAREDIR"
  189. export GMT_USERDIR="$GMT_USERDIR"
  190. export GMT_DATADIR="$src:@GMT_TEST_DATA@/"
  191. export GMT_SRCDIR="$src"
  192. gmt set -Du
  193. . "${script}"
  194. EOF
  195. chmod 755 gmtest.sh
  196. # Start with proper GMT defaults
  197. gmt set -Du
  198. # Now run the original script
  199. . "${script}"
  200. # vim: ft=sh
Tip!

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

Comments

Loading...