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

twister: coverage: Data collection and reporting per-test instance #66345

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

golowanow
Copy link
Member

@golowanow golowanow commented Dec 9, 2023

Twister code coverage data collection and reporting improvements:

  1. The new --coverage-split mode extend Twister code coverage operations to collect and report statistics on each test instance execution individually in addition to the default reporting mode of data aggregation for all the test instances in current scope of the Twister run.
    The split mode allows to identify precisely what amount of code coverage each test case provides and to analyze its contribution to the overall test plan's coverage. Each build directory will have its own coverage report and data files, so the overall disk space and the total execution time increase.
    The split mode reads the data files while the tests are running in parallel, so the report aggregation stage doesn't need to repeat the same at its turn.
    Another new --disable-coverage-aggregation option allows to execute only the --coverage-split mode if the summary statistics are not needed.

  2. New Twister option --coverage-sections allows to select what coverage data to include into the twister.json file for its further analysis together with the test meta-data and test results.
    The choices are to select either the coverage summary, or the detailed branch coverage, ztest coverage, or all the coverage data collected. Also the coverage run 'status' and coverage 'tool' values are added with any non-default choice. The 'environment' top object has additional 'gcov_tool' proverty to keep the command line argument selection.
    Depending on --coverage-split and --disable-coverage-aggregation options, the coverage data is attached either to its test suite object or/and at the report's top level as the aggregated summary of the test plan execution scope.
    Currently this mode is fully supported for the default gcovr reporting tool only, as it is based on the GCOVR json reports. For lcov only coverage run status is reported.

All the new modes are disabled by default for compatibility.

  1. Group Twister code coverage command line arguments for better usability. Add more details in descriptions.

Resolves #67058

@golowanow
Copy link
Member Author

golowanow commented Dec 11, 2023

for example, with ./scripts/twister -vv -j 1 -p unit_testing --coverage --coverage-tool gcovr -T tests/unit --coverage-split --coverage-report summary:

twister.json

