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

CI: Add Coverage Analysis #68624

Merged
merged 1 commit into from
Mar 5, 2024

Conversation

gbarkadiusz
Copy link
Collaborator

@gbarkadiusz gbarkadiusz commented Feb 6, 2024

Extend codecov workflow to include coverage analysis.
Coverage_analysis.py generates coverage report in both (json and xlsx) formats.
The generated report contains information about coverage per component, covered and uncovered functions.
Report.json

{
    "components": [
        {
            "name": "acpi",
            "sub_components": [ 
                {
                    "name": "basic",
                    "test_suites": [
                        {
                            "name": "tests/lib/acpi/acpi.basic",
                            "path": "tests/lib/acpi",
                            "platforms": [
                                "qemu_x86_64"
                            ],
                            "runnable": true,
                            "status": "sim_only",
                            "test_cases": [
                                {
                                    "name": "acpi.basic.irq_routing_table"
                                },
                                ...
                            ]
                        },
                        ...
                    ]
                },
                ...
            ]
        },
        ...
    ]
}

Moreover, this script parses Testplan.json generated by twister ( twister -E testplan.json ) to collect the data regarding all testsuites.
Report.xlsx

Components TestSuites Runnable Build only Simulators only Hardware only Mixed Coverage [%] Total Functions Uncovered Functions Comment
linker 2 2 0 2 0 0 100.00 2 0  
zdsp 3 3 0 3 0 0 100.00 60 0  
message_bus 7 7 0 7 0 0 99.70 34 0  
utilities 62 62 0 0 62 0 92.03 246 9  
printk 3 3 0 3 0 0 91.76 399 21  
kernel 164 150 14 157 7 0 90.94 826 36  
pm 13 12 1 12 1 0 87.81 80 3  
rtio 4 4 0 4 0 0 87.56 52 0  
settings 11 9 2 9 2 0 86.34 80 0  
libraries 191 187 4 191 0 0 84.76 755 64  
lib 1 1 0 0 1 0 84.76 755 64  
storage 7 6 1 6 1 0 84.70 27 2  
input 12 12 0 12 0 0 82.18 48 3  
portability 32 29 3 30 2 0 81.81 380 15  
filesystem 21 20 1 20 1 0 79.35 367 23  
logging 106 106 0 106 0 0 79.20 248 31  
modem 8 6 2 6 2 0 78.20 128 12  
gpio 1 1 0 1 0 0 77.84 115 28  
tracing 2 2 0 2 0 0 74.82 153 43  
gnss 1 1 0 1 0 0 74.70 31 2  
arch 60 49 11 57 3 0 73.63 268 62  
debug 8 8 0 8 0 0 70.67 64 8  
mgmt 22 18 4 18 4 0 67.52 175 35  
canbus 5 5 0 5 0 0 66.46 225 50  
cpp 14 8 6 14 0 0 60.00 7 4  
net 216 206 10 215 1 0 57.95 5553 1653  
llext 4 4 0 4 0 0 57.85 31 10  
shell 19 5 14 19 0 0 48.21 276 108  
dfu 4 4 0 4 0 0 47.29 17 6  
boards 20 2 18 3 17 0 45.65 622 297  
flash 1 0 1 0 1 0 43.95 45 19  
usb 6 6 0 6 0 0 42.44 498 203  
crypto 8 8 0 8 0 0 40.00 23 7  
bluetooth 276 160 116 102 174 0 39.64 4844 2646  
drivers 422 87 335 160 262 0 34.48 3778 1918  
sample 643 114 529 324 319 0 32.03 18 11  
ipc 2 2 0 2 0 0 25.26 33 26  
sensors 8 1 7 8 0 0 17.81 1936 1377  
acpi 1 1 0 1 0 0 11.57 33 27  
buildsystem 14 6 8 14 0 0 0.00 0 0  
application_development 5 3 2 2 3 0 0.00 0 0  
bootloader 6 0 6 0 6 0 0.00 0 0  
boot 3 1 2 1 2 0 0.00 0 0  
kconfig 2 2 0 2 0 0 0.00 0 0  
init 1 0 1 1 0 0 0.00 0 0 Missed in maintainers.yml file.
benchmark 24 18 6 24 0 0 0.00 0 0  
sip_svc 1 0 1 0 1 0 0.00 0 0  
testing 30 28 2 25 5 0 0.00 0 0 Missed in maintainers.yml file.
mem_mgmt 2 2 0 2 0 0 0.00 0 0 Missed in maintainers.yml file.
openthread 3 3 0 3 0 0 0.00 0 0  
modbus 2 0 2 1 1 0 0.00 0 0  
edac 6 0 6 0 6 0 0.00 0 0  
bindesc 7 7 0 7 0 0 0.00 0 0  
emul 1 1 0 1 0 0 0.00 0 0 Missed in maintainers.yml file.
samples 2 0 2 0 2 0 0.00 0 0  

@gbarkadiusz gbarkadiusz force-pushed the coverage_analysis branch 4 times, most recently from b29bd6b to 88154fa Compare February 6, 2024 12:38
@nashif nashif self-assigned this Feb 6, 2024
@nashif
Copy link
Member

