Chase Qi | d503f1a | 2018-08-01 17:49:17 +0800 | [diff] [blame] | 1 | #!/bin/sh -ex |
| 2 | # shellcheck disable=SC1090 |
| 3 | # shellcheck disable=SC2154 |
| 4 | # shellcheck disable=SC2034 |
| 5 | # shellcheck disable=SC2016 |
Chase Qi | fe4cdc1 | 2018-08-24 09:37:01 +0800 | [diff] [blame] | 6 | # shellcheck disable=SC2181 |
Chase Qi | d503f1a | 2018-08-01 17:49:17 +0800 | [diff] [blame] | 7 | |
| 8 | TEST_DIR=$(dirname "$(realpath "$0")") |
| 9 | OUTPUT="${TEST_DIR}/output" |
| 10 | LOGFILE="${OUTPUT}/stdout.txt" |
| 11 | RESULT_FILE="${OUTPUT}/result.txt" |
| 12 | |
| 13 | SKIP_INSTALL="false" |
| 14 | TEST="automated/linux/smoke/smoke.yaml" |
| 15 | TESTDEF_PARAMS="" |
| 16 | TARGET_IP="lava-target-ip" |
| 17 | DOCKER_IMG="linaro/testdef-arm64-debian-stretch:b6e5458" |
| 18 | |
| 19 | usage() { |
| 20 | echo "Usage: $0 [-s <skip_install>] [-t <test>] [-r <testdef_params>] [-i <target_ip>] [-u <ssh_user>] [-p <ssh_passwd>] [-d <docker_img>]" 1>&2 |
| 21 | exit 1 |
| 22 | } |
| 23 | |
| 24 | while getopts "s:t:r:o:i:u:p:d:h" opt; do |
| 25 | case "$opt" in |
| 26 | s) SKIP_INSTALL="${OPTARG}" ;; |
| 27 | t) TEST="${OPTARG}" ;; |
| 28 | r) TESTDEF_PARAMS="${OPTARG}" ;; |
| 29 | i) TARGET_IP="${OPTARG}" ;; |
| 30 | u) SSH_USER="${OPTARG}" ;; |
| 31 | p) SSH_PASSWD="${OPTARG}" ;; |
| 32 | d) DOCKER_IMG="${OPTARG}" ;; |
| 33 | *) usage ;; |
| 34 | esac |
| 35 | done |
| 36 | . "${TEST_DIR}/../../lib/sh-test-lib" |
| 37 | test -z "${SSH_USER}" && error_msg "Please set SSH_USER with -u <ssh_user>" |
| 38 | test -z "${SSH_PASSWD}" && error_msg "Please set SSH_PASSWD with -p <ssh_passwd>" |
| 39 | |
| 40 | create_out_dir "${OUTPUT}" |
| 41 | cd "${OUTPUT}" |
| 42 | |
| 43 | [ "${TARGET_IP}" = "lava-target-ip" ] && TARGET_IP="$(lava-target-ip)" |
| 44 | ssh_cmd="sshpass -p ${SSH_PASSWD} ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ${SSH_USER}@${TARGET_IP}" |
| 45 | |
| 46 | install_deps sshpass "${SKIP_INSTALL}" |
| 47 | # Assume docker pre-installed on test target. |
| 48 | # Installation on remote ssh target isn't supported yet. |
| 49 | eval "${ssh_cmd}" which docker | grep 'docker' || error_msg "docker not found on test target!" |
| 50 | |
| 51 | # When using ssh, to avoid 'x509: certificate has expired or is not yet valid', |
| 52 | # set time to client's date, which more likely has ntp sync enabled. |
| 53 | client_date="$(date +%Y%m%d)" |
| 54 | echo "${SSH_PASSWD}" | eval "${ssh_cmd}" sudo -S date +%Y%m%d -s "${client_date}" |
| 55 | |
| 56 | # Trigger test run. |
| 57 | if [ -z "${TESTDEF_PARAMS}" ]; then |
Chase Qi | fe4cdc1 | 2018-08-24 09:37:01 +0800 | [diff] [blame] | 58 | cmd1='eval "${ssh_cmd}" docker run --privileged --init "${DOCKER_IMG}" test-runner -d "${TEST}"' |
Chase Qi | d503f1a | 2018-08-01 17:49:17 +0800 | [diff] [blame] | 59 | else |
Chase Qi | fe4cdc1 | 2018-08-24 09:37:01 +0800 | [diff] [blame] | 60 | cmd1='eval "${ssh_cmd}" docker run --privileged --init "${DOCKER_IMG}" test-runner -d "${TEST}" -r "${TESTDEF_PARAMS}"' |
Chase Qi | d503f1a | 2018-08-01 17:49:17 +0800 | [diff] [blame] | 61 | fi |
| 62 | pipe0_status "${cmd1}" 'tee -a "${LOGFILE}"' |
| 63 | if [ "$?" != 0 ]; then |
| 64 | echo "docker-run fail" | tee -a "${RESULT_FILE}" |
| 65 | error_msg "Please check your docker image! |
| 66 | Here is an Dockerfile example: https://git.linaro.org/ci/dockerfiles.git/tree/stretch-arm64-testdef" |
| 67 | fi |
| 68 | |
| 69 | # Parse test log. |
| 70 | awk '/^<TEST_CASE_ID/ {gsub(/(<|>|=|TEST_CASE_ID|RESULT|UNITS|MEASUREMENT)/,""); print}' "${LOGFILE}" | tee -a "${RESULT_FILE}" |