1
1
#! /bin/bash
2
2
set -euo pipefail
3
3
4
- # Parameters passed from Makefile
5
- ABINEXE=" $PWD /src/$1 -x mini.dat"
6
-
7
- # verify that the number of parameters is correct!
4
+ # Parameters are passed from Makefile.
8
5
if [[ $# -ne 7 ]]; then
9
6
echo " ERROR: Incorrect number of parameters passed to $0 "
10
7
echo " Invoked as:"
11
8
echo " $0 $@ "
12
9
exit 1
13
10
fi
14
11
12
+ ABINEXE=" $PWD /src/$1 -x mini.xyz"
13
+ ABINOUT=" abin.out"
15
14
TESTS=" $2 "
16
15
MPI=" $3 "
17
16
FFTW=" $4 "
@@ -24,79 +23,100 @@ ACTION="$7"
24
23
# It's not needed if you use system-wide MPI installation
25
24
# or if mpirun is in your PATH.
26
25
27
- if [[ $ACTION = " makeref" ]]; then
26
+ if [[ $ACTION = " makeref" && $TESTS = " all " ]]; then
28
27
echo " ERROR: You should not call makeref on all tests at once."
29
28
echo " Specify a concrete test which you want to modify, e.g."
30
- echo " make test TEST=CMD"
29
+ echo " make makeref TEST=CMD"
31
30
exit 1
32
31
fi
33
32
34
33
cd $( dirname $0 )
35
34
TESTDIR=$PWD
36
35
37
- function dif_files {
38
- local status=0
39
- local cont
40
- local files
41
- local f
42
- # Do comparison for all existing reference files
43
- files=$( ls * .ref)
44
- for f in $files # $*
45
- do
46
- file=$( basename $f .ref)
47
- if [[ -e $file .ref ]]; then # this should now be always true
48
- error_code=0
49
- diff -q $file $file .ref || error_code=$?
50
- if [[ $error_code -eq 2 ]]; then
51
- # This means the $file does not exist.
52
- # Something is seriously wrong, ABIN probably crashed prematurely.
53
- # No need for further checks, exit NOW.
54
- return $error_code
55
-
56
- elif [[ $error_code -ne 0 ]]; then
57
- # The reference file is different, but maybe it's just numerical noise?
58
- error_code=0
59
- diff -y -W 500 $file $file .ref | egrep -e ' |' -e ' <' -e ' >' > $file .diff
60
- ../numdiff.py $file .diff || error_code=$?
61
- if [[ $error_code -ne 0 ]]; then
62
- # The changes were bigger that the thresholds specified in numdiff.py
63
- status=$error_code
64
- echo " File $file differs from the reference."
65
- fi
66
- fi
67
- fi
68
- done
69
- return $status
36
+ function diff_files {
37
+ local return_status=0
38
+ local error_code
39
+ local ref_file
40
+ local test_file
41
+ # Compare test results with all existing reference files
42
+ local reference_files=$( ls * .ref)
43
+ if [[ -z $reference_files ]]; then
44
+ echo " ERROR: No reference files were found"
45
+ return 1
46
+ fi
47
+
48
+ for ref_file in $reference_files
49
+ do
50
+ test_file=$( basename $ref_file .ref)
51
+ if [[ ! -f $test_file ]]; then
52
+ # The output file does not exist.
53
+ # Something went seriously wrong, ABIN probably crashed prematurely.
54
+ # No need for further checks, exit NOW.
55
+ echo " ERROR: Could not find output file \" $test_file \" "
56
+ return 1
57
+ fi
58
+
59
+ error_code=0
60
+ diff -q $test_file $ref_file || error_code=$?
61
+ if [[ $error_code -ne 0 ]]; then
62
+ # The reference file is different, but maybe it's just numerical noise?
63
+ error_code=0
64
+ diff -y -W 500 $test_file $ref_file | egrep -e ' |' -e ' <' -e ' >' > $test_file .diff
65
+
66
+ ../numdiff.py $test_file .diff || error_code=$?
67
+
68
+ if [[ $error_code -ne 0 ]]; then
69
+ # The changes were bigger that the thresholds specified in numdiff.py
70
+ return_status=$error_code
71
+ echo " File $test_file differs from the reference."
72
+ fi
73
+ fi
74
+ done
75
+ return $return_status
70
76
}
71
77
78
+ # Update already existing reference files.
79
+ # Called by `make makeref TEST=TEST_FOLDER`
80
+ # If you're creating a completely new test,
81
+ # you need to create the reference files manually.
72
82
function makeref {
73
- local files
74
- local f
75
- echo " Making new reference files."
76
- files=$( ls * .ref)
77
- for f in $files
78
- do
79
- file=$( basename $f .ref)
80
- if [[ -f $file .ref ]]; then
81
- mv $file $file .ref
82
- fi
83
- done
83
+ local ref_file
84
+ local test_file
85
+ local reference_files=$( ls * .ref)
86
+ echo " Making new reference files."
87
+ if [[ -z $reference_files ]]; then
88
+ echo " ERROR: No reference files were found."
89
+ exit 1
90
+ fi
91
+ for ref_file in $reference_files
92
+ do
93
+ test_file=$( basename $ref_file .ref)
94
+ if [[ ! -f $test_file ]]; then
95
+ echo " ERROR: Could not find output file \" $test_file \" "
96
+ exit 1
97
+ fi
98
+ echo " mv $test_file $ref_file "
99
+ mv $test_file $ref_file
100
+ done
84
101
}
85
102
86
103
function clean {
87
- rm -rf $* output
88
- rm -f * .diff
89
- if [[ -e " restart.xyz.0.ref " ]] ; then
90
- cp restart.xyz.0.ref restart.xyz
91
- fi
104
+ if [[ -f " test.sh " ]] ; then
105
+ ./test.sh clean
106
+ fi
107
+ rm -rf $*
108
+ rm -f * .diff
92
109
}
93
110
94
- files=( * -RESTART.wfn* cp2k.out bkl.dat phase.dat wfcoef.dat restart_sh.bin restart_sh.bin.old restart_sh.bin.?? nacm_all.dat minimize.dat geom.mini.xyz temper.dat temper.dat radius.dat vel.dat cv.dat cv_dcv.dat dist.dat angles.dat dihedrals.dat geom.dat.??? geom_mm.dat.??? DYN/OUT* MM/OUT* state.dat stateall.dat stateall_grad.dat ERROR debug.nacm dotprod.dat pop.dat prob.dat PES.dat energies.dat est_energy.dat movie.xyz movie.xyz movie_mini.xyz restart.xyz.old restart.xyz.? restart.xyz.?? restart.xyz SOC.dat )
111
+ # List of all possible ABIN output files.
112
+ # Used by `make testclean` to cleanup test directories.
113
+ output_files=( * .dat * .out ERROR movie.xyz forces.xyz velocities.xyz
114
+ geom.dat.??? geom_mm.dat.??? geom.mini.xyz nacmrest.dat.?? geom.? .? .? bck.* DYN/OUT* MM/OUT*
115
+ restart_sh.bin restart_sh.bin.old restart_sh.bin.?? restart.xyz.old restart.xyz.? restart.xyz.?? restart.xyz )
95
116
96
117
# Run all tests
97
- if [[ $TESTS = " all" ]]; then
98
- # folders=( CMD SH_EULER SH_RK4 SH_BUTCHER SH_RK4_PHASE PIMD SHAKE HARMON MINI QMMM GLE PIGLE)
99
- # DH: Temporarily disable GLE and PIGLE tests
118
+ if [[ $TESTS = " all" ]]; then
119
+ # TODO: Re-enable GLE and PIGLE tests!
100
120
folders=(CMD SH_EULER SH_RK4 SH_BUTCHER SH_RK4_PHASE LZ_SS LZ_ST LZ_ENE PIMD SHAKE HARMON MINI QMMM)
101
121
102
122
let index=${# folders[@]} +1
@@ -114,9 +134,9 @@ if [[ $TESTS = "all" ]];then
114
134
fi
115
135
116
136
if [[ $CP2K = " TRUE" ]]; then
117
- # At this point, we do not support MMWATER potential
118
- # with CP2K, which is used in majority of tests
119
- # ABINITIO needs OpenMP, which is not compatible with CP2K interface
137
+ # At this point, we do not support MMWATER potential.
138
+ # with CP2K, which is used in majority of tests.
139
+ # ABINITIO needs OpenMP, which is not compatible with CP2K interface.
120
140
folders=(SH_BUTCHER HARMON CP2K CP2K_MPI)
121
141
fi
122
142
154
174
echo " Entering directory $dir "
155
175
cd $dir
156
176
157
- # Always clean test directory
158
- # before runnning the test
159
- if [[ -f " test.sh" ]]; then
160
- ./test.sh clean
161
- else
162
- clean ${files[@]}
163
- fi
177
+ # Always clean the test directory before runnning the test.
178
+ clean ${output_files[@]}
164
179
165
180
# If we just want to clean the directories,
166
181
# we skip the the actual test here
170
185
continue
171
186
fi
172
187
173
- # Redirection to dev/null apparently needed for CP2K tests.
174
- # Otherwise, STDIN is screwed up. I have no idea why.
175
- # http://stackoverflow.com/questions/1304600/read-error-0-resource-temporarily-unavailable
176
- # TODO: Figure out a different solution
188
+ # For special cases such as REMD, we need a more complicated
189
+ # test setup. If a file, test.sh is present in the test directory,
190
+ # we will use it.
177
191
if [[ -f " test.sh" ]]; then
178
192
193
+ # Redirection to dev/null apparently needed for CP2K tests.
194
+ # Otherwise, STDIN is screwed up. I have no idea why.
195
+ # http://stackoverflow.com/questions/1304600/read-error-0-resource-temporarily-unavailable
196
+ # TODO: Figure out a different solution
179
197
# ./test.sh $ABINEXE 2> /dev/null
180
198
./test.sh $ABINEXE || true
181
199
182
200
else
183
201
if [[ -f " velocities.in" ]]; then
184
- $ABINEXE -v " velocities.in" > output || true
202
+ $ABINEXE -v " velocities.in" > $ABINOUT || true
185
203
else
186
- $ABINEXE > output || true
204
+ $ABINEXE > $ABINOUT || true
187
205
fi
188
206
189
207
# for testing restart
190
208
if [[ -e input.in2 ]]; then
191
- $ABINEXE -i input.in2 >> output || true
209
+ $ABINEXE -i input.in2 >> $ABINOUT || true
192
210
fi
193
211
fi
194
212
195
213
if [[ $ACTION = " makeref" ]]; then
196
214
197
- makeref ${files[@]}
215
+ makeref
198
216
199
217
else
200
218
201
219
# Since we're running in the -e mode,
202
220
# we need to "hide" this possibly failing command
203
221
# https://stackoverflow.com/a/11231970/3682277
204
222
current_error=0
205
- dif_files ${files[@]} || current_error=$?
223
+ diff_files || current_error=$?
206
224
if [[ $current_error -ne 0 ]]; then
207
225
global_error=1
208
226
echo " $dir FAILED"
0 commit comments