summaryrefslogtreecommitdiff
path: root/tct/conf/conf.sh
blob: b8d8d00612d90c6252bee52776228167605b3887 (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
# 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.

# Syntax is:
#   conf_device $ID $NATIVE_TCT_REPO
#   copy_ssh $IP $FILE [$DEST]
#   copy_sdb $ID $FILE [$DEST]
#
# conf_device runs install script from Native TCT repository and copies files
# required by TCT in order to properly test the image on a target device.
#
# Author: Aleksander Mistewicz <a.mistewicz@samsung.com>

DEFAULT_DEST="/tmp/smoke.sh"

conf_device() {
    ID="$1"
    NATIVE_TCT_REPO="$2"
    test -n "${ID}" || die "Missing argument: id"
    test -n "${NATIVE_TCT_REPO}" || die "Missing argument: native_tct_repo"
    test -n "${TESTLAB_SCRIPTS}" || die "Missing env: testlab_scripts"

    NATIVE_TCT_TOOLS="${NATIVE_TCT_REPO}/tool/native-tct-3.0/tools"
    cd "${NATIVE_TCT_TOOLS}" || die "cd to ${NATIVE_TCT_TOOLS} failed"
    python ./tct-config-device.py "--deviceid=${ID}"
    cd "${OLDPWD}"

    APP_DIR="/home/owner/content/Documents/tct"

    SUFFIX=''
    if [ ! -f "${TESTLAB_SCRIPTS}/conf/capability.xml" ]
    then
        SUFFIX='.example'
    fi
    sdb -s "${ID}" push "${TESTLAB_SCRIPTS}/conf/capability.xml$SUFFIX" \
        "${APP_DIR}/capability.xml"

    SUFFIX=''
    if [ ! -f "${TESTLAB_SCRIPTS}/conf/buildinfo.xml" ]
    then
        SUFFIX='.example'
    fi
    sdb -s "${ID}" push "${TESTLAB_SCRIPTS}/conf/buildinfo.xml$SUFFIX" \
        "${APP_DIR}/buildinfo.xml"

    sdb -s "${ID}" push "${TESTLAB_SCRIPTS}/conf/configure_env.sh" /etc/profile.d/
}

copy_ssh() {
    IP="$1"
    FILE="$2"
    DEST="$3"
    test -n "${IP}" || die "Missing argument: ip"
    test -n "${FILE}" || die "Missing argument: file"
    test -n "${DEST}" || DEST="${DEFAULT_DEST}"
    COUNT=1
    while ! timeout 60 sshpass -p 'tizen' scp -F "${TESTLAB_SCRIPTS}/conf/ssh_config" \
        "${FILE}" "root@${IP}:${DEST}"
    do
        echo "SSH connection to ${IP} failed: retrying" >&2
        if [ ${COUNT} -ge 6 ]
        then
            die "Timeout: ssh connection failed!"
        fi
        COUNT=$((COUNT+1))
    done
}

copy_sdb() {
    ID="$1"
    FILE="$2"
    DEST="$3"
    test -n "${ID}" || die "Missing argument: id"
    test -n "${FILE}" || die "Missing argument: file"
    test -n "${DEST}" || DEST="${DEFAULT_DEST}"
    sdb -s "${ID}" push "${FILE}" "${DEST}" || die "SDB copy failed!"
}

wait_sdb() {
    SDMUX="$1"
    test -n "${SDMUX}" || die "Missing argument: sdmux"
    test -n "${INIT_SLEEP}" || die "Missing env: init_sleep"

    CONNECT_CNT=0
    sdb start-server >&2
    SLEEP=${INIT_SLEEP}

    sleep "${SLEEP}"

    while [ -z "$(sdb devices | awk -v SDMUX="${SDMUX}" '$1 == SDMUX {print $1}')" ]
    do
        printf "." >&2
        if [ ${SLEEP} -ge ${MAX_SLEEP} ]
        then
            die "Timeout: sdb device not found!"
        fi
        if [ ${SLEEP} -ge ${RESTART_SLEEP} ]
        then
            echo "Restarting ${SDMUX}" >&2
            restart_device "${SDMUX}"
            case "${SDMUX}" in
                *artik*)
                    dyper_restart "${SDMUX}" "dyper1"
                    ;;
            esac
        fi
        sleep "${SLEEP}"
        SLEEP=$((SLEEP+INC_SLEEP))
        CONNECT_CNT=$((CONNECT_CNT+1))
    done

    echo "${CONNECT_CNT}"
}