#!/bin/bash # SPDX-License-Identifier: GPL-2.0-only # Copyright (C) 2019 Linaro Ltd. # shellcheck disable=SC1091 . ../../lib/sh-test-lib OUTPUT="$(pwd)/output" RESULT_FILE="${OUTPUT}/result.txt" YKUSHCMD=ykushcmd SKIP_INSTALL="false" SERIAL_NUM="" LIST="false" PORT_UP="" PORT_DOWN="" PORT_DEVICE="" RESULT=pass usage() { echo "\ Usage: $0 [-n ] [-l ] [-p ] [-d 1|2|3|a] [-u 1|2|3|a] [-s ] By default, this script will install /usr/bin/ykushcmd and do nothing else. The following parameters can be provided to modify the behaviour to the library: -n The serial number of the YepKit device to use. Leave blank if you do not know the serial number and there is only one YepKit device installed -l List attached Yepkit YKUSH boards. The serial number of each board attached to the host will be displayed. -d <1|2|3|a> Power Down/Off downstream port with the number provided. If a is provided as the port number then all ports will be switched. -u <1|2|3|a> Power Up/On downstream port with the number provided. If a is provided as the port number then all ports will be switched. -g <1|2|3> Get state of downstream port. -p In the case of a port being powered up, check the device appears. In the case of a port being powered down, check the device is removed. -s Tell the test to skip installation of dependencies, or not. If ykushcmd is not present, the repo will be cloned, the command built and installed. " } while getopts "d:g:h:l:n:p:s:u:" opts; do case "$opts" in d) PORT_DOWN="${OPTARG,,}" ;; g) PORT_GET="${OPTARG,,}" ;; l) LIST="${OPTARG,,}" ;; n) SERIAL_NUM="${OPTARG}"; if [ "${SERIAL_NUM}" != "" ]; then SERIAL_NUM_OPT="-s ${SERIAL_NUM}" fi ;; p) PORT_DEVICE="${OPTARG}" ;; u) PORT_UP="${OPTARG,,}" ;; s) SKIP_INSTALL="${OPTARG,,}" ;; h|*) usage ; exit 1 ;; esac done install() { if [ "${SKIP_INSTALL}" = "true" ]; then return # we don't want to report skip results else if [[ $(which "${YKUSHCMD}") ]]; then echo "A local ${YKUSHCMD} exists, use it" return # we don't want to report skip results else clonedir=$(mktemp -d "/tmp/ykush.XXXXX") git clone https://github.com/Yepkit/ykush "${clonedir}" if [ -e "${clonedir}" ]; then pushd "${clonedir}" > /dev/null 2>&1 || return make clean make ./install.sh popd > /dev/null 2>&1 || return else echo "ERROR: ykush repo doesn't exist" RESULT=fail fi rm -rf "${clonedir}" fi # after all that, if the command still doesn't exist, it's an error if [[ ! $(which "${YKUSHCMD}") ]]; then echo "ERROR: ${YKUSHCMD} doesn't exist" RESULT=fail exit 1 fi fi echo yepkit-install "${RESULT}" | tee -a "${RESULT_FILE}" } device_exists () { local device device="$1" if [[ -e ${device} ]]; then echo 1 else echo 0 fi } wait_for_device () { local device local removed local retries local check local extra_text device="${1}" removed="${2,,}" retries="20" check="1" extra_text="" if [ "${removed}" != "" ]; then check="0" extra_text=" to be removed" fi echo -n "Waiting for ${device}${extra_text}: " for ((i=0;i