• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2# Copyright (c) 2021 Huawei Device Co., Ltd.
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15set -e
16
17BASE_HOME=$(dirname $(dirname $(cd $(dirname $0); pwd)))
18NFS_IP=""
19NFS_PORT=""
20NFS_ROOT_TMP=""
21NFS_ROOT=$NFS_ROOT_TMP/data/nfsuser/data
22NFS_USER=""
23NFS_PWD=""
24USER=""
25DEVICE=""
26MODULE=""
27TEST_FILE_NAME=""
28PRODUCT=""
29
30usage()
31{
32    echo
33    echo "USAGE"
34    echo "       ./runtest.sh user=USERNAME product=PRODUCT platform=PLATFORM module=MODULE device=IP:PORT"
35    echo
36    echo "            user      : USERNAME  your name, no spaces allowed, such as xiaoming"
37    echo "            module    : MODULE   the module name"
38    echo "                                  which is same with BUILD.gn target name, such as wifiaware_test."
39    echo "            device    : IP:PORT  the host ip:port of the connected device, such as: xx.xx.xx.xx:xxxx"
40    echo "            product   : PRODUCT  the product name. such as wifiiot or ipcamera"
41    echo "            platform  : PLATFORM  the platform name."
42    echo
43    echo
44    exit 1
45}
46
47parse_cmdline()
48{
49    SUITE_OUT=""
50    DEVICE_IP=""
51    DEVICE_PORT=""
52    NFS_DIR=""
53    MODULE_FILES=""
54    while [ -n "$1" ]
55    do
56        var="$1"
57        OPTIONS=$(echo ${var%%=*})
58        PARAM=$(echo ${var#*=})
59        case "$OPTIONS" in
60        user)      USER="$PARAM"
61                   NFS_DIR=$NFS_ROOT/$USER/
62                   ;;
63        device)    DEVICE="$PARAM"
64                   DEVICE_IP=$(echo ${PARAM%%:*})
65                   DEVICE_PORT=$(echo ${PARAM#*:})
66                   ;;
67        module)    MODULE="$PARAM"
68                   ;;
69        product)   PRODUCT="$PARAM"
70                   ;;
71        platform)  PLATFORM="$PARAM"
72                   ;;
73        *)   usage
74             break;;
75        esac
76        shift
77    done
78    if [ "$USER" = "" ];then
79        echo "user is required!"
80        usage
81    fi
82    if [ "$PRODUCT" = "" ];then
83        echo "product is required!"
84        usage
85    fi
86    if [ "$DEVICE" = "" ];then
87        echo "device is required!"
88        usage
89    fi
90    if [ "$DEVICE_IP" = "" ] || [ "$DEVICE_PORT" = "" ];then
91        echo "device is required!"
92        usage
93    fi
94    if [ "$MODULE" = "" ];then
95        echo "module is required!"
96        usage
97    fi
98    if [ "$PLATFORM" = "" ];then
99        echo "platform is required!"
100        usage
101    fi
102    if [ "$PRODUCT" != "ipcamera" ];then
103        echo "Only ipcamera is supported!"
104        exit 1
105    fi
106    SUITE_OUT="${BASE_HOME}/out/${PRODUCT}_${PLATFORM}/suites"
107
108    if ! [ -x "$(command -v sshpass)" ]; then
109      echo "Please run 'sudo apt-get install sshpass' first."
110      exit 1
111    fi
112    local suite_zip=$(basename "$(find $SUITE_OUT -name *.zip)")
113    if [ -z "$suite_zip" ];then
114      echo "Please run xts/tools/build.sh to build target first"
115      exit 1
116    fi
117    local suite_name=$(echo ${suite_zip%%.*})
118    SUITE_OUT=$SUITE_OUT/$suite_name
119    MODULE_FILES=$(find $SUITE_OUT/testcases -name ${MODULE}*)
120    if [ -z "${MODULE_FILES}" ];then
121      echo "Can not find the target: ${MODULE}"
122      echo "Please run xts/tools/build.sh to build target first"
123      exit 1
124    fi
125}
126
127copy_files_to_nfs()
128{
129    sshpass -p $NFS_PWD ssh -p $NFS_PORT -t $NFS_USER@$NFS_IP "mkdir -p $NFS_DIR"
130    for file in $MODULE_FILES; do
131      echo "sync $file to nfs server"
132      sshpass -p $NFS_PWD scp -P $NFS_PORT $file $NFS_USER@$NFS_IP:$NFS_DIR
133    done
134
135}
136
137set_environment()
138{
139    USER_CONFIG=$SUITE_OUT/config/user_config.xml
140    sed -i 's/\$device_ip\$/'$DEVICE_IP'/g' $USER_CONFIG
141    sed -i 's/\$device_port\$/'$DEVICE_PORT'/g' $USER_CONFIG
142    sed -i 's/\$user\$/'$USER'/g' $USER_CONFIG
143}
144
145run_test()
146{
147    cd $SUITE_OUT
148    chmod +x run.sh
149    ./run.sh run -l $MODULE
150}
151
152parse_cmdline $@
153copy_files_to_nfs
154set_environment
155run_test
156