Skip to content

Commit

Permalink
Add more unit test for core_pkcs11_mbedtls.c (#196)
Browse files Browse the repository at this point in the history
* Increase line coverage for core_pkcs11_mbedtls.c to 100%
* Update CI line coverage threshold to 100% and branch coverage threshold to 92%
* Fix compiler warning in unit test
  • Loading branch information
chinglee-iot authored May 17, 2024
1 parent a0170b8 commit e32020b
Show file tree
Hide file tree
Showing 5 changed files with 265 additions and 54 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ jobs:
echo -e "::group::${{ env.bashInfo }} ${{ env.stepName }} ${{ env.bashEnd }}"
sudo apt-get install -y lcov
CFLAGS="--coverage -Wall -Wextra -DNDEBUG"
# target_enable_gcov is added in each unit test already, --coverage option is not required
CFLAGS="-Wall -Wextra -DNDEBUG"
cmake -S test -B build/ \
-G "Unix Makefiles" \
-DCMAKE_BUILD_TYPE=Debug \
Expand Down Expand Up @@ -128,8 +129,8 @@ jobs:
if: steps.build-unit-tests.outcome == 'success'
with:
coverage-file: ./build/coverage.info
line-coverage-min: 99
branch-coverage-min: 90
line-coverage-min: 100
branch-coverage-min: 92

- name: Archive Test Results
if: steps.build-unit-tests.outcome == 'success'
Expand Down
4 changes: 2 additions & 2 deletions docs/doxygen/include/size_table.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
<tr>
<td>core_pkcs11_mbedtls.c</td>
<td><center>9.0K</center></td>
<td><center>7.5K</center></td>
<td><center>7.4K</center></td>
</tr>
<tr>
<td><b>Total estimates</b></td>
<td><b><center>10.3K</center></b></td>
<td><b><center>8.5K</center></b></td>
<td><b><center>8.4K</center></b></td>
</tr>
</table>
12 changes: 3 additions & 9 deletions source/portable/mbedtls/core_pkcs11_mbedtls.c
Original file line number Diff line number Diff line change
Expand Up @@ -762,15 +762,9 @@ static CK_RV prvRsaContextParse( const CK_ATTRIBUTE * pxAttribute,
lMbedTLSResult = mbedtls_mpi_read_binary( &pxRsaContext->DQ, pxAttribute->pValue, pxAttribute->ulValueLen );
break;

case ( CKA_COEFFICIENT ):
lMbedTLSResult = mbedtls_mpi_read_binary( &pxRsaContext->QP, pxAttribute->pValue, pxAttribute->ulValueLen );
break;

default:

/* This should never be reached, as the above types are what gets this function called.
* Nevertheless this is an error case, and MISRA requires a default statement. */
xResult = CKR_ATTRIBUTE_TYPE_INVALID;
/* This is the CKA_COEFFICIENT case. The type is checked in prvRsaKeyAttParse. */
lMbedTLSResult = mbedtls_mpi_read_binary( &pxRsaContext->QP, pxAttribute->pValue, pxAttribute->ulValueLen );
break;
}

Expand Down Expand Up @@ -3449,7 +3443,7 @@ CK_DECLARE_FUNCTION( CK_RV, C_FindObjectsInit )( CK_SESSION_HANDLE hSession,
xResult = CKR_ARGUMENTS_BAD;
}

if( ( ulCount != 1UL ) && ( ulCount != 2UL ) )
if( ( ulCount < 1UL ) || ( ulCount > 2UL ) )
{
xResult = CKR_ARGUMENTS_BAD;
LogError( ( "Failed to initialize find object operation. Find objects "
Expand Down
Loading

0 comments on commit e32020b

Please sign in to comment.