Skip to content
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
117 changes: 117 additions & 0 deletions .github/workflows/generate-coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
name: Generate coverage data
on:
pull_request:
push:
branches: [master]

jobs:
generate-coverage:
name: Generate coverage and push to Coveralls.io
runs-on: ubuntu-20.04

env:
ONEAPI_ROOT: /opt/intel/oneapi
GTEST_ROOT: /home/runner/work/googletest-release-1.10.0/install

steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.6.0
with:
access_token: ${{ github.token }}

- name: Add Intel repository
run: |
wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB
sudo apt-key add GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB
rm GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB
sudo add-apt-repository "deb https://apt.repos.intel.com/oneapi all main"
sudo apt-get update

- name: Install Intel OneAPI
run: |
sudo apt-get install intel-oneapi-dpcpp-cpp-compiler
sudo apt-get install intel-oneapi-tbb

- name: Install CMake
run: |
sudo apt-get install cmake

- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: '3.8'
architecture: x64

- name: Cache Gtest
id: cache-gtest
uses: actions/cache@v2
with:
path: |
/home/runner/work/googletest-release-1.10.0/install
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('/home/runner/work/googletest-release-1.10.0/install/include/gtest/*') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-

- name: Install Gtest
if: steps.cache-gtest.outputs.cache-hit != 'true'
shell: bash -l {0}
run: |
cd /home/runner/work
wget https://github.com/google/googletest/archive/refs/tags/release-1.10.0.tar.gz
tar xf release-1.10.0.tar.gz
cd googletest-release-1.10.0
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/home/runner/work/googletest-release-1.10.0/install
make && make install

- name: Checkout repo
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Install Lcov
run: |
sudo apt-get install lcov

- name: Install dpctl dependencies
shell: bash -l {0}
run: |
pip install numpy cython setuptools pytest pytest-cov coverage

- name: Build dpctl with coverage
shell: bash -l {0}
run: |
source /opt/intel/oneapi/setvars.sh
python setup.py develop --coverage=True
python -c "import dpctl; print(dpctl.__version__); dpctl.lsplatform()"
pytest -q -ra --disable-warnings --cov dpctl --cov-report term-missing --pyargs dpctl -vv

- name: Install coverall dependencies
shell: bash -l {0}
run: |
sudo gem install coveralls-lcov
pip install coveralls

- name: Upload coverage data to coveralls.io
run: |
coveralls-lcov -v -n build_cmake/tests/dpctl.lcov > dpctl-c-api-coverage.json
coveralls --service=github --merge=dpctl-c-api-coverage.json
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_PARALLEL: true

coveralls:
name: Indicate completion to coveralls.io
needs: generate-coverage
runs-on: ubuntu-latest
container: python:3-slim
steps:
- name: Finished
run: |
pip3 install --upgrade coveralls
coveralls --finish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
93 changes: 48 additions & 45 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,20 @@ Install: `conda install clang-tools`
- Revision: `10.0.1`
- See the default configuration used by dpctl in `.clang-format`.

Run before each commit: `clang-format -style=file -i dpctl-capi/include/*.h dpctl-capi/include/Support/*.h dpctl-capi/source/*.cpp dpctl-capi/tests/*.cpp dpctl-capi/helper/include/*.h dpctl-capi/helper/source/*.cpp`
Run before each commit:

```bash
clang-format -style=file -i \
dpctl-capi/include/*.h \
dpctl-capi/include/Support/*.h \
dpctl-capi/source/*.cpp \
dpctl-capi/tests/*.cpp \
dpctl-capi/helper/include/*.h \
dpctl-capi/helper/source/*.cpp
```

> **_NOTE:_** A much simpler option is to use `pre-commit` and the
> `clang-format` hook that we provide.

### Python code style

Expand Down Expand Up @@ -121,61 +134,51 @@ Run before each commit: `bandit -r dpctl -lll`

## Code Coverage