nashif commented Feb 6, 2024

Please fix the CI issues

@gbarkadiusz gbarkadiusz force-pushed the coverage_analysis branch 2 times, most recently from 3ef37a9 to d462d57 Compare February 6, 2024 14:16
@gbarkadiusz
Copy link
Collaborator Author

Please fix the CI issues

Fixed.

@PerMac PerMac self-requested a review February 6, 2024 15:56
@nashif
Copy link
Member

nashif commented Feb 12, 2024

@gbarkadiusz why is this still in draft?

@gbarkadiusz gbarkadiusz marked this pull request as ready for review February 13, 2024 07:15
Copy link
Member

@nashif nashif left a comment

Choose a reason for hiding this comment

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

with:
name: Coverage Reports
path: |
coverage/reports/${{ steps.run_date.outputs.run_date_short }}.json
Copy link
Member

Choose a reason for hiding this comment

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

prefix file name with coverage-report

scripts/ci/coverage/coverage_analysis.py Outdated Show resolved Hide resolved
- name: Generate Coverage Report
if: always()
run: |
pip install xlsxwriter, ijson, json, yaml
Copy link
Member

Choose a reason for hiding this comment

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

remove the comma, just leave xlsxwrite and ijson.

Why do you need ijson and json and why cant this all be accomplished with json module alone?

not blocking, I would consider using openpyxl for excel in the future, it is much more powerful.

pip install xlsxwriter, ijson, json, yaml
cd ./coverage/reports
../scripts/twister -E testplan.json
python3 ../scripts/ci/coverage/coverage_analysis.py -t testplan.json -m ../MAINTAINERS.yml -c merged.json \
Copy link
Member

Choose a reason for hiding this comment

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

this is wrong, use something like that instead:

-          cd ./coverage/reports
-          ../scripts/twister -E testplan.json
-          python3 ../scripts/ci/coverage/coverage_analysis.py -t testplan.json -m ../MAINTAINERS.yml -c merged.json \
-          -o ${{ steps.run_date.outputs.run_date_short }} -f all
+          ./scripts/twister -E testplan.json
+          python3 ./scripts/ci/coverage/coverage_analysis.py -t testplan.json -m MAINTAINERS.yml -c coverage/reports/merged.json \
+          -o coverage-report-${{ steps.run_date.outputs.run_date_short }} -f all
+          cp coverage-report-* coverage/reports/
+

for item in self.maintainers_file:
_found_flag = False
try:
tests = self.maintainers_file[item]['tests']
Copy link
Member

Choose a reason for hiding this comment

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

that will fail if an area does not have tests....
You should look into using the maintainer file parser, see scripts/get_maintainer.py then
from get_maintainer import Maintainers

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Regarding this. I tried to use get_maintainer, but there is no functionality. Search the area according to the name of the tests.
AFAIK, this script provides the following functionalities:
Get area according to paths. get_maintainer path PATH_TO_FILE
Get a list of files regarding the area.  get_maintainer list AREA
While creating the report, I'm based on the component's name instead of area. The component's name came from test_case name.
That's why, I used that workaround.

if: always()
run: |
pip install xlsxwriter ijson
./scripts/twister -E testplan.json
Copy link
Member

Choose a reason for hiding this comment

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

This will not work, please look at the workflow link I provided. running twister here requires a different runner, you do not have the dependencies needed for twister in the default runner. see https://github.com/zephyrproject-rtos/zephyr-testing/actions/runs/7891137291/workflow

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You're right. I needed to take a look at this part of workflow again.

@gbarkadiusz gbarkadiusz force-pushed the coverage_analysis branch 2 times, most recently from 771b0ee to c7f9001 Compare February 14, 2024 12:59
@gbarkadiusz gbarkadiusz requested a review from nashif February 23, 2024 09:50
Copy link
Member

@nashif nashif left a comment

Choose a reason for hiding this comment

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

thw workflow will not work, you really need to take my changes from here: zephyrproject-rtos/zephyr-testing@c6f555a

I can also push those changes into this PR if you like

@@ -90,6 +90,7 @@ jobs:
export ZEPHYR_TOOLCHAIN_VARIANT=zephyr
mkdir -p coverage/reports
pip3 install gcovr==6.0
./scripts/twister -E testplan.json
Copy link
Member

Choose a reason for hiding this comment

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

this will not work, we will generate this for each platform, so we have later to deal with the same file name. Just pin it tot he platform name and later just pick one to avoid issues. see my workflow on zephyr-testing

@gbarkadiusz
Copy link
Collaborator Author

thw workflow will not work, you really need to take my changes from here: zephyrproject-rtos/zephyr-testing@c6f555a

I can also push those changes into this PR if you like

If my changes are not enough to work properly this workflow. Please push those changes into this PR. I'd like to learn what I did wrong.

nashif
nashif previously approved these changes Feb 28, 2024
Extend codecov workflow to include coverage analysis.

Signed-off-by: Arkadiusz Cholewinski <[email protected]>
Signed-off-by: Anas Nashif <[email protected]>
@nashif nashif merged commit 0e2a25b into zephyrproject-rtos:main Mar 5, 2024
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants