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

Fix #1370, workflow to validate OSAL API #1372

Merged
merged 1 commit into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions .github/actions/check-coverage/action.yml
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
105 changes: 105 additions & 0 deletions .github/actions/check-coverage/lcov-output.xslt
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 &lt; 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() &gt;= 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() &lt;= 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() &gt;= 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>
70 changes: 0 additions & 70 deletions .github/workflows/local_unit_test.yml

This file was deleted.

120 changes: 120 additions & 0 deletions .github/workflows/standalone-build.yml
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
Loading