blob: fb66611c7069581cae22b42aa52b6e70af0e5bc1 [file] [log] [blame]
Zack Williams3798b412018-07-12 15:31:52 -07001#!/usr/bin/env bash
2
Joey Armstrong518f3572024-02-11 07:56:25 -05003# Copyright 2018-2024 Open Networking Foundation (ONF) and the ONF Contributors
Zack Williams3798b412018-07-12 15:31:52 -07004#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17# xos-unit.sh - perform a unit test on XOS or synchronizers
18set -e -o pipefail
19
20# when not running under Jenkins, use current dir as workspace, and 'xos' as GERRIT_PROJECT
21WORKSPACE=${WORKSPACE:-.}
22GERRIT_PROJECT=${GERRIT_PROJECT:-xos}
23
Zack Williams3798b412018-07-12 15:31:52 -070024# find the path to the project that is checked out
Zack Williamsde1c6212020-02-24 17:00:17 -070025PROJECT_PATH=$(xmllint --xpath "string(//project[@name=\"$GERRIT_PROJECT\"]/@path)" cord/.repo/manifests/default.xml)
Zack Williams3798b412018-07-12 15:31:52 -070026
Scott Baker49d8e1a2019-03-29 10:09:21 -070027if [ -f "$WORKSPACE/cord/$PROJECT_PATH/Makefile" ]; then
Zack Williamsae8b48b2019-04-16 15:00:37 -070028 # assume newer testing method which uses Makefile
Zack Williams3798b412018-07-12 15:31:52 -070029 pushd "$WORKSPACE/cord/$PROJECT_PATH"
Scott Baker49d8e1a2019-03-29 10:09:21 -070030 make test
Zack Williamsae8b48b2019-04-16 15:00:37 -070031
Zack Williams3798b412018-07-12 15:31:52 -070032else
Zack Williamsae8b48b2019-04-16 15:00:37 -070033 # assume older branch, so set up the venv the old way
Scott Baker49d8e1a2019-03-29 10:09:21 -070034 echo "No Makefile present"
35
Zack Williamsae8b48b2019-04-16 15:00:37 -070036 export XOS_DIR=${WORKSPACE}/cord/orchestration/xos
37 "$XOS_DIR/scripts/setup_venv.sh"
38 source "$XOS_DIR/venv-xos/bin/activate"
39
Scott Baker49d8e1a2019-03-29 10:09:21 -070040 if [ "$GERRIT_PROJECT" = 'xos' ] ; then
41 pushd "$WORKSPACE/cord/$PROJECT_PATH"
42 else
43 pushd "$WORKSPACE/cord/$PROJECT_PATH/xos"
44 fi
45
46 echo "Checking Migrations"
47 if [ "$GERRIT_PROJECT" = 'xos' ] ; then
Zack Williamsae8b48b2019-04-16 15:00:37 -070048 xos-migrate -r "$WORKSPACE/cord" -s core --check
Scott Baker49d8e1a2019-03-29 10:09:21 -070049 else
Zack Williamsae8b48b2019-04-16 15:00:37 -070050 xos-migrate -r "$WORKSPACE/cord" -s "$GERRIT_PROJECT" --check
Scott Baker49d8e1a2019-03-29 10:09:21 -070051 fi
52
53 echo "Performing nose2 tests"
54 nose2 --verbose --coverage-report xml --coverage-report term --junit-xml
Zack Williams3798b412018-07-12 15:31:52 -070055fi
56
Zack Williams3798b412018-07-12 15:31:52 -070057popd