build.sh 19.7 KB
Newer Older
Y
Yan Chunwei 已提交
1
#!/bin/bash
2
set -ex
Y
Yan Chunwei 已提交
3

4
TESTS_FILE="./lite_tests.txt"
Y
Yan Chunwei 已提交
5
LIBS_FILE="./lite_libs.txt"
Y
Yan Chunwei 已提交
6

C
Chunwei 已提交
7
readonly ADB_WORK_DIR="/data/local/tmp"
Y
Yan Chunwei 已提交
8
readonly common_flags="-DWITH_LITE=ON -DLITE_WITH_LIGHT_WEIGHT_FRAMEWORK=OFF -DWITH_PYTHON=OFF -DWITH_TESTING=ON -DLITE_WITH_ARM=OFF"
9

C
Chunwei 已提交
10 11
NUM_CORES_FOR_COMPILE=8

12 13
# for code gen, a source file is generated after a test, but is dependended by some targets in cmake.
# here we fake an empty file to make cmake works.
14
function prepare_workspace {
15
    # in build directory
16 17 18 19 20 21 22 23 24
    # 1. Prepare gen_code file
    GEN_CODE_PATH_PREFIX=paddle/fluid/lite/gen_code
    mkdir -p ./${GEN_CODE_PATH_PREFIX}
    touch ./${GEN_CODE_PATH_PREFIX}/__generated_code__.cc

    # 2.Prepare debug tool
    DEBUG_TOOL_PATH_PREFIX=paddle/fluid/lite/tools/debug
    mkdir -p ./${DEBUG_TOOL_PATH_PREFIX}
    cp ../${DEBUG_TOOL_PATH_PREFIX}/analysis_tool.py ./${DEBUG_TOOL_PATH_PREFIX}/
25
}
S
up  
superjomn 已提交
26 27 28 29 30

function check_need_ci {
    git log -1 --oneline | grep "test=develop" || exit -1
}

