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

Serializing issue on Windows when gcov_tool specified to twister at the command line #83823

Closed
solsbarry opened this issue Jan 10, 2025 · 3 comments · Fixed by #84334
Closed
Assignees
Labels
area: Twister Twister area: Windows Support Related to building Zephyr on Windows bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug

Comments

@solsbarry
Copy link
Contributor

Describe the bug
I have a on target unit test that I am executing with twister and asking it to generate a code coverage report for. The build failed with this error:
Image

Here is a copy of the report being passed to json.dump
Image

The issue is that I am specifying a gcov_tool at the command line call to twister
twister....--coverage --gcov-tool my_windows_path...
And as you can see somehow twister is turning the gcov_tool path into a WindowsPath variable and not a string. And apparently a Windows Path type can't be in a dictionary passed to json.dump. That is the issue.

In reports.py I updated jason_report() to convert WindowsPath types in the report to strings, and that caused it to build fine. I am not suggesting that is the best answer, but something like it.
Image
You also have to add this at the top to get it to build
from pathlib import WindowsPath
Here is the text of that code if you want to try it.

def convert_windows_paths_to_strings(self, d):
      if isinstance(d, dict):
          return {k: self.convert_windows_paths_to_strings(v) for k, v in d.items()}
      elif isinstance(d, list):
          return [self.convert_windows_paths_to_strings(i) for i in d]
      elif isinstance(d, WindowsPath):
          return str(d)
      else:
          return d

To Reproduce
Steps to reproduce the behavior:

  1. Create a unit test
  2. Run it on Windows with twister, while specifying the path to gcov_tool in the twister command and enabling coverage.
    twister....--coverage --gcov-tool my_windows_path...
  3. See error

Expected behavior
The unit test should build without error

Impact
Can't include coverage in my on target unit tests when running on windows.

Environment (please complete the following information):

  • OS: Windows 10
  • Toolchain: Zephyr SDK 0.16.8
  • Commit SHA or Version used: 3.7.88-NCS1 ( I know that is a nordic version, but I think this issue is specific to Zephyr more generally.
@solsbarry solsbarry added the bug The issue is a bug, or the PR is fixing a bug label Jan 10, 2025
@kartben kartben added the priority: low Low impact/importance bug label Jan 14, 2025
@nashif
Copy link
Member

nashif commented Jan 20, 2025

@golowanow here

# Resolve known JSON serialization problems.
you already deal with PosixPath, need to make this also work with WindowsPath.

@nashif nashif assigned golowanow and unassigned nashif Jan 20, 2025
@nashif nashif changed the title Code coverage issue on Windows when gcov_tool specified to twister at the command line - Object of type WindowsPath is not JSON serializable Serializing issue on Windows when gcov_tool specified to twister at the command line Jan 20, 2025
@golowanow
Copy link
Member

@solsbarry, could you please check #84334 at your environment ?

@solsbarry
Copy link
Contributor Author

@golowanow That fixed the issue. Thank you very much, I appreciate the quick fix.

golowanow added a commit to golowanow/zephyr that referenced this issue Jan 22, 2025
Refactor Reporting to use custom ReportingJSONEncoder and encode
all pathlib.Path derived instances there which are possible
e.g. in 'environment.options' received from command line.

Fixes: zephyrproject-rtos#83823

Signed-off-by: Dmitrii Golovanov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Twister Twister area: Windows Support Related to building Zephyr on Windows bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants