Commit 0bcbd480 authored by Daniel Wortmann's avatar Daniel Wortmann

Added testing facilities using ctest. Read tests/REAME.tests for more details

parent 86901c15
......@@ -29,7 +29,7 @@ include(mix/CMakeLists.txt)
include(vgen/CMakeLists.txt)
include(inpgen/CMakeLists.txt)
include(docs/CMakeLists.txt)
include(tests/CMakeLists.txt)
if (${Fleur_uses_MPI})
include(mpi/CMakeLists.txt)
endif()
......
enable_testing()
add_test(CuBulk ${CMAKE_CURRENT_SOURCE_DIR}/tests/test.pl CuBulk "${CMAKE_BINARY_DIR}/fleur")
#add_test(NAME test2 WORKING_DIRECTORY tests COMMAND $ENV{HOME}/bin/testcmake a1 a2 )
add_test(test $ENV{HOME}/bin/testcmake arg1 arg2 )
This directory and its subdirectories contain the automatic tests for FLEUR.
They can be executed after compiling by running "ctest".
The following changes have to me made to create a new test:
A) Create the test scripts. Follow for example the files in tests/tests/CuBulk
1. create a sub-directory under tests/tests/TESTNAME containing your testcase
2. in TESTNAME create a test.desc file describing the test
3. in TESTNAME directory create one or more test.run1, test.run2... etc files that will be executed
4. in TESTNAME/file put files you need
B) Add the test to tests/CMakeLists.txt again copying an existing example.
package jt;
@EXPORT="";
use POSIX;
use strict;
sub initlog($$$){
my $workdir=shift;
my $test_name=shift;
my $config_name=shift;
if (-r "$workdir/../test.log"){
system("cat $workdir/../test.log >>$workdir/../test.oldlogs");
}
open(LOG,">$workdir/../test.log");
print LOG "Configuration: $config_name\n";
print LOG "*************************************\n";
print LOG POSIX::strftime("%m/%d/%Y %H:%M:%S\n", localtime);
print LOG "Starting\n";
print "Configuration: $config_name\n";
print "Test: $test_name\n";
print "Workdir: $workdir\n";
}
sub stoplog($){
my $time=shift;
print LOG "Finished after: $time\n";
close(LOG);
}
sub copyfile($$){
my $from=shift;
my $to=shift;
use POSIX;
print LOG POSIX::strftime("%m/%d/%Y %H:%M:%S--", localtime);
print LOG "Copying $from -> $to:";
system("cp $from $to");
my $res=system("diff -q $from $to");
if ($res==0) {print LOG "Done\n";}
else {print LOG "Failed\n";}
}
sub movefile($$){
my $from=shift;
my $to=shift;
use POSIX;
print LOG POSIX::strftime("%m/%d/%Y %H:%M:%S--", localtime);
print LOG "Moving $from -> $to:";
system("mv $from $to");
print LOG "Done\n";
}
sub deletefile($){
my $from=shift;
use POSIX;
print LOG POSIX::strftime("%m/%d/%Y %H:%M:%S--", localtime);
print LOG "Deleting $from";
system("rm $from ");
print LOG "Done\n";
}
sub testrun($$){
my $ex=shift;
my $dir=shift;
print LOG POSIX::strftime("%m/%d/%Y %H:%M:%S--", localtime);
print LOG "Running $ex:";
if (system("cd $dir;$ex")==0){
print LOG "Done\n";}
else {
print LOG "Failed\n";}
print LOG POSIX::strftime("%m/%d/%Y %H:%M:%S--", localtime);
print LOG "Finished execution\n";
}
sub test_fileexists($){
my $file=shift;
print LOG POSIX::strftime("%m/%d/%Y %H:%M:%S--", localtime);
print LOG "Testing for $file:";
if (-r $file){
print LOG "Exists\n";
return 0;
}else{
print LOG "Not found\n";
return 1;
}
}
sub test_grepexists($$){
my $file=shift;
my $text=shift;
print LOG POSIX::strftime("%m/%d/%Y %H:%M:%S--", localtime);
print LOG "Grep for $text in $file:";
if (system("grep -q \"$text\" $file")==0){
print LOG "Found\n";
return 0;
}else{
print LOG "Not found\n";
return 1;
}
}
sub test_grepnumber($$$$$){
my $file=shift;
my $grepfor=shift;
my $reg=shift;
my $value=shift;
my $tol=shift;
print LOG POSIX::strftime("%m/%d/%Y %H:%M:%S--", localtime);
print LOG "Grep for $grepfor in $file:";
my $l=`grep \"$grepfor\" $file`;
$l=~m/$reg/s;
print LOG "$1 == $value:";
if (abs($1-$value)<$tol){
print LOG "ok\n";
return 0;
}else{
print LOG "failed\n";
return 1;
}
}
sub stageresult($$$){
my $workdir=shift;
my $result=shift;
my $stage=shift;
system("rm -f $workdir/test_$stage.*");
if ($result==0){
system("touch $workdir/test_$stage.ok");
print "Stage $stage passed\n";
}else{
system("touch $workdir/test_$stage.failed");
print "Stage $stage failed\n";
}
}
sub testresult($){
my $workdir=shift;
my $result;
system("rm -f $workdir/test.ok $workdir/test.failed");
$result=1 if (system("ls $workdir/test_?.failed 2>/dev/null")==0);
if ($result==0){
system("touch $workdir/test.ok");
print "Test passed\n";
exit 0;
}else{
system("touch $workdir/test.failed");
print "Test failed\n";
die "Test failed";
}
}
package judft_tests;
@EXPORT="";
use jt;
#This runs a single test
sub execute_test($$$$){
my $testdir=shift;
my $exec=shift;
my $mpi=shift;
$workdir=shift;
#is this test ok for the current configuration?
my ($stages,$test_name)=
test_applicable($testdir,$exec);
if ($stages>0) {
$executable="$mpi $exec";
my $starttime=time();
jt::initlog($workdir,$test_name,$executable);
#prepare the workdir
if (-r $workdir){
system("rm -f $workdir/*");
}else{
die "Invalid workdir:$workdir" if (system("mkdir $workdir"));
}
my $old_dir=`pwd`;
chomp $old_dir;
chdir("tests/$testdir");
#run all stages of the test
for(my $stage=1;$stage<=$stages;$stage++){
print "Stage: $stage / $stages\n";
do "test.run$stage";
}
chdir($old_dir);
my $time=time()-$starttime;
jt::stoplog($time);
}
jt::testresult($workdir);
}
sub test_applicable($$){
my $testdir=shift;
my $exec=shift;
#read description of test
do "tests/$testdir/test.desc";
#check if executable name starts with code name
#if (!($exec=~/^\Q$test_code\E/i)){
# return (0,"");
#}
#test requirements
if ($exec=~/_SOC/){
return (0,"") if ($test_requirements{"SOC"}==0);
}else{
return (0,"") if ($test_requirements{"SOC"}==1);
}
if ($exec=~/_INVS/){
return (0,"") if ($test_requirements{"complex"}==1);
}
if (!($exec=~/_MPI/)){
return (0,"") if ($test_requirements{"MPI"}==1);
}
return ($test_stages,$test_name);
}
#!/usr/bin/perl
# Driver for cmake testing of FLEUR
# See README.tests for details
use strict;
my $dir;
BEGIN{
$dir=$0;
$dir=~s/test.pl//;
}
use lib "$dir/scripts";
use judft_tests;
my $testdir=shift;
my $executable=shift;
my $mpi=shift;
my $workdir="$ENV{PWD}/Testing/work";
chdir($dir);
judft_tests::execute_test($testdir,$executable,$mpi,$workdir);
energy parameters for window 1 spin 1 mix= 1.000000
atom s p d f
--> 1 0.22652 0.22652 0.21267 0.22652 change: TTTT skiplo: 0
--> 2 0.22652 0.22652 0.21267 0.22652 change: TTTT skiplo: 0
strho=F,film=f,dos=F,isec1=99,ndir= 0,secvar=F
FLEUR input generated with ASE
squ p4m ,invs=t,zrfs=t,invs2=T,jspins=1,l_noco=F,l_J=F
4.815397
6.81 6.81 0.97000000
pz non-relativi
igrd=1,lwb=F,ndvgrd=6,idsprs=0,chng=-0.100D-11
2
**********************************
Cu 29 7 12 935 2.200000 0.013000
1,force =T,nlo= 0,llo=
0.000000 0.000000 1.0 2.000000
**********************************
Cu 29 7 12 935 2.200000 0.013000
1,force =T,nlo= 0,llo=
1.000000 1.000000 0.000000 2.000000
**********************************
15.000000 10.000000
vchk=t,cdinf=f,pot8=F,gw=0,gw_neigd= 0
lpr=0,form66=F,l_f=F,eonly=F,eig66=F,soc66=T
8 8
1 0
Window # 1
-0.80000 0.50000 22.00000
3.50000 =kmax
gauss=F 0.00100tria=F
0.000000 0.000000,l_soc=F,spav=F,off=F
frcor=F,slice=F,ctail=T,disp=F,kcrel=0,u2f=F,f2u=F,bmt=F
itmax= 1,maxiter= 99,imix= 7,alpha= 0.05,spinf= 2.00
swsp=F 1.00 -0.50
lflip=F 1 1
vacdos=F,layers= 0,integ=F,star=F,nstars= 0 0.00 0.00 0.00 0.00,nstm=0,tworkf= 0.000000
iplot=F,score=F,plpot=F,band=F
0 0.000000 0.000000,nnne= 0,pallst=F
xa= 2.00000,thetad= 330.00000,epsdisp= 0.00001,epsforce= 0.00001
relax 111 111
emin_dos= -0.50000,emax_dos= 0.50000,sig_dos= 0.01500
nkpt= 4
3 8.0000000000
3.00000 3.00000 2.00000 8.00000
3.00000 1.00000 2.00000 16.00000
1.00000 1.00000 2.00000 8.00000
$test_name="Fleur Cu Bulk";
$test_code="Fleur";
%test_requirements=("SOC",0);
$test_stages=2;
$test_desc=<<EOF
Simple test of Fleur with two steps:
1.Generate a starting density
2.Run 1 iteration and compare fermi-energy & total energy
EOF
;
#juDFT Testscript
jt::copyfile("files/inp",$workdir);
jt::copyfile("files/kpts",$workdir);
jt::testrun($executable,$workdir);
#now test output
$result=jt::test_fileexists("$workdir/out");
$result+=jt::test_fileexists("$workdir/cdn1");
$result+=jt::test_grepexists("$workdir/out","total charge");
$result+=jt::test_grepnumber("$workdir/out","qfix","qfix= *([^ ]*)",1.0,0.00001);
jt::stageresult($workdir,$result,"1");
#juDFT Testscript
#The following arguments are passed: executable, working directory
jt::copyfile("files/inp",$workdir);
jt::copyfile("files/kpts",$workdir);
jt::copyfile("files/enpara",$workdir);
jt::testrun($executable,$workdir);
#now test output
$result=jt::test_grepexists("$workdir/out","it= 1 is completed");
$result+=jt::test_grepnumber("$workdir/out","new fermi energy",": *([^ ]*)",0.4250,0.0001);
$result+=jt::test_grepnumber("$workdir/out","total energy=","= *([^ ]*)",-3305.008,0.001);
$result+=jt::test_grepnumber("$workdir/out","distance of charge densitie","1: *([^ ]*)",49.035,0.001);
jt::stageresult($workdir,$result,"2");
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment