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

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

Comments

Loading...