Skip to content

Commit

Permalink
Added finish step script to make html from info files
Browse files Browse the repository at this point in the history
Running script when WITH_COVERAGE is 1. This script will run after all
tests and will get an html report for the coverage from all the info
files.

Fixes: eclipse-bluechi#397
Signed-off-by: Artiom Divak <[email protected]>
  • Loading branch information
ArtiomDivak authored and engelmi committed Dec 14, 2023
1 parent 001a0af commit 8e2d93e
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,28 @@ cd ~/bluechi/tests
tmt run -v -eCONTAINER_USED=integration-test-local
```

## Creating code coverage report from integration tests execution

To be able to produce code coverage report from integration tests execution you need to build BlueChi RPMs with code
coverage support:

```shell
cd ~/bluechi
skipper make rpm WITH_COVERAGE=1
createrepo_c ~/bluechi/tests/bluechi-rpms
```

When done, you need to run integration tests with code coverage report enabled:

```shell
tmt run -v -eCONTAINER_USED=integration-test-local -eWITH_COVERAGE=1
```

After the integration tests finishes, the code coverage html result can be found in `res` subdirectory inside the tmt
execution result directory, for example:

`/var/tmp/tmt/run-001/plans/tier0/report/default-0/report`

## Developing integration tests

### Code Style
Expand Down
1 change: 1 addition & 0 deletions tests/bluechi_test/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def gather_coverage(self, data_coverage_dir: str) -> None:

result, output = self.container.exec_run(
f"geninfo {gcda_file_location} -b {src_file_location} -o {coverage_file_name}")

self.get_file(f"/{coverage_file_name}", data_coverage_dir)

def cleanup(self):
Expand Down
5 changes: 5 additions & 0 deletions tests/plans/tier0.fmf
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ execute:
how: tmt
report:
how: junit
finish:
- name: Create coverage report
how: shell
script: |
pytest -svv scripts/create_coverage_report.py
51 changes: 51 additions & 0 deletions tests/scripts/create_coverage_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# SPDX-License-Identifier: LGPL-2.1-or-later

import os
from typing import Dict
from bluechi_test.util import read_file
import subprocess

from bluechi_test.test import BluechiTest
from bluechi_test.container import BluechiControllerContainer, BluechiNodeContainer
from bluechi_test.config import BluechiControllerConfig, BluechiNodeConfig


def merge_all_info_files(start_path):
add_merged_file = ""
all_bluchi_coverage_files = subprocess.check_output(
f"find {start_path} -name bluechi-coverage", shell=True).decode()
all_bluchi_coverage_files = all_bluchi_coverage_files.split("\n")
all_bluchi_coverage_files.pop()
for bluechi_coverage_dir in all_bluchi_coverage_files:
for path in os.listdir(bluechi_coverage_dir):
if "info" in path:
info_file = os.path.join(bluechi_coverage_dir, path)
if os.path.isfile(info_file):
if os.stat(info_file).st_size != 0:
os.system(
f'lcov --add-tracefile {info_file} {add_merged_file} -o merged.info > /dev/null')
add_merged_file = "-a merged.info"


def exec(ctrl: BluechiControllerContainer, nodes: Dict[str, BluechiNodeContainer]):
path_to_info_files = os.environ["TMT_TREE"].split('/tree')[0] + "/execute/data/"
path_to_tests_results = os.environ["TMT_TREE"].split('/tree')[0] + "/report/default-0"
merge_file_name = "merged.info"
merge_dir = "/tmp"
report_dir_name = "/report"

merge_all_info_files(path_to_info_files)
content = read_file(merge_file_name)
ctrl.create_file(merge_dir, merge_file_name, content)
ctrl.exec_run(f"genhtml {merge_dir}/{merge_file_name} --output-directory={report_dir_name}")
ctrl.get_file(report_dir_name, path_to_tests_results)


def test_create_coverag_report(
bluechi_test: BluechiTest,
bluechi_ctrl_default_config: BluechiControllerConfig,
bluechi_node_default_config: BluechiNodeConfig):

if (os.getenv("WITH_COVERAGE") == "1"):
bluechi_test.set_bluechi_controller_config(bluechi_ctrl_default_config)
bluechi_test.run(exec)

0 comments on commit 8e2d93e

Please sign in to comment.