tests.sh 2.3 KB
Newer Older
S
update  
superjom 已提交
1 2 3
#!/bin/bash
set -ex

S
init  
superjom 已提交
4
mode=$1
Y
Yan Chunwei 已提交
5 6 7
readonly TOP_DIR=$(pwd)
readonly core_path=$TOP_DIR/build/visualdl/logic
readonly python_path=$TOP_DIR/visualdl/python
Y
Yan Chunwei 已提交
8
readonly max_file_size=1000000 # 1MB
S
superjom 已提交
9 10

export PYTHONPATH="${core_path}:${python_path}"
S
init  
superjom 已提交
11

Y
Yan Chunwei 已提交
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
# install the visualdl wheel first
package() {
    # some bug with frontend build
    # a environment variable to skip frontend build
    export VS_BUILD_MODE="travis-CI"

    cd $TOP_DIR/visualdl/server
    # manully install protobuf3
    curl -OL https://github.com/google/protobuf/releases/download/v3.1.0/protoc-3.1.0-linux-x86_64.zip
    unzip protoc-3.1.0-linux-x86_64.zip -d protoc3
    export PATH="$PATH:$(pwd)/protoc3/bin"
    chmod +x protoc3/bin/*

    sudo pip install numpy
    sudo pip install Flask
    sudo pip install Pillow
    sudo pip install protobuf

    #sudo apt-get install protobuf-compiler
    cd $TOP_DIR
    python setup.py bdist_wheel
    sudo pip install dist/visualdl-0.0.1-py2-none-any.whl
}

S
init  
superjom 已提交
36
backend_test() {
Y
Yan Chunwei 已提交
37
    cd $TOP_DIR
S
init  
superjom 已提交
38
    sudo pip install numpy
S
superjom 已提交
39
    sudo pip install Pillow
S
init  
superjom 已提交
40 41 42 43 44 45 46 47
    mkdir -p build
    cd build
    cmake ..
    make
    make test
}

frontend_test() {
Y
Yan Chunwei 已提交
48
    cd $TOP_DIR
S
init  
superjom 已提交
49 50 51 52 53
    cd frontend
    npm install
    npm run build
}

S
superjom 已提交
54
server_test() {
D
daminglu 已提交
55 56 57
    sudo pip install google
    sudo pip install protobuf==3.1.0

Y
Yan Chunwei 已提交
58
    cd $TOP_DIR/visualdl/server
D
daminglu 已提交
59 60
    bash graph_test.sh

Y
Yan Chunwei 已提交
61
    cd $TOP_DIR/visualdl/server
S
superjom 已提交
62 63 64
    python lib_test.py
}

Y
Yan Chunwei 已提交
65 66 67
# check the size of files in the repo.
# reject PR that has some big data included.
bigfile_reject() {
Y
Yan Chunwei 已提交
68
    cd $TOP_DIR
Y
Yan Chunwei 已提交
69 70
    # it failed to exclude .git, remove it first.
    rm -rf .git
Y
Yan Chunwei 已提交
71
    local largest_file="$(find . -path .git -prune -o -printf '%s %p\n' | sort -nr | head -n1)"
Y
Yan Chunwei 已提交
72 73 74 75 76 77 78 79 80
    local size=$(echo $largest_file | awk '{print $1}')
    if [ "$size" -ge "$max_file_size" ]; then
        echo $largest_file
        echo "file size exceed $max_file_size"
        echo "Should not add large data or binary file."
        exit -1
    fi
}

S
init  
superjom 已提交
81 82 83 84
echo "mode" $mode

if [ $mode = "backend" ]; then
    backend_test
S
superjom 已提交
85
elif [ $mode = "all" ]; then
Y
Yan Chunwei 已提交
86
    # bigfile_reject should be tested first, or some files downloaded may fail this test.
Y
Yan Chunwei 已提交
87
    bigfile_reject
Y
Yan Chunwei 已提交
88
    package
S
superjom 已提交
89 90
    frontend_test
    backend_test
S
superjom 已提交
91
    server_test
Y
Yan Chunwei 已提交
92 93 94 95
elif [ $mode = "local" ]; then
    #frontend_test
    backend_test
    server_test
S
init  
superjom 已提交
96 97 98
else
    frontend_test
fi