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

Adds "screen saver" mode to signer app #190

Merged
merged 8 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ jobs:
- name: Ledger UI's unit tests
run: firmware/src/ledger/ui/test/run-all.sh

- name: Ledger Signer's unit tests
run: firmware/src/ledger/signer/test/run-all.sh

run-integration-tests:
name: Integration tests
runs-on: ubuntu-20.04
Expand Down
1 change: 1 addition & 0 deletions QUICKSTART.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Unless otherwise stated, only x86 platforms are supported for building this proj
~/repo> middleware/test-all # Middleware unit tests
~/repo> firmware/test/test-all # Firmware tests
~/repo> firmware/src/ledger/ui/test/run-all.sh # Ledger UI application unit tests
~/repo> firmware/src/ledger/signer/test/run-all.sh # Ledger Signer application unit tests
~/repo> firmware/src/common/test/run-all.sh # Common code unit tests
~/repo> firmware/src/powhsm/test/run-all.sh # powHSM logic unit tests
~/repo> firmware/src/hal/test/run-all.sh # HAL unit tests
Expand Down
1 change: 1 addition & 0 deletions firmware/coverage/gen-coverage
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ if [[ $1 == "exec" ]]; then
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/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

# Run tcpsigner test suite
Expand Down
31 changes: 31 additions & 0 deletions firmware/src/ledger/signer/test/common.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# 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.

INCDIR = ../../../include
SRCDIR = ../../src
CFLAGS = -iquote $(INCDIR) -iquote $(SRCDIR)

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

CFLAGS += $(COVFLAGS)

VPATH += $(SRCDIR):$(INCDIR)
13 changes: 13 additions & 0 deletions firmware/src/ledger/signer/test/run-all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/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
45 changes: 45 additions & 0 deletions firmware/src/ledger/signer/test/signer_ux/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# 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.

PROG = test.out
OBJS = signer_ux.o test_signer_ux.o

include ../common.mk

all: $(PROG)

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

test_signer_ux.o: test_signer_ux.c
$(CC) $(CFLAGS) -c -o $@ $^

signer_ux.o: $(SRCDIR)/signer_ux.c
$(CC) $(CFLAGS) -c -o $@ $^

.PHONY: clean test

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

test: all
./$(PROG)
113 changes: 113 additions & 0 deletions firmware/src/ledger/signer/test/signer_ux/test_signer_ux.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/**
* 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 <assert.h>
#include <stdio.h>
#include "signer_ux.h"

static unsigned int G_mock_idle_time_ms;
static unsigned int G_mock_screensaver_timeout_ms;
enum mock_ui_state { MOCK_UI_INFO, MOCK_UI_SCREENSAVER, MOCK_UI_INVALID };
enum mock_ui_state G_mock_ui_state;

// Helper functions
static unsigned int max(unsigned int a, unsigned int b) {
return a > b ? a : b;
}

// Mock function calls
void signer_ux_info(void) {
G_mock_ui_state = MOCK_UI_INFO;
}

void signer_ux_screensaver(void) {
G_mock_ui_state = MOCK_UI_SCREENSAVER;
}
italo-sampaio marked this conversation as resolved.
Show resolved Hide resolved

// Test cases
void setup() {
G_mock_idle_time_ms = 0;
G_mock_screensaver_timeout_ms = 30000;
G_mock_ui_state = MOCK_UI_INVALID;
signer_ux_init(G_mock_screensaver_timeout_ms);
}

void test_init() {
printf("Test init...\n");
setup();
assert(MOCK_UI_INFO == G_mock_ui_state);
}

void test_ui_info_ui_screensaver_transition() {
printf("Test transition from UI_INFO to UI_SCREENSAVER...\n");
setup();
signer_ux_handle_ticker_event(G_mock_screensaver_timeout_ms - 1);
assert(MOCK_UI_INFO == G_mock_ui_state);
signer_ux_handle_ticker_event(1);
assert(MOCK_UI_SCREENSAVER == G_mock_ui_state);
}

void test_ui_screensaver_ui_info_transition() {
printf("Test transition from UI_SCREENSAVER to UI_INFO...\n");
setup();
signer_ux_handle_ticker_event(G_mock_screensaver_timeout_ms);
assert(MOCK_UI_SCREENSAVER == G_mock_ui_state);
signer_ux_handle_button_press();
assert(MOCK_UI_INFO == G_mock_ui_state);
}

void test_multiple_button_presses() {
printf("Test multiple button presses...\n");
setup();
for (int i = 0; i < 100; ++i) {
signer_ux_handle_ticker_event(G_mock_screensaver_timeout_ms - 1);
assert(MOCK_UI_INFO == G_mock_ui_state);
signer_ux_handle_button_press();
assert(MOCK_UI_INFO == G_mock_ui_state);
}
}

void test_timer_overflow() {
printf("Test timer overflow protection...\n");
setup();
unsigned int mock_tick_ms = 100;
signer_ux_handle_ticker_event(__UINT32_MAX__ - 100);
assert(MOCK_UI_SCREENSAVER == G_mock_ui_state);
for (int i = 0; i < 1000; i += mock_tick_ms) {
signer_ux_handle_ticker_event(mock_tick_ms);
assert(MOCK_UI_SCREENSAVER == G_mock_ui_state);
}
signer_ux_handle_button_press();
assert(MOCK_UI_INFO == G_mock_ui_state);
}

int main() {
test_init();
test_ui_info_ui_screensaver_transition();
test_ui_screensaver_ui_info_transition();
test_multiple_button_presses();
test_timer_overflow();

return 0;
}
Loading