Setup testing environment

This commit is contained in:
Anthony Scemama 2014-04-07 16:56:29 +02:00
parent 1e5c09f75a
commit 65ffb4ad5f
7 changed files with 1255 additions and 1 deletions

49
scripts/create_test_ref.sh Executable file
View File

@ -0,0 +1,49 @@
#!/bin/bash
#
# usage:
# create_test_ref.sh <test_executable>
# Creates the test reference file using all possible input directories of the
# data directory.
# Mon Apr 7 12:00:55 CEST 2014
TEST_EXE=$1
REF_FILE=${TEST_EXE}.ref
if [[ $(basename ${PWD}) != "tests" ]]
then
echo "Error: This script should be run in the tests directory."
exit 1
fi
if [[ -z ${TEST_EXE} ]]
then
echo "usage: " $(basename $0) " <test_executable>"
exit 1
fi
if [[ -z ${MAKE} ]]
then
MAKE="make -j 4"
fi
echo "Unarchiving EZFIO input directories"
${MAKE} -C ${QPACKAGE_ROOT}/data/inputs all_ezfio > /dev/null
if [[ -f ${TEST_REF} ]]
then
mv ${TEST_REF} ${TEST_REF}.save
fi
printf "data = {\n " > ${REF_FILE}
printf "Running tests...."
for dir in ${QPACKAGE_ROOT}/data/inputs/*.ezfio
do
printf " '%s' : {\n " $(basename ${dir})
./${TEST_EXE} ${dir} | sed "s/\([^ ]*\) *\(:\) *\([^ ]*\)/'\1' : \3,/g"
printf " },\n"
done >> ${REF_FILE}
printf "}\n" >> ${REF_FILE}
echo "Done."

View File

@ -0,0 +1,49 @@
#!/bin/bash
#
# usage:
# create_tests_Makefile.sh
# Creates the Makefile of the tests directory. This command is supposed to be
# run in a tests directory.
# Mon Apr 7 11:50:30 CEST 2014
MODULE=$(basename $PWD)
if [[ $MODULE == "tests" ]]
then
echo "Error: This script should not be run in the tests directory."
exit 1
fi
cat << EOF > Makefile
OPENMP =1
PROFILE =0
DEBUG = 0
IRPF90+= -I tests
REF_FILES=$(subst %.irp.f, %.ref, $(wildcard *.irp.f))
.PHONY: clean executables serial_tests parallel_tests
all: clean executables serial_tests parallel_tests
parallel_tests: $(REF_FILES)
@echo ; echo " ---- Running parallel tests ----" ; echo
@OMP_NUM_THREADS=10 ${QPACKAGE_ROOT}/scripts/run_tests.py
serial_tests: $(REF_FILES)
@echo ; echo " ---- Running serial tests ----" ; echo
@OMP_NUM_THREADS=1 ${QPACKAGE_ROOT}/scripts/run_tests.py
executables: $(wildcard *.irp.f)
$(MAKE) -C ..
%.ref: $(wildcard $(QPACKAGE_ROOT)/data/inputs/*.md5) executables
$(QPACKAGE_ROOT)/scripts/create_test_ref.sh $*
clean:
$(MAKE) -C .. clean
EOF

60
scripts/run_tests.py Executable file
View File

@ -0,0 +1,60 @@
#!/usr/bin/python
import unittest
import os
import subprocess
from math import *
env = os.environ
try:
verbosity = int(sys.argv[1])
except:
verbosity = 1
testfiles = []
for f in os.listdir(os.getcwd()):
if f.endswith('.irp.f'):
testfiles.append(f.replace('.irp.f',''))
def run_test(test_name,inp):
command = './'+test_name+" ${QPACKAGE_ROOT}/data/inputs/"+inp
result = subprocess.check_output(command, shell=True)
return result
template = """
class $test(unittest.TestCase):
execfile('$test.ref')
def setUp(self):
self.name = '$test'
def _test_input(self,inp):
output = run_test(self.name, inp)
for line in output.splitlines():
buffer = line.split(':')
if len(buffer) == 1:
continue
l,r = buffer
l,r = l.strip(), eval(r)
if type(r) == float:
self.assertAlmostEqual(self.data[inp][l], r,
places=abs(int(log10(self.precision[l]*max(abs(self.data[inp][l]),1.e-12)))), msg=None)
else:
self.assertEqual(self.data[inp][l], r, msg=None)
t = "def test_$k(self): self._test_input('$i')"
for i in data.keys():
k = i
k = k.replace('.ezfio','')
k = k.replace('-','_m_')
k = k.replace('+','_p_')
exec t.replace('$i',i).replace('$k',k) in locals()
"""
for test in testfiles:
exec template.replace('$test',test) in locals()
if __name__ == '__main__':
unittest.main(verbosity=verbosity)

View File

@ -0,0 +1,31 @@
OPENMP =1
PROFILE =0
DEBUG = 0
IRPF90+= -I tests
REF_FILES=$(subst %.irp.f, %.ref, $(wildcard *.irp.f))
.PHONY: clean executables serial_tests parallel_tests
all: clean executables serial_tests parallel_tests
parallel_tests: $(REF_FILES)
@echo ; echo " ---- Running parallel tests ----" ; echo
@OMP_NUM_THREADS=10 ${QPACKAGE_ROOT}/scripts/run_tests.py
serial_tests: $(REF_FILES)
@echo ; echo " ---- Running serial tests ----" ; echo
@OMP_NUM_THREADS=1 ${QPACKAGE_ROOT}/scripts/run_tests.py
executables: $(wildcard *.irp.f)
$(MAKE) -C ..
%.ref: $(wildcard $(QPACKAGE_ROOT)/data/inputs/*.md5) executables
$(QPACKAGE_ROOT)/scripts/create_test_ref.sh $*
clean:
$(MAKE) -C .. clean

View File

@ -0,0 +1,6 @@
program test_number_electrons
implicit none
print *, 'elec_alpha_num :', elec_alpha_num
print *, 'elec_beta_num :', elec_beta_num
print *, 'elec_num :', elec_num
end

File diff suppressed because it is too large Load Diff

View File

@ -123,7 +123,9 @@ Makefile.depend: Makefile
include irpf90.make
# Dummy rule to enable to force recompilation
test:
make -j 1 -C tests
# Dummy rule to enable to force recompilation
FORCE: