File: run.sh

package info (click to toggle)
roc-toolkit 0.4.0%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 9,700 kB
  • sloc: cpp: 102,987; ansic: 8,959; python: 6,125; sh: 942; makefile: 19; javascript: 9
file content (130 lines) | stat: -rwxr-xr-x 3,522 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env bash

set -euo pipefail

function color_msg() {
    printf '%s \033[1;35m%s\033[0m\n' "---" "$1"
}

function run_cmd() {
    echo "+++ $*"
    "$@" || exit 1
}

action="${1:-}"

if [ -z "${ANDROID_NDK_ROOT:-}" ]
then
    export ANDROID_NDK_ROOT="${ANDROID_SDK_ROOT}/ndk/${NDK_VERSION}"
fi

case "${OSTYPE}" in
    darwin*)
        toolchain_root="${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/darwin-$(uname -m)"
        ;;
    linux*)
        toolchain_root="${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/linux-$(uname -m)"
        ;;
esac

case "${ABI}" in
    "x86_64")
        target_arch="x86_64"
        target_host="${ABI}-linux-android"
        target_toolchain="${target_host}${API}"
        sysroot="${toolchain_root}/sysroot/usr/lib/${target_host}"
        ;;
    "i686")
        target_arch="x86"
        target_host="${ABI}-linux-android"
        target_toolchain="${target_host}${API}"
        sysroot="${toolchain_root}/sysroot/usr/lib/${target_host}"
        ;;
    "aarch64")
        target_arch="arm64-v8a"
        target_host="${ABI}-linux-android"
        target_toolchain="${target_host}${API}"
        sysroot="${toolchain_root}/sysroot/usr/lib/${target_host}"
        ;;
    "armv7a")
        target_arch="armeabi-v7a"
        target_host="${ABI}-linux-androideabi"
        target_toolchain="${target_host}${API}"
        sysroot="${toolchain_root}/sysroot/usr/lib/arm-linux-androideabi"
        ;;
    *)
        echo "unrecognized android ABI: '${ABI}'"
        exit 1
        ;;
esac

export PATH="${ANDROID_SDK_ROOT}/tools/bin:${PATH}"
export PATH="${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin:${PATH}"
export PATH="${toolchain_root}/bin:${PATH}"

if [[ "${action}" == install ]]
then
    color_msg "installing dependencies"

    case "${OSTYPE}" in
        darwin*)
            brew install scons ragel gengetopt
            ;;
        linux*)
            sudo apt-get install -y scons ragel gengetopt
            ;;
    esac
fi

if [[ "${action}" == build ]]
then
    color_msg "building project"

    run_cmd scons -Q \
          --compiler=clang \
          --host="${target_toolchain}" \
          --enable-werror \
          --enable-tests \
          --disable-soversion \
          --disable-tools \
          --build-3rdparty=libuv,openfec,openssl,speexdsp,cpputest
fi

if [[ "${action}" == prep ]]
then
    color_msg "configuring routes"

    adb shell "ip a" | grep 'state UP' | cut -d':' -f2 | awk '{print $1}' | cut -d'@' -f1 |
        while read iface
        do
            if ! adb shell ip route show table all | \
                    grep -qF "224.0.0.0/4 dev ${iface} table local"
            then
                run_cmd adb shell "su 0 ip route add 224.0.0.0/4 dev ${iface} table local"
            fi
        done
fi

if [[ "${action}" == test ]]
then
    color_msg "running tests"

    target_prefix="/data/local/tmp"

    run_cmd adb shell "su 0 mkdir -p ${target_prefix}/lib"
    run_cmd adb push "${sysroot}/libc++_shared.so" "${target_prefix}/lib/libc++_shared.so"

    find "bin/${target_toolchain}" -name 'roc-test-*' | \
        while read test_path
        do
            test_name="$(basename ${test_path})"

            color_msg "running ${test_name}"

            run_cmd adb push "$test_path" "${target_prefix}/${test_name}"

            run_cmd python scripts/scons_helpers/timeout-run.py 300 \
                    adb shell "LD_LIBRARY_PATH=${target_prefix}/lib" \
                    "${target_prefix}/${test_name}" </dev/null
        done
fi