-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #1370, workflow to validate OSAL API
Adds a new build and test workflow that includes an API validation with both C and C++ compilers. This should catch any cases where syntactical elements that work in C but do not work in C++ appear in the headers.
- Loading branch information
Showing
7 changed files
with
341 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
name: Check Coverage Results | ||
description: 'Extracts a summary of the code coverage results' | ||
|
||
inputs: | ||
binary-dir: | ||
description: 'Directory containing binary files' | ||
required: true | ||
source-dir: | ||
description: 'Directory containing source code files' | ||
default: ./source | ||
|
||
outputs: | ||
ncov_lines: | ||
description: 'Actual number of uncovered lines' | ||
value: ${{ steps.stats.outputs.ncov_lines }} | ||
ncov_functions: | ||
description: 'Actual number of uncovered functions' | ||
value: ${{ steps.stats.outputs.ncov_functions }} | ||
ncov_branches: | ||
description: 'Actual number of uncovered branches' | ||
value: ${{ steps.stats.outputs.ncov_branches }} | ||
|
||
runs: | ||
using: 'composite' | ||
steps: | ||
- name: Capture Results | ||
shell: bash | ||
run: lcov | ||
--capture --rc lcov_branch_coverage=1 | ||
--include '${{ github.workspace }}/*' | ||
--directory '${{ inputs.binary-dir }}' | ||
--output-file '${{ inputs.binary-dir }}/coverage.info' | | ||
tee '${{ inputs.binary-dir }}/lcov_out.txt' | ||
|
||
- name: Generate HTML | ||
shell: bash | ||
run: genhtml | ||
'${{ inputs.binary-dir }}/coverage.info' | ||
--branch-coverage | ||
--output-directory '${{ inputs.binary-dir }}/lcov-html' | | ||
tee '${{ inputs.binary-dir }}/genhtml_out.txt' | ||
|
||
- name: Extract Overall Summary | ||
shell: bash | ||
run: xsltproc --html | ||
'${{ inputs.source-dir }}/.github/actions/check-coverage/lcov-output.xslt' | ||
'${{ inputs.binary-dir }}/lcov-html/index.html' | | ||
tee '${{ inputs.binary-dir }}/lcov-summary.xml' | ||
|
||
- name: Extract Stats | ||
id: stats | ||
shell: bash | ||
run: grep -A 3 "Overall coverage rate" '${{ inputs.binary-dir }}/genhtml_out.txt' | | ||
grep -oP '\([0-9]+ of [0-9]+.*\)' | | ||
tr -d '()' | | ||
awk '{print "ncov_" $4 "=" $3 - $1}' | | ||
tee -a $GITHUB_OUTPUT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?xml version="1.0"?> | ||
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> | ||
<xsl:output method="xml" omit-xml-declaration="yes" encoding="UTF-8"/> | ||
|
||
<!-- Identity Template --> | ||
<xsl:template match="@* | node()"> | ||
<xsl:copy> | ||
<xsl:apply-templates select="@* | node()"/> | ||
</xsl:copy> | ||
</xsl:template> | ||
|
||
<!-- Omit class attributes, width attributes, and img elements --> | ||
<xsl:template match="@class" /> | ||
<xsl:template match="@width" /> | ||
<xsl:template match="@align" /> | ||
<xsl:template match="img" /> | ||
|
||
<!-- The "coverBar" will not render on github, so pull out the alt text on the image --> | ||
<xsl:template match="td[@class='coverBar']"> | ||
<td> | ||
<xsl:for-each select=".//img[1]"> | ||
<xsl:if test="@width < 95">X</xsl:if> | ||
</xsl:for-each> | ||
</td> | ||
</xsl:template> | ||
|
||
<!-- Convert td w/class="tableHead" to a th tag --> | ||
<xsl:template match="td[@class='tableHead']"> | ||
<th> | ||
<xsl:if test="count(@colspan) > 0"> | ||
<xsl:attribute name="colspan"><xsl:value-of select="@colspan"/></xsl:attribute> | ||
</xsl:if> | ||
<xsl:for-each select="text()"> | ||
<xsl:copy/> | ||
</xsl:for-each> | ||
</th> | ||
</xsl:template> | ||
|
||
<xsl:template match="span|center"> | ||
<xsl:apply-templates select="@* | node()"/> | ||
</xsl:template> | ||
|
||
<!-- Rewrite links to be plain text --> | ||
<xsl:template match="a"> | ||
<xsl:for-each select="text()"> | ||
<xsl:copy/> | ||
</xsl:for-each> | ||
</xsl:template> | ||
|
||
<xsl:template name="summary_row"> | ||
<!-- Extract only cells 4-7 here (label, hit, total, coverage) --> | ||
<xsl:for-each select="td[position() >= 4]"> | ||
<xsl:copy> | ||
<xsl:apply-templates select="@* | node()" /> | ||
</xsl:copy> | ||
</xsl:for-each> | ||
<xsl:text> | ||
</xsl:text> | ||
</xsl:template> | ||
|
||
<xsl:template name="summary_table"> | ||
<table> | ||
<!-- Extract only rows 1-4 here (header, lines, functions, branches) --> | ||
<xsl:for-each select="tr[position() <= 4]"> | ||
<xsl:copy> | ||
<xsl:call-template name="summary_row" /> | ||
</xsl:copy> | ||
</xsl:for-each> | ||
</table> | ||
<xsl:text> | ||
</xsl:text> | ||
</xsl:template> | ||
|
||
<xsl:template name="detail_table"> | ||
<table> | ||
<!-- First row appears to be always blank/spacer, real content starts at 2 --> | ||
<xsl:for-each select="tr[position() >= 2]"> | ||
<xsl:copy> | ||
<xsl:apply-templates select="@* | node()"/> | ||
</xsl:copy> | ||
</xsl:for-each> | ||
</table> | ||
<xsl:text> | ||
</xsl:text> | ||
</xsl:template> | ||
|
||
<!-- The LCOV output uses tables for white-spacing purposes as well as actual tabular data --> | ||
<xsl:template match="/"> | ||
<h2>LCOV Report</h2> | ||
<xsl:text> | ||
</xsl:text> | ||
<!-- The first table is the summary, but we really want the embedded table within the table at row 3 --> | ||
<xsl:for-each select="/html/body/table[1]/tr[3]/td/table"> | ||
<xsl:call-template name="summary_table" /> | ||
</xsl:for-each> | ||
|
||
<!-- The centered table is the file-by-file details --> | ||
<xsl:for-each select="/html/body/center/table[1]"> | ||
<xsl:call-template name="detail_table" /> | ||
</xsl:for-each> | ||
|
||
</xsl:template> | ||
|
||
|
||
</xsl:stylesheet> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
name: Build and Test Standalone OSAL package | ||
|
||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
|
||
defaults: | ||
run: | ||
shell: bash | ||
|
||
env: | ||
allowed_ncov_lines: 0 | ||
allowed_ncov_branches: 4 | ||
allowed_ncov_functions: 0 | ||
|
||
jobs: | ||
|
||
build-and-test: | ||
name: Build and Execute Tests | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
build-type: [Debug, Release] | ||
base-os: [ubuntu-22.04, ubuntu-20.04] | ||
|
||
runs-on: ${{ matrix.base-os }} | ||
|
||
steps: | ||
|
||
- name: Checkout OSAL | ||
uses: actions/checkout@v3 | ||
with: | ||
path: source | ||
|
||
- name: Install Coverage Analysis Tools | ||
if: ${{ matrix.build-type == 'Debug' && matrix.base-os == 'ubuntu-20.04' }} | ||
run: sudo apt-get install -y lcov xsltproc && echo "run_lcov=TRUE" >> $GITHUB_ENV | ||
|
||
- name: Set up debug environment | ||
if: ${{ matrix.build-type == 'Debug' }} | ||
run: | | ||
echo "is_debug=TRUE" >> $GITHUB_ENV | ||
echo "is_release=FALSE" >> $GITHUB_ENV | ||
echo "build_tgt=all" >> $GITHUB_ENV | ||
echo "DESTDIR=${{ github.workspace }}/staging-debug" >> $GITHUB_ENV | ||
- name: Set up release environment | ||
if: ${{ matrix.build-type == 'Release' }} | ||
run: | | ||
echo "is_debug=FALSE" >> $GITHUB_ENV | ||
echo "is_release=TRUE" >> $GITHUB_ENV | ||
echo "build_tgt=install" >> $GITHUB_ENV | ||
echo "DESTDIR=${{ github.workspace }}/staging-release" >> $GITHUB_ENV | ||
- name: Set up build | ||
run: cmake | ||
-DCMAKE_BUILD_TYPE=${{ matrix.build-type }} | ||
-DENABLE_UNIT_TESTS=${{ env.is_debug }} | ||
-DOSAL_OMIT_DEPRECATED=${{ env.is_debug }} | ||
-DOSAL_VALIDATE_API=${{ env.is_release }} | ||
-DOSAL_INSTALL_LIBRARIES=${{ env.is_release }} | ||
-DOSAL_CONFIG_DEBUG_PERMISSIVE_MODE=${{ env.is_debug }} | ||
-DOSAL_SYSTEM_BSPTYPE=generic-linux | ||
-DCMAKE_PREFIX_PATH=/usr/lib/cmake | ||
-DCMAKE_INSTALL_PREFIX=/usr | ||
-S source | ||
-B build | ||
|
||
- name: Build OSAL | ||
working-directory: build | ||
run: make ${{ env.build_tgt }} -j2 | ||
|
||
- name: Validate API | ||
if: ${{ matrix.build-type == 'Release' }} | ||
working-directory: build | ||
run: make osal_apicheck | ||
|
||
- name: Execute Tests | ||
if: ${{ matrix.build-type == 'Debug' }} | ||
working-directory: build | ||
run: ctest --output-on-failure -j4 2>&1 | tee ../ctest.log | ||
|
||
- name: Check Coverage | ||
id: stats | ||
if: ${{ env.run_lcov == 'TRUE' }} | ||
uses: ./source/.github/actions/check-coverage | ||
with: | ||
binary-dir: build | ||
|
||
- name: Enforce coverage function minimum | ||
if: ${{ always() && steps.stats.outputs.ncov_functions > env.allowed_ncov_functions }} | ||
run: | | ||
echo "::error::Too many uncovered functions (${{ steps.stats.outputs.ncov_functions }})" | ||
/bin/false | ||
- name: Enforce coverage line minimum | ||
if: ${{ always() && steps.stats.outputs.ncov_lines > env.allowed_ncov_lines }} | ||
run: | | ||
echo "::error::Too many uncovered lines (${{ steps.stats.outputs.ncov_lines }})" | ||
/bin/false | ||
- name: Enforce coverage branch minimum | ||
if: ${{ always() && steps.stats.outputs.ncov_branches > env.allowed_ncov_branches }} | ||
run: | | ||
echo "::error::Too many uncovered branches (${{ steps.stats.outputs.ncov_branches }})" | ||
/bin/false | ||
- name: Assemble Results | ||
if: ${{ always() }} | ||
run: | | ||
if [ -s ctest.log ]; then | ||
echo '<h2>CTest Execution</h2>' >> $GITHUB_STEP_SUMMARY | ||
echo '<pre>' >> $GITHUB_STEP_SUMMARY | ||
cat ctest.log >> $GITHUB_STEP_SUMMARY | ||
echo '</pre>' >> $GITHUB_STEP_SUMMARY | ||
fi | ||
if [ -s 'build/lcov-summary.xml' ]; then | ||
cat 'build/lcov-summary.xml' >> $GITHUB_STEP_SUMMARY | ||
fi |
Oops, something went wrong.