source: palm/trunk/SCRIPTS/palmtest @ 2700

Last change on this file since 2700 was 2696, checked in by kanani, 7 years ago

Merge of branch palm4u into trunk

  • Property svn:executable set to *
File size: 6.0 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-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
60get_core_array() {
61   for i in 1 2 4 8 16 32; do
62      if [[ $i -le ${1} ]]; then
63         printf "$i "
64      fi
65   done
66}
67
68configure() {
69   hrule
70   printf "Configuring..."
71   if [[ -f ${existing_working_dir}/.palm.iofiles ]]; then
72      cp ${existing_trunk_dir}/SCRIPTS/.palm.iofiles ${tester_prefix}/.palm.iofiles
73   else
74      printf " failed (missing .palm.iofiles)\n"
75      hrule
76      exit 1
77   fi
78   if [[ -f ${existing_working_dir}/.palm.config.${configuration} ]]; then
79      cp ${existing_working_dir}/.palm.config.${configuration} ${tester_prefix}/.palm.config.${configuration}
80      sed -i -e "s#%base_directory .*#%base_directory      ${tester_prefix}#g" ${tester_prefix}/.palm.config.${configuration}
81      sed -i -e "s#%base_data .*#%base_data           ${tester_prefix}/JOBS#g" ${tester_prefix}/.palm.config.${configuration}
82      sed -i -e "s#%source_path .*#%source_path         ${tester_prefix}/trunk/SOURCE#g" ${tester_prefix}/.palm.config.${configuration}
83      sed -i -e "s#%user_source_path .*#%user_source_path    ${tester_prefix}/JOBS/\$fname/USER_CODE#g" ${tester_prefix}/.palm.config.${configuration}
84      sed -i -e "s#%fast_io_catalog .*#%fast_io_catalog     ${tester_prefix}/tmp#g" ${tester_prefix}/.palm.config.${configuration}
85      printf " finished (adapted existing .palm.config.${configuration})\n"
86   else
87      printf " failed (missing .palm.config.${configuration})\n"
88      hrule
89      exit 1
90   fi
91}
92
93build() {
94   hrule
95   rm -rf ${tester_prefix}/JOBS
96   rm -rf ${tester_prefix}/MAKE_DEPOSITORY*
97   bash ${trunk_dir}/SCRIPTS/palmbuild -h "${configuration}" -v
98}
99
100palm_installer_test() {
101   hrule
102   local name=${1}
103   local cores=${2}
104   printf "Testing with \"${name}\" on ${cores} core(s)... "
105   local job_id=${name}_${cores}
106   local input_dir=${tester_prefix}/JOBS/${job_id}/INPUT
107   local monitoring_dir=${tester_prefix}/JOBS/${job_id}/MONITORING
108   if [[ ! -f ${test_dir}/${name}_p3d ]] || [[ ! -f ${test_dir}/${name}_rc ]]; then
109      printf " test not found\n"
110      return 1
111   fi
112   rm -rf ${monitoring_dir}
113   mkdir -p ${input_dir}
114   mkdir -p ${monitoring_dir}
115   cp ${test_dir}/${name}_p3d ${input_dir}/${job_id}_p3d
116   cp ${test_dir}/${name}_rc ${monitoring_dir}/${job_id}_rc_reference
117   [[ -f ${test_dir}/${name}_topo ]] && cp ${test_dir}/${name}_topo ${input_dir}/${job_id}_topo
118   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
119   grep -A 99999 "Run-control output" ${monitoring_dir}/${job_id}_rc 1> ${monitoring_dir}/RC 2> /dev/null
120   grep -A 99999 "Run-control output" ${monitoring_dir}/${job_id}_rc_reference 1> ${monitoring_dir}/RC_REF 2> /dev/null
121   diff_output=$(diff ${monitoring_dir}/RC_REF ${monitoring_dir}/RC)
122   rm ${monitoring_dir}/RC ${monitoring_dir}/RC_REF
123   if [[ "${diff_output}" == "" ]]; then
124      printf " passed\n"
125      return 0
126   else
127      printf " failed\n"
128      test_status="failed"
129      return 1
130   fi
131}
132
133palm_installer_test_suite() {
134   for test_path in ${fnames}; do
135      for n_core in $(get_core_array $max_cores); do
136         testname_p3d=$(basename $test_path)
137         palm_installer_test "${testname_p3d%_p3d}" "${n_core}"
138      done
139   done
140   hrule
141   if [[ "${test_status}" == "failed" ]]; then
142      echo "Some tests failed!"
143      hrule
144      exit 1
145   else
146      echo "All found tests passed. :-)"
147      rm -rf ${tester_prefix}/tmp/*
148      hrule
149      exit 0
150   fi
151}
152
153existing_working_dir=$(readlink -f "${SCRIPT_LOCATION}/../../")
154existing_trunk_dir=$(readlink -f "${SCRIPT_LOCATION}/../")
155
156max_cores=$(get_number_of_cpu_cores)
157test_id=$(date +%Y-%m-%d_%H%M%S)
158do_plots=1
159configuration="default"
160fnames="$(echo ${existing_trunk_dir}/INSTALL/*_p3d)"
161
162while  getopts  :d:h:N:pX:  option
163do
164   case  $option  in
165      (d)   fnames="$OPTARG";;
166      (h)   configuration="$OPTARG";;
167      (N)   test_id="$OPTARG";;
168      (p)   do_plots=0;;
169      (X)   max_cores=$OPTARG;;
170      (\?)  printf "\n  +++ unknown option $OPTARG \n";
171            exit;;
172   esac
173done
174tester_prefix=${existing_working_dir}/tests/${test_id}
175trunk_dir=${tester_prefix}/trunk
176test_dir=${trunk_dir}/INSTALL
177
178mkdir -p ${tester_prefix}
179cd ${tester_prefix}
180
181ln -s ${existing_trunk_dir}
182
183
184
185configure
186build
187palm_installer_test_suite
Note: See TracBrowser for help on using the repository browser.