summaryrefslogtreecommitdiff
path: root/tsp/jobs/common_prep_flash_conf.sh
blob: 01e5c44d5ad90a3c18ebbeba58f5f0013fb47b12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/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 <a.mistewicz@samsung.com>

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*|*rpi3*)
        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
    rm -rf "${WORKDIR_REMOTE}" && mkdir -p "${WORKDIR_REMOTE}" || retrigger "remote ws cleanup failed"
    tsrun_target "${TARGET#*-}" -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
rm -rf "${WORKDIR_REMOTE}" && mkdir -p "${WORKDIR_REMOTE}" || retrigger "remote ws cleanup failed"

# Copy required files
case "$TARGET" in
    *odroid*|*artik*|*rpi3*)
        cp -s "${USERSPACE_IMG}" "${BOOT_IMG}" "${WORKDIR_REMOTE}/" || retrigger "copy failed"
        ;;
    *minnow*)
        cp -s "${USERSPACE_IMG}" "${USERSPACE_IMG_BMAP}" "${WORKDIR_REMOTE}/" || retrigger "copy failed"
        ;;
    *mbr64*)
        cp -s "${USERSPACE_IMG}" "${KERNEL}" "${WORKDIR_REMOTE}/" || retrigger "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
cp "${MULTIPLEX_FILE}" "${WORKDIR_REMOTE}/" || retrigger "copy failed"

echo "start remote script"
WORKDIR_REMOTE="${WORKDIR_REMOTE}" TARGET="${TARGET}" timeout 10m sh "${TSP_DIR}/scripts/common_prep_flash_conf.sh" \
    || retrigger "script execution failed"
echo "finish remote script"

# Copy the results
cp "${WORKDIR_REMOTE}/sysctl.result" "${WORKDIR_REMOTE}/screenshot.png" .
cp -r "${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"