aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/Dockerfile.sonarcloud20
-rw-r--r--scripts/build-extras.sh13
-rw-r--r--scripts/build-packages.sh76
-rw-r--r--scripts/build-sonar.sh26
-rw-r--r--scripts/checkstyle.sh104
-rw-r--r--scripts/docker-compose-sonar.yml18
-rw-r--r--scripts/functional-tests.sh35
-rw-r--r--scripts/functions.sh226
-rw-r--r--scripts/install-vpp.sh59
-rwxr-xr-xscripts/run-sonar.sh69
10 files changed, 472 insertions, 174 deletions
diff --git a/scripts/Dockerfile.sonarcloud b/scripts/Dockerfile.sonarcloud
new file mode 100644
index 000000000..e1f40a789
--- /dev/null
+++ b/scripts/Dockerfile.sonarcloud
@@ -0,0 +1,20 @@
+FROM --platform=linux/amd64 ubuntu:focal
+
+ENV DEBIAN_FRONTEND=noninteractive
+WORKDIR /workspace
+COPY Makefile versions.cmake ./
+COPY scripts scripts/
+
+RUN apt update && apt-get install -y \
+ make \
+ sudo \
+ curl \
+ git
+
+RUN curl -sL https://deb.nodesource.com/setup_18.x | sudo bash -
+
+RUN apt update && apt-get install -y \
+ nodejs \
+ unzip
+
+RUN make deps debug-tools \ No newline at end of file
diff --git a/scripts/build-extras.sh b/scripts/build-extras.sh
index 78a6ac98e..becfc7517 100644
--- a/scripts/build-extras.sh
+++ b/scripts/build-extras.sh
@@ -17,23 +17,12 @@ set -euxo pipefail
SCRIPT_PATH=$( cd "$(dirname "${BASH_SOURCE}")" ; pwd -P )
source ${SCRIPT_PATH}/functions.sh
-# Libparc and libmemif are still not available in Ubuntu 20, so
-# we remove it from the list for now.
-# TODO Remove it as soon as they are available.
-DEPS_UBUNTU=(${DEPS_UBUNTU[@]/"libmemif-dev"})
-DEPS_UBUNTU=(${DEPS_UBUNTU[@]/"libmemif"})
-DEPS_UBUNTU=(${DEPS_UBUNTU[@]/"libparc-dev"})
-
-DEPS_CENTOS=(${DEPS_CENTOS[@]/"libmemif-devel"})
-DEPS_CENTOS=(${DEPS_CENTOS[@]/"libmemif"})
-DEPS_CENTOS=(${DEPS_CENTOS[@]/"libparc-devel"})
-
# Parameters:
# $1 = Package name
#
function build_package() {
- setup
+ setup_extras
echo "**************************************************************************"
echo "********************* STARTING PACKAGE EXTRAS BUILD **********************"
diff --git a/scripts/build-packages.sh b/scripts/build-packages.sh
index c9f329d9a..dddc98deb 100644
--- a/scripts/build-packages.sh
+++ b/scripts/build-packages.sh
@@ -1,4 +1,4 @@
-# Copyright (c) 2017-2019 Cisco and/or its affiliates.
+# Copyright (c) 2017-2022 Cisco and/or its affiliates.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
@@ -17,6 +17,20 @@ set -euxo pipefail
SCRIPT_PATH=$( cd "$(dirname "${BASH_SOURCE}")" ; pwd -P )
source ${SCRIPT_PATH}/functions.sh
+BUILD_PATH="${SCRIPT_PATH}/../packages"
+TEST_REPORT_DIR="${BUILD_PATH}/reports"
+BUILD_ROOT_DIR="${BUILD_PATH}/build-root/bin"
+MAKE_FOLDER="${SCRIPT_PATH}/.."
+
+function execute_tests() {
+ mkdir -p "${TEST_REPORT_DIR}"
+ pushd "${BUILD_ROOT_DIR}"
+ for component in "${TEST_COMPONENTS[@]}"; do
+ GTEST_OUTPUT="xml:${TEST_REPORT_DIR}/${component}-report.xml" "./${component}_tests"
+ done
+ popd
+}
+
# Parameters:
# $1 = Package name
#
@@ -27,29 +41,18 @@ function build_package() {
echo "********************* STARTING PACKAGE BUILD **********************"
echo "*******************************************************************"
- # Make the package
- mkdir -p ${SCRIPT_PATH}/../build && pushd ${SCRIPT_PATH}/../build
- rm -rf *
-
- # First round - Without libmemif
- cmake -G Ninja -DCMAKE_INSTALL_PREFIX=/usr -DBUILD_APPS=ON ..
- ninja -j8 package
-
- # Second round - With Libmemif
- rm -rf libtransport ctrl/libhicnctrl
- cmake -G Ninja -DCMAKE_INSTALL_PREFIX=/usr \
- -DBUILD_HICNPLUGIN=ON \
- -DBUILD_LIBTRANSPORT=ON \
- -DBUILD_APPS=ON \
- -DBUILD_HICNLIGHT=OFF \
- -DBUILD_SYSREPOPLUGIN=OFF \
- -DBUILD_TELEMETRY=ON \
- ${SCRIPT_PATH}/..
-
- ninja -j8 package
-
- find . -not -name '*.deb' -not -name '*.rpm' -print0 | xargs -0 rm -rf -- || true
- rm *Unspecified* || true
+ # Run unit tests and make the package
+ make -C "${MAKE_FOLDER}" BUILD_PATH="${BUILD_PATH}" INSTALL_PREFIX=/usr package-release
+
+ execute_tests
+
+ pushd "${BUILD_PATH}"
+ find . -not -name '*.deb' \
+ -not -name '*.rpm' \
+ -not -name 'reports' \
+ -not -name '*report.xml' \
+ -print0 | xargs -0 rm -rf -- || true
+ rm ./*Unspecified* ./*Development* ./*development* || true
popd
echo "*******************************************************************"
@@ -64,30 +67,15 @@ build_sphinx() {
echo "********************* STARTING DOC BUILD **************************"
echo "*******************************************************************"
- # Make the package
- pip3 install -r ${SCRIPT_PATH}/../docs/etc/requirements.txt
- pushd ${SCRIPT_PATH}/../docs
- make html
-
- popd
+ make doc
echo "*******************************************************************"
echo "***************** BUILD COMPLETED SUCCESSFULLY *******************"
echo "*******************************************************************"
}
-build_doxygen() {
- setup
-
- mkdir -p ${SCRIPT_PATH}/../build-doxygen
- pushd ${SCRIPT_PATH}/../build-doxygen
- cmake -DBUILD_HICNPLUGIN=On -DBUILD_HICNLIGHT=OFF -DBUILD_LIBTRANSPORT=OFF -DBUILD_UTILS=OFF -DBUILD_APPS=OFF -DBUILD_CTRL=OFF ..
- make doc
- popd
-}
-
function usage() {
- echo "Usage: ${0} [sphinx|doxygen|packages]"
+ echo "Usage: ${0} [sphinx|packages]"
exit 1
}
@@ -99,14 +87,14 @@ case "${1}" in
sphinx)
build_sphinx
;;
- doxygen)
- build_doxygen
- ;;
packages)
build_package
;;
+ vpp_master)
+ ;;
*)
usage
+ exit 1
esac
exit 0
diff --git a/scripts/build-sonar.sh b/scripts/build-sonar.sh
new file mode 100644
index 000000000..eb6f0f5f2
--- /dev/null
+++ b/scripts/build-sonar.sh
@@ -0,0 +1,26 @@
+# Copyright (c) 2017-2022 Cisco and/or its affiliates.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at:
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+#!/bin/bash
+
+set -euxo pipefail
+
+# Download docker compose
+sudo curl -L "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
+sudo chmod +x /usr/local/bin/docker-compose
+
+# Update/Init submodules
+git submodule update --init --recursive
+
+# Run sonarscanner
+docker-compose -f docker-compose-sonar.yml up
diff --git a/scripts/checkstyle.sh b/scripts/checkstyle.sh
index ae775aca9..4d3413c67 100644
--- a/scripts/checkstyle.sh
+++ b/scripts/checkstyle.sh
@@ -1,4 +1,4 @@
-# Copyright (c) 2017-2019 Cisco and/or its affiliates.
+# Copyright (c) 2022 Cisco and/or its affiliates.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
@@ -11,4 +11,104 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-exit 0 \ No newline at end of file
+#!/bin/bash
+
+set -eEo pipefail
+
+sudo apt-get install -y clang-format-12
+sudo pip3 install -U Commitizen
+
+CLANG_FORMAT_VER_REGEX='([0-9]+)\.[0-9]+\.[0-9]+'
+CLANG_FORMAT_DIFF="/usr/share/clang/clang-format-diff.py"
+
+if [[ -z ${CHANGE_TARGET} ]]; then
+ DIFF_TARGET="HEAD~1"
+else
+ DIFF_TARGET="origin/${CHANGE_TARGET}...HEAD"
+fi
+
+###############################################
+# Check commit mesage
+###############################################
+
+cz check --rev-range HEAD~1...HEAD
+
+###############################################
+# Check code style
+###############################################
+
+CLANG_FORMAT_VER=${CLANG_FORMAT_VER:-12}
+GIT_DIFF_ARGS="-U0 --no-color --relative ${DIFF_TARGET}"
+CLANG_FORMAT_DIFF_ARGS="-style file -p1"
+SUFFIX="-${CLANG_FORMAT_VER}"
+
+# Attempt to find clang-format to confirm Clang version.
+if command -v clang-format${SUFFIX} &>/dev/null; then
+ CLANG_FORMAT=clang-format${SUFFIX}
+elif command -v clang-format &>/dev/null; then
+ CLANG_FORMAT=clang-format
+fi
+
+CLANG_FORMAT_VERSION=$(${CLANG_FORMAT} --version)
+echo $CLANG_FORMAT_VERSION
+
+# Confirm that Clang is the expected version.
+if [[ ! $CLANG_FORMAT_VERSION =~ $CLANG_FORMAT_VER_REGEX ]]; then
+ echo "*******************************************************************"
+ echo "* CHECKSTYLE VERSION REGEX CHECK FAILED"
+ echo "* $CLANG_FORMAT_VERSION"
+ echo "*******************************************************************"
+ exit 1
+fi
+
+if [[ ! $CLANG_FORMAT_VER == "${BASH_REMATCH[1]}" ]]; then
+ echo "*******************************************************************"
+ echo "* CHECKSTYLE VERSION CHECK FAILED"
+ echo "* Expected major version $CLANG_FORMAT_VER, found ${BASH_REMATCH[1]}"
+ echo "*******************************************************************"
+ exit 1
+fi
+
+# Attempt to find clang-format-diff.
+if command -v clang-format-diff${SUFFIX} &>/dev/null; then
+ CLANG_FORMAT_DIFF=clang-format-diff${SUFFIX}
+elif command -v clang-format-diff &>/dev/null; then
+ CLANG_FORMAT=clang-format-diff
+elif [ ! -f $CLANG_FORMAT_DIFF ]; then
+ echo "*******************************************************************"
+ echo "* CHECKSTYLE FAILED"
+ echo "* Could not locate the clang-format-diff script"
+ echo "*******************************************************************"
+ exit 1
+fi
+
+in=$(mktemp)
+git diff ${GIT_DIFF_ARGS} ':!*.patch' >${in}
+
+out=$(mktemp)
+cat ${in} | ${CLANG_FORMAT_DIFF} ${CLANG_FORMAT_DIFF_ARGS} >${out}
+rm ${in}
+
+line_count=$(cat ${out} | wc -l)
+
+if [ -t 1 ] && [ -n $(tput colors) ] && [ $(tput colors) -ge 1 ] &&
+ command -v highlight &>/dev/null; then
+ highlight --syntax diff -O ansi ${out}
+else
+ cat ${out}
+fi
+
+rm ${out}
+
+if [ ${line_count} -gt 0 ]; then
+ echo "*******************************************************************"
+ echo "* CHECKSTYLE FAILED"
+ echo "* CONSULT DIFF ABOVE"
+ echo "*******************************************************************"
+ exit 1
+else
+ echo "*******************************************************************"
+ echo "* CHECKSTYLE SUCCESSFULLY COMPLETED"
+ echo "*******************************************************************"
+ exit 0
+fi
diff --git a/scripts/docker-compose-sonar.yml b/scripts/docker-compose-sonar.yml
new file mode 100644
index 000000000..198490546
--- /dev/null
+++ b/scripts/docker-compose-sonar.yml
@@ -0,0 +1,18 @@
+version: "3"
+services:
+ sonar:
+ build:
+ context: ../
+ dockerfile: scripts/Dockerfile.sonarcloud
+ container_name: sonarcloud
+ hostname: sonarcloud
+ environment:
+ API_TOKEN: $API_TOKEN
+ SONAR_HOST_URL: $SONAR_HOST_URL
+ PROJECT_KEY: $PROJECT_KEY
+ PROJECT_ORGANIZATION: $PROJECT_ORGANIZATION
+ volumes:
+ - ..:/workspace:z
+ command:
+ - |
+ /workspace/scripts/run-sonar.sh \ No newline at end of file
diff --git a/scripts/functional-tests.sh b/scripts/functional-tests.sh
new file mode 100644
index 000000000..05cc4193b
--- /dev/null
+++ b/scripts/functional-tests.sh
@@ -0,0 +1,35 @@
+# Copyright (c) 2017-2022 Cisco and/or its affiliates.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at:
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+#!/bin/bash
+
+set -euxo pipefail
+
+SCRIPT_PATH=$( cd "$(dirname "${BASH_SOURCE}")" ; pwd -P )
+source "${SCRIPT_PATH}/functions.sh"
+
+echo "---------------------------------------------------------"
+echo "----- INSTALLING FUNCTIONAL TEST DEPENDENCIES ---------"
+echo "---------------------------------------------------------"
+
+# This docker compose version is well supported also in CentOS.
+# Versions >= 2.0.0 do not seem to work.
+DOCKER_COMPOSE_VERSION=1.29.2
+
+sudo curl -L "https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
+sudo chmod +x /usr/local/bin/docker-compose
+sudo pip3 install robotframework
+
+functional_test
+
+exit 0
diff --git a/scripts/functions.sh b/scripts/functions.sh
index 7258800b2..66235cf5f 100644
--- a/scripts/functions.sh
+++ b/scripts/functions.sh
@@ -1,4 +1,4 @@
-# Copyright (c) 2020 Cisco and/or its affiliates.
+# Copyright (c) 2021 Cisco and/or its affiliates.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
@@ -14,147 +14,141 @@
#!/bin/bash
set -euxo pipefail
-APT_PATH=`which apt-get` || true
+APT_PATH=$(which apt-get) || true
apt_get=${APT_PATH:-"/usr/local/bin/apt-get"}
# Cmake executable
CMAKE_INSTALL_DIR="/opt/cmake"
export PATH=:${CMAKE_INSTALL_DIR}/bin:${PATH}
-PACKAGECLOUD_RELEASE_REPO_DEB="https://packagecloud.io/install/repositories/fdio/release/script.deb.sh"
-PACKAGECLOUD_RELEASE_REPO_RPM="https://packagecloud.io/install/repositories/fdio/release/script.rpm.sh"
-
-VPP_GIT_REPO="https://github.com/FDio/vpp"
-VPP_BRANCH="stable/2005"
-
- # Figure out what system we are running on
+# Figure out what system we are running on
if [ -f /etc/os-release ]; then
- . /etc/os-release
+ . /etc/os-release
else
- echo "ERROR: System configuration not recognized. Build failed"
- exit 1
+ echo "ERROR: System configuration not recognized. Build failed"
+ exit 1
fi
-VERSION_REGEX="s/v([0-9]+).([0-9]+)(.*)?-([0-9]+)-(g[0-9a-f]+)/\1.\2-release/g"
-VPP_VERSION_DEB=$(git describe --long --match "v*" | sed -E ${VERSION_REGEX})
-VPP_VERSION_RPM="${VPP_VERSION_DEB}.x86_64"
-
-DEPS_UBUNTU=("build-essential"
- "doxygen"
- "curl"
- "libparc-dev"
- "libmemif-dev"
- "libmemif"
- "libasio-dev"
- "libconfig-dev"
- "libcurl4-openssl-dev"
- "collectd-dev"
- "libevent-dev"
- "libssl-dev"
- "ninja-build"
- "vpp=${VPP_VERSION_DEB}"
- "vpp-dev=${VPP_VERSION_DEB}"
- "libvppinfra=${VPP_VERSION_DEB}"
- "libvppinfra-dev=${VPP_VERSION_DEB}"
- "vpp-plugin-core=${VPP_VERSION_DEB}"
- "python3-ply")
-
-# BUILD_TOOLS_GROUP_CENTOS="'Development Tools'"
-DEPS_CENTOS=("vpp-devel-${VPP_VERSION_RPM}"
- "vpp-lib-${VPP_VERSION_RPM}"
- "libparc-devel"
- "curl"
- "libmemif-devel"
- "ninja-build"
- "libmemif"
- "libcurl-devel"
- "asio-devel"
- "libconfig-devel"
- "centos-release-scl"
- "bzip2"
- "devtoolset-7"
- "rpm-build")
-
-LATEST_EPEL_REPO="http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm"
-COLLECTD_SOURCE="https://storage.googleapis.com/collectd-tarballs/collectd-5.9.2.tar.bz2"
+COLLECTD_SOURCE="https://github.com/collectd/collectd/releases/download/collectd-5.12.0/collectd-5.12.0.tar.bz2"
+
+declare -a TEST_COMPONENTS=(
+ "libtransport"
+ "lib"
+ "hicn_light"
+ "hicnplugin"
+ "libhicnctrl"
+)
function install_collectd_headers() {
- DISTRIB_ID=${ID}
- if [ "${DISTRIB_ID}" == "centos" ]; then
- curl -OL ${COLLECTD_SOURCE}
- tar -xf collectd-5.9.2.tar.bz2
+ curl -OL ${COLLECTD_SOURCE}
+ tar -xf collectd-5.12.0.tar.bz2
- pushd collectd-5.9.2
- ./configure && make -j$(nproc)
- popd
+ pushd collectd-5.12.0
+ ./configure && make -j$(nproc)
+ popd
- export COLLECTD_HOME=${PWD}/collectd-5.9.2/src
- fi
+ export COLLECTD_HOME=${PWD}/collectd-5.12.0/src
}
-function install_cmake() {
- [[ $(uname --hardware-platform) = "x86_64" ]] || return 0
- CMAKE_INSTALL_SCRIPT_URL="https://github.com/Kitware/CMake/releases/download/v3.18.4/cmake-3.18.4-Linux-x86_64.sh"
- CMAKE_INSTALL_SCRIPT="/tmp/install_cmake.sh"
- curl -L ${CMAKE_INSTALL_SCRIPT_URL} > ${CMAKE_INSTALL_SCRIPT}
+# Call a function once
+function call_once() {
+ # OP_NAME is the name of the function
+ OP_NAME=${1}
+ # If function was already called return
+ [[ -f /tmp/${OP_NAME} ]] && return 0
+ # Otherwise call the function
+ ${@}
+ # And mark the function as called if no error occurred
+ echo ${OP_NAME} >/tmp/${OP_NAME}
+}
- sudo mkdir -p ${CMAKE_INSTALL_DIR}
- sudo bash ${CMAKE_INSTALL_SCRIPT} --skip-license --prefix=${CMAKE_INSTALL_DIR}
+# Install dependencies
+function install_deps() {
+ make -C ${SCRIPT_PATH}/.. deps
}
-function setup_fdio_repo() {
- DISTRIB_ID=${ID}
+function setup() {
+ echo DISTRIBUTION: ${PRETTY_NAME}
+ # export variables depending on the platform we are running
+ call_once install_deps
+ call_once install_collectd_headers
+}
- if [ "${DISTRIB_ID}" == "ubuntu" ]; then
- curl -s ${PACKAGECLOUD_RELEASE_REPO_DEB} | sudo bash
- elif [ "${DISTRIB_ID}" == "centos" ]; then
- curl -s ${PACKAGECLOUD_RELEASE_REPO_RPM} | sudo bash
- curl -L ${LATEST_EPEL_REPO} > /tmp/epel-release-latest-7.noarch.rpm
- rpm -ivh /tmp/epel-release-latest-7.noarch.rpm || true
- else
- echo "Distribution ${DISTRIB_ID} is not supported"
- exit 1
- fi
+function setup_extras() {
+ echo DISTRIBUTION: ${PRETTY_NAME}
+ # export variables depending on the platform we are running
+
+ call_once install_deps
+ call_once install_collectd_headers
}
-# Install dependencies
-function install_deps() {
- DISTRIB_ID=${ID}
-
- if [ ${DISTRIB_ID} == "ubuntu" ]; then
- echo ${DEPS_UBUNTU[@]} | xargs sudo ${apt_get} install -y --allow-unauthenticated --no-install-recommends
- elif [ ${DISTRIB_ID} == "centos" ]; then
- echo ${DEPS_CENTOS[@]} | xargs sudo yum install -y --nogpgcheck
- ${CXX_COMPILER} --version
- ${CC_COMPILER} --version
- fi
+# Download artifacts of this patchset from jenkins
+function download_artifacts() {
+ if [[ -n ${GERRIT_HOST:-} ]] &&
+ [[ -n ${GERRIT_CHANGE_NUMBER:-} ]] &&
+ [[ -n ${GERRIT_PATCHSET_NUMBER:-} ]] &&
+ [[ -n ${GERRIT_BRANCH:-} ]]; then
+
+ PC_STREAM="${GERRIT_BRANCH#'stable/'}"
+
+ # Retrieve the Jenkins URL of the build relative to this PATCHSET
+ JENKINS_URLS=$(
+ curl -s "https://${GERRIT_HOST}/r/changes/${GERRIT_CHANGE_NUMBER}/detail" |
+ tail -n +2 | jq '.messages[].message?' |
+ grep -E "Patch Set ${GERRIT_PATCHSET_NUMBER}:.*hicn-verify-build.*build_success-${PC_STREAM}-ubuntu2004-$(uname -m)" |
+ grep -Eo "https?://jenkins.fd.io/job/hicn-verify-build-${PC_STREAM}-ubuntu2004-$(uname -m)[^ ]+"
+ )
+
+ # Transform string to array and get last
+ JENKINS_URLS_ARRAY=(${JENKINS_URLS})
+ ARTIFACTS_URL="${JENKINS_URLS_ARRAY[-1]}/artifact/packages/*zip*/packages.zip"
+
+ # Download artifacts
+ curl -o "${SCRIPT_PATH}/../packages.zip" -L "${ARTIFACTS_URL}"
+
+ # Unzip them
+ unzip "${SCRIPT_PATH}/../packages.zip" -d "${SCRIPT_PATH}/.."
+
+ return 0
+ fi
+
+ # Fall back to image re-build if artifacts cannot be downloaded
+ echo "GERRIT_* environment is not set. Image will be rebuilt from scratch" >&2
+ return 1
}
-# Call a function once
-function call_once() {
- # OP_NAME is the name of the function
- OP_NAME=${1}
- # If function was already called return
- [[ -f /tmp/${OP_NAME} ]] && return 0
- # Otherwise call the function
- ${@}
- # And mark the function as called if no error occurred
- echo ${OP_NAME} > /tmp/${OP_NAME}
+function is_selinuxenabled() {
+ sudo selinuxenabled && return 1 || return 0
}
-function setup() {
- echo DISTRIBUTION: ${PRETTY_NAME}
- # export variables depending on the platform we are running
-
- if [ ${ID} == "centos" ]; then
- # Compilers location
- CXX_COMPILER="/opt/rh/devtoolset-7/root/usr/bin/c++"
- CC_COMPILER="/opt/rh/devtoolset-7/root/usr/bin/cc"
- export CC=${CC_COMPILER} CXX=${CXX_COMPILER}
+# Run functional tests
+function functional_test() {
+ echo "*******************************************************************"
+ echo "********************* STARTING FUNCTIONAL TESTS *******************"
+ echo "*******************************************************************"
+
+ if download_artifacts; then
+ local build_sw=0
+ local dockerfile_path="tests/Dockerfile.ci"
+ else
+ local build_sw=1
+ local dockerfile_path="Dockerfile.dev"
+ fi
+
+ # Run functional tests
+ pushd "${SCRIPT_PATH}/../tests"
+ # If selinux, let's run the tests with a privileged container to bypass
+ # the checks, which cost also in performance
+ if is_selinuxenabled; then
+ local privileged=false
+ else
+ local privileged=true
fi
- call_once setup_fdio_repo
- call_once install_deps
- call_once install_cmake
- call_once install_collectd_headers
+ BUILD_SOFTWARE=${build_sw} DOCKERFILE=${dockerfile_path} TEST_PRIVILEGED=${privileged} bash ./run-functional.sh
+ popd
+
+ echo "*******************************************************************"
+ echo "********** FUNCTIONAL TESTS COMPLETED SUCCESSFULLY ***************"
+ echo "*******************************************************************"
}
diff --git a/scripts/install-vpp.sh b/scripts/install-vpp.sh
new file mode 100644
index 000000000..30e560d39
--- /dev/null
+++ b/scripts/install-vpp.sh
@@ -0,0 +1,59 @@
+#!/bin/bash
+
+# Copyright (c) 2022-2023 Cisco and/or its affiliates.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at:
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set -euxo pipefail
+
+################################################################
+# Install defined VPP version
+################################################################
+
+VPP_VERSION=2210
+
+if [[ -z ${VERSION_PATH-} ]]; then
+ echo >&2 "No version path provided. Using version ${VPP_VERSION}"
+else
+ VPP_VERSION=$(grep VPP_DEFAULT_VERSION "${VERSION_PATH}" | cut -d ' ' -f 2 | tr -d '"' | grep -Po '\d\d.\d\d')
+ VPP_VERSION=${VPP_VERSION//./}
+fi
+
+# Prevent vpp to set sysctl
+export VPP_INSTALL_SKIP_SYSCTL=1
+
+apt-get update
+apt-get install -y curl
+
+curl -s https://packagecloud.io/install/repositories/fdio/${VPP_VERSION}/script.deb.sh | bash
+curl -L https://packagecloud.io/fdio/${VPP_VERSION}/gpgkey | apt-key add -
+sed -E -i 's/(deb.*)(\[.*\])(.*)/\1\3/g' /etc/apt/sources.list.d/fdio_"${VPP_VERSION}".list
+
+# create apt pinning
+cat << EOF | tee /etc/apt/preferences.d/vpp-pin
+Package: vpp*
+Pin: release o=packagecloud.io/fdio/${VPP_VERSION}
+Pin-Priority: 1000
+
+Package: libvpp*
+Pin: release o=packagecloud.io/fdio/${VPP_VERSION}
+Pin-Priority: 1000
+EOF
+
+apt-get update
+
+apt-get install -y \
+ vpp-dev \
+ libvppinfra-dev \
+ vpp-plugin-core \
+ vpp \
+ libvppinfra
diff --git a/scripts/run-sonar.sh b/scripts/run-sonar.sh
new file mode 100755
index 000000000..87a94b592
--- /dev/null
+++ b/scripts/run-sonar.sh
@@ -0,0 +1,69 @@
+#!/bin/bash
+
+set -euxo pipefail
+
+# SONAR_HOST_URL=https://sonarcloud.io
+# PROJECT_KEY=fdio-hicn
+# PROJECT_ORGANIZATION=fdio
+
+SCRIPT_PATH=$( cd "$(dirname "${BASH_SOURCE}")" ; pwd -P )
+source "${SCRIPT_PATH}/functions.sh"
+
+export SONAR_TOKEN=$API_TOKEN
+export SONAR_SCANNER_VERSION=4.7.0.2747
+export SONAR_SCANNER_HOME=$HOME/.sonar/sonar-scanner-$SONAR_SCANNER_VERSION-linux
+curl --create-dirs -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR_SCANNER_VERSION-linux.zip
+unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/
+export PATH=$SONAR_SCANNER_HOME/bin:$PATH
+export SONAR_SCANNER_OPTS="-server"
+curl --create-dirs -sSLo $HOME/.sonar/build-wrapper-linux-x86.zip https://sonarcloud.io/static/cpp/build-wrapper-linux-x86.zip
+unzip -o $HOME/.sonar/build-wrapper-linux-x86.zip -d $HOME/.sonar/
+export PATH=$HOME/.sonar/build-wrapper-linux-x86:$PATH
+
+cd /workspace
+
+git config --global --add safe.directory /workspace
+git config --global --add safe.directory /workspace/cmake
+
+BUILD_PATH=${PWD}/build-debug
+TEST_PATH="${BUILD_PATH}/build-root/bin"
+
+make SONAR_BUILD_WRAPPER=${HOME}/.sonar/build-wrapper-linux-x86/build-wrapper-linux-x86-64 SONAR_OUT_DIR=bw-output BUILD_PATH=${BUILD_PATH} wipe build-coverage
+
+# Run tests to compute test coverage
+pushd ${BUILD_PATH}
+
+# Save first test executable
+FIRST_COMPONENT="${TEST_COMPONENTS[0]}"
+FIRST_TEST="${TEST_PATH}/${FIRST_COMPONENT}_tests"
+
+# Iterate over all tests: build parameters for next tests and get .profraw data
+extension=".profraw"
+PROFRAW_FILES=""
+REMAINING_TESTS=""
+for component in "${TEST_COMPONENTS[@]}"; do
+ # Build PROFRAW parameters for next command
+ PROFRAW_FILES="${PROFRAW_FILES}${component}${extension} "
+
+ # Save if not first binary
+ [[ "${component}" != "${FIRST_COMPONENT}" ]] && REMAINING_TESTS="${REMAINING_TESTS} -object ${TEST_PATH}/${component}_tests"
+
+ # Generate profraw data
+ LLVM_PROFILE_FILE="${BUILD_PATH}/${component}${extension}" ${TEST_PATH}/${component}_tests
+done
+
+# Merge profraw files
+llvm-profdata-11 merge -sparse ${PROFRAW_FILES} -o hicn.profdata
+
+# Generate coverage report
+llvm-cov-11 show ${FIRST_TEST} ${REMAINING_TESTS} -instr-profile=hicn.profdata --format=text > ${BUILD_PATH}/coverage.txt
+
+popd
+
+$SONAR_SCANNER_HOME/bin/sonar-scanner \
+ -Dsonar.organization=$PROJECT_ORGANIZATION \
+ -Dsonar.projectKey=$PROJECT_KEY \
+ -Dsonar.sources=/workspace \
+ -Dsonar.cfamily.build-wrapper-output=bw-output \
+ -Dsonar.host.url=$SONAR_HOST_URL \
+ -Dsonar.cfamily.llvm-cov.reportPath=${BUILD_PATH}/coverage.txt