You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by tq...@apache.org on 2020/04/23 22:05:15 UTC

[incubator-tvm] branch master updated: [RFC] Pytest environment improvements (#5421)

This is an automated email from the ASF dual-hosted git repository.

tqchen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git


The following commit(s) were added to refs/heads/master by this push:
     new e149db2  [RFC] Pytest environment improvements (#5421)
e149db2 is described below

commit e149db2830db5fca86b34afbec60fca05ac4179d
Author: Ramana Radhakrishnan <ra...@arm.com>
AuthorDate: Thu Apr 23 23:05:03 2020 +0100

    [RFC] Pytest environment improvements (#5421)
    
    * [RFC] Pass pytest options globally.
    
    In many places having a global pytest flag is useful . For me with the
    build and test of tvm , I would like to be able to globally pass in
    pytest options as part of development flow or CI flows where one would
    like to measure other things regularly that need measurements including
    pytest coverage data that I would like to experiment with across the stack.
    
    This has been achieved with an additional setup-pytest-env.sh file in
    tests/scripts rather than putting in something in every single task test
    script and something I would like to avoid.
    
    This now means the -v option to pytest is superfluous. I did consider
    having a pytest.ini file but that doesn't allow me to pass any old
    environment variable in and this seems to be the compromise.
    
    * Improve other use case documentation
    
    * Rationalize pytest environment.
    
    * Remove the setting from docker/with_same_user.
    * Take the opportunity to migrate common PYTHONPATH and
    TVM_PATH into the common environment setting.
    
    * Fixup vta fsim
    
    * Be more explicit with common PYTHONPATH
    
    * Fix python path for task_python_vta_fsim.sh properly
    
    * Fix nit in documentation.
---
 docker/bash.sh                                      |  1 +
 docker/build.sh                                     |  1 +
 docker/with_the_same_user                           |  1 +
 docs/contribute/pull_request.rst                    |  3 +++
 .../{task_python_topi.sh => setup-pytest-env.sh}    | 15 ++++-----------
 tests/scripts/task_python_docs.sh                   |  1 +
 tests/scripts/task_python_frontend.sh               | 20 ++++++++++----------
 tests/scripts/task_python_integration.sh            | 21 +++++++++++----------
 tests/scripts/task_python_nightly.sh                |  4 ++--
 tests/scripts/task_python_topi.sh                   |  5 ++---
 tests/scripts/task_python_unittest.sh               |  6 +++---
 tests/scripts/task_python_vta_fsim.sh               |  8 ++++----
 tests/scripts/task_python_vta_tsim.sh               |  8 ++++----
 13 files changed, 47 insertions(+), 47 deletions(-)

diff --git a/docker/bash.sh b/docker/bash.sh
index 61823f9..a6aab53 100755
--- a/docker/bash.sh
+++ b/docker/bash.sh
@@ -89,6 +89,7 @@ ${DOCKER_BINARY} run --rm --pid=host\
     -e "CI_BUILD_GROUP=$(id -g -n)" \
     -e "CI_BUILD_GID=$(id -g)" \
     -e "PYTHONPATH=python:topi/python"\
+    -e "CI_PYTEST_ADD_OPTIONS=$CI_PYTEST_ADD_OPTIONS" \
     ${CUDA_ENV}\
     ${CI_DOCKER_EXTRA_PARAMS[@]} \
     ${DOCKER_IMAGE_NAME}\
diff --git a/docker/build.sh b/docker/build.sh
index defa282..d5925dc 100755
--- a/docker/build.sh
+++ b/docker/build.sh
@@ -162,6 +162,7 @@ ${DOCKER_BINARY} run --rm --pid=host \
     -e "CI_BUILD_UID=$(id -u)" \
     -e "CI_BUILD_GROUP=$(id -g -n)" \
     -e "CI_BUILD_GID=$(id -g)" \
+    -e "CI_PYTEST_ADD_OPTIONS=$CI_PYTEST_ADD_OPTIONS" \
     ${CUDA_ENV}\
     ${CI_DOCKER_EXTRA_PARAMS[@]} \
     ${DOCKER_IMG_NAME} \
diff --git a/docker/with_the_same_user b/docker/with_the_same_user
index 1288afd..2338f63 100644
--- a/docker/with_the_same_user
+++ b/docker/with_the_same_user
@@ -41,6 +41,7 @@ getent passwd "${CI_BUILD_UID}" || adduser --gid "${CI_BUILD_GID}" --uid "${CI_B
     --gecos "${CI_BUILD_USER} (generated by with_the_same_user script)" \
     --disabled-password --home "${CI_BUILD_HOME}" --quiet "${CI_BUILD_USER}"
 usermod -a -G sudo "${CI_BUILD_USER}"
+# This is a grotesque hack to get PYTEST_ADD_OPTS available to all task scripts.
 echo "${CI_BUILD_USER} ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/90-nopasswd-sudo
 
 if [[ ! -z $CUDA_VISIBLE_DEVICES ]]; then
diff --git a/docs/contribute/pull_request.rst b/docs/contribute/pull_request.rst
index 51626a1..25dc0da 100644
--- a/docs/contribute/pull_request.rst
+++ b/docs/contribute/pull_request.rst
@@ -118,3 +118,6 @@ If you want to run a single test:
   rm -rf python/tvm/*.pyc python/tvm/*/*.pyc python/tvm/*/*/*.pyc
 
   TVM_FFI=ctypes python -m pytest -v tests/python/unittest/test_pass_storage_rewrite.py
+
+  # Additionally if you want to run a single test, for example test_all_elemwise inside a file.
+  TVM_FFI=ctypes python -m pytest -v -k "test_all_elemwise" tests/python/frontend/tflite/test_forward.py
diff --git a/tests/scripts/task_python_topi.sh b/tests/scripts/setup-pytest-env.sh
similarity index 82%
copy from tests/scripts/task_python_topi.sh
copy to tests/scripts/setup-pytest-env.sh
index 5e5fcb8..36d0956 100755
--- a/tests/scripts/task_python_topi.sh
+++ b/tests/scripts/setup-pytest-env.sh
@@ -16,15 +16,8 @@
 # specific language governing permissions and limitations
 # under the License.
 
-set -e
 set -u
-
-export PYTHONPATH=python:topi/python
-
-# Rebuild cython
-make cython3
-
-# cleanup pycache
-find . -type f -path "*.pyc" | xargs rm -f
-
-python3 -m pytest -v topi/tests/python
+set -e
+export TVM_PATH=`pwd`
+export PYTHONPATH=${TVM_PATH}/python:${TVM_PATH}/topi/python
+export PYTEST_ADDOPTS="-v $CI_PYTEST_ADD_OPTIONS"
diff --git a/tests/scripts/task_python_docs.sh b/tests/scripts/task_python_docs.sh
index d24ed1a..819961d 100755
--- a/tests/scripts/task_python_docs.sh
+++ b/tests/scripts/task_python_docs.sh
@@ -19,6 +19,7 @@
 set -e
 set -u
 
+source tests/scripts/setup-pytest-env.sh
 # cleanup old states
 rm -rf docs/_build
 mkdir -p docs/_build/html
diff --git a/tests/scripts/task_python_frontend.sh b/tests/scripts/task_python_frontend.sh
index 862de5a..46cb1bb 100755
--- a/tests/scripts/task_python_frontend.sh
+++ b/tests/scripts/task_python_frontend.sh
@@ -19,7 +19,7 @@
 set -e
 set -u
 
-export PYTHONPATH=python:topi/python
+source tests/scripts/setup-pytest-env.sh
 # to avoid openblas threading error
 export TVM_BIND_THREADS=0
 export OMP_NUM_THREADS=1
@@ -30,28 +30,28 @@ find . -type f -path "*.pyc" | xargs rm -f
 make cython3
 
 echo "Running relay TFLite frontend test..."
-python3 -m pytest -v tests/python/frontend/tflite
+python3 -m pytest tests/python/frontend/tflite
 
 echo "Running relay MXNet frontend test..."
-python3 -m pytest -v tests/python/frontend/mxnet
+python3 -m pytest tests/python/frontend/mxnet
 
 echo "Running relay Keras frontend test..."
-python3 -m pytest -v tests/python/frontend/keras
+python3 -m pytest tests/python/frontend/keras
 
 echo "Running relay ONNX frontend test..."
-python3 -m pytest -v tests/python/frontend/onnx
+python3 -m pytest tests/python/frontend/onnx
 
 echo "Running relay CoreML frontend test..."
-python3 -m pytest -v tests/python/frontend/coreml
+python3 -m pytest tests/python/frontend/coreml
 
 echo "Running relay Tensorflow frontend test..."
-python3 -m pytest -v tests/python/frontend/tensorflow
+python3 -m pytest tests/python/frontend/tensorflow
 
 echo "Running relay caffe2 frontend test..."
-python3 -m pytest -v tests/python/frontend/caffe2
+python3 -m pytest tests/python/frontend/caffe2
 
 echo "Running relay DarkNet frontend test..."
-python3 -m pytest -v tests/python/frontend/darknet
+python3 -m pytest tests/python/frontend/darknet
 
 echo "Running relay PyTorch frontend test..."
-python3 -m pytest -v tests/python/frontend/pytorch
+python3 -m pytest tests/python/frontend/pytorch
diff --git a/tests/scripts/task_python_integration.sh b/tests/scripts/task_python_integration.sh
index cfd6bd0..296f933 100755
--- a/tests/scripts/task_python_integration.sh
+++ b/tests/scripts/task_python_integration.sh
@@ -19,7 +19,8 @@
 set -e
 set -u
 
-export PYTHONPATH=`pwd`/python:`pwd`/topi/python:`pwd`/apps/extension/python
+source tests/scripts/setup-pytest-env.sh
+export PYTHONPATH=${PYTHONPATH}:${TVM_PATH}/apps/extension/python
 export LD_LIBRARY_PATH="build:${LD_LIBRARY_PATH:-}"
 export TVM_BIND_THREADS=0
 export TVM_NUM_THREADS=2
@@ -42,26 +43,26 @@ rm -rf lib
 make
 cd ../..
 
-TVM_FFI=cython python3 -m pytest -v apps/extension/tests
-TVM_FFI=ctypes python3 -m pytest -v apps/extension/tests
+TVM_FFI=cython python3 -m pytest apps/extension/tests
+TVM_FFI=ctypes python3 -m pytest apps/extension/tests
 
 # Test dso plugin
 cd apps/dso_plugin_module
 rm -rf lib
 make
 cd ../..
-TVM_FFI=cython python3 -m pytest -v apps/dso_plugin_module
-TVM_FFI=ctypes python3 -m pytest -v apps/dso_plugin_module
+TVM_FFI=cython python3 -m pytest apps/dso_plugin_module
+TVM_FFI=ctypes python3 -m pytest apps/dso_plugin_module
 
 # Do not enable TensorFlow op
 # TVM_FFI=cython sh prepare_and_test_tfop_module.sh
 # TVM_FFI=ctypes sh prepare_and_test_tfop_module.sh
 
-TVM_FFI=ctypes python3 -m pytest -v tests/python/integration
-TVM_FFI=ctypes python3 -m pytest -v tests/python/contrib
+TVM_FFI=ctypes python3 -m pytest tests/python/integration
+TVM_FFI=ctypes python3 -m pytest tests/python/contrib
 
-TVM_FFI=ctypes python3 -m pytest -v tests/python/relay
+TVM_FFI=ctypes python3 -m pytest tests/python/relay
 
 # Do not enable OpenGL
-# TVM_FFI=cython python -m pytest -v tests/webgl
-# TVM_FFI=ctypes python3 -m pytest -v tests/webgl
+# TVM_FFI=cython python -m pytest tests/webgl
+# TVM_FFI=ctypes python3 -m pytest tests/webgl
diff --git a/tests/scripts/task_python_nightly.sh b/tests/scripts/task_python_nightly.sh
index 6ada8af..c2c0eab 100755
--- a/tests/scripts/task_python_nightly.sh
+++ b/tests/scripts/task_python_nightly.sh
@@ -19,7 +19,7 @@
 set -e
 set -u
 
-export PYTHONPATH=python:topi/python
+source tests/scripts/setup-pytest-env.sh
 
 # Rebuild cython
 make cython3
@@ -27,4 +27,4 @@ make cython3
 # cleanup pycache
 find . -type f -path "*.pyc" | xargs rm -f
 
-python3 -m pytest -v topi/tests/python/nightly
+python3 -m pytest topi/tests/python/nightly
diff --git a/tests/scripts/task_python_topi.sh b/tests/scripts/task_python_topi.sh
index 5e5fcb8..66585d5 100755
--- a/tests/scripts/task_python_topi.sh
+++ b/tests/scripts/task_python_topi.sh
@@ -19,12 +19,11 @@
 set -e
 set -u
 
-export PYTHONPATH=python:topi/python
-
+source tests/scripts/setup-pytest-env.sh
 # Rebuild cython
 make cython3
 
 # cleanup pycache
 find . -type f -path "*.pyc" | xargs rm -f
 
-python3 -m pytest -v topi/tests/python
+python3 -m pytest topi/tests/python
diff --git a/tests/scripts/task_python_unittest.sh b/tests/scripts/task_python_unittest.sh
index a5ad5ca..622646b 100755
--- a/tests/scripts/task_python_unittest.sh
+++ b/tests/scripts/task_python_unittest.sh
@@ -19,11 +19,11 @@
 set -e
 set -u
 
-export PYTHONPATH=python:topi/python
+source tests/scripts/setup-pytest-env.sh
 
 # cleanup pycache
 find . -type f -path "*.pyc" | xargs rm -f
 
-TVM_FFI=ctypes python3 -m pytest -v tests/python/unittest
+TVM_FFI=ctypes python3 -m pytest tests/python/unittest
 make cython3
-TVM_FFI=cython python3 -m pytest -v tests/python/unittest
+TVM_FFI=cython python3 -m pytest tests/python/unittest
diff --git a/tests/scripts/task_python_vta_fsim.sh b/tests/scripts/task_python_vta_fsim.sh
index f269866..f48b7d6 100755
--- a/tests/scripts/task_python_vta_fsim.sh
+++ b/tests/scripts/task_python_vta_fsim.sh
@@ -19,8 +19,8 @@
 set -e
 set -u
 
-export TVM_PATH=`pwd`
-export PYTHONPATH=${TVM_PATH}/python:${TVM_PATH}/vta/python:${TVM_PATH}/topi/python
+source tests/scripts/setup-pytest-env.sh
+export PYTHONPATH=${PYTHONPATH}:${TVM_PATH}/vta/python
 export VTA_HW_PATH=`pwd`/3rdparty/vta-hw
 
 # cleanup pycache
@@ -36,8 +36,8 @@ cp ${VTA_HW_PATH}/config/fsim_sample.json ${VTA_HW_PATH}/config/vta_config.json
 
 # Run unit tests in functional/fast simulator
 echo "Running unittest in fsim..."
-python3 -m pytest -v ${TVM_PATH}/vta/tests/python/unittest
+python3 -m pytest ${TVM_PATH}/vta/tests/python/unittest
 
 # Run unit tests in functional/fast simulator
 echo "Running integration test in fsim..."
-python3 -m pytest -v ${TVM_PATH}/vta/tests/python/integration
+python3 -m pytest ${TVM_PATH}/vta/tests/python/integration
diff --git a/tests/scripts/task_python_vta_tsim.sh b/tests/scripts/task_python_vta_tsim.sh
index 4936674..8e9a5ea 100755
--- a/tests/scripts/task_python_vta_tsim.sh
+++ b/tests/scripts/task_python_vta_tsim.sh
@@ -19,8 +19,8 @@
 set -e
 set -u
 
-export TVM_PATH=`pwd`
-export PYTHONPATH=${TVM_PATH}/python:${TVM_PATH}/vta/python:${TVM_PATH}/topi/python
+source tests/scripts/setup-pytest-env.sh
+export PYTHONPATH=${PYTHONPATH}:${TVM_PATH}/vta/python
 export VTA_HW_PATH=`pwd`/3rdparty/vta-hw
 
 # cleanup pycache
@@ -51,11 +51,11 @@ make -C ${VTA_HW_PATH}/hardware/chisel USE_THREADS=0 lib
 
 # Run unit tests in cycle accurate simulator
 echo "Running unittest in tsim..."
-python3 -m pytest -v ${TVM_PATH}/vta/tests/python/unittest
+python3 -m pytest ${TVM_PATH}/vta/tests/python/unittest
 
 # Run unit tests in cycle accurate simulator
 echo "Running integration test in tsim..."
-python3 -m pytest -v ${TVM_PATH}/vta/tests/python/integration
+python3 -m pytest ${TVM_PATH}/vta/tests/python/integration
 
 # Reset default fsim simulation
 cp ${VTA_HW_PATH}/config/fsim_sample.json ${VTA_HW_PATH}/config/vta_config.json