Skip to content

test cvmfs availability in pytests #1217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions test/pytest/ci-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
- git submodule update --init --recursive hls4ml/templates/catapult/
- if [ $EXAMPLEMODEL == 1 ]; then git submodule update --init example-models; fi
- pip install .[testing,sr,optimization]
- sudo yum install libtinfo.so.6 -y
- sudo ln -s /lib64/libtinfo.so.6 /lib64/libtinfo.so.5
- sudo ln -s /cvmfs/projects.cern.ch/hls4ml/vivado/2020.1_v1/vivado-2020.1_v1/opt/Xilinx /opt/Xilinx
- source /opt/Xilinx/Vivado/2020.1/settings64.sh
script:
- cd test/pytest
- pytest $PYTESTFILE -rA --cov-report xml --cov-report term --cov=hls4ml --junitxml=report.xml --randomly-seed=42 --randomly-dont-reorganize --randomly-dont-reset-seed
Expand Down
78 changes: 7 additions & 71 deletions test/pytest/generate_ci_yaml.py
Original file line number Diff line number Diff line change
@@ -1,84 +1,20 @@
import itertools
import os
from pathlib import Path

import yaml

'''
Create a Gitlab CI yml file with a separate entry for each test_* file
in the pytests directory to parallelise the CI jobs.
'''


template = """
pytest.{}:
pytest.test_cvmfs_mount:
extends: .pytest
variables:
PYTESTFILE: {}
EXAMPLEMODEL: {}
PYTESTFILE: test_keras_api.py
EXAMPLEMODEL: 0
"""


n_test_files_per_yml = int(os.environ.get('N_TESTS_PER_YAML', 4))

# Blacklisted tests will be skipped
BLACKLIST = {'test_reduction'}

# Long-running tests will not be bundled with other tests
LONGLIST = {'test_hgq_layers', 'test_hgq_players', 'test_qkeras', 'test_pytorch_api'}


def path_to_name(test_path):
path = Path(test_path)
name = path.stem.replace('test_', '')
return name


def batched(iterable, chunk_size):
iterator = iter(iterable)
while chunk := tuple(itertools.islice(iterator, chunk_size)):
yield chunk


def uses_example_model(test_filename):
with open(test_filename) as f:
content = f.read()
return 'example-models' in content


def generate_test_yaml(test_root='.'):
test_root = Path(test_root)
test_paths = [path for path in test_root.glob('**/test_*.py') if path.stem not in (BLACKLIST | LONGLIST)]
need_example_models = [uses_example_model(path) for path in test_paths]

idxs = list(range(len(need_example_models)))
idxs = sorted(idxs, key=lambda i: f'{need_example_models[i]}_{path_to_name(test_paths[i])}')

yml = None
for batch_idxs in batched(idxs, n_test_files_per_yml):
batch_paths: list[Path] = [test_paths[i] for i in batch_idxs]
names = [path_to_name(path) for path in batch_paths]
name = '+'.join(names)
test_files = ' '.join([str(path.relative_to(test_root)) for path in batch_paths])
batch_need_example_model = int(any([need_example_models[i] for i in batch_idxs]))
diff_yml = yaml.safe_load(template.format(name, test_files, batch_need_example_model))
if yml is None:
yml = diff_yml
else:
yml.update(diff_yml)

test_paths = [path for path in test_root.glob('**/test_*.py') if path.stem in LONGLIST]
for path in test_paths:
name = path.stem.replace('test_', '')
test_file = str(path.relative_to(test_root))
needs_examples = uses_example_model(path)
diff_yml = yaml.safe_load(template.format(name, test_file, int(needs_examples)))
yml.update(diff_yml)

def generate_fixed_test_yaml():
yml = yaml.safe_load(template)
return yml


if __name__ == '__main__':
yml = generate_test_yaml(Path(__file__).parent)
yml = generate_fixed_test_yaml()
with open('pytests.yml', 'w') as yamlfile:
yaml.safe_dump(yml, yamlfile)
yaml.safe_dump(yml, yamlfile, default_flow_style=False)
Loading
Loading