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

CI: Get coverage of filecheck tests #256

Merged
merged 2 commits into from
Dec 12, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ omit =
xdsl/_version.py
concurrency = multiprocessing
parallel = True
source =
xdsl/
tests/



[report]
# Regexes for lines to exclude from consideration
Expand Down
8 changes: 2 additions & 6 deletions .github/workflows/ci-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,10 @@ jobs:
pip install --upgrade pip
- name: Install the package locally
run: pip install -e .[extras]
- name: Test with pytest and check code coverage
- name: Test with pytest
run: |
pytest --cov --cov-config=.coveragerc --cov-report=xml tests/
pytest
- name: Execute lit tests
run: |
export PYTHONPATH=$(pwd)
lit -v tests/filecheck/
math-fehr marked this conversation as resolved.
Show resolved Hide resolved
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
32 changes: 27 additions & 5 deletions .github/workflows/ci-mlir.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ jobs:
pip install --upgrade pip

- name: Install the package locally
run: |
pip install -e ${GITHUB_WORKSPACE}/xdsl
run: pip install -e .[extras]

- name: MLIR Build Setup
run: |
Expand All @@ -77,10 +76,33 @@ jobs:
cd llvm-project/build
cmake --build . --target mlir-opt MLIRPythonModules

- name: Test
- name: Test with pytest and generate code coverage
run: |
# Add the Python Bindings to the pythonpath
cd xdsl
# Add the MLIR Python bindings to the PYTHONPATH
export PYTHONPATH=$PYTHONPATH:${GITHUB_WORKSPACE}/llvm-project/build/tools/mlir/python_packages/mlir_core
pytest --cov --cov-config=.coveragerc tests

- name: Execute lit tests
run: |
cd xdsl
export PYTHONPATH=$(pwd)
# Add mlir-opt to the path
export PATH=$PATH:${GITHUB_WORKSPACE}/llvm-project/build/bin/
lit -v ${GITHUB_WORKSPACE}/xdsl/tests/filecheck/mlir-conversion/with-bindings/
# Add the MLIR Python bindings to the PYTHONPATH
export PYTHONPATH=$PYTHONPATH:${GITHUB_WORKSPACE}/llvm-project/build/tools/mlir/python_packages/mlir_core
lit -v tests/filecheck/ -DCOVERAGE -DCOVERAGE_CONFIG=$(pwd)/.coveragerc

- name: Combine coverage data
run: |
coverage combine --append $(find xdsl/tests/filecheck -type d)
coverage report --data-file=xdsl/.coverage
coverage xml --data-file=xdsl/.coverage

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
fail_ci_if_error: true
verbose: true
directory: ${GITHUB_WORKSPACE}/../
files: coverage.xml
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ pytest<8.0
filecheck<0.0.23
lit<16.0.0
frozenlist<1.4.*
coverage<7.0.0
6 changes: 5 additions & 1 deletion tests/filecheck/lit.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ else:

config.environment["PATH"] = config.test_source_root + "/../../xdsl/tools/:" + os.environ["PATH"]


if "COVERAGE" in lit_config.params:
if "COVERAGE_CONFIG" in lit_config.params:
config.substitutions.append(('xdsl-opt', "xdsl-opt --generate-coverage --coverage-config=" + lit_config.params["COVERAGE_CONFIG"]))
else:
config.substitutions.append(('xdsl-opt', "xdsl-opt --generate-coverage"))
27 changes: 27 additions & 0 deletions xdsl/xdsl_opt_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import sys
import os
from io import IOBase, StringIO
import coverage

from xdsl.ir import MLContext
from xdsl.parser import Parser
Expand Down Expand Up @@ -69,6 +70,14 @@ def run(self):
"""
Executes the different steps.
"""
if self.args.generate_coverage:
cov = coverage.Coverage(config_file=self.args.coverage_config,
auto_data=True,
data_file='.coverage',
data_suffix=True)

cov.start()

module = self.parse_input()
if not self.args.verify_diagnostics:
self.apply_passes(module)
Expand All @@ -82,6 +91,9 @@ def run(self):
contents = self.output_resulting_program(module)
self.print_to_output_stream(contents)

if self.args.generate_coverage:
cov.stop()

def register_all_arguments(self, arg_parser: argparse.ArgumentParser):
"""
Registers all the command line arguments that are used by this tool.
Expand Down Expand Up @@ -155,6 +167,21 @@ def register_all_arguments(self, arg_parser: argparse.ArgumentParser):
action='store_true',
help="Allow the parsing of unregistered operations.")

arg_parser.add_argument(
"--generate-coverage",
default=False,
action='store_true',
help="Generate the xDSL code coverage for this run.")

arg_parser.add_argument(
"--coverage-config",
type=str,
default=False,
required=False,
help=
"Link to the coverage config file. This flag only takes effect if `--generate-config` was specified."
)

def register_all_dialects(self):
"""
Register all dialects that can be used.
Expand Down