source: palm/trunk/SCRIPTS/palmtest @ 2566

Last change on this file since 2566 was 2515, checked in by kanani, 7 years ago

Generalization of the palmtest script

  • Property svn:executable set to *
File size: 5.7 KB
Line 
1#!/usr/bin/env bash
2
3#--------------------------------------------------------------------------------#
4# This file is part of PALM.
5#
6# PALM is free software: you can redistribute it and/or modify it under the terms
7# of the GNU General Public License as published by the Free Software Foundation,
8# either version 3 of the License, or (at your option) any later version.
9#
10# PALM is distributed in the hope that it will be useful, but WITHOUT ANY
11# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License along with
15# PALM. If not, see <http://www.gnu.org/licenses/>.
16#
17# Copyright 1997-2017  Leibniz Universitaet Hannover
18#--------------------------------------------------------------------------------#
19#
20# Current revisions:
21# -----------------
22#
23#
24# Former revisions:
25# -----------------
26# $Id$
27# Initial revision
28#
29# Description:
30# ------------
31# Testsuite execution script
32#------------------------------------------------------------------------------#
33SOURCE="${BASH_SOURCE[0]}"
34while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
35  DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
36  SOURCE="$(readlink "$SOURCE")"
37  [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
38done
39SCRIPT_LOCATION="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
40
41hrule() {
42   printf "#"
43   printf -- '-%.0s' {1..72}
44   printf "#\n"
45}
46
47get_number_of_cpu_cores() {
48   {
49      n=$(sysctl -n machdep.cpu.core_count 2> /dev/null)
50   } || {
51      n=$(grep -c ^processor /proc/cpuinfo 2> /dev/null)
52   } || {
53   if ! [[ $n =~ ^-?[0-9]+$ ]]; then
54      n=1
55   fi
56   }
57   echo $n
58}
59
60
61configure() {
62   hrule
63   printf "Configuring..."
64   if [[ -f ${existing_working_dir}/.palm.iofiles ]]; then
65      cp ${existing_trunk_dir}/SCRIPTS/.palm.iofiles ${tester_prefix}/.palm.iofiles
66   else
67      printf " failed (missing .palm.iofiles)\n"
68      hrule
69      exit 1
70   fi
71   if [[ -f ${existing_working_dir}/.palm.config.${configuration} ]]; then
72      cp ${existing_working_dir}/.palm.config.${configuration} ${tester_prefix}/.palm.config.${configuration}
73      sed -i -e "s#%base_directory .*#%base_directory      ${tester_prefix}#g" ${tester_prefix}/.palm.config.${configuration}
74      sed -i -e "s#%base_data .*#%base_data           ${tester_prefix}/JOBS#g" ${tester_prefix}/.palm.config.${configuration}
75      sed -i -e "s#%source_path .*#%source_path         ${tester_prefix}/trunk/SOURCE#g" ${tester_prefix}/.palm.config.${configuration}
76      sed -i -e "s#%user_source_path .*#%user_source_path    ${tester_prefix}/JOBS/\$fname/USER_CODE#g" ${tester_prefix}/.palm.config.${configuration}
77      sed -i -e "s#%fast_io_catalog .*#%fast_io_catalog     ${tester_prefix}/tmp#g" ${tester_prefix}/.palm.config.${configuration}
78      printf " finished (adapted existing .palm.config.${configuration})\n"
79   else
80      printf " failed (missing .palm.config.${configuration})\n"
81      hrule
82      exit 1
83   fi
84}
85
86build() {
87   hrule
88   rm -rf ${tester_prefix}/JOBS
89   rm -rf ${tester_prefix}/MAKE_DEPOSITORY*
90   bash ${trunk_dir}/SCRIPTS/palmbuild -h "${configuration}" -v
91}
92
93palm_installer_test() {
94   hrule
95   printf "Testing with \"${1}\"... "
96   local input_dir=${tester_prefix}/JOBS/${1}/INPUT
97   local monitoring_dir=${tester_prefix}/JOBS/${1}/MONITORING
98   local test_dir=${trunk_dir}/INSTALL
99   if [[ ! -f ${test_dir}/${1}_p3d ]] || [[ ! -f ${test_dir}/${1}_rc ]]; then
100      printf " test not found\n"
101      return 1
102   fi
103   rm -rf ${monitoring_dir}
104   mkdir -p ${input_dir}
105   mkdir -p ${monitoring_dir}
106   cp ${test_dir}/${1}_p3d ${input_dir}/${1}_p3d
107   cp ${test_dir}/${1}_rc ${monitoring_dir}/${1}_rc_reference
108   [[ -f ${test_dir}/${1}_topo ]] && cp ${test_dir}/${1}_topo ${input_dir}/
109   bash ${trunk_dir}/SCRIPTS/palmrun -d ${1} -a "d3#" -h "${configuration}" -X "$cores" -T "$cores" -v -B > ${monitoring_dir}/${1}_stdout 2>&1
110   grep -A 99999 "Run-control output" ${monitoring_dir}/${1}_rc 1> ${monitoring_dir}/RC 2> /dev/null
111   grep -A 99999 "Run-control output" ${monitoring_dir}/${1}_rc_reference 1> ${monitoring_dir}/RC_REF 2> /dev/null
112   diff_output=$(diff ${monitoring_dir}/RC_REF ${monitoring_dir}/RC)
113   rm ${monitoring_dir}/RC ${monitoring_dir}/RC_REF
114   if [[ "${diff_output}" == "" ]]; then
115      printf " passed\n"
116      return 0
117   else
118      printf " failed\n"
119      test_status="failed"
120      return 1
121   fi
122}
123
124palm_installer_test_suite() {
125   for test_path in ${fnames}; do
126      testname_p3d=$(basename $test_path)
127      palm_installer_test "${testname_p3d%_p3d}"
128   done
129   hrule
130   if [[ "${test_status}" == "failed" ]]; then
131      echo "Some tests failed!"
132      hrule
133      exit 1
134   else
135      echo "All found tests passed. :-)"
136      rm -rf ${tester_prefix}/tmp/*
137      hrule
138      exit 0
139   fi
140}
141
142existing_working_dir=$(readlink -f "${SCRIPT_LOCATION}/../../")
143existing_trunk_dir=$(readlink -f "${SCRIPT_LOCATION}/../")
144
145cores=$(get_number_of_cpu_cores)
146test_id=$(date +%Y-%m-%d_%H%M%S)
147do_plots=1
148configuration="default"
149fnames="$(echo ${existing_trunk_dir}/INSTALL/*_p3d)"
150
151while  getopts  :d:h:N:pX:  option
152do
153   case  $option  in
154      (d)   fnames="$OPTARG";;
155      (h)   configuration="$OPTARG";;
156      (N)   test_id="$OPTARG";;
157      (p)   do_plots=0;;
158      (X)   cores=$OPTARG;;
159      (\?)  printf "\n  +++ unknown option $OPTARG \n";
160            exit;;
161   esac
162done
163tester_prefix=${existing_working_dir}/tests/${test_id}
164trunk_dir=${tester_prefix}/trunk
165
166mkdir -p ${tester_prefix}
167cd ${tester_prefix}
168
169ln -s ${existing_trunk_dir}
170
171configure
172build
173palm_installer_test_suite
Note: See TracBrowser for help on using the repository browser.