# 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. # This function takes up to two arguments: # 1. error message # 2. exit code (default: 1) # # Example: test -n "$VAR" || die "VAR is not set!" 5 # If variable $VAR is not set, "VAR is not set!" will be printed on stderr # and script in which it was invoked will exit with exit code equal to 5. # # Author: Aleksander Mistewicz die() { printf >&2 -- '%s\n' "$1" exit "${2:-1}" } # Supported targets are: # * artik5, headless-artik5, artik10, headless-artik10 # * artik710 headless-artik710, artik530, headless-artik530 # * minnow32, minnow64 # * common-odroid, tv-odroid # * mbr64 # * headless-rpi3, common-rpi3, tv-rpi3 TARGET_LIST="artik10 headless-artik5 mbr64 minnow64 minnow32 common-odroid tv-odroid ivi-odroid headless-rpi3 common-rpi3 tv-rpi3" test -z "${TSP_DIR}" || { export TS_ONFINISH="${TSP_DIR}/scripts/log.sh" export TS_MAXFINISHED="32767" } WS="${HOME}/ws" WS_WATCHER="${WS}/watcher" WS_DOWNLOAD="${WS}/dwn" WS_TEST="${WS}/img_test" WS_TEST_REMOTE="${WS}/img_test_remote" WS_PUBLISH="${WS}/publish" SNAPSHOT_WS_DOWNLOAD="${WS_DOWNLOAD}/snapshot" SNAPSHOT_WS_DOWNLOAD_NEW="${WS_DOWNLOAD}/new_snapshot" PROM_DIR="${WS}/prom" test -d "${PROM_DIR}" || mkdir -p "${PROM_DIR}" test -d "${WS_PUBLISH}" || mkdir -p "${WS_PUBLISH}" DBNAME="results.db3" DBPATH="${WS_PUBLISH}/${DBNAME}" WWW_PUBLISH="${WS_PUBLISH}/current_status.html" WWW_3_PUBLISH="${WS_PUBLISH}/current_status_3.html" WWW_4_PUBLISH="${WS_PUBLISH}/current_status_4.html" UPDATE_WWW="/var/tmp/should_update_www" WS_PUBLISH_WWW="${WS_PUBLISH}/www" TSP_WWW="${TSP_DIR}/www" test -d "${WS_PUBLISH_WWW}" || cp -r "${TSP_WWW}" "${WS_PUBLISH_WWW}" TMP_POLL="/tmp/tl-master-poll" TMP_MASTER="/tmp/tl-master" TMP_PWB="/tmp/tl-pwb" TMP_PWB_RESULTS="/tmp/tl-pwb-results" test -d "$TMP_POLL" || mkdir "$TMP_POLL" test -d "$TMP_MASTER" || mkdir "$TMP_MASTER" test -d "$TMP_PWB" || mkdir "$TMP_PWB" test -d "$TMP_PWB_RESULTS" || mkdir "$TMP_PWB_RESULTS" alias tspoll="TMPDIR=$TMP_POLL TS_SLOTS=1 tsp" alias tsmaster="TMPDIR=$TMP_MASTER TS_SLOTS=100 tsp" alias tspwb="TMPDIR=$TMP_PWB TS_SLOTS=1 tsp" alias tsresults="TMPDIR=$TMP_PWB_RESULTS TS_SLOTS=1 tsp" init_db() { # Load schema sqlite3 -batch "${DBPATH}" < "${TSP_DIR}/results-schema.sql" # Load initial values to tables 'device' and 'result' sqlite3 -batch "${DBPATH}" < "${TSP_DIR}/results-values-device.sql" sqlite3 -batch "${DBPATH}" < "${TSP_DIR}/results-values-result.sql" } test -f "${DBPATH}" || init_db post_prom() { NAME="$1" VALUE="$2" HELP="$3" test -n "$NAME" || die "Missing argument: name" test -n "$VALUE" || die "Missing argument: value" { test -z "$HELP" || echo "# HELP $NAME $HELP" echo "# TYPE $NAME gauge" echo "$NAME $VALUE" } > "$PROM_DIR/temp.$$" mv "$PROM_DIR/temp.$$" "$PROM_DIR/$NAME.prom" } tsrun_target() { test -n "$1" || die "Missing argument: target" TMPDIR="/tmp/tl-runner-$1" test -d "$TMPDIR" || mkdir "$TMPDIR" shift TMPDIR="$TMPDIR" TS_SLOTS=1 tsp $@ } url2sr() { URL="$1" test -n "$URL" || die "Missing argument: url" RET="${URL%/}" RET="${RET##*/}" echo "$RET" } project2sr() { PROJECT_FILE="$1" test -n "$PROJECT_FILE" || die "Missing argument: project_file" head -n 1 "${PROJECT_FILE}" | tr -d '\n' } url2profile() { URL="$1" test -n "$URL" || die "Missing argument: url" RET="${URL%%/tizen-*/}" RET="${RET##*/}" echo "$RET" } sr2profile() { SR="$1" test -n "$SR" || die "Missing argument: sr" RET="${SR%%_*}" RET="${RET#*-}" echo "$RET" } update_db() { SR="$1" TAG="$2" BUILD_NR="$3" TARGET="$4" test -n "$SR" || die "Missing argument: sr" test -n "$TAG" || die "Missing argument: tag" test -n "$BUILD_NR" || die "Missing argument: build_nr" test -n "$TARGET" || die "Missing argument: target" tsresults -L DB sh "${TSP_DIR}/jobs/update_db.sh" "$SR" "$TAG" "$BUILD_NR" "$TARGET" } get_userspace_dir() { TARGET="$1" DWN_WORKDIR="$2" test -n "$TARGET" || die "Missing argument: target" test -n "$DWN_WORKDIR" || die "Missing argument: dwn_workdir" case "$TARGET" in *common-odroid*) USR_DIR="$(find "${DWN_WORKDIR}/" -type d -name "common*-wayland*-armv7l-odroidu3")" ;; *ivi-odroid*) USR_DIR="$(find "${DWN_WORKDIR}/" -type d -name "ivi-target-odroidxu3")" ;; *tv-odroid*) USR_DIR="$(find "${DWN_WORKDIR}/" -type d -name "tv-wayland*-armv7l-odroidu3")" ;; *headless-rpi3*) USR_DIR="$(find "${DWN_WORKDIR}/" -type d -name "*-gps_tracker-*-armv7l-rpi3")" ;; *common-rpi3*) USR_DIR="$(find "${DWN_WORKDIR}/" -type d -name "common*-wayland*-armv7l-rpi3")" ;; *tv-rpi3*) USR_DIR="$(find "${DWN_WORKDIR}/" -type d -name "tv-wayland*-armv7l-rpi3")" ;; *headless-artik*) USR_DIR="$(find "${DWN_WORKDIR}/" -type d -name "*-headless-*-armv7l-artik*")" ;; *artik710*|*artik530*) USR_DIR="$(find "${DWN_WORKDIR}/" -type d -name "*-headed-*-armv7l-artik*")" ;; *artik*) USR_DIR="$(find "${DWN_WORKDIR}/" -type d -name "*-wayland*-armv7l-artik*")" ;; *minnow32*) USR_DIR="$(find "${DWN_WORKDIR}/" -type d -name "*-wayland-efi-i586")" ;; *minnow64*) USR_DIR="$(find "${DWN_WORKDIR}/" -type d -name "*-wayland-efi-x86_64")" ;; *mbr64*) USR_DIR="$(find "${DWN_WORKDIR}/" -type d -name "*-minimal-mbr-x86_64")" ;; *emulator32*) USR_DIR="$(find "${DWN_WORKDIR}/" -type d -name "*-emulator-wayland-mbr-i586")" ;; *) die "Unknown target: ${TARGET}" ;; esac test -n "${USR_DIR}" || die "Userspace directory not found" echo "${USR_DIR}" } get_boot_dir() { TARGET="$1" DWN_WORKDIR="$2" test -n "$TARGET" || die "Missing argument: target" test -n "$DWN_WORKDIR" || die "Missing argument: dwn_workdir" case "$TARGET" in *common-odroid*|*ivi-odroid*) BOOT_DIR="$(find "${DWN_WORKDIR}/" -type d -name "common*-boot-armv7l-odroidu3")" ;; *tv-odroid*) BOOT_DIR="$(find "${DWN_WORKDIR}/" -type d -name "tv-boot-armv7l-odroidu3")" ;; *rpi3*) BOOT_DIR="$(find "${DWN_WORKDIR}/" -type d -name "*-boot-arm64-rpi3")" ;; *artik710*) BOOT_DIR="$(find "${DWN_WORKDIR}/" -type d -name "*-boot-arm64-artik710")" ;; *artik530*) BOOT_DIR="$(find "${DWN_WORKDIR}/" -type d -name "*-boot-armv7l-artik530")" ;; *artik5*) BOOT_DIR="$(find "${DWN_WORKDIR}/" -type d -name "*-boot-armv7l-artik520")" ;; *artik10*) BOOT_DIR="$(find "${DWN_WORKDIR}/" -type d -name "*-boot-armv7l-artik10")" ;; *) die "Unknown target: ${TARGET}" ;; esac test -n "${BOOT_DIR}" || die "Userspace directory not found" echo "${BOOT_DIR}" }