Skip to content

Commit

Permalink
add test for expected logs from loader.py
Browse files Browse the repository at this point in the history
  • Loading branch information
h-vetinari committed Feb 11, 2021
1 parent 18cbb00 commit 019fdef
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -185,29 +185,35 @@ outputs:
imports:
- faiss
commands:
# the linux & windows CI agents support AVX2, so by default, we expect faiss will
# load the library with AVX2-support, see faiss/python/loader.py;
{% if not osx %}
# the linux & windows CI agents support AVX2 (OSX doesn't yet), so by default,
# we expect faiss will load the library with AVX2-support, see
# https://github.com/facebookresearch/faiss/blob/master/faiss/python/loader.py#L48-L60
- python -c "from numpy.core._multiarray_umath import __cpu_features__; print(f'Testing version with AVX2-support - ' + str(__cpu_features__['AVX2']))"
- pytest tests --log-file-level=INFO --log-file=log.txt
# print logfile to see logger-messages from loader.py (sleep so log has time to print)
# print logfile for completeness (sleep so log has time to print)
- cat log.txt && sleep 2 # [not win]
- type log.txt # [win]
# Azure OSX agents currently do not support AVX2, so the above will have
# tested the library without AVX2 support; pointless to do so again below
{% if not osx %}
# ensure that expected logger-messages from loader.py is present;
# avoid final '\n', as well as the first 35 = len('INFO faiss.loader:loader.py:51 ')
- python -c "q = open('log.txt').readlines(); import sys; sys.exit(0 if 'Loading faiss with AVX2 support.' in [x[35:-1] for x in q] else 1)"
# ensure that we did not fall through with an exception, see link to loader.py above
- python -c "q = open('log.txt').readlines(); import sys; sys.exit(1 if 'Loading faiss.' in [x[35:-1] for x in q] else 0)"
# OTOH, we also want to test the packaged library without AVX2 support;
# the advantage of the CPU feature detection in numpy is that it can be
# deactivated, see documentation of NPY_DISABLE_CPU_FEATURES upstream;
# however, the dict of CPU features is determined (and frozen) upon the
# first import, so we cannot run both variants in a single run_test.py
- export NPY_DISABLE_CPU_FEATURES=AVX2 # [not win]
- set NPY_DISABLE_CPU_FEATURES=AVX2 # [win]
{% endif %}
- python -c "from numpy.core._multiarray_umath import __cpu_features__; print(f'Testing version with AVX2-support - ' + str(__cpu_features__['AVX2']))"
# rerun test suite again without AVX2 support
- pytest tests --log-file-level=INFO --log-file=log.txt
- cat log.txt # [not win]
- type log.txt # [win]
{% endif %}
# opposite test to above, this should have run without AVX2
- python -c "q = open('log.txt').readlines(); import sys; sys.exit(0 if 'Loading faiss.' in [x[35:-1] for x in q] else 1)"

# running the following test requires an actual GPU device, which is not available in CI
# - pytest faiss/gpu/test/
Expand Down

0 comments on commit 019fdef

Please sign in to comment.