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 2718 2018-01-02 08:49:38Z kanani $ |
---|
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 | #------------------------------------------------------------------------------# |
---|
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 | |
---|
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 | } |
---|
82 | |
---|
83 | configure() { |
---|
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 | |
---|
108 | build() { |
---|
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 | |
---|
115 | palm_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 | 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 |
---|
134 | grep -A 99999 "Run-control output" ${monitoring_dir}/${job_id}_rc 1> ${monitoring_dir}/RC 2> /dev/null |
---|
135 | grep -A 99999 "Run-control output" ${monitoring_dir}/${job_id}_rc_reference 1> ${monitoring_dir}/RC_REF 2> /dev/null |
---|
136 | diff_output=$(diff ${monitoring_dir}/RC_REF ${monitoring_dir}/RC) |
---|
137 | rm ${monitoring_dir}/RC ${monitoring_dir}/RC_REF |
---|
138 | if [[ "${diff_output}" == "" ]]; then |
---|
139 | printf " passed\n" |
---|
140 | return 0 |
---|
141 | else |
---|
142 | printf " failed\n" |
---|
143 | test_status="failed" |
---|
144 | return 1 |
---|
145 | fi |
---|
146 | } |
---|
147 | |
---|
148 | palm_installer_test_suite() { |
---|
149 | for test_path in ${fnames}; do |
---|
150 | for n_core in $(get_core_array $max_cores); do |
---|
151 | testname_p3d=$(basename $test_path) |
---|
152 | palm_installer_test "${testname_p3d%_p3d}" "${n_core}" |
---|
153 | done |
---|
154 | done |
---|
155 | hrule |
---|
156 | if [[ "${test_status}" == "failed" ]]; then |
---|
157 | echo "Some tests failed!" |
---|
158 | hrule |
---|
159 | exit 1 |
---|
160 | else |
---|
161 | echo "All found tests passed. :-)" |
---|
162 | rm -rf ${tester_prefix}/tmp/* |
---|
163 | hrule |
---|
164 | exit 0 |
---|
165 | fi |
---|
166 | } |
---|
167 | |
---|
168 | existing_working_dir=$(readlink -f "${SCRIPT_LOCATION}/../../") |
---|
169 | existing_trunk_dir=$(readlink -f "${SCRIPT_LOCATION}/../") |
---|
170 | |
---|
171 | max_cores=$(get_number_of_cpu_cores) |
---|
172 | test_id=$(date +%Y-%m-%d_%H%M%S) |
---|
173 | do_plots=1 |
---|
174 | configuration="default" |
---|
175 | fnames="$(echo ${existing_trunk_dir}/INSTALL/*_p3d)" |
---|
176 | |
---|
177 | while getopts :d:h:N:pX: option |
---|
178 | do |
---|
179 | case $option in |
---|
180 | (d) fnames="$OPTARG";; |
---|
181 | (h) configuration="$OPTARG";; |
---|
182 | (N) test_id="$OPTARG";; |
---|
183 | (p) do_plots=0;; |
---|
184 | (X) max_cores=$OPTARG;; |
---|
185 | (\?) printf "\n +++ unknown option $OPTARG \n"; |
---|
186 | exit;; |
---|
187 | esac |
---|
188 | done |
---|
189 | tester_prefix=${existing_working_dir}/tests/${test_id} |
---|
190 | trunk_dir=${tester_prefix}/trunk |
---|
191 | test_dir=${trunk_dir}/INSTALL |
---|
192 | |
---|
193 | mkdir -p ${tester_prefix} |
---|
194 | cd ${tester_prefix} |
---|
195 | |
---|
196 | ln -s ${existing_trunk_dir} |
---|
197 | |
---|
198 | |
---|
199 | |
---|
200 | configure |
---|
201 | build |
---|
202 | palm_installer_test_suite |
---|