Skip to content

Commit 28e01f6

Browse files
committed
Refactor cleaning test directories
This is a minor refactor of how we clean up test directories in tests/*/. We clean the test directory each time we run the test. We also cleanup all test directories by running `make testclean`. As part of this, I renamed 'mini.dat' to 'mini.xyz' in all tests so that we can simply delete all *.dat files. To ensure I did not forget any output files, I asked Git about the untracked files after I ran the `make test && make testclean` command. To find all untracked files, even those ignored by .gitignore, I used `git ls-files -o` I also cleaned up the 'diff_files' and 'makeref' functions, hopefully they are a bit more readable now. We need to carefully test that I didn't break anything! Test plan: - clone fresh repo - ./configure && make && make test - make clean && make testclean - `git ls-files -o` should not list any extra files.
1 parent 142515a commit 28e01f6

File tree

29 files changed

+138
-117
lines changed

29 files changed

+138
-117
lines changed

.gitignore

+2-39
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,6 @@
1-
*mod
1+
# See also .gitignore files in doc/, tests/ and src/
22
make.vars
3-
src/libabin.a
4-
*.o
53
*.gcda
64
*.gcno
75
*.gcov
8-
*temp
9-
tests/*/*diff
10-
tests/*/*dat
11-
tests/*/*out
12-
tests/*/*bin
13-
tests/*/*bin.??
14-
tests/*/*bin.old
15-
tests/*/*dat.??
16-
tests/*/*xyz
17-
tests/*/*xyz.?
18-
tests/*/*xyz.??
19-
tests/*/geom.dat.00*
20-
tests/*/geom_mm.dat.00*
21-
tests/REMD/DFTB/OUT*
22-
tests/*/output
23-
tests/REMD/restart.xyz.??.*
24-
tests/*/restart.xyz.old
25-
tests/*/restart.xyz.0?
26-
tests/*/restart.xyz.10
27-
tests/*/restart.xyz.0?.old
28-
tests/*/debug.nacm
29-
tests/*/ERROR
30-
tests/SH_BUTCHER/geom.?.?.?
31-
tests/CP2K*/WATER*
32-
tests/PLUMED/*
33-
docs/*.log
34-
docs/*.bbl
35-
docs/*.aux
36-
docs/*.blg
37-
docs/*.toc
38-
docs/*out
39-
# Default binary name
40-
src/abin
41-
src/abin.*
42-
# Include mini.dat, needed for tests
43-
!mini.dat
6+
*.mod

docs/.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*.log
2+
*.bbl
3+
*.aux
4+
*.blg
5+
*.toc
6+
*out

src/.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*mod
2+
libabin.a
3+
*.o
4+
# Default binary name
5+
abin

src/surfacehop.F90

+2
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,8 @@ subroutine surfacehop(x, y, z, vx, vy, vz, vx_old, vy_old, vz_old, dt, eclas)
758758
write(chist,*)ist
759759
write(chihop,*)ihop
760760
write(chit,*)it
761+
! TODO: Rename this file to something more specific,
762+
! e.g. geom_hop.from.to.timestep.xyz
761763
formt='geom.'//trim(adjustl(chist))//'.'//trim(adjustl(chihop))//'.'//adjustl(chit)
762764
open(500,file=trim(formt))
763765
write(500,*)natom

tests/.gitignore

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
*/*diff
2+
*/*dat
3+
*/*out
4+
*/*bin
5+
*/*bin.??
6+
*/*bin.old
7+
*/*dat.??
8+
*/*xyz
9+
*/*xyz.?
10+
*/*xyz.??
11+
*/geom.dat.00*
12+
*/geom_mm.dat.00*
13+
REMD/DFTB/OUT*
14+
*/abin.out
15+
REMD/restart.xyz.??.*
16+
*/restart.xyz.old
17+
*/restart.xyz.0?
18+
*/restart.xyz.10
19+
*/restart.xyz.0?.old
20+
*/debug.nacm
21+
*/ERROR
22+
SH_BUTCHER/geom.?.?.?
23+
CP2K*/WATER*
24+
PLUMED/*
File renamed without changes.
File renamed without changes.

tests/CP2K/clean.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
rm cp2k.inp.* WATER?-RESTART.wfn* movie.xyz restart.xyz cp2k.out*
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

tests/test.sh

+96-78
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
#!/bin/bash
22
set -euo pipefail
33

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.
85
if [[ $# -ne 7 ]]; then
96
echo "ERROR: Incorrect number of parameters passed to $0"
107
echo "Invoked as:"
118
echo "$0 $@"
129
exit 1
1310
fi
1411

12+
ABINEXE="$PWD/src/$1 -x mini.xyz"
13+
ABINOUT="abin.out"
1514
TESTS="$2"
1615
MPI="$3"
1716
FFTW="$4"
@@ -24,79 +23,100 @@ ACTION="$7"
2423
# It's not needed if you use system-wide MPI installation
2524
# or if mpirun is in your PATH.
2625

27-
if [[ $ACTION = "makeref" ]];then
26+
if [[ $ACTION = "makeref" && $TESTS = "all" ]];then
2827
echo "ERROR: You should not call makeref on all tests at once."
2928
echo "Specify a concrete test which you want to modify, e.g."
30-
echo "make test TEST=CMD"
29+
echo "make makeref TEST=CMD"
3130
exit 1
3231
fi
3332

3433
cd $(dirname $0)
3534
TESTDIR=$PWD
3635

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
7076
}
7177

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.
7282
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
84101
}
85102

86103
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
92109
}
93110

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 )
95116

96117
# 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!
100120
folders=(CMD SH_EULER SH_RK4 SH_BUTCHER SH_RK4_PHASE LZ_SS LZ_ST LZ_ENE PIMD SHAKE HARMON MINI QMMM)
101121

102122
let index=${#folders[@]}+1
@@ -114,9 +134,9 @@ if [[ $TESTS = "all" ]];then
114134
fi
115135

116136
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.
120140
folders=(SH_BUTCHER HARMON CP2K CP2K_MPI)
121141
fi
122142

@@ -154,13 +174,8 @@ do
154174
echo "Entering directory $dir"
155175
cd $dir
156176

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[@]}
164179

165180
# If we just want to clean the directories,
166181
# we skip the the actual test here
@@ -170,39 +185,42 @@ do
170185
continue
171186
fi
172187

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.
177191
if [[ -f "test.sh" ]];then
178192

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
179197
#./test.sh $ABINEXE 2> /dev/null
180198
./test.sh $ABINEXE || true
181199

182200
else
183201
if [[ -f "velocities.in" ]];then
184-
$ABINEXE -v "velocities.in" > output || true
202+
$ABINEXE -v "velocities.in" > $ABINOUT || true
185203
else
186-
$ABINEXE > output || true
204+
$ABINEXE > $ABINOUT || true
187205
fi
188206

189207
#for testing restart
190208
if [[ -e input.in2 ]];then
191-
$ABINEXE -i input.in2 >> output || true
209+
$ABINEXE -i input.in2 >> $ABINOUT || true
192210
fi
193211
fi
194212

195213
if [[ $ACTION = "makeref" ]];then
196214

197-
makeref ${files[@]}
215+
makeref
198216

199217
else
200218

201219
# Since we're running in the -e mode,
202220
# we need to "hide" this possibly failing command
203221
# https://stackoverflow.com/a/11231970/3682277
204222
current_error=0
205-
dif_files ${files[@]} || current_error=$?
223+
diff_files || current_error=$?
206224
if [[ $current_error -ne 0 ]];then
207225
global_error=1
208226
echo "$dir FAILED"

0 commit comments

Comments
 (0)