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

ghdl coverage report fails when base_path of file_name isn't there yet #924

Closed
Tracked by #997
schrolli opened this issue Mar 24, 2023 · 2 comments
Closed
Tracked by #997

Comments

@schrolli
Copy link

when generating code-coverage reports, the call to results.merge_coverage() fails when the supplied parameter file_name is a path, where the basepath doesn't exist yet.

In order to not clutter the source-path, i wanted to put all files and folders produced by the gcov/lcov chain into a subfolder of vunit_out.

how to reproduce

run-script with the call to results.merge_coverage in the

#!/usr/bin/env python3

from vunit import VUnit
import os

def post_run(results):
	merge_path = "vunit_out/coverage/coverage_data"
	#os.makedirs(merge_path, exist_ok = True)
	results.merge_coverage(file_name=merge_path)

VU = VUnit.from_argv()
VU.add_osvvm()

src_files = []

for file in os.listdir('.'):
	if os.path.isfile(file):
		if os.path.splitext(file)[1] == ".vhd":
			src_files.append(file)

LIB = VU.add_library("lib")
LIB.add_source_files(src_files)
LIB.set_compile_option("enable_coverage", True)

VU.set_compile_option("ghdl.a_flags", ["-frelaxed"])
VU.set_sim_option("ghdl.elab_flags", ["-frelaxed"])
VU.set_sim_option("enable_coverage", True)
VU.main(post_run = post_run)

what is expected

when the file_name parameter is simply set to coverage_data, this folder is created with no intervention.

it is expected when making the path longer, the basefolders get created, too.

what is not expected

script exits with assertion error after call to gcov-tool. output ending:

===========================================================
pass 9 of 9
===========================================================
Total time was 2.1 seconds
Elapsed time was 2.1 seconds
===========================================================
All passed!
gcov-tool: fatal error: Cannot make directory vunit_out/coverage/coverage_data
compilation terminated.
cannot access directory vunit_out/coverage/coverage_data
cannot access directory vunit_out/coverage/coverage_data
cannot access directory vunit_out/coverage/coverage_data
cannot access directory vunit_out/coverage/coverage_data
cannot access directory vunit_out/coverage/coverage_data
cannot access directory vunit_out/coverage/coverage_data
cannot access directory vunit_out/coverage/coverage_data
cannot access directory vunit_out/coverage/coverage_data
Traceback (most recent call last):
  File "/home/user/.local/lib/python3.8/site-packages/vunit/ui/__init__.py", line 672, in main
    all_ok = self._main(post_run)
  File "/home/user/.local/lib/python3.8/site-packages/vunit/ui/__init__.py", line 716, in _main
    all_ok = self._main_run(post_run)
  File "/home/user/.local/lib/python3.8/site-packages/vunit/ui/__init__.py", line 761, in _main_run
    post_run(results=Results(self._output_path, simulator_if, report))
  File "./testrun.py", line 9, in post_run
    results.merge_coverage(file_name=merge_path)
  File "/home/user/.local/lib/python3.8/site-packages/vunit/ui/results.py", line 33, in merge_coverage
    self._simulator_if.merge_coverage(file_name=file_name, args=args)
  File "/home/user/.local/lib/python3.8/site-packages/vunit/sim_if/ghdl.py", line 416, in merge_coverage
    assert len(gcda_dirs) == 1, "Expected exactly one folder with gcda files"
AssertionError: Expected exactly one folder with gcda files

changes to mitigate this

The root-cause is in https://github.com/VUnit/vunit/blob/master/vunit/sim_if/ghdl.py#L408 where gcov-tool is called with the not-existing path, that it could not handle.

There are several options to change behaviour, that came to my mind:

  • catch errors from call to gcov-tool and exit appropiately
  • check for path in existence and print error message and exit appropiately before the call to gcov-tool
  • simply create the path beforehand. e.g. os.makedirs(file_name, exist_ok = True)

I'm not quite shure which method is preferred, so i wanted to ask before creating a pr.

@umarcor
Copy link
Member

umarcor commented Apr 19, 2023

I think that the third method is ok. However, the second would also be acceptable. I don't think it's worth the complexity of the first solution just for solving this issue, because the problem is not with gcov-tool per se. We know the problem is that by design it expects the location to exist, the same as VUnit at the moment.

@albydnc
Copy link

albydnc commented Dec 1, 2023

Is there any news on this?

LarsAsplund added a commit that referenced this issue Feb 25, 2024
LarsAsplund added a commit that referenced this issue Feb 25, 2024
@eine eine added this to the v5.0.0 milestone Mar 13, 2024
markuspg pushed a commit to markuspg/vunit that referenced this issue Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants