1*da0073e9SAndroid Build Coastguard Worker#!/bin/bash 2*da0073e9SAndroid Build Coastguard Worker 3*da0073e9SAndroid Build Coastguard Worker# shellcheck source=./common.sh 4*da0073e9SAndroid Build Coastguard Workersource "$(dirname "${BASH_SOURCE[0]}")/common.sh" 5*da0073e9SAndroid Build Coastguard Worker 6*da0073e9SAndroid Build Coastguard Workerif [[ ${BUILD_ENVIRONMENT} == *onnx* ]]; then 7*da0073e9SAndroid Build Coastguard Worker pip install click mock tabulate networkx==2.0 8*da0073e9SAndroid Build Coastguard Worker pip -q install --user "file:///var/lib/jenkins/workspace/third_party/onnx#egg=onnx" 9*da0073e9SAndroid Build Coastguard Workerfi 10*da0073e9SAndroid Build Coastguard Worker 11*da0073e9SAndroid Build Coastguard Worker# Skip tests in environments where they are not built/applicable 12*da0073e9SAndroid Build Coastguard Workerif [[ "${BUILD_ENVIRONMENT}" == *-android* ]]; then 13*da0073e9SAndroid Build Coastguard Worker echo 'Skipping tests' 14*da0073e9SAndroid Build Coastguard Worker exit 0 15*da0073e9SAndroid Build Coastguard Workerfi 16*da0073e9SAndroid Build Coastguard Workerif [[ "${BUILD_ENVIRONMENT}" == *-rocm* ]]; then 17*da0073e9SAndroid Build Coastguard Worker # temporary to locate some kernel issues on the CI nodes 18*da0073e9SAndroid Build Coastguard Worker export HSAKMT_DEBUG_LEVEL=4 19*da0073e9SAndroid Build Coastguard Workerfi 20*da0073e9SAndroid Build Coastguard Worker# These additional packages are needed for circleci ROCm builds. 21*da0073e9SAndroid Build Coastguard Workerif [[ $BUILD_ENVIRONMENT == *rocm* ]]; then 22*da0073e9SAndroid Build Coastguard Worker # Need networkx 2.0 because bellmand_ford was moved in 2.1 . Scikit-image by 23*da0073e9SAndroid Build Coastguard Worker # defaults installs the most recent networkx version, so we install this lower 24*da0073e9SAndroid Build Coastguard Worker # version explicitly before scikit-image pulls it in as a dependency 25*da0073e9SAndroid Build Coastguard Worker pip install networkx==2.0 26*da0073e9SAndroid Build Coastguard Worker # click - onnx 27*da0073e9SAndroid Build Coastguard Worker pip install --progress-bar off click protobuf tabulate virtualenv mock typing-extensions 28*da0073e9SAndroid Build Coastguard Workerfi 29*da0073e9SAndroid Build Coastguard Worker 30*da0073e9SAndroid Build Coastguard Worker# Find where cpp tests and Caffe2 itself are installed 31*da0073e9SAndroid Build Coastguard Workerif [[ "$BUILD_ENVIRONMENT" == *cmake* ]]; then 32*da0073e9SAndroid Build Coastguard Worker # For cmake only build we install everything into /usr/local 33*da0073e9SAndroid Build Coastguard Worker cpp_test_dir="$INSTALL_PREFIX/cpp_test" 34*da0073e9SAndroid Build Coastguard Worker ld_library_path="$INSTALL_PREFIX/lib" 35*da0073e9SAndroid Build Coastguard Workerelse 36*da0073e9SAndroid Build Coastguard Worker # For Python builds we install into python 37*da0073e9SAndroid Build Coastguard Worker # cd to /usr first so the python import doesn't get confused by any 'caffe2' 38*da0073e9SAndroid Build Coastguard Worker # directory in cwd 39*da0073e9SAndroid Build Coastguard Worker python_installation="$(dirname $(dirname $(cd /usr && $PYTHON -c 'import os; import caffe2; print(os.path.realpath(caffe2.__file__))')))" 40*da0073e9SAndroid Build Coastguard Worker caffe2_pypath="$python_installation/caffe2" 41*da0073e9SAndroid Build Coastguard Worker cpp_test_dir="$python_installation/torch/test" 42*da0073e9SAndroid Build Coastguard Worker ld_library_path="$python_installation/torch/lib" 43*da0073e9SAndroid Build Coastguard Workerfi 44*da0073e9SAndroid Build Coastguard Worker 45*da0073e9SAndroid Build Coastguard Worker################################################################################ 46*da0073e9SAndroid Build Coastguard Worker# C++ tests # 47*da0073e9SAndroid Build Coastguard Worker################################################################################ 48*da0073e9SAndroid Build Coastguard Worker# Only run cpp tests in the first shard, don't run cpp tests a second time in the second shard 49*da0073e9SAndroid Build Coastguard Workerif [[ "${SHARD_NUMBER:-1}" == "1" ]]; then 50*da0073e9SAndroid Build Coastguard Worker echo "Running C++ tests.." 51*da0073e9SAndroid Build Coastguard Worker for test in $(find "$cpp_test_dir" -executable -type f); do 52*da0073e9SAndroid Build Coastguard Worker case "$test" in 53*da0073e9SAndroid Build Coastguard Worker # skip tests we know are hanging or bad 54*da0073e9SAndroid Build Coastguard Worker */mkl_utils_test|*/aten/integer_divider_test) 55*da0073e9SAndroid Build Coastguard Worker continue 56*da0073e9SAndroid Build Coastguard Worker ;; 57*da0073e9SAndroid Build Coastguard Worker */scalar_tensor_test|*/basic|*/native_test) 58*da0073e9SAndroid Build Coastguard Worker if [[ "$BUILD_ENVIRONMENT" == *rocm* ]]; then 59*da0073e9SAndroid Build Coastguard Worker continue 60*da0073e9SAndroid Build Coastguard Worker else 61*da0073e9SAndroid Build Coastguard Worker LD_LIBRARY_PATH="$ld_library_path" "$test" 62*da0073e9SAndroid Build Coastguard Worker fi 63*da0073e9SAndroid Build Coastguard Worker ;; 64*da0073e9SAndroid Build Coastguard Worker */*_benchmark) 65*da0073e9SAndroid Build Coastguard Worker LD_LIBRARY_PATH="$ld_library_path" "$test" --benchmark_color=false 66*da0073e9SAndroid Build Coastguard Worker ;; 67*da0073e9SAndroid Build Coastguard Worker *) 68*da0073e9SAndroid Build Coastguard Worker # Currently, we use a mixture of gtest (caffe2) and Catch2 (ATen). While 69*da0073e9SAndroid Build Coastguard Worker # planning to migrate to gtest as the common PyTorch c++ test suite, we 70*da0073e9SAndroid Build Coastguard Worker # currently do NOT use the xml test reporter, because Catch doesn't 71*da0073e9SAndroid Build Coastguard Worker # support multiple reporters 72*da0073e9SAndroid Build Coastguard Worker # c.f. https://github.com/catchorg/Catch2/blob/master/docs/release-notes.md#223 73*da0073e9SAndroid Build Coastguard Worker # which means that enabling XML output means you lose useful stdout 74*da0073e9SAndroid Build Coastguard Worker # output for Jenkins. It's more important to have useful console 75*da0073e9SAndroid Build Coastguard Worker # output than it is to have XML output for Jenkins. 76*da0073e9SAndroid Build Coastguard Worker # Note: in the future, if we want to use xml test reporter once we switch 77*da0073e9SAndroid Build Coastguard Worker # to all gtest, one can simply do: 78*da0073e9SAndroid Build Coastguard Worker LD_LIBRARY_PATH="$ld_library_path" \ 79*da0073e9SAndroid Build Coastguard Worker "$test" --gtest_output=xml:"$gtest_reports_dir/$(basename $test).xml" 80*da0073e9SAndroid Build Coastguard Worker ;; 81*da0073e9SAndroid Build Coastguard Worker esac 82*da0073e9SAndroid Build Coastguard Worker done 83*da0073e9SAndroid Build Coastguard Workerfi 84*da0073e9SAndroid Build Coastguard Worker 85*da0073e9SAndroid Build Coastguard Worker################################################################################ 86*da0073e9SAndroid Build Coastguard Worker# Python tests # 87*da0073e9SAndroid Build Coastguard Worker################################################################################ 88*da0073e9SAndroid Build Coastguard Workerif [[ "$BUILD_ENVIRONMENT" == *cmake* ]]; then 89*da0073e9SAndroid Build Coastguard Worker exit 0 90*da0073e9SAndroid Build Coastguard Workerfi 91*da0073e9SAndroid Build Coastguard Worker 92*da0073e9SAndroid Build Coastguard Worker# If pip is installed as root, we must use sudo. 93*da0073e9SAndroid Build Coastguard Worker# CircleCI docker images could install conda as jenkins user, or use the OS's python package. 94*da0073e9SAndroid Build Coastguard WorkerPIP=$(which pip) 95*da0073e9SAndroid Build Coastguard WorkerPIP_USER=$(stat --format '%U' $PIP) 96*da0073e9SAndroid Build Coastguard WorkerCURRENT_USER=$(id -u -n) 97*da0073e9SAndroid Build Coastguard Workerif [[ "$PIP_USER" = root && "$CURRENT_USER" != root ]]; then 98*da0073e9SAndroid Build Coastguard Worker MAYBE_SUDO=sudo 99*da0073e9SAndroid Build Coastguard Workerfi 100*da0073e9SAndroid Build Coastguard Worker 101*da0073e9SAndroid Build Coastguard Worker# Uninstall pre-installed hypothesis and coverage to use an older version as newer 102*da0073e9SAndroid Build Coastguard Worker# versions remove the timeout parameter from settings which ideep/conv_transpose_test.py uses 103*da0073e9SAndroid Build Coastguard Worker$MAYBE_SUDO pip -q uninstall -y hypothesis 104*da0073e9SAndroid Build Coastguard Worker$MAYBE_SUDO pip -q uninstall -y coverage 105*da0073e9SAndroid Build Coastguard Worker 106*da0073e9SAndroid Build Coastguard Worker# "pip install hypothesis==3.44.6" from official server is unreliable on 107*da0073e9SAndroid Build Coastguard Worker# CircleCI, so we host a copy on S3 instead 108*da0073e9SAndroid Build Coastguard Worker$MAYBE_SUDO pip -q install attrs==18.1.0 -f https://s3.amazonaws.com/ossci-linux/wheels/attrs-18.1.0-py2.py3-none-any.whl 109*da0073e9SAndroid Build Coastguard Worker$MAYBE_SUDO pip -q install coverage==4.5.1 -f https://s3.amazonaws.com/ossci-linux/wheels/coverage-4.5.1-cp36-cp36m-macosx_10_12_x86_64.whl 110*da0073e9SAndroid Build Coastguard Worker$MAYBE_SUDO pip -q install hypothesis==3.44.6 -f https://s3.amazonaws.com/ossci-linux/wheels/hypothesis-3.44.6-py3-none-any.whl 111*da0073e9SAndroid Build Coastguard Worker 112*da0073e9SAndroid Build Coastguard Worker# Collect additional tests to run (outside caffe2/python) 113*da0073e9SAndroid Build Coastguard WorkerEXTRA_TESTS=() 114*da0073e9SAndroid Build Coastguard Worker 115*da0073e9SAndroid Build Coastguard Worker# CUDA builds always include NCCL support 116*da0073e9SAndroid Build Coastguard Workerif [[ "$BUILD_ENVIRONMENT" == *-cuda* ]] || [[ "$BUILD_ENVIRONMENT" == *-rocm* ]]; then 117*da0073e9SAndroid Build Coastguard Worker EXTRA_TESTS+=("$caffe2_pypath/contrib/nccl") 118*da0073e9SAndroid Build Coastguard Workerfi 119*da0073e9SAndroid Build Coastguard Worker 120*da0073e9SAndroid Build Coastguard Workerrocm_ignore_test=() 121*da0073e9SAndroid Build Coastguard Workerif [[ $BUILD_ENVIRONMENT == *-rocm* ]]; then 122*da0073e9SAndroid Build Coastguard Worker # Currently these tests are failing on ROCM platform: 123*da0073e9SAndroid Build Coastguard Worker 124*da0073e9SAndroid Build Coastguard Worker # On ROCm, RCCL (distributed) development isn't complete. 125*da0073e9SAndroid Build Coastguard Worker # https://github.com/ROCmSoftwarePlatform/rccl 126*da0073e9SAndroid Build Coastguard Worker rocm_ignore_test+=("--ignore $caffe2_pypath/python/data_parallel_model_test.py") 127*da0073e9SAndroid Build Coastguard Worker 128*da0073e9SAndroid Build Coastguard Worker # This test has been flaky in ROCm CI (but note the tests are 129*da0073e9SAndroid Build Coastguard Worker # cpu-only so should be unrelated to ROCm) 130*da0073e9SAndroid Build Coastguard Worker rocm_ignore_test+=("--ignore $caffe2_pypath/python/operator_test/blobs_queue_db_test.py") 131*da0073e9SAndroid Build Coastguard Worker # This test is skipped on Jenkins(compiled without MKL) and otherwise known flaky 132*da0073e9SAndroid Build Coastguard Worker rocm_ignore_test+=("--ignore $caffe2_pypath/python/ideep/convfusion_op_test.py") 133*da0073e9SAndroid Build Coastguard Worker # This test is skipped on Jenkins(compiled without MKL) and causing segfault on Circle 134*da0073e9SAndroid Build Coastguard Worker rocm_ignore_test+=("--ignore $caffe2_pypath/python/ideep/pool_op_test.py") 135*da0073e9SAndroid Build Coastguard Workerfi 136*da0073e9SAndroid Build Coastguard Worker 137*da0073e9SAndroid Build Coastguard Workerecho "Running Python tests.." 138*da0073e9SAndroid Build Coastguard Worker# locale setting is required by click package 139*da0073e9SAndroid Build Coastguard Workerfor loc in "en_US.utf8" "C.UTF-8"; do 140*da0073e9SAndroid Build Coastguard Worker if locale -a | grep "$loc" >/dev/null 2>&1; then 141*da0073e9SAndroid Build Coastguard Worker export LC_ALL="$loc" 142*da0073e9SAndroid Build Coastguard Worker export LANG="$loc" 143*da0073e9SAndroid Build Coastguard Worker break; 144*da0073e9SAndroid Build Coastguard Worker fi 145*da0073e9SAndroid Build Coastguard Workerdone 146*da0073e9SAndroid Build Coastguard Worker 147*da0073e9SAndroid Build Coastguard Worker# Some Caffe2 tests fail when run using AVX512 ISA, see https://github.com/pytorch/pytorch/issues/66111 148*da0073e9SAndroid Build Coastguard Workerexport DNNL_MAX_CPU_ISA=AVX2 149*da0073e9SAndroid Build Coastguard Worker 150*da0073e9SAndroid Build Coastguard Worker# Should still run even in the absence of SHARD_NUMBER 151*da0073e9SAndroid Build Coastguard Workerif [[ "${SHARD_NUMBER:-1}" == "1" ]]; then 152*da0073e9SAndroid Build Coastguard Worker # TODO([email protected]) remove this when the linked issue resolved. 153*da0073e9SAndroid Build Coastguard Worker # py is temporary until https://github.com/Teemu/pytest-sugar/issues/241 is fixed 154*da0073e9SAndroid Build Coastguard Worker pip install --user py==1.11.0 155*da0073e9SAndroid Build Coastguard Worker pip install --user pytest-sugar 156*da0073e9SAndroid Build Coastguard Worker # NB: Warnings are disabled because they make it harder to see what 157*da0073e9SAndroid Build Coastguard Worker # the actual erroring test is 158*da0073e9SAndroid Build Coastguard Worker "$PYTHON" \ 159*da0073e9SAndroid Build Coastguard Worker -m pytest \ 160*da0073e9SAndroid Build Coastguard Worker -x \ 161*da0073e9SAndroid Build Coastguard Worker -v \ 162*da0073e9SAndroid Build Coastguard Worker --disable-warnings \ 163*da0073e9SAndroid Build Coastguard Worker --junit-xml="$pytest_reports_dir/result.xml" \ 164*da0073e9SAndroid Build Coastguard Worker --ignore "$caffe2_pypath/python/test/executor_test.py" \ 165*da0073e9SAndroid Build Coastguard Worker --ignore "$caffe2_pypath/python/operator_test/matmul_op_test.py" \ 166*da0073e9SAndroid Build Coastguard Worker --ignore "$caffe2_pypath/python/operator_test/pack_ops_test.py" \ 167*da0073e9SAndroid Build Coastguard Worker --ignore "$caffe2_pypath/python/mkl/mkl_sbn_speed_test.py" \ 168*da0073e9SAndroid Build Coastguard Worker --ignore "$caffe2_pypath/python/trt/test_pt_onnx_trt.py" \ 169*da0073e9SAndroid Build Coastguard Worker ${rocm_ignore_test[@]} \ 170*da0073e9SAndroid Build Coastguard Worker "$caffe2_pypath/python" \ 171*da0073e9SAndroid Build Coastguard Worker "${EXTRA_TESTS[@]}" 172*da0073e9SAndroid Build Coastguard Workerfi 173