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 b7debd7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 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
14 changes: 9 additions & 5 deletions tests/unit/conftests/test_base_conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
def prepare_base_dir(directory: 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 @@ -39,12 +42,13 @@ def test_prepare_speculos_args_simple_with_gui(self):

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 Down

0 comments on commit b7debd7

Please sign in to comment.