aboutsummaryrefslogtreecommitdiff
path: root/lava_android_test/test_definitions/hostshells/workload.sh
blob: a01a4a1a6537d3a8153b98aa15f334aed1f6fac3 (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
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/bash
# Copyright (c) 2012 Linaro

# Author: Linaro Validation Team <linaro-dev@lists.linaro.org>
#
# This file is part of LAVA Android Test.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

function parse_argv() {
    # Parse command line arguments
    while test -n "$1"; do
        case "$1" in
            --serial|-s)
                SERIAL="$2"
                if [ -n "${SERIAL}" ]; then
                    shift 2
                else
                    show_usage
                    exit 1
                fi
                ;;
            --config|-c)
                CONFIG="$2"
                if [ -n "${CONFIG}" ]; then
                    shift 2
                else
                    show_usage
                    exit 1
                fi
                ;;
            --git|-g)
                GIT_URL="$2"
                if [ -n "${GIT_URL}" ]; then
                    shift 2
                else
                    show_usage
                    exit 1
                fi
                ;;
            --help|-h)
                show_usage
                exit 1
                ;;
            *)
                if [ -n "${OPTIONS}" ]; then
                    OPTIONS="${OPTIONS} $1"
                else
                    OPTIONS="$1"
                fi
                shift
                ;;
        esac
    done
}

function show_usage(){
    # Display the usage line
    echo "Usage $(basename $0) [--serial|-s <serial>] [--config|-c <config_file>] [--git|g <git-url>] <other-option>"
    echo "Usage $(basename $0) [--help|-h]"
}

function parse_output_result(){
    result_f=${1}
    if [ ! -f "${1}" ]; then
        echo "There is no result file output/results.csv"
        return
    fi

    file_tmp=${result_f}.tmp
    sed 's/ /_/g'  ${result_f} > ${file_tmp}
    keys=`head -n 1 ${file_tmp}`
    values=`tail -n 1 ${file_tmp}`
    for ((i=1; i<21; i++)); do
        key=`echo ${keys}|cut -d , -f ${i}|sed 's/\r//'`
        value=`echo ${values}|cut -d , -f ${i}|sed 's/\r//'`

       echo ${value}|grep -P '^[.\d]+$' &>/dev/null
       if [ $? -ne 0 ]; then
            key="${key}_${value}"
            value="true"
        fi
        echo ${key}=${value}
    done
    rm -f ${file_tmp}
}

function main(){
    local_git="file:///home/bhoj/workload-automation.git"
    branch="lava"
    outputdir="outputdir"
    result="${outputdir}/result.csv"

    parse_argv "$@"

    config_file="config.csv"
    if [ -n "${CONFIG}" ]; then
        config_file="${CONFIG}"
    fi

    if [ -n "${GIT_URL}" ]; then
        git_url="${GIT_URL}"
    else
        git_url="${local_git}"
    fi

    git clone "${git_url}" -b ${branch}
    if [ $? -ne 0 ]; then
        echo "Failed to clone git repository: ${git_url}"
        exit 1
    fi
    ip=`echo ${SERIAL}|sed 's/:5555//'`
    cd "workload-automation"

    #update the ip address and patch config.csv file
    sed -i "s/192.168.1.38/${ip}/g" workload_config.py

    python workload_setup_dependencies.py
    if [ $? -ne 0 ]; then
        echo "Failed to run workload_setup_dependencies.py"
        exit 1
    fi

    rm -fr ${outputdir}
    python workload.py ${config_file} ${outputdir}/
    if [ $? -ne 0 ]; then
        echo "Failed to run workload.py config.csv outputdir/"
        exit 1
    fi
    cat ${result}
    parse_output_result ${result}
}

main "$@"