{
    "environment":{
        "os":"posix",
        "zephyr_version":"zephyr-v3.5.0-2849-g38e4b5f370df",
        "toolchain":"zephyr",
        "commit_date":"2023-12-09T22:30:12+01:00",
        "run_date":"2023-12-11T09:00:36+00:00",
        "gcov_tool":"gcov"
    },
    "testsuites":[
        {
            "name":"tests/unit/crc/utilities.crc",
            "arch":"unit",
            "platform":"unit_testing",
            "path":"tests/unit/crc",
            "run_id":"037ce42604eb9fb89aef5d37a15e7e2a",
            "runnable":true,
            "retries":0,
            "status":"passed",
            "execution_time":"0.01",
            "build_time":"2.55",
            "testcases":[
                {
                    "identifier":"utilities.crc.crc32c",
                    "execution_time":"0.00",
                    "status":"passed"
                },
.......
            "coverage":{
                "status":true,
                "tool":"gcovr",
                "summary":{
                    "branch_covered":121,
                    "branch_percent":48.0,
                    "branch_total":252,
                    "files":[
                        {
                            "branch_covered":0,
                            "branch_percent":null,
                            "branch_total":0,
                            "filename":"include/zephyr/sys/crc.h",
                            "function_covered":1,
                            "function_percent":100.0,
                            "function_total":1,
                            "line_covered":2,
                            "line_percent":100.0,
                            "line_total":2
                        },
.........
                    ],
                    "function_covered":38,
                    "function_percent":63.3,
                    "function_total":60,
                    "gcovr/summary_format_version":"0.5",
                    "line_covered":315,
                    "line_percent":55.6,
                    "line_total":567,
                    "root":"../../../../../.."
                }
            }
        },
.........
    ],
    "coverage":{
        "status":true,
        "tool":"gcovr",
        "summary":{
            "branch_covered":1067,
            "branch_percent":76.1,
            "branch_total":1403,
            "files":[
                {
                    "branch_covered":4,
                    "branch_percent":100.0,
                    "branch_total":4,
                    "filename":"include/zephyr/sys/cbprintf.h",
                    "function_covered":5,
                    "function_percent":100.0,
                    "function_total":5,
                    "line_covered":16,
                    "line_percent":100.0,
                    "line_total":16
                },
.........
            ],
            "function_covered":191,
            "function_percent":86.8,
            "function_total":220,
            "gcovr/summary_format_version":"0.5",
            "line_covered":2093,
            "line_percent":83.8,
            "line_total":2499,
            "root":".."
        }
    }
}
```

@golowanow
Copy link
Member Author

@gchwier, @gopiotr, @hakehuang, @nashif, @PerMac up to your attention

@golowanow
Copy link
Member Author

rebased to resolve conflicts with #66406

@golowanow golowanow added the Enhancement Changes/Updates/Additions to existing features label Dec 15, 2023
@hakehuang
Copy link
Collaborator

@golowanow , maybe change the PR title to enable json report with coverage for each file?

@golowanow
Copy link
Member Author

@golowanow , maybe change the PR title to enable json report with coverage for each file?

That title will be misleading as gcovr coverage report already has details for each file, and now it is included into twister.json.
The example snippet above is to show the gcovr 'summary' mode results embedded.

hakehuang
hakehuang previously approved these changes Dec 21, 2023
Copy link
Collaborator

@hakehuang hakehuang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, with some code suggestion on group coverage options. beside the conflict need to be resolved

@golowanow golowanow changed the title twister: coverage: Data collection per-test instance twister: coverage: Data collection and reporting per-test instance Dec 22, 2023
@golowanow
Copy link
Member Author

rebased to resolve conflicts with #66487 and with some minor improvements:

  • command line arguments re-arranged;
  • additional properties added to the json (to keep which gcov-tool and gcovr/lcov was used).

@golowanow
Copy link
Member Author

rebased resolving merge conflict with #66898

@golowanow
Copy link
Member Author

rebased resolving merge conflict with #66905

hakehuang
hakehuang previously approved these changes Feb 15, 2024
Copy link

This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time.

@github-actions github-actions bot added the Stale label Apr 16, 2024
@golowanow golowanow removed the Stale label Apr 16, 2024
@PerMac
Copy link
Member

PerMac commented Apr 17, 2024

@nordic-piks Maybe you'd like to have a look at this?

Group Twister code coverage command line arguments for better usability.
Add more details in descriptions.

Signed-off-by: Dmitrii Golovanov <[email protected]>
@golowanow
Copy link
Member Author

rebased to resolve merge conflicts (with #67129), some minor corrections and adjustments to twister tests.

@hakehuang, please refresh your +1

The new `--coverage-split` mode extends Twister code coverage operations
to report coverage statistics on each test instance execution individually
in addition to the default reporting mode which aggregates data to one
report with all the test instances in the current scope of the Twister run.
The split mode allows to identify precisely what amount of code coverage
each test case provides and to analyze its contribution to the overall
test plan's coverage. Each build directory will have its own coverage
report and data files, so the overall disk space and the total execution
time increase.
The split mode reads the raw data fies while the tests are running
in parallel, so the report aggregation stage doesn't need to do the same
at its turn.

Another new `--disable-coverage-aggregation` option allows to execute
only the `--coverage-split` mode if the summary statistics are not needed.

Signed-off-by: Dmitrii Golovanov <[email protected]>
New Twister option `--coverage-sections` allow to select what coverage
data to include into the `twister.json` file for its further analysis
in addition to the test meta-data and the test results.

The choices are to select either the coverage summary, or the detailed
branch coverage, ztest coverage, or all the coverage data collected.
Also the coverage run 'status' and coverage 'tool' values are added
with any non-default choice. The 'environment' top object has additional
'gcov_tool' proverty to keep the command line argument selection.

Depending on `--coverage-split` and `--disable-coverage-aggregation`
options the coverage data is attached either to its test suite object
or/and at the report's top level as the aggregated summary of the test
plan execution scope.

Currently this mode is fully supported for the default gcovr reporting
tool only, as it is based on the GCOVR json reports. For lcov only
coverage run status is reported.

Signed-off-by: Dmitrii Golovanov <[email protected]>
@golowanow
Copy link
Member Author

@gchwier, @gopiotr, @nashif, @PerMac, any objections or comments on this PR ?
some more details are also in the RFC #67058

@katgiadla
Copy link
Collaborator

katgiadla commented Apr 24, 2024

@gchwier, @gopiotr, @nashif, @PerMac, any objections or comments on this PR ? some more details are also in the RFC #67058

I want to check it before PR merge. Please give me about 23 days.

@golowanow
Copy link
Member Author

golowanow commented May 7, 2024

I want to check it before PR merge. Please give me about 23 days.

@katgiadla, did you have time to check ?

@katgiadla
Copy link
Collaborator

I want to check it before PR merge. Please give me about 23 days.

@katgiadla, did you have time to check ?

No, I hadn't. I'll check it at this week.

@golowanow
Copy link
Member Author

@katgiadla, do you have any feedback to share ?

Copy link

github-actions bot commented Aug 5, 2024

This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time.

Copy link

github-actions bot commented Oct 5, 2024

This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time.

@github-actions github-actions bot added the Stale label Oct 5, 2024
@golowanow golowanow removed the Stale label Oct 5, 2024
@kartben
Copy link
Collaborator

kartben commented Nov 26, 2024

This needs rebasing but not sure what's the current status of this PR?

@golowanow golowanow added the In progress For PRs: is work in progress and should not be merged yet. For issues: Is being worked on label Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Code Coverage area: Twister Twister Enhancement Changes/Updates/Additions to existing features In progress For PRs: is work in progress and should not be merged yet. For issues: Is being worked on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RFC: Deeper code coverage profiling with Twister test automation
8 participants