Skip to content
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

Speed up CI tests #407

Merged
merged 1 commit into from
Oct 5, 2021
Merged
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
37 changes: 21 additions & 16 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
pytest:
image: gitlab-registry.cern.ch/fastmachinelearning/hls4ml-testing:0.2.base
stages:
- generate
- trigger
- test

generator:
stage: generate
image: python:3.7-alpine
tags:
- docker
before_script:
- source ~/.bashrc
- git submodule init
- git submodule update
- conda activate hls4ml-testing
- pip install .[profiling]
script:
- pip install pyyaml
script:
- cd test/pytest
- pytest -rA --cov-report xml --cov-report term --cov=hls4ml --junitxml=report.xml --randomly-seed=42 --randomly-dont-reorganize --randomly-dont-reset-seed
- python generate_ci_yaml.py
artifacts:
when: always
reports:
junit:
- test/pytest/report.xml
cobertura:
- test/pytest/coverage.xml
paths:
- test/pytest/hls4mlprj*.tar.gz
- test/pytest/pytests.yml

pytests:
stage: trigger
trigger:
include:
- local: test/pytest/ci-template.yml
- artifact: test/pytest/pytests.yml
job: generator
strategy: depend
22 changes: 22 additions & 0 deletions test/pytest/ci-template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.pytest:
stage: test
image: gitlab-registry.cern.ch/fastmachinelearning/hls4ml-testing:0.2.base
tags:
- docker
before_script:
- source ~/.bashrc
- if [ $EXAMPLEMODEL == 1 ]; then git submodule init; git submodule update; fi
- conda activate hls4ml-testing
- pip install .[profiling]
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
artifacts:
when: always
reports:
junit:
- test/pytest/report.xml
cobertura:
- test/pytest/coverage.xml
paths:
- test/pytest/hls4mlprj*.tar.gz
33 changes: 33 additions & 0 deletions test/pytest/generate_ci_yaml.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import yaml
import glob

'''
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.{}:
extends: .pytest
variables:
PYTESTFILE: {}
EXAMPLEMODEL: {}
"""

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

yml = None
tests = glob.glob('test_*.py')
for test in tests:
name = test.replace('test_','').replace('.py','')
new_yml = yaml.safe_load(template.format(name, 'test_{}.py'.format(name), int(uses_example_model(test))))
if yml is None:
yml = new_yml
else:
yml.update(new_yml)

yamlfile = open('pytests.yml', 'w')
yaml.safe_dump(yml, yamlfile)