Little automation of Tochnog testing

[email protected] Thu, 12 Sep 2013 03:21:19 +0200
Newsgroups gmane.comp.mathematics.tochnog.user
Message-ID <[email protected]>
--0F1p//8PRICkK4MW
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Dear All, 

I am going to do some more careful testing of Tochnog in various
configurations, thus I have prepared a little bash script to run Tochnog
on several data files and gather the results.

I am sending the script in attachment as maybe someone will consider it useful.

The script allows to run Tochnog on all data files in given directory,
for instance for directory OLA: 

$ ./run_tochnog_test.sh --superlu -e ../build/tnlfem/tochnog OLA/
Running test examp1 ... PASSED
Running test refine5 ... FAILED
Total number of tests run: 2
Passed: 1  Failed: 1 Timeout: 0

It isn't perfect (and I should implement it in Python instead of bash, anyway)
so be forgiving :).

Regards,

Roman
-- 
Roman Putanowicz, PhD  < [email protected]  >
Institute for Computational Civil Engng (L-5)
Dept. of Civil Engng, Cracow Univ. of Technology
www.l5.pk.edu.pl, tel. +48 12 628 2569, fax 2034

--0F1p//8PRICkK4MW
Content-Type: application/sh
Content-Disposition: attachment; filename="run_tochnog_test.sh"
Content-Transfer-Encoding: quoted-printable

#!/bin/bash=0A=0A# Script to run tochnog on sample files and to gather the =
execution status=0A# Permission to copy and modify is granted under the BSD=
-2 license -- see below=0A# Last revised: 11/09/2013=0A=0A# Note: this scri=
pt requires 'comm' and 'sort' commands, see Debain coreutils=0A# package.=
=0A=0A# Bugs: the script will fail if the data file name contains space=0A=
=0A=0A#--------------------------------------------------------------------=
--------=0A# Copyright (c) 2013, Roman Putanowicz All rights reserved.=0A#=
=0A# Redistribution and use in source and binary forms, with or without=0A#=
 modification, are permitted provided that the following conditions are met=
:=0A#=0A#  * Redistributions of source code must retain the above copyright=
 notice,=0A#    this list of conditions and the following disclaimer.  =0A#=
  * Redistributions in binary form must reproduce the above copyright notic=
e,=0A#    this list of conditions and the following disclaimer in the docum=
entation=0A#    and/or other materials provided with the distribution.=0A#=
=0A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "A=
S IS"=0A# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED=
 TO, THE=0A# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTIC=
ULAR PURPOSE ARE=0A# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR =
CONTRIBUTORS BE LIABLE=0A# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, E=
XEMPLARY, OR CONSEQUENTIAL=0A# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROC=
UREMENT OF SUBSTITUTE GOODS OR=0A# SERVICES; LOSS OF USE, DATA, OR PROFITS;=
 OR BUSINESS INTERRUPTION) HOWEVER=0A# CAUSED AND ON ANY THEORY OF LIABILIT=
Y, WHETHER IN CONTRACT, STRICT LIABILITY,=0A# OR TORT (INCLUDING NEGLIGENCE=
 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE=0A# OF THIS SOFTWARE, EVEN=
 IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.=0A#-------------------------=
-----------------------------------------------------=0A=0A# global variabl=
es=0Ause_superlu=3Dno=0Areport_time=3Dyes=0Along_tests=3Dno=0Adata_path=3D=
=0Atochnog_path=3Dtochnog=0Adebug_mode=3Dno=0Atest_duration=3D"0"=0A=0A# lo=
g file=0AlogFile=3Dtn_log=0A=0A# error codes=0AERROR_CMDL=3D1=0AERROR_INTER=
NAL=3D99=0AERROR_DEPENDENCIES=3D66=0AEXIT_SUCCESS=3D0=0ATIME_OUT=3D124=0A=
=0A# This function prints the usage message.=0Afunction usage() {=0Acat <<-=
EOH=0A=0AUsage: $0 DATA_PATH=0A  where DATA_PATH is path to directory conta=
ining Tochnog input files=0A=0AOptions:=0A      -h|--help         -- prints=
 this message=0A      -l|--long-tests   -- run also lenghty (time consuming=
) tests=0A      -t|--timeout DURATION -- specify the test timeout duration=
=0A      -s|--superlu      -- use SuperLU solver=0A      -r|--report-time  =
-- report test execution time=0A      -e|--tochnog-path PATH -- specify pat=
h to tochnog executable=0A      -d|--debug        -- run this script in deb=
ug mode=0A=0AEOH=0A}=0A=0A#=0A# Parse command line and setup global variabl=
es=0A#=0Afunction parse_command_line() {=0A  TEMP=3D`getopt -o hlsrde:t: \=
=0A     --long help,long-tests,superlu,report-time,debug,tochnog-path:,time=
out: \=0A     -n 'run_tochnog_tests.sh' -- "$@"`=0A=0A  if [ $? !=3D 0 ] ; =
then echo "Terminating..." >&2 ; exit 1 ; fi=0A=0A  # Note the quotes aroun=
d `$TEMP': they are essential!=0A  eval set -- "$TEMP"=0A=0A  while true ; =
do=0A	  case "$1" in=0A      -h|--help) usage ; exit ${EXIT_SUCCESS} ;;=0A	=
    -l|--long-tests) long_tests=3D"yes" ; shift ;;=0A		  -s|--superlu) use_=
