summaryrefslogtreecommitdiff
path: root/tsp/jobs/img_test_common.sh
blob: 09529d47c061c5990fbe2550edb22b70c6008911 (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
#!/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"
WORKDIR="${WS_TEST}/${BUILD_NR}"
DWN_WORKDIR="${WS_DOWNLOAD}/${BUILD_NR}"
TARGET="$2"

test -n "$BUILD_NR" || die "Missing argument: build_nr"
test -n "$TARGET" || die "Missing argument: target"

# update symlink (all images are downloaded)
SR="$(project2sr "${DWN_WORKDIR}/project.conf")"

rm -rf "${WORKDIR}"
mkdir -p "${WORKDIR}"

check_diff() {
    DIFF_FILE1="$1"
    DIFF_FILE2="$2"
    JOB_NR="$3"
    TARGET="$4"
    test -n "${DIFF_FILE1}" || die "Missing argument: diff_file1"
    test -n "${JOB_NR}" || die "Missing argument: build_nr"
    test -n "${TARGET}" || die "Missing argument: target"
    test -n "${TSP_DIR}" || die "Missing environment variable: TSP_DIR"
    if ( grep -q "identical" "${DIFF_FILE1}" ) && ( [ -z "${DIFF_FILE2}" ] || grep -q "identical" "${DIFF_FILE2}" )
    then
        echo "Image is unchanged in respect to snapshot"
        tspwb -L PUBLISH sh "${TSP_DIR}/jobs/publish.sh" "${JOB_NR}" "${TARGET}" "IDENTICAL"
        return 1
    fi
}

report_no_image() {
    DWN_WORKDIR="$1"
    JOB_NR="$2"
    TARGET="$3"
    test -n "${DWN_WORKDIR}" || die "Missing argument: dwn_workdir"
    test -n "${JOB_NR}" || die "Missing argument: build_nr"
    test -n "${TARGET}" || die "Missing argument: target"
    test -n "${SR}" || die "Missing argument: sr"
    echo "Report missing image"
    update_db "$SR" "No image" "$JOB_NR" "$TARGET"
    return 1
}

test -n "$TARGET" || die "Missing argument: target"

USR_IMG_DIR="$(get_userspace_dir "${TARGET}" "${DWN_WORKDIR}")" \
    || report_no_image "${DWN_WORKDIR}" "${BUILD_NR}" "${TARGET}" || die "No image"

DIFF_FILE1="${USR_IMG_DIR}/diff.report"
case "${TARGET}" in
    *artik*|*odroid*|*rpi3*)
        DIFF_FILE2="$(get_boot_dir "${TARGET}" "${DWN_WORKDIR}")/diff.report" \
            || report_no_image "${DWN_WORKDIR}" "${BUILD_NR}" "${TARGET}" || die "No image"
        ;;
    *)
        DIFF_FILE2=""
        ;;
esac

if check_diff "${DIFF_FILE1}" "${DIFF_FILE2}" "${BUILD_NR}" "${TARGET}"
then
    # Preserve both diff files
    cp "${DIFF_FILE1}" "${WORKDIR}/diff_usr.report"
    test -f "${DIFF_FILE2}" && cp "${DIFF_FILE2}" "${WORKDIR}/diff_boot.report"

    echo "Add common_prep_flash_conf job to the $TARGET queue"
    tsrun_target "${TARGET#*-}" -L "$(echo "$TARGET" | tr '[:lower:]' '[:upper:]')_PREPARE_FLASH_CONF" \
        sh "${TSP_DIR}/jobs/common_prep_flash_conf.sh" "${BUILD_NR}" "${TARGET}"
    # Update status in database
    update_db "$SR" "In test queue" "${BUILD_NR}" "$TARGET"
fi