Skip to content

Commit

Permalink
Fixes coverage report for feature/sgx branch (#224)
Browse files Browse the repository at this point in the history
- Triggers the coverage workflow for pushes to master and feature/sgx branches
- Adds optional exec argument unit tests scripts
- Some additional fixes to unit tests
  • Loading branch information
italo-sampaio authored Nov 26, 2024
1 parent 1d0044f commit fc5aab6
Show file tree
Hide file tree
Showing 12 changed files with 170 additions and 98 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: "Code coverage"

on:
push:
branches: [ "master" ]
branches: [ "master", "feature/sgx" ]

jobs:
coverage:
Expand Down
16 changes: 8 additions & 8 deletions firmware/coverage/gen-coverage
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ if [[ $1 == "exec" ]]; then
find $REPOROOT/firmware -name "*.gcno" -o -name "*.gcda" | xargs rm -f

# Run unit tests with coverage generation
COVERAGE=y $REPOROOT/firmware/src/common/test/run-all.sh
COVERAGE=y $REPOROOT/firmware/src/powhsm/test/run-all.sh
COVERAGE=y $REPOROOT/firmware/src/sgx/test/run-all.sh
COVERAGE=y $REPOROOT/firmware/src/ledger/ui/test/run-all.sh
COVERAGE=y $REPOROOT/firmware/src/ledger/signer/test/run-all.sh
COVERAGE=y $REPOROOT/firmware/src/tcpsigner/test/run-all.sh
COVERAGE=y $REPOROOT/firmware/src/hal/sgx/test/run-all.sh
# The `exec` argument is used for all scripts, since we are running them inside a docker container
COVERAGE=y $REPOROOT/firmware/src/common/test/run-all.sh exec
COVERAGE=y $REPOROOT/firmware/src/powhsm/test/run-all.sh exec
COVERAGE=y $REPOROOT/firmware/src/sgx/test/run-all.sh exec
COVERAGE=y $REPOROOT/firmware/src/ledger/ui/test/run-all.sh exec
COVERAGE=y $REPOROOT/firmware/src/ledger/signer/test/run-all.sh exec
COVERAGE=y $REPOROOT/firmware/src/hal/sgx/test/run-all.sh exec

# Run tcpsigner test suite
pushd $REPOROOT/firmware/src/tcpsigner > /dev/null
Expand All @@ -37,7 +37,7 @@ if [[ $1 == "exec" ]]; then
# Remove unwanted coverage info (test files, tcpsigner, x86 HAL implementation, mock files)
lcov --remove $BASEDIR/coverage.info "*/test_*.c" --output-file $BASEDIR/coverage.info
lcov --remove $BASEDIR/coverage.info "*/tcpsigner/src/*" --output-file $BASEDIR/coverage.info
lcov --remove $BASEDIR/coverage.info "*/hal/src/x86/*" --output-file $BASEDIR/coverage.info
lcov --remove $BASEDIR/coverage.info "*/hal/x86/src/*" --output-file $BASEDIR/coverage.info
lcov --remove $BASEDIR/coverage.info "*/mock_*.c" --output-file $BASEDIR/coverage.info
# Generate report and summary
genhtml $BASEDIR/coverage.info --output $BASEDIR/output -p $SRCDIR -t "powHSM firmware"
Expand Down
30 changes: 19 additions & 11 deletions firmware/src/common/test/run-all.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
#!/bin/bash
BASEDIR=$(dirname $0)
TESTDIRS="bigdigits_helper ints memutil"
TESTDIRS=${1:-"$TESTDIRS"}

for d in $TESTDIRS; do
echo "******************************"
echo "Testing $d..."
echo "******************************"
cd "$BASEDIR/$d"
make clean test || exit $?
cd - > /dev/null
done
if [[ $1 == "exec" ]]; then
BASEDIR=$(realpath $(dirname $0))
TESTDIRS="bigdigits_helper ints memutil"
for d in $TESTDIRS; do
echo "******************************"
echo "Testing $d..."
echo "******************************"
cd "$BASEDIR/$d"
make clean test || exit $?
cd - > /dev/null
done
exit 0
else
# Script directory
REPOROOT=$(realpath $(dirname $0)/../../../../)
SCRIPT=$(realpath $0 --relative-to=$REPOROOT)

$REPOROOT/docker/mware/do-notty-nousb /hsm2 "./$SCRIPT exec"
fi
30 changes: 19 additions & 11 deletions firmware/src/hal/common/test/run-all.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
#!/bin/bash
BASEDIR=$(dirname $0)
TESTDIRS="sha256"
TESTDIRS=${1:-"$TESTDIRS"}

for d in $TESTDIRS; do
echo "******************************"
echo "Testing $d..."
echo "******************************"
cd "$BASEDIR/$d"
make clean test || exit $?
cd - > /dev/null
done
if [[ $1 == "exec" ]]; then
BASEDIR=$(realpath $(dirname $0))
TESTDIRS="sha256"
for d in $TESTDIRS; do
echo "******************************"
echo "Testing $d..."
echo "******************************"
cd "$BASEDIR/$d"
make clean test || exit $?
cd - > /dev/null
done
exit 0
else
# Script directory
REPOROOT=$(realpath $(dirname $0)/../../../../../)
SCRIPT=$(realpath $0 --relative-to=$REPOROOT)

$REPOROOT/docker/mware/do-notty-nousb /hsm2 "./$SCRIPT exec"
fi
29 changes: 19 additions & 10 deletions firmware/src/hal/sgx/test/run-all.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
#!/bin/bash
ROOTDIR=$(dirname $0)/../../../../..
TESTDIR=$(realpath $(dirname $0) --relative-to $ROOTDIR)
TESTDIRS="nvmem secret_store seed"
TESTDIRS=${1:-"$TESTDIRS"}

for d in $TESTDIRS; do
echo "******************************"
echo "Testing $d..."
echo "******************************"
$ROOTDIR/docker/mware/do-notty-nousb /hsm2/$TESTDIR/$d "make clean test" || exit $?
done
if [[ $1 == "exec" ]]; then
BASEDIR=$(realpath $(dirname $0))
TESTDIRS="nvmem secret_store seed"
for d in $TESTDIRS; do
echo "******************************"
echo "Testing $d..."
echo "******************************"
cd "$BASEDIR/$d"
make clean test || exit $?
cd - > /dev/null
done
exit 0
else
# Script directory
REPOROOT=$(realpath $(dirname $0)/../../../../..)
SCRIPT=$(realpath $0 --relative-to=$REPOROOT)

$REPOROOT/docker/mware/do-notty-nousb /hsm2 "./$SCRIPT exec"
fi
29 changes: 19 additions & 10 deletions firmware/src/hal/x86/test/run-all.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
#!/bin/bash
ROOTDIR=$(dirname $0)/../../../../..
TESTDIR=$(realpath $(dirname $0) --relative-to $ROOTDIR)
TESTDIRS="bip32 endian hmac_sha256 hmac_sha512 keccak256"
TESTDIRS=${1:-"$TESTDIRS"}

for d in $TESTDIRS; do
echo "******************************"
echo "Testing $d..."
echo "******************************"
$ROOTDIR/docker/mware/do-notty-nousb /hsm2/$TESTDIR/$d "make clean test" || exit $?
done
if [[ $1 == "exec" ]]; then
BASEDIR=$(realpath $(dirname $0))
TESTDIRS="bip32 endian hmac_sha256 hmac_sha512 keccak256"
for d in $TESTDIRS; do
echo "******************************"
echo "Testing $d..."
echo "******************************"
cd "$BASEDIR/$d"
make clean test || exit $?
cd - > /dev/null
done
exit 0
else
# Script directory
REPOROOT=$(realpath $(dirname $0)/../../../../..)
SCRIPT=$(realpath $0 --relative-to=$REPOROOT)

$REPOROOT/docker/mware/do-notty-nousb /hsm2 "./$SCRIPT exec"
fi
30 changes: 19 additions & 11 deletions firmware/src/ledger/signer/test/run-all.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
#!/bin/bash
BASEDIR=$(dirname $0)
TESTDIRS="signer_ux"
TESTDIRS=${1:-"$TESTDIRS"}

for d in $TESTDIRS; do
echo "******************************"
echo "Testing $d..."
echo "******************************"
cd "$BASEDIR/$d"
make clean test || exit $?
cd - > /dev/null
done
if [[ $1 == "exec" ]]; then
BASEDIR=$(realpath $(dirname $0))
TESTDIRS="signer_ux"
for d in $TESTDIRS; do
echo "******************************"
echo "Testing $d..."
echo "******************************"
cd "$BASEDIR/$d"
make clean test || exit $?
cd - > /dev/null
done
exit 0
else
# Script directory
REPOROOT=$(realpath $(dirname $0)/../../../../../)
SCRIPT=$(realpath $0 --relative-to=$REPOROOT)

$REPOROOT/docker/mware/do-notty-nousb /hsm2 "./$SCRIPT exec"
fi
31 changes: 20 additions & 11 deletions firmware/src/ledger/ui/test/run-all.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
#!/bin/bash
BASEDIR=$(dirname $0)
TESTDIRS="attestation bootloader onboard pin signer_authorization ui_comm ui_heartbeat unlock ux_handlers"
TESTDIRS=${1:-"$TESTDIRS"}

for d in $TESTDIRS; do
echo "******************************"
echo "Testing $d..."
echo "******************************"
cd "$BASEDIR/$d"
make clean test || exit $?
cd - > /dev/null
done
if [[ $1 == "exec" ]]; then
BASEDIR=$(realpath $(dirname $0))
TESTDIRS="attestation bootloader onboard pin signer_authorization ui_comm ui_heartbeat unlock ux_handlers"
for d in $TESTDIRS; do
echo "******************************"
echo "Testing $d..."
echo "******************************"
cd "$BASEDIR/$d"
make clean test || exit $?
cd - > /dev/null
done
exit 0
else
# Script directory
REPOROOT=$(realpath $(dirname $0)/../../../../../)
SCRIPT=$(realpath $0 --relative-to=$REPOROOT)

$REPOROOT/docker/mware/do-notty-nousb /hsm2 "./$SCRIPT exec"
fi

6 changes: 4 additions & 2 deletions firmware/src/powhsm/test/btctx/test_btctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,14 @@ int read_hex_file(const char* file_name, unsigned char** buffer, size_t* len) {
fread(tmp, 2, 1, f);
read_hex(tmp, 2, *buffer + off);
}
fclose(f);

if (ferror(f)) {
return -1;
}

if (fclose(f)) {
return -1;
}

return 0;
}

