Skip to content

Commit

Permalink
Update path finding to main app in library mode
Browse files Browse the repository at this point in the history
  • Loading branch information
agrojean-ledger committed Feb 8, 2024
1 parent 063cd2c commit a5bc041
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
11 changes: 10 additions & 1 deletion src/ragger/conftest/base_conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,16 @@ def prepare_speculos_args(root_pytest_dir: Path, firmware: Firmware, display: bo
project_root_dir = find_project_root_dir(root_pytest_dir)

# Find the standalone application for the requested device
app_path = find_main_application(project_root_dir / conf.OPTIONAL.APP_DIR, device)
app_path = None
if conf.OPTIONAL.LOAD_MAIN_APP_AS_LIBRARY:
app_dir_children = list((project_root_dir / conf.OPTIONAL.APP_DIR).iterdir())
if len(app_dir_children) != 1:
raise ValueError(
f"Expected a single folder in {conf.OPTIONAL.APP_DIR}, found {len(app_dir_children)}"
)
app_path = find_main_application(app_dir_children[0], device)
else:
app_path = find_main_application(project_root_dir / conf.OPTIONAL.APP_DIR, device)

# Find all libraries that have to be sideloaded
if conf.OPTIONAL.LOAD_MAIN_APP_AS_LIBRARY:
Expand Down
23 changes: 14 additions & 9 deletions tests/unit/conftests/test_base_conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pathlib import Path
from typing import Tuple
from unittest import TestCase
from unittest.mock import patch

Expand All @@ -8,12 +9,15 @@
from ..helpers import temporary_directory


def prepare_base_dir(directory: Path) -> Path:
def prepare_base_dir(directory: Path) -> Tuple[Path, Path]:
(directory / ".git").mkdir()
(directory / "build" / "stax" / "bin").mkdir(parents=True, exist_ok=True)
(directory / "deps" / "dep" / "build" / "stax" / "bin").mkdir(parents=True, exist_ok=True)
dep_path = (directory / "deps" / "dep" / "build" / "stax" / "bin" / "app.elf")
dep_path.touch()
app_path = (directory / "build" / "stax" / "bin" / "app.elf")
app_path.touch()
return app_path
return app_path, dep_path


class TestBaseConftest(TestCase):
Expand All @@ -23,28 +27,29 @@ def setUp(self):

def test_prepare_speculos_args_simplest(self):
with temporary_directory() as temp_dir:
app_path = prepare_base_dir(temp_dir)
app_path, _ = prepare_base_dir(temp_dir)
result_app, result_args = bc.prepare_speculos_args(temp_dir, Firmware.STAX, False,
self.seed)
self.assertEqual(result_app, app_path)
self.assertEqual(result_args, {"args": ["--seed", self.seed]})

def test_prepare_speculos_args_simple_with_gui(self):
with temporary_directory() as temp_dir:
app_path = prepare_base_dir(temp_dir)
app_path, _ = prepare_base_dir(temp_dir)
result_app, result_args = bc.prepare_speculos_args(temp_dir, Firmware.STAX, True,
self.seed)
self.assertEqual(result_app, app_path)
self.assertEqual(result_args, {"args": ["--display", "qt", "--seed", self.seed]})

def test_prepare_speculos_args_main_as_library(self):
with temporary_directory() as temp_dir:
app_path = prepare_base_dir(temp_dir)
app_path, dep_path = prepare_base_dir(temp_dir)
with patch("ragger.conftest.base_conftest.conf.OPTIONAL.LOAD_MAIN_APP_AS_LIBRARY",
True):
result_app, result_args = bc.prepare_speculos_args(temp_dir, Firmware.STAX, False,
self.seed)
self.assertEqual(result_app, app_path)
with patch("ragger.conftest.base_conftest.conf.OPTIONAL.APP_DIR", "deps"):
result_app, result_args = bc.prepare_speculos_args(
temp_dir, Firmware.STAX, False, self.seed)
self.assertEqual(result_app, dep_path)
self.assertEqual(result_args, {"args": [f"-l{app_path}", "--seed", self.seed]})

def test_prepare_speculos_args_sideloaded_apps_nok_no_dir(self):
Expand All @@ -58,7 +63,7 @@ def test_prepare_speculos_args_sideloaded_apps_nok_no_dir(self):
def test_prepare_speculos_args_sideloaded_apps_ok(self):
lib1_bin, lib1_name, lib2_bin, lib2_name = "lib1", "name1", "lib2", "name2"
with temporary_directory() as temp_dir:
app_path = prepare_base_dir(temp_dir)
app_path, _ = prepare_base_dir(temp_dir)
sideloaded_apps_dir = temp_dir / "here"
sideloaded_apps_dir.mkdir()
lib1_path = sideloaded_apps_dir / f"{lib1_bin}_stax.elf"
Expand Down

0 comments on commit a5bc041

Please sign in to comment.