summaryrefslogtreecommitdiff
path: root/common/common.sh
blob: ffb94666147cefb124ba4d62533b34f9e432d49d (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
#!/bin/bash

local_common_file_path="${BASH_SOURCE[0]}"
local_common_parent_dir=$(cd $(dirname ${local_common_file_path}); pwd)
source ${local_common_parent_dir}/common2.sh

base_url="http://testdata.validation.linaro.org/apks/"
post_install=""
pre_uninstall=""
ret_value=0
timeout=10m

dir_sys_cpu="/sys/devices/system/cpu/"
f_tmp_governor="/data/local/tmp/governor.txt"

func_setgovernor(){
    local target_governor="$1"
    local target_freq="$2"
    if [ -z "${target_governor}" ]; then
        return
    fi
    for cpu in $(adb shell "ls -d ${dir_sys_cpu}/cpu[0-9]*" |tr '\r' ' '); do
        local dir_cpu_cpufreq="${cpu}/cpufreq"
        adb shell "echo ${target_governor}>${dir_cpu_cpufreq}/scaling_governor"
        if [ -n "${target_freq}" ]; then
            adb shell "echo ${target_freq} >${dir_cpu_cpufreq}/scaling_setspeed"
        fi
    done
}

func_cleanup(){
    local target_governor=$(adb shell cat ${f_tmp_governor})
    func_setgovernor "${target_governor}"
    adb shell rm ${f_tmp_governor}
    func_kill_uninstall "RotationOff.apk" "rotation.off"
}

func_install_start_RotationAPK(){
    local apk_name="RotationOff.apk"
    local apk_path="${D_APKS}/RotationOff.apk"
    if [ -f "${apk_path}" ]; then
        echo "The file(${apk_path}) already exists."
    else
        get_file_with_base_url "${apk_name}" "${BASE_URL}" "${D_APKS}"
    fi
    adb shell pm list packages | grep rotation.off
    if [ $? -ne 0 ]; then
        adb install "${apk_path}"
    fi
    sleep 2
    adb shell am start 'rotation.off/.RotationOff'
    sleep 2
}

function init(){

    func_install_start_RotationAPK

    adb shell "cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor > ${f_tmp_governor}"
    func_setgovernor "performance"
}

func_prepare_benchmark(){
    func_prepare_environment

    init
    echo "init done"
}

func_run_test_bench(){
    local test_script="${D_ROOT}/${loop_app_name}/vc.py"
    local ret
    if [ -f "${test_script}" ]; then
        local test_command="python ${test_script}"
        if [ -n "${var_test_command_timeout}" ]; then
            timeout ${var_test_command_timeout} ${test_command}
            ret=$?
            if [ $ret -eq 124 ]; then
                local tmp_f_name=$(basename $(mktemp -u -t timeout_screen_XXX.png))
                adb shell screencap /data/local/tmp/${tmp_f_name}
                adb pull /data/local/tmp/${tmp_f_name} ${D_SCREENSHOT}/${tmp_f_name}
                echo  "Time out to run ${test_command}: ${var_test_command_timeout}"
                echo  "You can check ${D_SCREENSHOT}/${tmp_f_name} for reference."
            fi
        else
            ${test_command}
            ret=$?
        fi
        sleep 5
        return $ret
    fi
}

func_post_uninstall_bench(){
    func_post_uninstall
    if [ -n "${post_uninstall}" ]; then
        ${post_uninstall}
    fi
}

function main(){
    echo "test timeout: ${timeout}"
    parent_dir=$(cd ${parent_dir}; pwd)
    export parent_dir=${parent_dir}

    var_func_parse_parameters=""
    var_func_prepare_environment="func_prepare_benchmark"
    var_func_post_test="func_cleanup"

    var_func_pre_install=""
    var_func_post_install="${post_install}"
    var_func_run_test="func_run_test_bench"
    var_test_command=""
    var_test_command_timeout="${timeout}"
    var_func_pre_uninstall="${pre_uninstall}"
    var_func_post_uninstall="func_post_uninstall_bench"

    G_APPS="${apk_file_name},${activity},$(basename ${parent_dir})"
    BASE_URL="${base_url}"
    common_main "$@"

    return ${ret_value}
}