source: palm/trunk/SCRIPTS/testsuite @ 3461

Last change on this file since 3461 was 2718, checked in by maronga, 7 years ago

deleting of deprecated files; headers updated where needed

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 5.7 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 1997-2018  Leibniz Universitaet Hannover
18#--------------------------------------------------------------------------------#
19#
20# Current revisions:
21# -----------------
22#
23#
24# Former revisions:
25# -----------------
26# $Id: testsuite 2718 2018-01-02 08:49:38Z knoop $
27# Corrected "Former revisions" section
28#
29#
30#
31# 2696 kanani
32# Change in file header (GPL part)
33#
34# 2410 giersch
35# Change of option -h argument
36#
37# 2372 sward
38# Change of option -h argument
39#
40# 2349 giersch
41# Change of option -h argument
42#
43# 2347 knoop
44# Initial revision
45#
46# Description:
47# ------------
48# Testsuite execution script
49#------------------------------------------------------------------------------#
50
51hrule() {
52   printf "#"
53   printf -- '-%.0s' {1..72}
54   printf "#\n"
55}
56
57get_number_of_cpu_cores() {
58   {
59      n=$(sysctl -n machdep.cpu.core_count 2> /dev/null)
60   } || {
61      n=$(grep -c ^processor /proc/cpuinfo 2> /dev/null)
62   } || {
63   if ! [[ $n =~ ^-?[0-9]+$ ]]; then
64      n=1
65   fi
66   }
67   echo $n
68}
69
70
71configure() {
72   hrule
73   printf "Configuring .mrun.config ..."
74   if [[ -f ${existing_working_dir}/.mrun.config ]]; then
75      cp ${existing_working_dir}/.mrun.config ${tester_prefix}/.mrun.config
76      sed -i -e "s#%base_directory .*#%base_directory    ${tester_prefix}#g" ${tester_prefix}/.mrun.config
77      sed -i -e "s#%base_data .*#%base_data         ${tester_prefix}/JOBS#g" ${tester_prefix}/.mrun.config
78      sed -i -e "s#%tmp_user_catalog .*#%tmp_user_catalog  ${tester_prefix}/tmp#g" ${tester_prefix}/.mrun.config
79      printf " finished (adapted existing .mrun.config)\n"
80   else
81      cp ${PALM_BIN}/.mrun.config.gfortran ${tester_prefix}/.mrun.config
82      sed -i -e "s/<replace_with_your_hostname>/${HOSTNAME}/g" ${tester_prefix}/.mrun.config
83      sed -i -e "s/<replace_with_your_local_username>/${USER}/g" ${tester_prefix}/.mrun.config
84      sed -i -e "s/<hi>/lcmuk/g" ${tester_prefix}/.mrun.config
85      sed -i -e "s#%base_directory    \$HOME/palm/current_version#%base_directory    ${tester_prefix}#g" ${tester_prefix}/.mrun.config
86      sed -i -e "s#%base_data         ~/palm/current_version/JOBS#%base_data         ${tester_prefix}/JOBS#g" ${tester_prefix}/.mrun.config
87      sed -i -e "s#%tmp_user_catalog  \$HOME/palm/tmp#%tmp_user_catalog  ${tester_prefix}/tmp#g" ${tester_prefix}/.mrun.config
88      sed -i -e "s#<replace_by_netcdf_include_path>#/usr/include#g" ${tester_prefix}/.mrun.config
89      sed -i -e "s#-L:<replace_by_netcdf_library_path>:-lnetcdf#/usr/lib/x86_64-linux-gnu/libnetcdff.so#g" ${tester_prefix}/.mrun.config
90      sed -i -e "s#-j:4#-j:1#g" ${tester_prefix}/.mrun.config
91      printf " finished (created .mrun.config from template)\n"
92   fi
93}
94
95build() {
96   hrule
97   rm -rf ${tester_prefix}/JOBS
98   rm -rf ${tester_prefix}/MAKE_DEPOSITORY*
99   rm -rf ${tester_prefix}/SOURCES_FOR_RUN_*
100   bash ${trunk_dir}/SCRIPTS/mbuild -h "lcmuk" -K "parallel" -v -u
101   bash ${trunk_dir}/SCRIPTS/mbuild -h "lcmuk" -K "parallel" -v
102}
103
104palm_installer_test() {
105   hrule
106   printf "Testing with \"${1}\"... "
107   local input_dir=${tester_prefix}/JOBS/${1}/INPUT
108   local monitoring_dir=${tester_prefix}/JOBS/${1}/MONITORING
109   local test_dir=${trunk_dir}/INSTALL
110   if [[ ! -f ${test_dir}/${1}_p3d ]] || [[ ! -f ${test_dir}/${1}_rc ]]; then
111      printf " test not found\n"
112      return 1
113   fi
114   rm -rf ${monitoring_dir}
115   mkdir -p ${input_dir}
116   mkdir -p ${monitoring_dir}
117   cp ${test_dir}/${1}_p3d ${input_dir}/${1}_p3d
118   cp ${test_dir}/${1}_rc ${monitoring_dir}/${1}_rc_reference
119   [[ -f ${test_dir}/${1}_topo ]] && cp ${test_dir}/${1}_topo ${input_dir}/
120   bash ${trunk_dir}/SCRIPTS/mrun -d ${1} -r "d3#" -h "lcmuk" -K "parallel" -X "$NUM_PROC" -T "$NUM_PROC" -v -B > ${monitoring_dir}/${1}_stdout 2>&1
121   grep -A 99999 "Run-control output" ${monitoring_dir}/${1}_rc 1> ${monitoring_dir}/RC 2> /dev/null
122   grep -A 99999 "Run-control output" ${monitoring_dir}/${1}_rc_reference 1> ${monitoring_dir}/RC_REF 2> /dev/null
123   diff_output=$(diff ${monitoring_dir}/RC_REF ${monitoring_dir}/RC)
124   rm ${monitoring_dir}/RC ${monitoring_dir}/RC_REF
125   if [[ "${diff_output}" == "" ]]; then
126      printf " passed\n"
127      return 0
128   else
129      printf " failed\n"
130      test_status="failed"
131      return 1
132   fi
133}
134
135palm_installer_test_suite() {
136   for test_path in ${trunk_dir}/INSTALL/*_p3d; do
137      testname_p3d=$(basename $test_path)
138      palm_installer_test "${testname_p3d%_p3d}"
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
153NUM_PROC=$(get_number_of_cpu_cores)
154existing_trunk_dir=$(readlink -f "${PALM_BIN}/../")
155existing_working_dir=$(readlink -f "${PALM_BIN}/../../")
156tester_prefix=${existing_working_dir}/tests/${BUILD_NUMBER:-$(date +%Y-%m-%d_%H%M%S)}
157trunk_dir=${tester_prefix}/trunk
158
159# redirect PALM_BIN for duration of tests
160export PALM_BIN=${trunk_dir}/SCRIPTS
161
162mkdir -p ${tester_prefix}
163cd ${tester_prefix}
164
165ln -s ${existing_trunk_dir}
166
167configure
168build
169palm_installer_test_suite
Note: See TracBrowser for help on using the repository browser.