3 # Copyright 2016-2017 Huawei Technologies Co., Ltd.
4 # Modification Copyright 2019 © Samsung Electronics Co., Ltd.
5 # Modification Copyright 2021 © AT&T Intellectual Property.
6 # Modification Copyright 2021-2023 Nordix Foundation.
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
12 # http://www.apache.org/licenses/LICENSE-2.0
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
29 if [[ ${WORKSPACE} ]]; then
30 # Record list of active docker containers
31 docker ps --format "table {{ .Names }}\t{{ .Status }}"
33 # show memory consumption after all docker instances initialized
36 source_safely ${WORKSPACE}/compose/stop-compose.sh
38 if [[ ${WORKDIR} ]]; then
39 rsync -av "${WORKDIR}/" "${WORKSPACE}/csit/archives/${PROJECT}"
41 rm -rf ${WORKSPACE}/models
43 # TODO: do something with the output
47 # ensure that teardown and other finalizing steps are always executed
50 function docker_stats(){
51 # General memory details
52 if [ "$(uname -s)" == "Darwin" ]
54 sh -c "top -l1 | head -10"
57 sh -c "top -bn1 | head -3"
64 # Memory details per Docker
65 docker ps --format "table {{ .Names }}\t{{ .Status }}"
68 docker stats --no-stream
72 # save current set options
74 RUN_CSIT_SAVE_SET="$-"
75 RUN_CSIT_SHELLOPTS="${SHELLOPTS}"
78 # load the saved set options
83 for i in $(echo "${SHELLOPTS}" | tr ':' ' ') ; do
86 for i in $(echo "${RUN_CSIT_SHELLOPTS}" | tr ':' ' ') ; do
91 for i in $(echo "$_setopts" | sed 's/./& /g') ; do
94 set -${RUN_CSIT_SAVE_SET}
97 # set options for quick bailout when error
98 function harden_set() {
100 set +u # enabled it would probably fail too many often
103 # relax set options so the sourced file will not fail
104 # the responsibility is shifted to the sourced file...
105 function relax_set() {
110 # wrapper for sourcing a file
111 function source_safely() {
112 [ -z "$1" ] && return 1
122 # set and save options for quick failure
123 harden_set && save_set
128 echo "Usage: $0 <project> [<robot-options>]"
130 echo " <project> <robot-options>: "
135 if [ -z "${WORKSPACE}" ]; then
136 WORKSPACE=$(git rev-parse --show-toplevel)
140 # Add csit scripts to PATH
141 export PATH="${PATH}:${WORKSPACE}/csit:${WORKSPACE}/scripts:${ROBOT_VENV}/bin"
142 export SCRIPTS="${WORKSPACE}/csit/resources/scripts"
143 export ROBOT_VARIABLES=
145 export PROJECT="${1}"
149 rm -rf "${WORKSPACE}/csit/archives/${PROJECT}"
150 mkdir -p "${WORKSPACE}/csit/archives/${PROJECT}"
152 # Run installation of pre-required libraries
153 source_safely "${SCRIPTS}/prepare-robot-env.sh"
155 # Activate the virtualenv containing all the required libraries installed by prepare-robot-env.sh
156 source_safely "${ROBOT_VENV}/bin/activate"
158 export TEST_PLAN_DIR="${WORKSPACE}/csit/resources/tests"
159 export TEST_OPTIONS="${2}"
164 # Sign in to nexus3 docker repo
165 docker login -u docker -p docker nexus3.onap.org:10001
167 # Run setup script plan if it exists
168 SETUP="${SCRIPTS}/setup-${PROJECT}.sh"
169 if [ -f "${SETUP}" ]; then
170 echo "Running setup script ${SETUP}"
171 source_safely "${SETUP}"
174 # show memory consumption after all docker instances initialized
175 docker_stats | tee "${WORKSPACE}/csit/archives/${PROJECT}/_sysinfo-1-after-setup.txt"
179 echo "Reading the testplan:"
180 echo "${SUITES}" | egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' | sed "s|^|${TEST_PLAN_DIR}/|" > testplan.txt
182 SUITES=$( xargs < testplan.txt )
184 echo ROBOT_VARIABLES="${ROBOT_VARIABLES}"
185 echo "Starting Robot test suites ${SUITES} ..."
187 python3 -m robot.run -N "${PROJECT}" -v WORKSPACE:/tmp ${ROBOT_VARIABLES} ${SUITES}
190 echo "RESULT: ${RESULT}"
191 # Note that the final steps are done in on_exit function after this exit!