Y
Yan Chunwei 已提交
31
function cmake_x86 {
32
    prepare_workspace
33
    cmake ..  -DWITH_GPU=OFF -DWITH_MKLDNN=OFF -DLITE_WITH_X86=ON ${common_flags}
Y
Yan Chunwei 已提交
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
function cmake_opencl {
    prepare_workspace
    # $1: ARM_TARGET_OS in "android" , "armlinux"
    # $2: ARM_TARGET_ARCH_ABI in "armv8", "armv7" ,"armv7hf"
    # $3: ARM_TARGET_LANG in "gcc" "clang"
    cmake .. \
        -DLITE_WITH_OPENCL=ON \
        -DWITH_GPU=OFF \
        -DWITH_MKL=OFF \
        -DWITH_LITE=ON \
        -DLITE_WITH_CUDA=OFF \
        -DLITE_WITH_X86=OFF \
        -DLITE_WITH_ARM=ON \
        -DLITE_WITH_LIGHT_WEIGHT_FRAMEWORK=ON \
        -DWITH_TESTING=ON \
        -DARM_TARGET_OS=$1 -DARM_TARGET_ARCH_ABI=$2 -DARM_TARGET_LANG=$3
}

# $1: ARM_TARGET_OS in "android" , "armlinux"
# $2: ARM_TARGET_ARCH_ABI in "armv8", "armv7" ,"armv7hf"
# $3: ARM_TARGET_LANG in "gcc" "clang"
function build_opencl {
    os=$1
    abi=$2
    lang=$3

    cur_dir=$(pwd)
    if [[ ${os} == "armlinux" ]]; then
        # TODO(hongming): enable compile armv7 and armv7hf on armlinux, and clang compile
        if [[ ${lang} == "clang" ]]; then
            echo "clang is not enabled on armlinux yet"
            return 0
        fi
        if [[ ${abi} == "armv7hf" ]]; then
            echo "armv7hf is not supported on armlinux yet"
            return 0
        fi
        if [[ ${abi} == "armv7" ]]; then
            echo "armv7 is not supported on armlinux yet"
            return 0
        fi
    fi

    if [[ ${os} == "android" && ${abi} == "armv7hf" ]]; then
        echo "android do not need armv7hf"
        return 0
    fi

    build_dir=$cur_dir/build.lite.${os}.${abi}.${lang}.opencl
    mkdir -p $build_dir
    cd $build_dir

    cmake_opencl ${os} ${abi} ${lang}
    build $TESTS_FILE

    # test publish inference lib
    make publish_inference_lite
}

C
Chunwei 已提交
95
# This method is only called in CI.
Y
Yan Chunwei 已提交
96
function cmake_x86_for_CI {
97
    prepare_workspace # fake an empty __generated_code__.cc to pass cmake.
Y
Yan Chunwei 已提交
98
    cmake ..  -DWITH_GPU=OFF -DWITH_MKLDNN=OFF -DLITE_WITH_X86=ON ${common_flags} -DLITE_WITH_PROFILE=ON
C
Chunwei 已提交
99 100 101 102 103 104 105

    # Compile and execute the gen_code related test, so it will generate some code, and make the compilation reasonable.
    make test_gen_code_lite -j$NUM_CORES_FOR_COMPILE
    make test_cxx_api_lite -j$NUM_CORES_FOR_COMPILE
    ctest -R test_cxx_api_lite
    ctest -R test_gen_code_lite
    make test_generated_code -j$NUM_CORES_FOR_COMPILE
Y
Yan Chunwei 已提交
106 107
}

Y
Yan Chunwei 已提交
108
function cmake_gpu {
109
    prepare_workspace
Y
Yan Chunwei 已提交
110 111 112
    cmake .. " -DWITH_GPU=ON {common_flags} -DLITE_WITH_GPU=ON"
}

S
up  
superjomn 已提交
113 114
function check_style {
    export PATH=/usr/bin:$PATH
S
update  
superjomn 已提交
115
    #pre-commit install
S
up  
superjomn 已提交
116 117 118 119 120 121 122 123
    clang-format --version

    if ! pre-commit run -a ; then
        git diff
        exit 1
    fi
}

T
tensor-tang 已提交
124
function build_single {
125
    #make $1 -j$(expr $(nproc) - 2)
C
Chunwei 已提交
126
    make $1 -j$NUM_CORES_FOR_COMPILE
T
tensor-tang 已提交
127 128
}

Y
Yan Chunwei 已提交
129
function build {
130
    make lite_compile_deps -j$NUM_CORES_FOR_COMPILE
C
Chunwei 已提交
131 132

    # test publish inference lib
133
    # make publish_inference_lite
Y
Yan Chunwei 已提交
134
}
Y
Yan Chunwei 已提交
135 136 137 138 139

# It will eagerly test all lite related unittests.
function test_lite {
    local file=$1
    echo "file: ${file}"
Y
Yan Chunwei 已提交
140

Y
Yan Chunwei 已提交
141 142 143 144 145
    for _test in $(cat $file); do
        ctest -R $_test -V
    done
}

146 147 148 149 150
# Build the code and run lite server tests. This is executed in the CI system.
function build_test_server {
    mkdir -p ./build
    cd ./build
    export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/paddle/build/third_party/install/mklml/lib"
Y
Yan Chunwei 已提交
151
    cmake_x86_for_CI
C
Chunwei 已提交
152
    build
C
Chunwei 已提交
153

154 155 156
    test_lite $TESTS_FILE
}

157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
function build_test_train {
    mkdir -p ./build
    cd ./build
    export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/paddle/build/third_party/install/mklml/lib"
    prepare_workspace # fake an empty __generated_code__.cc to pass cmake.
    cmake .. -DWITH_LITE=ON -DWITH_GPU=OFF -DWITH_PYTHON=ON -DLITE_WITH_X86=ON -DLITE_WITH_LIGHT_WEIGHT_FRAMEWORK=OFF -DWITH_TESTING=ON -DWITH_MKL=OFF 
    
    make test_gen_code_lite -j$NUM_CORES_FOR_COMPILE
    make test_cxx_api_lite -j$NUM_CORES_FOR_COMPILE
    ctest -R test_cxx_api_lite
    ctest -R test_gen_code_lite
    make test_generated_code -j$NUM_CORES_FOR_COMPILE

    make -j$NUM_CORES_FOR_COMPILE

    find -name "*.whl" | xargs pip2 install 
    python ../paddle/fluid/lite/python/lite_test.py

}

T
tensor-tang 已提交
177 178
# test_arm_android <some_test_name> <adb_port_number>
function test_arm_android {
C
Chunwei 已提交
179 180
    local test_name=$1
    local port=$2
T
tensor-tang 已提交
181 182 183 184 185 186 187 188 189 190 191
    if [[ "${test_name}x" == "x" ]]; then
        echo "test_name can not be empty"
        exit 1
    fi
    if [[ "${port}x" == "x" ]]; then
        echo "Port can not be empty"
        exit 1
    fi

    echo "test name: ${test_name}"
    adb_work_dir="/data/local/tmp"
S
sangoly 已提交
192

C
Chunwei 已提交
193
    skip_list=("test_model_parser_lite" "test_mobilenetv1_lite" "test_mobilenetv2_lite" "test_resnet50_lite" "test_inceptionv4_lite" "test_light_api_lite" "test_apis_lite" "test_paddle_api_lite")
S
sangoly 已提交
194 195 196 197
    for skip_name in ${skip_list[@]} ; do
        [[ $skip_name =~ (^|[[:space:]])$test_name($|[[:space:]]) ]] && echo "skip $test_name" && return
    done

C
Chunwei 已提交
198 199
    local testpath=$(find ./paddle/fluid -name ${test_name})

C
Chunwei 已提交
200 201 202 203 204 205 206 207 208 209
    adb -s emulator-${port} push ${testpath} ${adb_work_dir}
    adb -s emulator-${port} shell "${adb_work_dir}/${test_name}"
}

# test the inference high level api
function test_arm_api {
    local port=$1
    local test_name="test_paddle_api_lite"

    make $test_name -j$NUM_CORES_FOR_COMPILE
C
Chunwei 已提交
210

C
Chunwei 已提交
211 212 213 214 215 216
    local model_path=$(find . -name "lite_naive_model")
    local remote_model=${adb_work_dir}/paddle_api
    local testpath=$(find ./paddle/fluid -name ${test_name})

    arm_push_necessary_file $port $model_path $remote_model
    adb -s emulator-${port} shell mkdir -p $remote_model
T
tensor-tang 已提交
217 218
    adb -s emulator-${port} push ${testpath} ${adb_work_dir}
    adb -s emulator-${port} shell chmod +x "${adb_work_dir}/${test_name}"
C
Chunwei 已提交
219
    adb -s emulator-${port} shell "${adb_work_dir}/${test_name} --model_dir $remote_model"
T
tensor-tang 已提交
220 221
}

S
sangoly 已提交
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
function test_arm_model {
    local test_name=$1
    local port=$2
    local model_dir=$3

    if [[ "${test_name}x" == "x" ]]; then
        echo "test_name can not be empty"
        exit 1
    fi
    if [[ "${port}x" == "x" ]]; then
        echo "Port can not be empty"
        exit 1
    fi
    if [[ "${model_dir}x" == "x" ]]; then
        echo "Model dir can not be empty"
        exit 1
    fi

    echo "test name: ${test_name}"
    adb_work_dir="/data/local/tmp"

    testpath=$(find ./paddle/fluid -name ${test_name})
    adb -s emulator-${port} push ${model_dir} ${adb_work_dir}
    adb -s emulator-${port} push ${testpath} ${adb_work_dir}
    adb -s emulator-${port} shell chmod +x "${adb_work_dir}/${test_name}"
C
Chunwei 已提交
247
    local adb_model_path="${adb_work_dir}/`basename ${model_dir}`"
248
    adb -s emulator-${port} shell "${adb_work_dir}/${test_name} --model_dir=$adb_model_path"
C
Chunwei 已提交
249 250 251 252 253 254 255 256 257
}

function _test_model_optimize_tool {
    local port=$1
    local remote_model_path=$ADB_WORK_DIR/lite_naive_model
    local remote_test=$ADB_WORK_DIR/model_optimize_tool
    local adb="adb -s emulator-${port}"

    make model_optimize_tool -j$NUM_CORES_FOR_COMPILE
C
Chunwei 已提交
258 259
    local test_path=$(find . -name model_optimize_tool | head -n1)
    local model_path=$(find . -name lite_naive_model | head -n1)
C
Chunwei 已提交
260 261 262 263 264 265
    $adb push ${test_path} ${ADB_WORK_DIR}
    $adb shell mkdir -p $remote_model_path
    $adb push $model_path/* $remote_model_path
    $adb shell $remote_test --model_dir $remote_model_path --optimize_out ${remote_model_path}.opt \
         --valid_targets "arm"
}
T
tensor-tang 已提交
266

C
Chunwei 已提交
267 268 269 270 271 272 273 274
function _test_paddle_code_generator {
    local port=$1
    local test_name=paddle_code_generator
    local remote_test=$ADB_WORK_DIR/$test_name
    local remote_model=$ADB_WORK_DIR/lite_naive_model.opt
    local adb="adb -s emulator-${port}"

    make paddle_code_generator -j$NUM_CORES_FOR_COMPILE
C
Chunwei 已提交
275
    local test_path=$(find . -name $test_name | head -n1)
C
Chunwei 已提交
276 277 278

    $adb push $test_path $remote_test
    $adb shell $remote_test --optimized_model $remote_model --generated_code_file $ADB_WORK_DIR/gen_code.cc
S
sangoly 已提交
279 280
}

T
tensor-tang 已提交
281
function cmake_arm {
282
    prepare_workspace
T
tensor-tang 已提交
283 284 285
    # $1: ARM_TARGET_OS in "android" , "armlinux"
    # $2: ARM_TARGET_ARCH_ABI in "armv8", "armv7" ,"armv7hf"
    # $3: ARM_TARGET_LANG in "gcc" "clang"
286 287 288 289 290 291 292 293 294 295
    cmake .. \
        -DWITH_GPU=OFF \
        -DWITH_MKL=OFF \
        -DWITH_LITE=ON \
        -DLITE_WITH_CUDA=OFF \
        -DLITE_WITH_X86=OFF \
        -DLITE_WITH_ARM=ON \
        -DLITE_WITH_LIGHT_WEIGHT_FRAMEWORK=ON \
        -DWITH_TESTING=ON \
        -DARM_TARGET_OS=$1 -DARM_TARGET_ARCH_ABI=$2 -DARM_TARGET_LANG=$3
T
tensor-tang 已提交
296 297 298 299 300 301 302 303 304 305
}

# $1: ARM_TARGET_OS in "android" , "armlinux"
# $2: ARM_TARGET_ARCH_ABI in "armv8", "armv7" ,"armv7hf"
# $3: ARM_TARGET_LANG in "gcc" "clang"
function build_arm {
    os=$1
    abi=$2
    lang=$3

C
Chunwei 已提交
306
    cur_dir=$(pwd)
T
tensor-tang 已提交
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327
    if [[ ${os} == "armlinux" ]]; then
        # TODO(hongming): enable compile armv7 and armv7hf on armlinux, and clang compile
        if [[ ${lang} == "clang" ]]; then
            echo "clang is not enabled on armlinux yet"
            return 0
        fi
        if [[ ${abi} == "armv7hf" ]]; then
            echo "armv7hf is not supported on armlinux yet"
            return 0
        fi
        if [[ ${abi} == "armv7" ]]; then
            echo "armv7 is not supported on armlinux yet"
            return 0
        fi
    fi

    if [[ ${os} == "android" && ${abi} == "armv7hf" ]]; then
        echo "android do not need armv7hf"
        return 0
    fi

328
    build_dir=$cur_dir/build.lite.${os}.${abi}.${lang}
T
tensor-tang 已提交
329 330 331
    mkdir -p $build_dir
    cd $build_dir

332
    cmake_arm ${os} ${abi} ${lang}
T
tensor-tang 已提交
333
    build $TESTS_FILE
C
Chunwei 已提交
334 335 336

    # test publish inference lib
    make publish_inference_lite
T
tensor-tang 已提交
337 338 339 340 341 342 343 344 345 346 347 348
}

# $1: ARM_TARGET_OS in "android" , "armlinux"
# $2: ARM_TARGET_ARCH_ABI in "armv8", "armv7" ,"armv7hf"
# $3: ARM_TARGET_LANG in "gcc" "clang"
# $4: android test port
# Note: test must be in build dir
function test_arm {
    os=$1
    abi=$2
    lang=$3
    port=$4
C
Chunwei 已提交
349

T
tensor-tang 已提交
350 351 352 353 354 355 356 357 358 359
    if [[ ${os} == "armlinux" ]]; then
        # TODO(hongming): enable test armlinux on armv8, armv7 and armv7hf
        echo "Skip test arm linux yet. armlinux must in another docker"
        return 0
    fi

    if [[ ${os} == "android" && ${abi} == "armv7hf" ]]; then
        echo "android do not need armv7hf"
        return 0
    fi
360
   
T
tensor-tang 已提交
361 362 363
    echo "test file: ${TESTS_FILE}"
    for _test in $(cat $TESTS_FILE); do
        test_arm_android $_test $port
T
tensor-tang 已提交
364
    done
C
Chunwei 已提交
365 366 367

    # test finally
    test_arm_api $port
C
Chunwei 已提交
368 369 370

    _test_model_optimize_tool $port
    _test_paddle_code_generator $port
T
tensor-tang 已提交
371
}
T
tensor-tang 已提交
372

C
Chunwei 已提交
373 374 375
function prepare_emulator {
    local port_armv8=$1
    local port_armv7=$2
T
tensor-tang 已提交
376 377 378 379 380

    adb kill-server
    adb devices | grep emulator | cut -f1 | while read line; do adb -s $line emu kill; done
    # start android armv8 and armv7 emulators first
    echo n | avdmanager create avd -f -n paddle-armv8 -k "system-images;android-24;google_apis;arm64-v8a"
S
superjomn 已提交
381
    echo -ne '\n' | ${ANDROID_HOME}/emulator/emulator -avd paddle-armv8 -noaudio -no-window -gpu off -port ${port_armv8} &
T
tensor-tang 已提交
382 383
    sleep 1m
    echo n | avdmanager create avd -f -n paddle-armv7 -k "system-images;android-24;google_apis;armeabi-v7a"
S
superjomn 已提交
384
    echo -ne '\n' | ${ANDROID_HOME}/emulator/emulator -avd paddle-armv7 -noaudio -no-window -gpu off -port ${port_armv7} &
T
tensor-tang 已提交
385
    sleep 1m
C
Chunwei 已提交
386 387
}

C
Chunwei 已提交
388 389 390 391 392 393 394 395
function arm_push_necessary_file {
    local port=$1
    local testpath=$2
    local adb_work_dir=$3

    adb -s emulator-${port} push ${testpath} ${adb_work_dir}
}

Z
ZhenWang 已提交
396 397 398 399
function build_test_arm_opencl {
    ########################################################################
    cur=$PWD

400 401
    # job 1
    build_opencl "android" "armv8" "gcc"
Z
ZhenWang 已提交
402 403
    cd $cur

404 405
    # job 2
    build_opencl "android" "armv7" "gcc"
Z
ZhenWang 已提交
406 407 408 409
    cd $cur

    echo "Done"
}
C
Chunwei 已提交
410 411 412 413 414 415 416 417 418 419

# We split the arm unittest into several sub-tasks to parallel and reduce the overall CI timetime.
# sub-task1
function build_test_arm_subtask_android {
    ########################################################################
    # job 1-4 must be in one runner
    port_armv8=5554
    port_armv7=5556

    prepare_emulator $port_armv8 $port_armv7
T
tensor-tang 已提交
420

T
tensor-tang 已提交
421 422 423 424 425 426
    # job 1
    build_arm "android" "armv8" "gcc"
    test_arm "android" "armv8" "gcc" ${port_armv8}
    cd -

    # job 2
C
Chunwei 已提交
427 428 429
    #build_arm "android" "armv8" "clang"
    #test_arm "android" "armv8" "clang" ${port_armv8}
    #cd -
T
tensor-tang 已提交
430

T
tensor-tang 已提交
431 432 433 434 435 436
    # job 3
    build_arm "android" "armv7" "gcc"
    test_arm "android" "armv7" "gcc" ${port_armv7}
    cd -

    # job 4
C
Chunwei 已提交
437 438 439
    #build_arm "android" "armv7" "clang"
    #test_arm "android" "armv7" "clang" ${port_armv7}
    #cd -
T
tensor-tang 已提交
440

T
tensor-tang 已提交
441 442
    adb devices | grep emulator | cut -f1 | while read line; do adb -s $line emu kill; done
    echo "Done"
C
Chunwei 已提交
443 444 445 446
}

# sub-task2
function build_test_arm_subtask_armlinux {
T
tensor-tang 已提交
447
    ########################################################################
C
Chunwei 已提交
448 449 450 451 452
    # job 1-4 must be in one runner
    port_armv8=5554
    port_armv7=5556

    prepare_emulator $port_armv8 $port_armv7
T
tensor-tang 已提交
453

C
Chunwei 已提交
454 455
    cur=$PWD

T
tensor-tang 已提交
456
    # job 5
Z
ZhenWang 已提交
457
    build_arm "armlinux" "armv8" "gcc"
C
Chunwei 已提交
458 459
    test_arm "armlinux" "armv8" "gcc" $port_armv8
    cd $cur
T
tensor-tang 已提交
460 461

    # job 6
Z
ZhenWang 已提交
462
    build_arm "armlinux" "armv7" "gcc"
C
Chunwei 已提交
463 464
    test_arm "armlinux" "armv7" "gcc" $port_armv8
    cd $cur
T
tensor-tang 已提交
465 466

    # job 7
Z
ZhenWang 已提交
467
    build_arm "armlinux" "armv7hf" "gcc"
C
Chunwei 已提交
468 469
    test_arm "armlinux" "armv7hf" "gcc" $port_armv8
    cd $cur
T
tensor-tang 已提交
470

C
Chunwei 已提交
471 472 473 474
    adb devices | grep emulator | cut -f1 | while read line; do adb -s $line emu kill; done
    echo "Done"
}

475 476
# sub-task-model
function build_test_arm_subtask_model {
C
Chunwei 已提交
477 478 479 480 481 482 483
    local port_armv8=5554
    local port_armv7=5556
    # We just test following single one environment to limit the CI time.
    local os=android
    local abi=armv8
    local lang=gcc

484 485 486
    local test_name=$1
    local model_name=$2

C
Chunwei 已提交
487 488 489 490 491
    cur_dir=$(pwd)
    build_dir=$cur_dir/build.lite.${os}.${abi}.${lang}
    mkdir -p $build_dir
    cd $build_dir
    cmake_arm $os $abi $lang
492
    make $test_name -j$NUM_CORES_FOR_COMPILE
C
Chunwei 已提交
493 494 495 496

    prepare_emulator $port_armv8 $port_armv7

    # just test the model on armv8
497
    test_arm_model $test_name $port_armv8 "./third_party/install/$model_name"
C
Chunwei 已提交
498 499

    adb devices | grep emulator | cut -f1 | while read line; do adb -s $line emu kill; done
T
tensor-tang 已提交
500
    echo "Done"
T
tensor-tang 已提交
501 502
}

S
update  
superjomn 已提交
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518

# this test load a model, optimize it and check the prediction result of both cxx and light APIS.
function test_arm_predict_apis {
    local port=$1
    local workspace=$2
    local naive_model_path=$3
    local api_test_path=$(find . -name "test_apis_lite")
    # the model is pushed to ./lite_naive_model
    adb -s emulator-${port} push ${naive_model_path} ${workspace}
    adb -s emulator-${port} push $api_test_path ${workspace}

    # test cxx_api first to store the optimized model.
    adb -s emulator-${port} shell ./test_apis_lite --model_dir ./lite_naive_model --optimized_model ./lite_naive_model_opt
}


C
Chunwei 已提交
519 520 521 522 523 524 525 526 527 528 529 530
# Build the code and run lite arm tests. This is executed in the CI system.
function build_test_arm {
    ########################################################################
    # job 1-4 must be in one runner
    port_armv8=5554
    port_armv7=5556

    build_test_arm_subtask_android
    build_test_arm_subtask_armlinux
}


Y
Yan Chunwei 已提交
531 532 533 534 535 536 537
############################# MAIN #################################
function print_usage {
    echo -e "\nUSAGE:"
    echo
    echo "----------------------------------------"
    echo -e "cmake_x86: run cmake with X86 mode"
    echo -e "cmake_cuda: run cmake with CUDA mode"
T
tensor-tang 已提交
538
    echo -e "--arm_os=<os> --arm_abi=<abi> cmake_arm: run cmake with ARM mode"
Y
Yan Chunwei 已提交
539 540
    echo
    echo -e "build: compile the tests"
T
tensor-tang 已提交
541
    echo -e "--test_name=<test_name> build_single: compile single test"
Y
Yan Chunwei 已提交
542 543
    echo
    echo -e "test_server: run server tests"
T
tensor-tang 已提交
544
    echo -e "--test_name=<test_name> --adb_port_number=<adb_port_number> test_arm_android: run arm test"
Y
Yan Chunwei 已提交
545 546 547 548 549 550 551 552 553 554 555 556
    echo "----------------------------------------"
    echo
}

function main {
    # Parse command line.
    for i in "$@"; do
        case $i in
            --tests=*)
                TESTS_FILE="${i#*=}"
                shift
                ;;
T
tensor-tang 已提交
557 558 559 560 561 562 563 564 565 566 567 568
            --test_name=*)
                TEST_NAME="${i#*=}"
                shift
                ;;
            --arm_os=*)
                ARM_OS="${i#*=}"
                shift
                ;;
            --arm_abi=*)
                ARM_ABI="${i#*=}"
                shift
                ;;
T
tensor-tang 已提交
569 570 571 572
            --arm_lang=*)
                ARM_LANG="${i#*=}"
                shift
                ;;
T
tensor-tang 已提交
573 574 575 576
            --arm_port=*)
                ARM_PORT="${i#*=}"
                shift
                ;;
Y
Yan Chunwei 已提交
577 578 579 580 581
            build)
                build $TESTS_FILE
                build $LIBS_FILE
                shift
                ;;
T
tensor-tang 已提交
582 583 584 585
            build_single)
                build_single $TEST_NAME
                shift
                ;;
Y
Yan Chunwei 已提交
586 587 588 589
            cmake_x86)
                cmake_x86
                shift
                ;;
590 591 592 593
            cmake_opencl)
                cmake_opencl $ARM_OS $ARM_ABI $ARM_LANG
                shift
                ;;
Y
Yan Chunwei 已提交
594 595 596 597 598
            cmake_cuda)
                cmake_cuda
                shift
                ;;
            cmake_arm)
599 600 601 602 603
                cmake_arm $ARM_OS $ARM_ABI $ARM_LANG
                shift
                ;;
            build_opencl)
                build_opencl $ARM_OS $ARM_ABI $ARM_LANG
T
tensor-tang 已提交
604 605 606
                shift
                ;;
            build_arm)
607
                build_arm $ARM_OS $ARM_ABI $ARM_LANG
Y
Yan Chunwei 已提交
608 609 610 611 612 613
                shift
                ;;
            test_server)
                test_lite $TESTS_FILE
                shift
                ;;
T
tensor-tang 已提交
614
            test_arm)
Z
ZhenWang 已提交
615
                test_arm $ARM_OS $ARM_ABI $ARM_LANG $ARM_PORT
T
tensor-tang 已提交
616 617
                shift
                ;;
T
tensor-tang 已提交
618 619
            test_arm_android)
                test_arm_android $TEST_NAME $ARM_PORT
Y
Yan Chunwei 已提交
620 621
                shift
                ;;
622 623 624 625
            build_test_server)
                build_test_server
                shift
                ;;
626 627 628 629
            build_test_train)
                build_test_train
                shift
                ;;
T
tensor-tang 已提交
630 631 632 633
            build_test_arm)
                build_test_arm
                shift
                ;;
Z
ZhenWang 已提交
634 635 636 637
            build_test_arm_opencl)
                build_test_arm_opencl
                shift
                ;;
C
Chunwei 已提交
638 639 640 641 642 643 644 645
            build_test_arm_subtask_android)
                build_test_arm_subtask_android
                shift
                ;;
            build_test_arm_subtask_armlinux)
                build_test_arm_subtask_armlinux
                shift
                ;;
646 647 648 649 650
            build_test_arm_model_mobilenetv1)
                build_test_arm_subtask_model test_mobilenetv1_lite mobilenet_v1
                shift
                ;;
            build_test_arm_model_mobilenetv2)
S
sangoly 已提交
651
                build_test_arm_subtask_model test_mobilenetv2_lite mobilenet_v2_relu
652 653 654 655 656 657 658
                shift
                ;;
            build_test_arm_model_resnet50)
                build_test_arm_subtask_model test_resnet50_lite resnet50
                shift
                ;;
            build_test_arm_model_inceptionv4)
S
sangoly 已提交
659
                build_test_arm_subtask_model test_inceptionv4_lite inception_v4_simple
C
Chunwei 已提交
660 661
                shift
                ;;
S
up  
superjomn 已提交
662 663 664 665
            check_style)
                check_style
                shift
                ;;
S
up  
superjomn 已提交
666 667 668 669
            check_need_ci)
                check_need_ci
                shift
                ;;
Y
Yan Chunwei 已提交
670 671 672 673 674 675 676 677 678 679
            *)
                # unknown option
                print_usage
                exit 1
                ;;
        esac
    done
}

main $@