1#!/bin/bash 2# SPDX-License-Identifier: BSD-3-Clause 3# Copyright (C) 2018 Intel Corporation. 4# Copyright (c) 2018 by NetApp, Inc. 5# All Rights Reserved. 6 7if [ -z "${MAKE}" ]; then 8 export MAKE=make 9fi 10 11if [ -z "${GIT}" ]; then 12 export GIT=git 13fi 14 15if [ -z "${READLINK}" ]; then 16 export READLINK=readlink 17fi 18 19AUTOTEST_DRIVER_PATH=$($READLINK -f ${BASH_SOURCE%/*}) 20SPDK_AUTOTEST_LOCAL_PATH=$PWD 21TIMESTAMP=$(date +"%Y%m%d%H%M%S") 22BUILD_NAME="build-${TIMESTAMP}" 23 24# The command line help 25display_help() { 26 echo 27 echo "Usage: $0 -d <path_to_spdk_tree> [-h] | [-q] | [-n]" 28 echo " -d : Specify a path to an SPDK source tree" 29 echo " -q : No output to screen" 30 echo " -n : Noop - dry-run" 31 echo " -h : This help" 32 echo 33 echo "Examples:" 34 echo " run-spdk-autotest.sh -d . -q" 35 echo " run-spdk-autotest.sh -d /home/vagrant/spdk_repo/spdk" 36 echo 37} 38 39set -e 40 41NOOP=0 42METHOD=0 43V=1 44OPTIND=1 # Reset in case getopts has been used previously in the shell. 45while getopts "d:qhn" opt; do 46 case "$opt" in 47 d) 48 SPDK_SOURCE_PATH=$($READLINK -f $OPTARG) 49 echo Using SPDK source at ${SPDK_SOURCE_PATH} 50 METHOD=1 51 ;; 52 q) 53 V=0 54 ;; 55 n) 56 NOOP=1 57 ;; 58 h) 59 display_help >&2 60 exit 0 61 ;; 62 *) 63 echo "Invalid option" 64 echo "" 65 display_help >&2 66 exit 1 67 ;; 68 esac 69done 70 71if [ -z "${SPDK_SOURCE_PATH}" ]; then 72 echo "Error: Must specify a source path " 73 display_help 74 exit 1 75fi 76 77# The following code verifies the input parameters and sets up the following variables: 78# 79# SPDK_AUTOTEST_LOCAL_PATH 80# GIT_REPO_PATH 81# GIT_BRANCH 82# 83 84case "$METHOD" in 85 1) 86 if [ ! -d "${SPDK_SOURCE_PATH}" ]; then 87 echo "${SPDK_SOURCE_PATH} does not exist!" 88 exit 1 89 fi 90 if [ ! -d "${SPDK_SOURCE_PATH}/.git" ]; then 91 echo "${SPDK_SOURCE_PATH} is not a git repository" 92 exit 1 93 fi 94 95 GIT_REPO_SRC_DIR=$($READLINK -f "${SPDK_SOURCE_PATH}" | tr -t '/' ' ' | awk '{print $NF}') 96 97 if [ ! "${GIT_REPO_SRC_DIR}" = "spdk" ]; then 98 echo "The ${SPDK_SOURCE_PATH} git repository is not named \"spdk\"" 99 exit 1 100 fi 101 102 pushd "${SPDK_SOURCE_PATH}" 103 GIT_REPO_SRC=$(git rev-parse --show-toplevel) 104 GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD) 105 popd 106 107 if [ "${SPDK_AUTOTEST_LOCAL_PATH}" = "${SPDK_SOURCE_PATH}" ]; then 108 SPDK_AUTOTEST_LOCAL_PATH=$($READLINK -f ${SPDK_AUTOTEST_LOCAL_PATH}/..) 109 echo "Set SPDK_AUTOTEST_LOCAL_PATH to ${SPDK_AUTOTEST_LOCAL_PATH}" 110 fi 111 112 if [ -d "${SPDK_AUTOTEST_LOCAL_PATH}/${GIT_BRANCH}" ]; then 113 if [ -d "${SPDK_AUTOTEST_LOCAL_PATH}/${GIT_BRANCH}/.git" ]; then 114 echo "${SPDK_AUTOTEST_LOCAL_PATH}/${GIT_BRANCH} is a git repository!" 115 exit 1 116 fi 117 fi 118 119 GIT_REPO_PATH="${SPDK_AUTOTEST_LOCAL_PATH}/${GIT_BRANCH}/${BUILD_NAME}" 120 ;; 121 *) 122 echo "Internal Error: Must specify a source path or branch name" 123 display_help 124 exit 1 125 ;; 126esac 127 128AUTOTEST_RESULTS="${SPDK_AUTOTEST_LOCAL_PATH}/${GIT_BRANCH}/${BUILD_NAME}" 129AUTOTEST_OUTPUT_PATH="${GIT_REPO_PATH}/output" 130rootdir="${GIT_REPO_PATH}/spdk" 131BUILD_LOG_FILE="${AUTOTEST_OUTPUT_PATH}/build.log" 132 133if [[ ${NOOP} -eq 1 ]]; then 134 echo "AUTOTEST_DRIVER_PATH $AUTOTEST_DRIVER_PATH" 135 #echo "SPDK_AUTOTEST_LOCAL_PATH $SPDK_AUTOTEST_LOCAL_PATH" 136 echo "AUTOTEST_OUTPUT_PATH $AUTOTEST_OUTPUT_PATH" 137 #echo "rootdir $rootdir" 138 echo "BUILD_LOG_FILE $BUILD_LOG_FILE" 139 #echo "GIT_BRANCH $GIT_BRANCH" 140 #echo "BUILD_NAME $BUILD_NAME" 141 echo "GIT_REPO_PATH $GIT_REPO_PATH" 142 echo "AUTOTEST_RESULTS $AUTOTEST_RESULTS" 143fi 144 145# 146# I'd like to keep these files under source control 147# 148if [[ -e "${AUTOTEST_DRIVER_PATH}/autorun-spdk.conf" ]]; then 149 conf="${AUTOTEST_DRIVER_PATH}/autorun-spdk.conf" 150fi 151if [[ -e ~/autorun-spdk.conf ]]; then 152 conf=~/autorun-spdk.conf 153fi 154 155if [[ -z $conf ]]; then 156 echo Conf file not found. 157 exit 1 158fi 159 160mkdir -pv --mode=775 "${AUTOTEST_OUTPUT_PATH}" 161rm -f latest 162ln -sv ${GIT_REPO_PATH} latest 163 164if [[ ${NOOP} -eq 0 ]]; then 165 echo V=$V 166 if [[ $V -eq 0 ]]; then 167 echo Quieting output 168 exec 3>&1 4>&2 > "${BUILD_LOG_FILE}" 2>&1 169 else 170 echo Teeing to ${BUILD_LOG_FILE} 171 exec > >(tee -a "${BUILD_LOG_FILE}") 2>&1 172 fi 173 174 case "$METHOD" in 175 1) 176 echo "rsync git repository from ${GIT_REPO_SRC} to ${GIT_REPO_PATH}" 177 rsync -av "${GIT_REPO_SRC}" "${GIT_REPO_PATH}" 178 pushd "${GIT_REPO_PATH}/spdk" 179 sudo "${MAKE}" clean -j $(nproc) 180 sudo "${GIT}" clean -d -f 181 popd 182 ;; 183 *) 184 echo "Internal Error: Must specify a source path or branch name" 185 display_help 186 exit 1 187 ;; 188 esac 189 190 trap "echo ERROR; exit" INT TERM EXIT 191 192 pushd "${AUTOTEST_OUTPUT_PATH}" 193 export output_dir="${AUTOTEST_OUTPUT_PATH}" 194 195 # Runs agent scripts 196 "${rootdir}/autobuild.sh" "$conf" 197 sudo -E "${rootdir}/autotest.sh" "$conf" 198 "${rootdir}/autopackage.sh" "$conf" 199 sudo -E "${rootdir}/autorun_post.py" -d "${AUTOTEST_OUTPUT_PATH}" -r "${rootdir}" 200 201 echo "All Tests Passed" > ${GIT_REPO_PATH}/passed 202 203 # Redirect back to screen 204 if [[ $V -eq 0 ]]; then 205 echo Redirect to screen 206 exec 1>&3 2>&4 > >(tee -a "${BUILD_LOG_FILE}") 2>&1 207 fi 208 209 popd 210 211fi 212 213echo "all tests passed" 214 215echo Output directory: ${GIT_REPO_PATH} 216echo Build log: "${BUILD_LOG_FILE}" 217