Expand Down
30 changes: 19 additions & 11 deletions firmware/src/powhsm/test/run-all.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
#!/bin/bash
BASEDIR=$(dirname $0)
TESTDIRS="btcscript btctx difficulty srlp svarint trie"
TESTDIRS=${1:-"$TESTDIRS"}

for d in $TESTDIRS; do
echo "******************************"
echo "Testing $d..."
echo "******************************"
cd "$BASEDIR/$d"
make clean test || exit $?
cd - > /dev/null
done
if [[ $1 == "exec" ]]; then
BASEDIR=$(realpath $(dirname $0))
TESTDIRS="btcscript btctx difficulty srlp svarint trie"
for d in $TESTDIRS; do
echo "******************************"
echo "Testing $d..."
echo "******************************"
cd "$BASEDIR/$d"
make clean test || exit $?
cd - > /dev/null
done
exit 0
else
# Script directory
REPOROOT=$(realpath $(dirname $0)/../../../../)
SCRIPT=$(realpath $0 --relative-to=$REPOROOT)

$REPOROOT/docker/mware/do-notty-nousb /hsm2 "./$SCRIPT exec"
fi
5 changes: 4 additions & 1 deletion firmware/src/powhsm/test/srlp/test_srlp.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,15 @@ int read_block_file(const char* file_name, char** buffer, size_t* len) {

*buffer = malloc(*len);
fread(*buffer, *len, 1, f);
fclose(f);

if (ferror(f)) {
return -1;
}

if (fclose(f)) {
return -1;
}

return 0;
}

Expand Down
30 changes: 19 additions & 11 deletions firmware/src/sgx/test/run-all.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
#!/bin/bash
BASEDIR=$(dirname $0)
TESTDIRS="system"
TESTDIRS=${1:-"$TESTDIRS"}

for d in $TESTDIRS; do
echo "******************************"
echo "Testing $d..."
echo "******************************"
cd "$BASEDIR/$d"
make clean test || exit $?
cd - > /dev/null
done
if [[ $1 == "exec" ]]; then
BASEDIR=$(realpath $(dirname $0))
TESTDIRS="system"
for d in $TESTDIRS; do
echo "******************************"
echo "Testing $d..."
echo "******************************"
cd "$BASEDIR/$d"
make clean test || exit $?
cd - > /dev/null
done
exit 0
else
# Script directory
REPOROOT=$(realpath $(dirname $0)/../../../../)
SCRIPT=$(realpath $0 --relative-to=$REPOROOT)

$REPOROOT/docker/mware/do-notty-nousb /hsm2 "./$SCRIPT exec"
fi

0 comments on commit fc5aab6

Please sign in to comment.