Keil μVision is a popular integrated development environment (IDE) used for developing and debugging embedded applications based on ARM Cortex microcontrollers. One useful feature it provides is code coverage analysis, which shows how much of your source code is executed during testing. μVision can generate detailed code coverage reports, but it does not directly support exporting these results for further processing. This article explores different techniques for getting the code coverage data out of μVision and into a format you can use in other tools.
Using Report Files
The most straightforward way to export coverage results from μVision is to use the report files it can generate. When you run code coverage analysis in μVision, it produces two files: a .htm file containing a nicely formatted report, and a .csv file with the raw coverage data in comma-separated values format.
The .htm report file provides a great way to visualize coverage directly in μVision. It shows which source lines were executed versus not executed using color coding. But since this is an HTML document, it can be saved and shared with others. You could even upload it to a web server to share code coverage reports.
The .csv file contains the real data behind the report. Each row lists a source file, the number of times each line executed, and a summary of coverage for that file. By saving this .csv, you can easily get the coverage data into other tools like Excel or a custom program for further processing and analysis.
Using the .htm Report File
To generate an HTML code coverage report in μVision:
- Run your tests and enable code coverage tracing
- In the coverage window, right click and select Export -> Export to HTML…
- Save the generated .htm file
Now you have a standalone HTML report file that can be opened in any web browser. It contains toggle buttons to switch between showing source code lines that were executed or not executed. There is also a summary table showing statistics like how many lines were covered for each file.
To share this report, simply copy the .htm file or put it on a shared drive. You can also upload it to an internal web server or public hosting service to allow access via web browsers.
Using the .csv Coverage Data File
Along with the HTML report, μVision also generates a .csv file with the underlying coverage data. Each row contains a source file path, stats on how many lines were executable and how many were executed, and details on the execution count for each line number.
This raw coverage data can be easily imported into Excel for further analysis. You can generate charts to visualize coverage across different files. And if you need to process the data programmatically, it is simple to parse as structured CSV data.
To export the .csv coverage data file:
- Run your tests and enable coverage tracing in μVision
- In the coverage window, right click and select Export -> Export to CSV…
- Save the generated .csv file
With this raw coverage data exported, you have maximum flexibility in post-processing. Try loading it into Excel and generating pivot tables or charts for customizable reports. You can also write scripts in Python, C#, or other languages to analyze the data however you need.
Custom Export to Text Files
The built-in report and CSV export options provide an easy way to get code coverage out of μVision. But if you need more control over the output format, you can create a custom text file export.
The basic approach is to iterate through the code coverage results in μVision’s analysis back-end and write the data you need to a custom text file. This takes more work to set up, but allows exporting the exact data you need in whatever format your other tools require.
Exporting Per-Line Coverage
This example exports one line per source code line, indicating whether it was executed or not. The output text file works with external tools expecting this per-line coverage information.
Walk through these steps to set up a custom per-line coverage export:
- Create an empty text file to serve as output
- Enable coverage tracing and run tests in μVision
- In the μVision IDE, open the Automation | C/C++ API document
- Locate the CodeCoverageResultsMgr APIs
- Use these to iterate coverage results and print per-line data
- Sample pseudocode:
for each source file print filename for each line number get execution count for line if count > 0 print “Executed” else print “Not Executed”
With these APIs, you can export exactly the per-line coverage information you need in a compact format suited for further processing.
Exporting File Summary Data
Instead of per-line details, you may want to export high-level stats for each source file. This can be useful for integration with reporting tools that don’t need line-by-line data.
To export file-level summary coverage data:
- Create an empty output text file
- Enable coverage tracing and run tests
- Iterate source files using CodeCoverageResultsMgr
- For each file, print summary info like:
filename.c: Total Lines: 345 Executed Lines: 242 Percent Covered: 70%
With this high-level summary data, you can easily process coverage results without dealing with large amounts of per-line detail.
Integrating with Third-Party Tools
Once you have code coverage results exported from μVision, you can feed them into various third-party tools for further analysis and reporting.
Here are some examples of how exported coverage data can integrate with other platforms:
- CI/CD pipelines – export coverage files and archive as artifacts
- GitHub – upload coverage reports to display status on projects
- Spreadsheets – import .csv for pivots, charts, etc in Excel
- Custom apps – parse exported text or .csv data to generate reports
- Coverage services – upload to coveralls.io, codecov.io, etc
With all the options for exporting data from μVision, it’s easy to connect coverage results to your other development tools for a complete analysis workflow.
Keil μVision provides powerful code coverage analysis directly in the IDE. While it can generate nice HTML reports, getting the coverage data out for external processing requires exporting it.
Using the built-in export options for HTML and CSV files provides a quick way to access coverage results. For more advanced scenarios, you can create custom exports by iterating results and writing your own output file format. And integrating exported results with third-party tools enables consolidating coverage analysis across your entire development process.
With the techniques outlined in this guide, you should have a good understanding of the options for exporting code coverage data from μVision. The ability to easily get this data out of the IDE opens up many possibilities for further processing, analysis, reporting and integration with your other systems.