Skip to content

Commit

Permalink
Added unit tests for system module (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
italo-sampaio authored Oct 22, 2024
1 parent decfba2 commit 8984008
Show file tree
Hide file tree
Showing 9 changed files with 1,066 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ jobs:

- name: Firmware PowHSM's unit tests
run: firmware/src/powhsm/test/run-all.sh

- name: Firmware SGX's unit tests
run: firmware/src/sgx/test/run-all.sh

- name: Ledger UI's unit tests
run: firmware/src/ledger/ui/test/run-all.sh
Expand Down
1 change: 1 addition & 0 deletions firmware/coverage/gen-coverage
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ if [[ $1 == "exec" ]]; then
# 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
Expand Down
2 changes: 1 addition & 1 deletion firmware/src/sgx/src/trusted/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ bool system_init(unsigned char *msg_buffer, size_t msg_buffer_size) {
return false;
}

// Make sure both access and init are in the same state
// Make sure both access and seed are in the same state
if (!seed_available() ^ access_is_wiped()) {
LOG("Inconsistent system state detected\n");
if (!access_wipe() || !seed_wipe()) {
Expand Down
1 change: 1 addition & 0 deletions firmware/src/sgx/test/common/apdu_utils.h
1 change: 1 addition & 0 deletions firmware/src/sgx/test/common/assert_utils.h
20 changes: 20 additions & 0 deletions firmware/src/sgx/test/common/common.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
TESTCOMMONDIR = ../common
SGXTRUSTEDDIR = ../../src/trusted
HALINCDIR = ../../../hal/include
HALSGXSRCDIR = ../../../hal/sgx/src/trusted
POWHSMSRCDIR = ../../../powhsm/src
COMMONDIR = ../../../common/src

CFLAGS = -iquote $(TESTCOMMONDIR)
CFLAGS += -iquote $(SGXTRUSTEDDIR)
CFLAGS += -iquote $(HALINCDIR)
CFLAGS += -iquote $(HALSGXSRCDIR)
CFLAGS += -iquote $(POWHSMSRCDIR)
CFLAGS += -iquote $(COMMONDIR)
CFLAGS += -DHSM_PLATFORM_SGX

VPATH += $(SGXTRUSTEDDIR):$(COMMONDIR)

include ../../../../coverage/coverage.mk

CFLAGS += $(COVFLAGS)
13 changes: 13 additions & 0 deletions firmware/src/sgx/test/run-all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/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
38 changes: 38 additions & 0 deletions firmware/src/sgx/test/system/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# The MIT License (MIT)
#
# Copyright (c) 2021 RSK Labs Ltd
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
# of the Software, and to permit persons to whom the Software is furnished to do
# so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

include ../common/common.mk

PROG = test.out
OBJS = system.o test_system.o

all: $(PROG)

$(PROG): $(OBJS)
$(CC) $(COVFLAGS) -o $@ $^

.PHONY: clean test
clean:
rm -f $(PROG) *.o $(COVFILES)

test: all
./$(PROG)
Loading

0 comments on commit 8984008

Please sign in to comment.