#!/bin/sh # Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved # # 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. # Author: Aleksander Mistewicz export TSP_DIR="$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd -P)/.." . "${TSP_DIR}/common.sh" BUILD_NR="$1" TARGET="$2" WORKDIR="${WS_TEST}/${BUILD_NR}" test -n "${BUILD_NR}" || die "Missing argument: build nr" test -n "$TARGET" || die "Missing argument: target" mkdir -p "${WORKDIR}" cd "${WORKDIR}" WORKDIR_REMOTE="${WS_TEST_REMOTE}/${BUILD_NR}" DWN_WORKDIR="${WS_DOWNLOAD}/${BUILD_NR}" SR="$(project2sr "${DWN_WORKDIR}/project.conf")" PROFILE="$(sr2profile "${SR}")" # Update status in database update_db "${SR}" "Testing" "$BUILD_NR" "$TARGET" USR_IMG_DIR="$(get_userspace_dir "${TARGET}" "${DWN_WORKDIR}")" case "$TARGET" in *odroid*|*artik*) BOOT_IMG="$(ls "$(get_boot_dir "${TARGET}" "${DWN_WORKDIR}")"/*.tar.gz)" test -f "${BOOT_IMG}" || BOOT_IMG="$(ls "$(get_boot_dir "${TARGET}" "${SNAPSHOT_WS_DOWNLOAD}-${PROFILE}")"/*.tar.gz)" USERSPACE_IMG="$(ls "${USR_IMG_DIR}"/*.tar.gz)" test -f "${USERSPACE_IMG}" || USERSPACE_IMG="$(ls "$(get_userspace_dir "${TARGET}" "${SNAPSHOT_WS_DOWNLOAD}-${PROFILE}")"/*.tar.gz)" # TODO: Both images shouldn't be replaced by snapshot's at the same time ;; *minnow*) USERSPACE_IMG="$(ls "${USR_IMG_DIR}"/*.raw.bz2)" USERSPACE_IMG_BMAP="$(ls "${USR_IMG_DIR}"/*.bmap)" ;; *mbr64*) USERSPACE_IMG="$(ls "${USR_IMG_DIR}"/*.tar.gz)" KERNEL="$(ls "${USR_IMG_DIR}"/*-vmlinuz-*)" ;; *) die "Unknown target: ${TARGET}" ;; esac test -z "${BOOT_IMG}" || test -f "${BOOT_IMG}" || die "No boot image found: ${BOOT_IMG}!" test -f "${USERSPACE_IMG}" || die "No userspace image found: ${USERSPACE_IMG}!" FAIL_CNT="$3" test -n "${FAIL_CNT}" || FAIL_CNT=0 retrigger() { # Add job back to the queue echo "Retrigger... ($1)" echo "FAILED 1" > sysctl.result if [ "$FAIL_CNT" -ge 3 ]; then # Trigger publish job tspwb -L PUBLISH sh "${TSP_DIR}/jobs/publish.sh" "$BUILD_NR" "$TARGET" exit 1 fi ssh tl-runner "rm -rf \"${WORKDIR_REMOTE}\"; mkdir -p \"${WORKDIR_REMOTE}\"" || retrigger "ssh: remote ws cleanup failed" tsrun_target "${TARGET#headless-}" -L "RETRIGGERED_$(echo "$TARGET" | tr '[:lower:]' '[:upper:]')_PREPARE_FLASH_CONF" \ sh "${TSP_DIR}/jobs/common_prep_flash_conf.sh" "$BUILD_NR" "${TARGET}" "$((FAIL_CNT + 1))" # Update status in database update_db "${SR}" "In test queue" "$BUILD_NR" "$TARGET" exit 0 } # Create and clean required directories on remote machine (tl-runner) ssh tl-runner "rm -rf \"${WORKDIR_REMOTE}\"; mkdir -p \"${WORKDIR_REMOTE}\"" || retrigger "ssh: remote ws cleanup failed" # Copy required files case "$TARGET" in *odroid*|*artik*) scp "${USERSPACE_IMG}" "${BOOT_IMG}" tl-runner:"${WORKDIR_REMOTE}/" || retrigger "ssh: copy failed" ;; *minnow*) scp "${USERSPACE_IMG}" "${USERSPACE_IMG_BMAP}" tl-runner:"${WORKDIR_REMOTE}/" || retrigger "ssh: copy failed" ;; *mbr64*) scp "${USERSPACE_IMG}" "${KERNEL}" tl-runner:"${WORKDIR_REMOTE}/" || retrigger "ssh: copy failed" ;; esac MULTIPLEX_FILE="common_test.yaml" ORG_MULTIPLEX_FILE="${TSP_DIR}/common_test.yaml" test -f "${ORG_MULTIPLEX_FILE}" || ORG_MULTIPLEX_FILE="${TSP_DIR}/common_test.yaml.example" cp "${ORG_MULTIPLEX_FILE}" "${MULTIPLEX_FILE}" # Copy multiplex file used by avocado scp "${MULTIPLEX_FILE}" tl-runner:"${WORKDIR_REMOTE}/" || retrigger "ssh: copy failed" echo "start remote script" ssh tl-runner "TARGET=${TARGET} WORKDIR_REMOTE=${WORKDIR_REMOTE} timeout 10m sh -s --" \ < "${TSP_DIR}/scripts/common_prep_flash_conf.sh" || retrigger "ssh: remote script execution failed" echo "finish remote script" # Copy the results scp tl-runner:"${WORKDIR_REMOTE}/sysctl.result" . scp tl-runner:"${WORKDIR_REMOTE}/screenshot.png" . scp -r tl-runner:"${WORKDIR_REMOTE}/avocado-results" . { echo "RETRIGGER_CNT ${FAIL_CNT}" echo "Build nr: ${BUILD_NR}" echo "Date: $(date)" } >> sysctl.result # Check if they have run successfully, otherwise reschedule the job if grep -q "Testing failed." sysctl.result then retrigger "Testing failed." fi # Trigger publish job tspwb -L PUBLISH sh "${TSP_DIR}/jobs/publish.sh" "$BUILD_NR" "$TARGET"