[2497] | 1 | #!/usr/bin/env bash |
---|
| 2 | |
---|
| 3 | #--------------------------------------------------------------------------------# |
---|
[2696] | 4 | # This file is part of the PALM model system. |
---|
[2497] | 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 | # |
---|
[2718] | 17 | # Copyright 2017-2018 Leibniz Universitaet Hannover |
---|
[2497] | 18 | #--------------------------------------------------------------------------------# |
---|
| 19 | # |
---|
| 20 | # Current revisions: |
---|
| 21 | # ----------------- |
---|
| 22 | # |
---|
| 23 | # |
---|
| 24 | # Former revisions: |
---|
| 25 | # ----------------- |
---|
| 26 | # $Id: palmtest 2775 2018-01-30 16:43:52Z hellstea $ |
---|
[2716] | 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 |
---|
[2497] | 42 | # Initial revision |
---|
| 43 | # |
---|
| 44 | # Description: |
---|
| 45 | # ------------ |
---|
| 46 | # Testsuite execution script |
---|
| 47 | #------------------------------------------------------------------------------# |
---|
| 48 | SOURCE="${BASH_SOURCE[0]}" |
---|
| 49 | while [ -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 |
---|
| 53 | done |
---|
| 54 | SCRIPT_LOCATION="$( cd -P "$( dirname "$SOURCE" )" && pwd )" |
---|
| 55 | |
---|
| 56 | hrule() { |
---|
| 57 | printf "#" |
---|
| 58 | printf -- '-%.0s' {1..72} |
---|
| 59 | printf "#\n" |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | get_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 | |
---|
[2579] | 75 | get_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 | } |
---|
[2497] | 82 | |
---|
| 83 | configure() { |
---|
| 84 | hrule |
---|
| 85 | printf "Configuring..." |
---|
| 86 | if [[ -f ${existing_working_dir}/.palm.config.${configuration} ]]; then |
---|
| 87 | cp ${existing_working_dir}/.palm.config.${configuration} ${tester_prefix}/.palm.config.${configuration} |
---|
| 88 | sed -i -e "s#%base_directory .*#%base_directory ${tester_prefix}#g" ${tester_prefix}/.palm.config.${configuration} |
---|
| 89 | sed -i -e "s#%base_data .*#%base_data ${tester_prefix}/JOBS#g" ${tester_prefix}/.palm.config.${configuration} |
---|
| 90 | sed -i -e "s#%source_path .*#%source_path ${tester_prefix}/trunk/SOURCE#g" ${tester_prefix}/.palm.config.${configuration} |
---|
| 91 | sed -i -e "s#%user_source_path .*#%user_source_path ${tester_prefix}/JOBS/\$fname/USER_CODE#g" ${tester_prefix}/.palm.config.${configuration} |
---|
| 92 | sed -i -e "s#%fast_io_catalog .*#%fast_io_catalog ${tester_prefix}/tmp#g" ${tester_prefix}/.palm.config.${configuration} |
---|
| 93 | printf " finished (adapted existing .palm.config.${configuration})\n" |
---|
| 94 | else |
---|
| 95 | printf " failed (missing .palm.config.${configuration})\n" |
---|
| 96 | hrule |
---|
| 97 | exit 1 |
---|
| 98 | fi |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | build() { |
---|
| 102 | hrule |
---|
| 103 | rm -rf ${tester_prefix}/JOBS |
---|
| 104 | rm -rf ${tester_prefix}/MAKE_DEPOSITORY* |
---|
| 105 | bash ${trunk_dir}/SCRIPTS/palmbuild -h "${configuration}" -v |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | palm_installer_test() { |
---|
| 109 | hrule |
---|
[2579] | 110 | local name=${1} |
---|
| 111 | local cores=${2} |
---|
| 112 | printf "Testing with \"${name}\" on ${cores} core(s)... " |
---|
| 113 | local job_id=${name}_${cores} |
---|
| 114 | local input_dir=${tester_prefix}/JOBS/${job_id}/INPUT |
---|
| 115 | local monitoring_dir=${tester_prefix}/JOBS/${job_id}/MONITORING |
---|
| 116 | if [[ ! -f ${test_dir}/${name}_p3d ]] || [[ ! -f ${test_dir}/${name}_rc ]]; then |
---|
[2497] | 117 | printf " test not found\n" |
---|
| 118 | return 1 |
---|
| 119 | fi |
---|
| 120 | rm -rf ${monitoring_dir} |
---|
| 121 | mkdir -p ${input_dir} |
---|
| 122 | mkdir -p ${monitoring_dir} |
---|
[2579] | 123 | cp ${test_dir}/${name}_p3d ${input_dir}/${job_id}_p3d |
---|
| 124 | cp ${test_dir}/${name}_rc ${monitoring_dir}/${job_id}_rc_reference |
---|
| 125 | [[ -f ${test_dir}/${name}_topo ]] && cp ${test_dir}/${name}_topo ${input_dir}/${job_id}_topo |
---|
[2767] | 126 | [[ -f ${test_dir}/${name}_static ]] && cp ${test_dir}/${name}_static ${input_dir}/${job_id}_static |
---|
| 127 | [[ -f ${test_dir}/${name}_dynamic ]] && cp ${test_dir}/${name}_dynamic ${input_dir}/${job_id}_dynamic |
---|
[2579] | 128 | 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 |
---|
| 129 | grep -A 99999 "Run-control output" ${monitoring_dir}/${job_id}_rc 1> ${monitoring_dir}/RC 2> /dev/null |
---|
| 130 | grep -A 99999 "Run-control output" ${monitoring_dir}/${job_id}_rc_reference 1> ${monitoring_dir}/RC_REF 2> /dev/null |
---|
[2497] | 131 | diff_output=$(diff ${monitoring_dir}/RC_REF ${monitoring_dir}/RC) |
---|
| 132 | rm ${monitoring_dir}/RC ${monitoring_dir}/RC_REF |
---|
| 133 | if [[ "${diff_output}" == "" ]]; then |
---|
| 134 | printf " passed\n" |
---|
| 135 | return 0 |
---|
| 136 | else |
---|
| 137 | printf " failed\n" |
---|
| 138 | test_status="failed" |
---|
| 139 | return 1 |
---|
| 140 | fi |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | palm_installer_test_suite() { |
---|
| 144 | for test_path in ${fnames}; do |
---|
[2579] | 145 | for n_core in $(get_core_array $max_cores); do |
---|
| 146 | testname_p3d=$(basename $test_path) |
---|
| 147 | palm_installer_test "${testname_p3d%_p3d}" "${n_core}" |
---|
| 148 | done |
---|
[2497] | 149 | done |
---|
| 150 | hrule |
---|
| 151 | if [[ "${test_status}" == "failed" ]]; then |
---|
| 152 | echo "Some tests failed!" |
---|
| 153 | hrule |
---|
| 154 | exit 1 |
---|
| 155 | else |
---|
| 156 | echo "All found tests passed. :-)" |
---|
| 157 | rm -rf ${tester_prefix}/tmp/* |
---|
| 158 | hrule |
---|
| 159 | exit 0 |
---|
| 160 | fi |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | existing_working_dir=$(readlink -f "${SCRIPT_LOCATION}/../../") |
---|
| 164 | existing_trunk_dir=$(readlink -f "${SCRIPT_LOCATION}/../") |
---|
| 165 | |
---|
[2579] | 166 | max_cores=$(get_number_of_cpu_cores) |
---|
[2497] | 167 | test_id=$(date +%Y-%m-%d_%H%M%S) |
---|
| 168 | do_plots=1 |
---|
| 169 | configuration="default" |
---|
| 170 | fnames="$(echo ${existing_trunk_dir}/INSTALL/*_p3d)" |
---|
| 171 | |
---|
| 172 | while getopts :d:h:N:pX: option |
---|
| 173 | do |
---|
| 174 | case $option in |
---|
| 175 | (d) fnames="$OPTARG";; |
---|
| 176 | (h) configuration="$OPTARG";; |
---|
| 177 | (N) test_id="$OPTARG";; |
---|
| 178 | (p) do_plots=0;; |
---|
[2579] | 179 | (X) max_cores=$OPTARG;; |
---|
[2497] | 180 | (\?) printf "\n +++ unknown option $OPTARG \n"; |
---|
| 181 | exit;; |
---|
| 182 | esac |
---|
| 183 | done |
---|
| 184 | tester_prefix=${existing_working_dir}/tests/${test_id} |
---|
| 185 | trunk_dir=${tester_prefix}/trunk |
---|
[2579] | 186 | test_dir=${trunk_dir}/INSTALL |
---|
[2497] | 187 | |
---|
| 188 | mkdir -p ${tester_prefix} |
---|
| 189 | cd ${tester_prefix} |
---|
| 190 | |
---|
| 191 | ln -s ${existing_trunk_dir} |
---|
| 192 | |
---|
[2579] | 193 | |
---|
| 194 | |
---|
[2497] | 195 | configure |
---|
| 196 | build |
---|
| 197 | palm_installer_test_suite |
---|