Implement python, cython and c++ file coverage using `coverage` and `llvm-cov`
packages on Linux.

### Using Code Coverage

You need to install additional packages and add an environment variable to
cover:
- conda install cmake
- conda install coverage
- conda install conda-forge::lcov
- conda install conda-forge::gtest
- export CODE_COVERAGE=ON

CODE_COVERAGE allows you to build a debug version of dpctl and enable string
tracing, which allows you to analyze strings to create a coverage report.
It was added for the convenience of configuring the CI in the future.

Installing the dpctl package:
- python setup.py develop
Code coverage for both C and Python sources in dpctl is generated for each
pull request (PR). A PR cannot be merged if it leads to a drop in the code
coverage by more than five percentage points. *Ergo, do not forget to write
unit tests for your changes.* To check the code coverage for your code, follow
these steps:

It is important that there are no files of the old build in the folder.
Use `git clean -xdf` to clean up the working tree.
1. Install dependencies for C/C++ source.

The coverage report will appear during the build in the console. This report
contains information about c++ file coverage.
The `dpctl-c-api-coverage` folder will appear in the root folder after
installation. The folder contains a report on the coverage of c++ files in html
format.
For C/C++ source we require `lcov`, `llvm-cov`, and `llvm-profdata`. Note
that `llvm-cov` and `llvm-profdata` should be version 11.0 or higher. If you
have multiple `llvm-cov` tools installed, most likely because you have
multiple llvm installations, you should set the `LLVM_TOOLS_HOME`
environment variable to make sure the correct one is used to generate
coverage.

You need to run tests to cover the cython and python files:
- coverage run -m unittest dpctl.tests
2. Install dependencies for Python sources.

The required flags for the command coverage run are contained in the file
`.coveragerc`.
To generate the coverage data for dpctl's Python sources, you only need to
install `coverage`.

The simplest reporting is a textual summary produced with report:
- coverage report
3. Build dpctl with code coverage support.

For each module executed, the report shows the count of executable statements,
the number of those statements missed, and the resulting coverage, expressed as
a percentage.
```bash
python setup.py develop --coverage=True
pytest -q -ra --disable-warnings --cov dpctl --cov-report term-missing --pyargs dpctl -vv
coverage html
```

The `-m` flag also shows the line numbers of missing statements:
- coverage report -m
Note that code coverage builds the C sources with debug symbols. For this
reason, the coverage flag is only available with the `develop` mode of
`setup.py`.

To create an annotated HTML listings with coverage results:
- coverage html
The coverage results for the C and Python sources will be printed to the
terminal during the build (C API) and during the pytest execution (Python).
The detailed coverage reports for the C API is saved to the
`dpctl-c-api-coverage` directory. The Python coverage reports are saved to
the `htmlcov` directory.

The `htmlcov` folder will appear in the root folder of the project. It contains
reports on the coverage of python and cython files in html format.
The coverage data for every PR is also available online at
[coveralls.io](https://coveralls.io/github/IntelPython/dpctl).

Erase previously collected coverage data:
- coverage erase
> **_NOTE:_** Run `git clean -xdf` to clean up the working tree before running
> a fresh build with code coverage data generation.

### Error in the build process
## Error in the build process

An error occurs during the dcptl build with the CODE_COVERAGE environment
variable:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/)
[![Coverage Status](https://coveralls.io/repos/github/IntelPython/dpctl/badge.svg?branch=master)](https://coveralls.io/github/IntelPython/dpctl?branch=master)

What?
====
Expand Down
2 changes: 1 addition & 1 deletion scripts/build_for_develop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ set +xe

python setup.py clean --all
python setup.py develop --coverage=True
pytest -q -ra --disable-warnings --cov dpctl --cov-report term-missing --pyargs dpctl -vv --cov-config=.coveragerc
pytest -q -ra --disable-warnings --cov dpctl --cov-report term-missing --pyargs dpctl -vv