source: palm/trunk/SCRIPTS/palmtest @ 2773

Last change on this file since 2773 was 2767, checked in by knoop, 7 years ago

Added _static and _dynamic file-support to palmtest

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 6.5 KB
Line 
1#!/usr/bin/env bash
2
3#--------------------------------------------------------------------------------#
4# This file is part of the PALM model system.
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 2017-2018  Leibniz Universitaet Hannover
18#--------------------------------------------------------------------------------#
19#
20# Current revisions:
21# -----------------
22#
23#
24# Former revisions:
25# -----------------
26# $Id: palmtest 2767 2018-01-23 12:14:24Z suehring $
27# Corrected "Former revisions" section
28# svn propset keyword
29#
30#
31#
32# 2696 kanani
33# Change in file header (GPL part)
34#
35# 2579 knoop
36# palmtest now testing for multiple cpu-setups
37#
38# 2515 kanani
39# Generalization of the palmtest script
40#
41# 2497 knoop
42# Initial revision
43#
44# Description:
45# ------------
46# Testsuite execution script
47#------------------------------------------------------------------------------#
48SOURCE="${BASH_SOURCE[0]}"
49while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
50  DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
51  SOURCE="$(readlink "$SOURCE")"
52  [[ $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
53done
54SCRIPT_LOCATION="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
55
56hrule() {
57   printf "#"
58   printf -- '-%.0s' {1..72}
59   printf "#\n"
60}
61
62get_number_of_cpu_cores() {
63   {
64      n=$(sysctl -n machdep.cpu.core_count 2> /dev/null)
65   } || {
66      n=$(grep -c ^processor /proc/cpuinfo 2> /dev/null)
67   } || {
68   if ! [[ $n =~ ^-?[0-9]+$ ]]; then
69      n=1
70   fi
71   }
72   echo $n
73}
74
75get_core_array() {
76   for i in 1 2 4 8 16 32; do
77      if [[ $i -le ${1} ]]; then
78         printf "$i "
79      fi
80   done
81}
82
83configure() {
84   hrule
85   printf "Configuring..."
86   if [[ -f ${existing_working_dir}/.palm.iofiles ]]; then
87      cp ${existing_trunk_dir}/SCRIPTS/.palm.iofiles ${tester_prefix}/.palm.iofiles
88   else
89      printf " failed (missing .palm.iofiles)\n"
90      hrule
91      exit 1
92   fi
93   if [[ -f ${existing_working_dir}/.palm.config.${configuration} ]]; then
94      cp ${existing_working_dir}/.palm.config.${configuration} ${tester_prefix}/.palm.config.${configuration}
95      sed -i -e "s#%base_directory .*#%base_directory      ${tester_prefix}#g" ${tester_prefix}/.palm.config.${configuration}
96      sed -i -e "s#%base_data .*#%base_data           ${tester_prefix}/JOBS#g" ${tester_prefix}/.palm.config.${configuration}
97      sed -i -e "s#%source_path .*#%source_path         ${tester_prefix}/trunk/SOURCE#g" ${tester_prefix}/.palm.config.${configuration}
98      sed -i -e "s#%user_source_path .*#%user_source_path    ${tester_prefix}/JOBS/\$fname/USER_CODE#g" ${tester_prefix}/.palm.config.${configuration}
99      sed -i -e "s#%fast_io_catalog .*#%fast_io_catalog     ${tester_prefix}/tmp#g" ${tester_prefix}/.palm.config.${configuration}
100      printf " finished (adapted existing .palm.config.${configuration})\n"
101   else
102      printf " failed (missing .palm.config.${configuration})\n"
103      hrule
104      exit 1
105   fi
106}
107
108build() {
109   hrule
110   rm -rf ${tester_prefix}/JOBS
111   rm -rf ${tester_prefix}/MAKE_DEPOSITORY*
112   bash ${trunk_dir}/SCRIPTS/palmbuild -h "${configuration}" -v
113}
114
115palm_installer_test() {
116   hrule
117   local name=${1}
118   local cores=${2}
119   printf "Testing with \"${name}\" on ${cores} core(s)... "
120   local job_id=${name}_${cores}
121   local input_dir=${tester_prefix}/JOBS/${job_id}/INPUT
122   local monitoring_dir=${tester_prefix}/JOBS/${job_id}/MONITORING
123   if [[ ! -f ${test_dir}/${name}_p3d ]] || [[ ! -f ${test_dir}/${name}_rc ]]; then
124      printf " test not found\n"
125      return 1
126   fi
127   rm -rf ${monitoring_dir}
128   mkdir -p ${input_dir}
129   mkdir -p ${monitoring_dir}
130   cp ${test_dir}/${name}_p3d ${input_dir}/${job_id}_p3d
131   cp ${test_dir}/${name}_rc ${monitoring_dir}/${job_id}_rc_reference
132   [[ -f ${test_dir}/${name}_topo ]] && cp ${test_dir}/${name}_topo ${input_dir}/${job_id}_topo
133   [[ -f ${test_dir}/${name}_static ]] && cp ${test_dir}/${name}_static ${input_dir}/${job_id}_static
134   [[ -f ${test_dir}/${name}_dynamic ]] && cp ${test_dir}/${name}_dynamic ${input_dir}/${job_id}_dynamic
135   bash ${trunk_dir}/SCRIPTS/palmrun -d ${job_id} -a "d3#" -h "${configuration}" -X "$cores" -T "$cores" -v -B > ${monitoring_dir}/${job_id}_stdout 2>&1
136   grep -A 99999 "Run-control output" ${monitoring_dir}/${job_id}_rc 1> ${monitoring_dir}/RC 2> /dev/null
137   grep -A 99999 "Run-control output" ${monitoring_dir}/${job_id}_rc_reference 1> ${monitoring_dir}/RC_REF 2> /dev/null
138   diff_output=$(diff ${monitoring_dir}/RC_REF ${monitoring_dir}/RC)
139   rm ${monitoring_dir}/RC ${monitoring_dir}/RC_REF
140   if [[ "${diff_output}" == "" ]]; then
141      printf " passed\n"
142      return 0
143   else
144      printf " failed\n"
145      test_status="failed"
146      return 1
147   fi
148}
149
150palm_installer_test_suite() {
151   for test_path in ${fnames}; do
152      for n_core in $(get_core_array $max_cores); do
153         testname_p3d=$(basename $test_path)
154         palm_installer_test "${testname_p3d%_p3d}" "${n_core}"
155      done
156   done
157   hrule
158   if [[ "${test_status}" == "failed" ]]; then
159      echo "Some tests failed!"
160      hrule
161      exit 1
162   else
163      echo "All found tests passed. :-)"
164      rm -rf ${tester_prefix}/tmp/*
165      hrule
166      exit 0
167   fi
168}
169
170existing_working_dir=$(readlink -f "${SCRIPT_LOCATION}/../../")
171existing_trunk_dir=$(readlink -f "${SCRIPT_LOCATION}/../")
172
173max_cores=$(get_number_of_cpu_cores)
174test_id=$(date +%Y-%m-%d_%H%M%S)
175do_plots=1
176configuration="default"
177fnames="$(echo ${existing_trunk_dir}/INSTALL/*_p3d)"
178
179while  getopts  :d:h:N:pX:  option
180do
181   case  $option  in
182      (d)   fnames="$OPTARG";;
183      (h)   configuration="$OPTARG";;
184      (N)   test_id="$OPTARG";;
185      (p)   do_plots=0;;
186      (X)   max_cores=$OPTARG;;
187      (\?)  printf "\n  +++ unknown option $OPTARG \n";
188            exit;;
189   esac
190done
191tester_prefix=${existing_working_dir}/tests/${test_id}
192trunk_dir=${tester_prefix}/trunk
193test_dir=${trunk_dir}/INSTALL
194
195mkdir -p ${tester_prefix}
196cd ${tester_prefix}
197
198ln -s ${existing_trunk_dir}
199
200
201
202configure
203build
204palm_installer_test_suite
Note: See TracBrowser for help on using the repository browser.