• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env sh
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
15BASE_HOME=$(dirname $(dirname $(cd `dirname $0`; pwd)))
16NFS_IP=
17NFS_PORT=
18NFS_ROOT=/data/nfsuser/data
19NFS_USER=
20NFS_PWD=
21USER=
22DEVICE=
23DEVICE_IP=
24DEVICE_PORT=
25NFS_DIR=
26MODULE=
27TEST_FILE_NAME=
28PRODUCT=
29SUITE_OUT=
30MODULE_FILES=
31
32usage()
33{
34    echo
35    echo "USAGE"
36    echo "       ./runtest.sh user=USERNAME product=PRODUCT platform=PLATFORM module=MODULE device=IP:PORT"
37    echo
38    echo "            user      : USERNAME  your name, no spaces allowed, such as xiaoming"
39    echo "            module    : MODULE   the module name"
40    echo "                                  which is same with BUILD.gn target name, such as wifiaware_test."
41    echo "            device    : IP:PORT  the host ip:port of the connected device, such as: xx.xx.xx.xx:xxxx"
42    echo "            product   : PRODUCT  the product name. such as wifiiot or ipcamera"
43    echo "            platform  : PLATFORM  the platform name."
44    echo
45    echo
46    exit 1
47}
48
49parse_cmdline()
50{
51    while [ -n "$1" ]
52    do
53        var="$1"
54        OPTIONS=`echo ${var%%=*}`
55        PARAM=`echo ${var#*=}`
56        case "$OPTIONS" in
57        user)      USER="$PARAM"
58                   NFS_DIR=$NFS_ROOT/$USER/
59                   ;;
60        device)    DEVICE="$PARAM"
61                   DEVICE_IP=`echo ${PARAM%%:*}`
62                   DEVICE_PORT=`echo ${PARAM#*:}`
63                   ;;
64        module)    MODULE="$PARAM"
65                   ;;
66        product)   PRODUCT="$PARAM"
67                   ;;
68        platform)  PLATFORM="$PARAM"
69                   ;;
70        *)   usage
71             break;;
72        esac
73        shift
74    done
75    if [ "$USER" = "" ];then
76        echo "user is required!"
77        usage
78    fi
79    if [ "$PRODUCT" = "" ];then
80        echo "product is required!"
81        usage
82    fi
83    if [ "$DEVICE" = "" ];then
84        echo "device is required!"
85        usage
86    fi
87    if [ "$DEVICE_IP" = "" ] || [ "$DEVICE_PORT" = "" ];then
88        echo "device is required!"
89        usage
90    fi
91    if [ "$MODULE" = "" ];then
92        echo "module is required!"
93        usage
94    fi
95    if [ "$PLATFORM" = "" ];then
96        echo "platform is required!"
97        usage
98    fi
99    if [ "$PRODUCT" != "ipcamera" ];then
100        echo "Only ipcamera is supported!"
101        exit 1
102    fi
103    SUITE_OUT="${BASE_HOME}/out/${PRODUCT}_${PLATFORM}/suites"
104}
105
106check_environment()
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 $@
153check_environment
154copy_files_to_nfs
155set_environment
156run_test
157