superlu=3D"yes" ; shift ;;=0A      -r|--report-time) report_time=3D"yes" ; =
shift ;;=0A      -t|--timeout) test_duration=3D$2 ; shift 2 ;; =0A		  -e|--=
tochnog-path) =0A		     case "$2" in=0A				   *)  tochnog_path=3D$2 ; shift=
 2 ;;=0A			   esac ;;=0A      -d|--debug) debug_mode=3D"yes"; shift ;;=0A		=
  --) shift ; break ;;=0A		  *) echo "Internal error"; exit ${ERROR_INTENAL=
} ;;=0A	  esac=0A  done=0A=0A  if [ $# -ne 1 ]; then=0A     echo "Missing D=
ATA_PATH argument."=0A     usage=0A     exit ${ERROR_CMDL}=0A  fi=0A  data_=
path=3D$1=0A=0A  if [ ${debug_mode} =3D "yes" ]; then=0A    echo "Number of=
 argument $#"=0A    echo "Data path: ${data_path}"=0A    echo "Tochnog path=
: ${tochnog_path}"=0A    echo "Use SupeLU: ${use_superlu}"=0A    echo "Repo=
rt time: ${report_time}" =0A    echo "Test duration: ${test_duration}"=0A  =
  echo "Run long tests: ${long_tests}"=0A    echo "Debug: ${debug_mode}"=0A=
  fi=0A}=0A=0A#=0A# Run tochnog on given dat file =0A# The stdout and stder=
r of of tochnog are redirected to log file.=0A# The function updates counte=
rs of tests=0A#=0Afunction run_test_case() { #arg1 -- file name=0A  testNam=
e=3D`basename ${f} .dat`=0A  echo -n "Running test ${testName} ... "=0A  ec=
ho "=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D" >> ${logFile}=0A  echo "BEGIN $=
testName" >> ${logFile}=0A=0A  { # the braces provide the unit of I/O redir=
ection=0A    if [ ${test_duration} !=3D "0" ]; then=0A      timeout -k 1s $=
{test_duration} ${tochnog_path} ${f}=0A       status=3D$?=0A    else =0A   =
    ${tochnog_path} ${f}=0A       status=3D$?=0A    fi=0A  }  >> ${logFile}=
 2>&1=0A=0A  echo -n "END $testName" >> ${logFile}=0A  if [ ${status} -eq 0=
 ]; then=0A    echo "PASSED"=0A    ((testsPassed +=3D 1))=0A    echo " PASS=
ED" >> ${logFile}=0A  elif [ ${status} -eq ${TIME_OUT} ]; then=0A     ((tes=
tsTimeout +=3D1 ))=0A    echo "TIMEOUT"=0A    echo " TIMEOUT" >> ${logFile}=
=0A  else =0A   echo "FAILED"=0A    echo " FAILED" >> ${logFile}=0A    ((te=
stsFailed +=3D 1))=0A  fi=0A  ((numOfTests +=3D 1))=0A}=0A=0A=0A#=0A# Main =
body of the script.=0A# This function initializes global variables, filters=
 data file to be=0A# run by tochnog, runs tochnog on the data files and pri=
nts the summary=0A#=0Afunction main() {=0A  numOfTests=3D0=0A  testsPassed=
=3D0=0A  testsFailed=3D0=0A  testsTimeout=3D0=0A  # The array of base names=
 of long tests=0A  tests_to_skip=3D("examp14" "examp23" "examp24" "ho_mech1=
" "ho_mech3")=0A=0A  # Build the full path of long tests=0A  for index in $=
{!tests_to_skip[@]}=0A  do=0A    skip_paths[$index]=3D${data_path}/${tests_=
to_skip[$index]}.dat=0A  done=0A  skip_paths=3D( $(sort <(printf "%s\n" ${s=
kip_paths[@]}) ) )=0A=0A  # The array of paths of all tests=0A  all_tests=
=3D(`ls -1 ${data_path}/*.dat`)=0A=0A  # Filter out the tests to skip. The =
key is the use of comm command=0A  if [ ${long_tests} =3D "yes" ]; then=0A =
   torun_tests=3D${all_tests[@]}   =0A  else =0A    torun_tests=3D( $(comm =
-23 <( printf "%s\n" "${all_tests[@]}" ) <( printf "%s\n" "${skip_paths[@]}=
") ) )=0A  fi=0A=0A  # Setup default solver for tochnog=0A  if [ ${use_supe=
rlu} =3D "yes" ]; then=0A    export TOCHNOG_OPTIONS_SOLVER=3D"-matrix_super=
lu"=0A  fi=0A=0A  for f in ${torun_tests[@]}=0A  do=0A    run_test_case $f=
=0A  done=0A  echo "Total number of tests run: $numOfTests"=0A  echo "Passe=
d: $testsPassed  Failed: $testsFailed" Timeout: $testsTimeout=0A}=0A=0A#=0A=
# Check if required commands are available.=0A# This script depends on the =
following comm=0A#=0Afunction check_dependencies() {=0A  required_commands=
=3D("comm" "sort")=0A  for c in ${required_commands[@]}=0A  do =0A    if ! =
hash $c 2>/dev/null; then=0A      echo "Command '$c' is not found ... canno=
t work without it"=0A      echo "If your system is Debian consider to insta=
ll coreutils package."=0A      exit ${ERROR_DEPENDENCIES}=0A    fi=0A  done=
=0A}=0A=0Acheck_dependencies=0Aparse_command_line $@ =0Amain =0A=0A
--0F1p//8PRICkK4MW
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

------------------------------------------------------------------------------
How ServiceNow helps IT people transform IT departments:
1. Consolidate legacy IT systems to a single system of record for IT
2. Standardize and globalize service processes across IT
3. Implement zero-touch automation to replace manual, redundant tasks
http://pubads.g.doubleclick.net/gampad/clk?id=51271111&iu=/4140/ostg.clktrk
--0F1p//8PRICkK4MW
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Tochnog-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tochnog-users

--0F1p//8PRICkK4MW--