[SOLVED] Unit tests do not work

When I was trying to make a PR, I had a problem in unit testing. According to the document I did unit testing both for c++ and python, but all failed.

For C++, I could not set up gtest, like the following;

TakeonoMacBook-puro:tvm takeo$ CACHE_PREFIX=. make -f 3rdparty/dmlc-core/scripts/packages.mk gtest
rm -rf gtest release-1.7.0.zip
wget https://github.com/google/googletest/archive/release-1.7.0.zip
--2018-10-18 01:54:34--  https://github.com/google/googletest/archive/release-1.7.0.zip
github.com (github.com) をDNSに問いあわせています... 192.30.255.112, 192.30.255.113
github.com (github.com)|192.30.255.112|:443 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 302 Found

(snip)

   creating: googletest-release-1.7.0/xcode/gtest.xcodeproj/
  inflating: googletest-release-1.7.0/xcode/gtest.xcodeproj/project.pbxproj
mv googletest-release-1.7.0 gtest
cd gtest; g++ -Iinclude -pthread -c src/gtest-all.cc -o gtest-all.o; cd ..
src/gtest-all.cc:42:10: fatal error: 'src/gtest.cc' file not found
#include "src/gtest.cc"
         ^~~~~~~~~~~~~~
1 error generated.
ar -rv libgtest.a gtest/gtest-all.o
a - gtest/gtest-all.o
ar: gtest/gtest-all.o: No such file or directory
make: *** [include/gtest] Error 1

And for Python, 80 tests out of 88 failed, due to lack of tvm._ffi._cy3.core module, like:

======================================================================
ERROR: Failure: ModuleNotFoundError (No module named 'tvm._ffi._cy3.core')
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/takeo/.pyenv/versions/3.6.3/lib/python3.6/site-packages/nose/failure.py", line 39, in runTest
    raise self.exc_val.with_traceback(self.tb)
  File "/Users/takeo/.pyenv/versions/3.6.3/lib/python3.6/site-packages/nose/loader.py", line 418, in loadTestsFromName
    addr.filename, addr.module)
  File "/Users/takeo/.pyenv/versions/3.6.3/lib/python3.6/site-packages/nose/importer.py", line 47, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/Users/takeo/.pyenv/versions/3.6.3/lib/python3.6/site-packages/nose/importer.py", line 94, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/Users/takeo/.pyenv/versions/3.6.3/lib/python3.6/imp.py", line 235, in load_module
    return load_source(name, filename, file)
  File "/Users/takeo/.pyenv/versions/3.6.3/lib/python3.6/imp.py", line 172, in load_source
    module = _load(spec)
  File "<frozen importlib._bootstrap>", line 684, in _load
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/Users/takeo/work/tvm/tests/python/unittest/test_schedule_tensorize.py", line 1, in <module>
    import tvm
  File "/Users/takeo/work/tvm/python/tvm/__init__.py", line 5, in <module>
    from . import tensor
  File "/Users/takeo/work/tvm/python/tvm/tensor.py", line 4, in <module>
    from ._ffi.node import NodeBase, NodeGeneric, register_node, convert_to_node
  File "/Users/takeo/work/tvm/python/tvm/_ffi/node.py", line 17, in <module>
    from ._cy3.core import _register_node, NodeBase as _NodeBase
ModuleNotFoundError: No module named 'tvm._ffi._cy3.core'

Is there any problem in my environment?

Note: The python version is 3.6.3 on macOS 10.13.6.

C++

As I mentioned in https://github.com/dmlc/tvm/pull/1868, we need to update dmlc-core version in tvm for c++. For now you can probably just pull the latest via:

git submodule update --remote

The try the commands again. @tqchen what’s the policy/schedule of updating 3rd party dependencies?

Python

I just installed 3.6.3 on my mac and follow the instructions for test tests/python/unittest/test_schedule_tensorize.py:

➜  TVM_FFI=ctypes python -m nose -v tests/python/unittest/test_schedule_tensorize.py

test_schedule_tensorize.test_tensorize_vadd ... ok

test_schedule_tensorize.test_tensorize_matmul ... ok

test_schedule_tensorize.test_tensorize_op ... ok

----------------------------------------------------------------------
Ran 3 tests in 0.046s

I suggest that you use virtualenv to create a clean isolated python environment for tvm and don’t worry about these dependency issues.

Command I use:

pyenv shell 3.6.3

# create a virtual environment for tvm
python3 -m venv tvm_3.6.3

# activate the virtual environment
source tvm_3.6.3/bin/activate

export PYTHONPATH=python:topi/python
TVM_FFI=ctypes python -m nose -v tests/python/unittest/test_schedule_tensorize.py

We can update submodule when necessary. Since submodules are relatively stable and there won’t be too many updates

@wweic I tried both tests for C++ and Python as you suggested, and all worked well. Thank you. (I must be somehow in a panic.)