Skip to content

Commit

Permalink
Rebase on latest boilerplate 1a07884
Browse files Browse the repository at this point in the history
  • Loading branch information
b0l0k committed Aug 6, 2023
1 parent c203fc7 commit f3744aa
Show file tree
Hide file tree
Showing 99 changed files with 521 additions and 3,031 deletions.
2 changes: 1 addition & 1 deletion .doxygen/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ DOXYFILE_ENCODING = UTF-8
# title of most generated pages and in a few other places.
# The default value is: My Project.

PROJECT_NAME = "Boilerplate"
PROJECT_NAME = "Ledgstr"

# The PROJECT_NUMBER tag can be used to enter a project or revision number. This
# could be handy for archiving the generated documentation or if some version
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,16 @@ jobs:
- name: Clone
uses: actions/checkout@v3

- name: Clone SDK
uses: actions/checkout@v3
with:
repository: ledgerHQ/ledger-secure-sdk
path: sdk

- name: Build unit tests
run: |
cd unit-tests/
export BOLOS_SDK=../sdk
cmake -Bbuild -H. && make -C build && make -C build test
- name: Generate code coverage
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ __pycache__/
# Doxygen
doc/html
doc/latex

# Virtual env for sideload (macOS and Windows)
ledger/
1 change: 1 addition & 0 deletions .vscode/20-ledger.ledgerblue.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SUBSYSTEMS=="usb", ATTRS{idVendor}=="2c97", ATTRS{idProduct}=="0006|6000|6001|6002|6003|6004|6005|6006|6007|6008|6009|600a|600b|600c|600d|600e|600f|6010|6011|6012|6013|6014|6015|6016|6017|6018|6019|601a|601b|601c|601d|601e|601f", TAG+="uaccess", TAG+="udev-acl"
3 changes: 1 addition & 2 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@
"browse": {
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
},
"configurationProvider": "ms-vscode.makefile-tools"
}
}
],
"version": 4
Expand Down
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"ms-vscode.cpptools",
]
}
20 changes: 10 additions & 10 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"files.associations": {
"*.h": "c",
"string": "c"
"*.h": "c"
},
"C_Cpp.clang_format_path": "/usr/bin/clang-format-11",
"editor.formatOnSave": true,
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
"C_Cpp.clang_format_path": "/usr/bin/clang-format",
"editor.formatOnSave": false,
"task.autoDetect": "off",
"python.terminal.activateEnvironment": false,
"buid_dir_relative_path":".",
"linux_udev_ledgerblue_rule_file":"20-ledger.ledgerblue.rules",
"docker_image": "ghcr.io/ledgerhq/ledger-app-builder/ledger-app-dev-tools:latest",
"container_name": "${workspaceFolderBasename}-container",
}
152 changes: 121 additions & 31 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,53 @@
"version": "2.0.0",
"tasks": [
{
"label": "make",
"label": "Run dev-tools image",
"type": "shell",
"command": "make clean && make",
// Checks if a container with the name ${config:container_name} exists, and if it does, it is stopped and removed before a new container is created using the same name and other specified configuration parameters
"linux" : {
"command": "docker ps -a --format '{{.Names}}' | grep -q ${config:container_name} && (docker container stop ${config:container_name} && docker container rm ${config:container_name}) ; docker pull ${config:docker_image} && docker run --user $(id -u):$(id -g) --privileged -e DISPLAY=$DISPLAY -v '/dev/bus/usb:/dev/bus/usb' -v '/tmp/.X11-unix:/tmp/.X11-unix' -v '${workspaceFolder}:/app' -t -d --name ${config:container_name} ${config:docker_image}",
},
"windows" : {
"command": "if (docker ps -a --format '{{.Names}}' | Select-String -Quiet ${config:container_name}) { docker container stop ${config:container_name}; docker container rm ${config:container_name} }; docker pull ${config:docker_image}; docker run --privileged -e DISPLAY='host.docker.internal:0' -v '${workspaceFolder}:/app' -t -d --name ${config:container_name} ${config:docker_image} ",
},
"osx" : {
"command": "xhost + ; docker ps -a --format '{{.Names}}' | grep -q ${config:container_name} && (docker container stop ${config:container_name} && docker container rm ${config:container_name}) ; docker pull ${config:docker_image} && docker run --user $(id -u):$(id -g) --privileged -e DISPLAY='host.docker.internal:0' -v '/tmp/.X11-unix:/tmp/.X11-unix' -v '${workspaceFolder}:/app' -t -d --name ${config:container_name} ${config:docker_image}",
},
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [
"$gcc"
]
"problemMatcher": []
},
{
"label": "[debug] make",
"label": "Open dev-tools container terminal",
"type": "shell",
"command": "make clean && make DEBUG=1",
// Opens a terminal of the dev-tools container.
"command": "docker exec -it ${config:container_name} bash",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": []
},
{
"label": "Build app",
"type": "shell",
// Builds the app in release mode using the make command, inside the docker container.
"command": "docker exec -it ${config:container_name} bash -c 'export BOLOS_SDK=$(echo ${input:sdk}) && make -j'",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [
"$gcc"
]
},
{
"label": "make clean",
"label": "Build app [debug]",
"type": "shell",
"command": "make clean",
// Builds the app with debug mode enabled using the make command, inside the docker container.
"command": "docker exec -it ${config:container_name} bash -c 'export BOLOS_SDK=$(echo ${input:sdk}) && make -j DEBUG=1'",
"group": {
"kind": "build",
"isDefault": true
Expand All @@ -38,9 +58,10 @@
]
},
{
"label": "make load",
"label": "Clean build files",
"type": "shell",
"command": "make load",
// Cleans all app build files (for all device models).
"command": "docker exec -it ${config:container_name} bash -c 'make clean'",
"group": {
"kind": "build",
"isDefault": true
Expand All @@ -50,62 +71,131 @@
]
},
{
"label": "run unit tests",
"label": "Test app with Speculos",
"type": "shell",
"command": "cd unit-tests && rm -rf build && cmake -Bbuild -H. && make -C build && CTEST_OUTPUT_ON_FAILURE=1 make -C build test",
// Runs the app on the speculos emulator for the selected device model, in the docker container.
"command":"docker exec -it ${config:container_name} bash -c 'speculos --model ${input:model} build/${input:model}/bin/app.elf'",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [
"$gcc"
]
"problemMatcher": []
},
{
"label": "run Speculos",
"label": "Kill Speculos",
"type": "shell",
"command": "python /path/to/speculos/speculos.py ${workspaceFolder}/bin/app.elf --ontop --sdk 1.6 --apdu-port 9999 --button-port 42000 --automation-port 43000",
// Kills speculos emulator in the docker container.
"command": "docker exec -it ${config:container_name} bash -c 'pkill -f speculos'",
"group": {
"kind": "build",
"isDefault": true
},
"dependsOn": [
"make debug"
],
"problemMatcher": []
},
{
"label": "[debug] run Speculos",
"label": "Run functional tests",
"type": "shell",
"command": "python /path/to/speculos/speculos.py -d ${workspaceFolder}/bin/app.elf --ontop --sdk 1.6 --apdu-port 9999 --button-port 42000 --automation-port 43000",
// Runs functional tests inside the docker container (with Qt display disabled).
"command": "docker exec -it ${config:container_name} bash -c 'pytest tests/ --tb=short -v --device ${input:model}'",
"group": {
"kind": "build",
"isDefault": true
},
"dependsOn": [
"make debug"
],
"problemMatcher": []
},
{
"label": "run tests",
"label": "Run functional tests (with display)",
"type": "shell",
"command": "cd tests && pytest",
// Runs functional tests inside the docker container (with Qt display enabled).
"command": "docker exec -it ${config:container_name} bash -c 'pytest tests/ --tb=short -v --device ${input:model} --display'",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": []
},
{
"label": "kill Speculos",
"label": "Install tests requirements",
"type": "shell",
"command": "pkill -f speculos.py",
// Installs functional tests python requirements in the docker container.
"command":"docker exec -it -u 0 ${config:container_name} bash -c 'apk add gcc musl-dev python3-dev && pip install -r tests/requirements.txt'",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": []
},
{
"label": "Load app on device",
"type": "shell",
"linux" : {
// Executes make load in the container to load the app on a physical device.
"command": "docker exec -it ${config:container_name} bash -c 'export BOLOS_SDK=$(echo ${input:sdk}) && make load'",
},
"windows" : {
// Side loads the app APDU file using ledgerblue runScript.
"command": "cmd.exe /C '.\\ledger\\Scripts\\activate.bat && python -m ledgerblue.runScript --scp --fileName ${config:buid_dir_relative_path}/bin/app.apdu --elfFile ${config:buid_dir_relative_path}/bin/app.elf'",
},
"osx" : {
// Side loads the app APDU file using ledgerblue runScript.
"command": "source ledger/bin/activate && python3 -m ledgerblue.runScript --scp --fileName ${config:buid_dir_relative_path}/bin/app.apdu --elfFile ${config:buid_dir_relative_path}/bin/app.elf",
},
"group": {
"kind": "build",
"isDefault": true
},
"dependsOn": [
"Install app loading requirements"
],
"problemMatcher": []
},
// ------------------------------------------------------------------------------
// Helper tasks put in 'test' group so they are hidden from the build tasks menu.
// ------------------------------------------------------------------------------
{
"label": "Install app loading requirements",
"type": "shell",
"linux" : {
// Copies the ledger udev rule file to the /etc/udev/rules.d/ directory if it does not exist, then reloads the rules and triggers udev.
"command": "if [ ! -f '/etc/udev/rules.d/${config:linux_udev_ledgerblue_rule_file}' ]; then sudo cp .vscode/${config:linux_udev_ledgerblue_rule_file} /etc/udev/rules.d/ && sudo udevadm control --reload-rules && sudo udevadm trigger; fi",
},
"windows" : {
// Checks that virtual env is installed, otherwise installs it. Then installs ledgerblue in a virtualenv.
"command": "cmd.exe /C 'if not exist ledger (python -m pip install virtualenv && python -m venv ledger && call ledger\\Scripts\\activate.bat && python -m pip install ledgerblue)'",
},
"osx" : {
// Checks that virtual env is installed, otherwise installs it. Then installs ledgerblue in a virtualenv.
"command": "[ -n '$VIRTUAL_ENV' ] || if ! python3 -m virtualenv --version >/dev/null 2>&1; then python3 -m pip install virtualenv; fi && [ -d 'ledger' ] || python3 -m virtualenv ledger && source ledger/bin/activate && python3 -m pip show ledgerblue >/dev/null 2>&1 || python3 -m pip install ledgerblue",
},
"group": {
"kind": "test",
"isDefault": true
},
"problemMatcher": []
},
],
"inputs": [
{
"id" : "sdk",
"type": "pickString",
"description": "Choose a SDK to build with",
"options": [
"$NANOS_SDK",
"$NANOX_SDK",
"$NANOSP_SDK",
"$STAX_SDK",
]
},
{
"id" : "model",
"type": "pickString",
"description": "Which model to run speculos for ?",
"options": [
"nanos",
"nanox",
"nanosp",
"stax",
]
}
]
}
}
Loading

0 comments on commit f3744aa

Please sign in to comment.