Skip to content

Commit

Permalink
[ci][fix] Comply with CI checks
Browse files Browse the repository at this point in the history
  • Loading branch information
lpascal-ledger committed Nov 20, 2023
1 parent a8e8731 commit f9b9ffa
Show file tree
Hide file tree
Showing 21 changed files with 116 additions and 71 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ file generated previously.
- `scan_all.yml`: Scans for selected devices
- `refresh_inputs.yml`: Check whether the input list needs updating.

To reduce CI run times, the input file is automatically splitted into 10 sub-inputs, and then all the inputs are run through a matrix strategy.
To reduce CI run times, the input file is automatically split into 10 sub-inputs, and then all the inputs are run through a matrix strategy.
### 3. Planned Improvements

- **Support for ZEMU Tests**
Expand All @@ -58,5 +58,5 @@ Alternatively you can run the script from the actions tab of the repo.
You can view the result in the summary of the GH action:
:red_circle: means a fail.
:heavy_check_mark: means success,
:fast_forward: means the action was explicitely blacklisted in the input file.
:fast_forward: means the action was explicitly blacklisted in the input file.
nothing: means there was no variant associated to the device when running make listvariants.
Empty file.
21 changes: 16 additions & 5 deletions scripts/build_and_test/build_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,25 @@
from utils import run_cmd
import os

def build_variant(target: str, sdk_path: str, variant_param: str, variant_value: str, app_build_path:
Path, extra_flags: str=""):

def build_variant(target: str,
sdk_path: str,
variant_param: str,
variant_value: str,
app_build_path: Path,
extra_flags: str = ""):

if not os.path.exists(app_build_path):
print("\t=> KO")
return True, f"Error: {app_build_path} does not exists\n"

error = run_cmd(f"TARGET={target} BOLOS_SDK={sdk_path} make clean", cwd=app_build_path, no_throw=True)
if variant_param:
error, log = run_cmd(f"TARGET={target} BOLOS_SDK={sdk_path} make {variant_param}={variant_value} {extra_flags}", cwd=app_build_path, no_throw=True)
error, log = run_cmd(f"TARGET={target} BOLOS_SDK={sdk_path} make {variant_param}={variant_value} {extra_flags}",
cwd=app_build_path, no_throw=True)
else:
error, log = run_cmd(f"TARGET={target} BOLOS_SDK={sdk_path} make -j {extra_flags}", cwd=app_build_path, no_throw=True)
error, log = run_cmd(f"TARGET={target} BOLOS_SDK={sdk_path} make -j {extra_flags}",
cwd=app_build_path, no_throw=True)

if error:
print("\t=> KO")
Expand Down Expand Up @@ -50,7 +57,11 @@ def build_device(device: Device, variant_param: str, app_build_path: Path, sdk_p
variants = app_json.get(f"variants_{device.model_name}", [])
variant_output = {}
if len(variants) > 0:
variant_output, error_log = build_all_variants(device.target_name, sdk_path, variant_param, variants, app_build_path)
variant_output, error_log = build_all_variants(device.target_name,
sdk_path,
variant_param,
variants,
app_build_path)

return variant_output, error_log

Expand Down
3 changes: 2 additions & 1 deletion scripts/build_and_test/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
NANOX_API_LEVEL = 5
STAX_API_LEVEL = 12


class Device:
def __init__(self, target_name: str, model_name:str, sdk_name: str, api_level: int, enabled: bool):
def __init__(self, target_name: str, model_name: str, sdk_name: str, api_level: int, enabled: bool):
self.selected = enabled
self.target_name = target_name
self.model_name = model_name
Expand Down
8 changes: 4 additions & 4 deletions scripts/build_and_test/main.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import json
from pathlib import Path
from argparse import ArgumentParser
from sha1 import override_sha1

from build_app import build_all_devices
from test_app import test_all_devices
from scan_app import scan_all_devices
from device import Devices
from utils import git_setup, merge_json
from sha1 import override_sha1

SDK_NAME = "sdk"
SDK_URL = "https://github.com/LedgerHQ/ledger-secure-sdk.git"
Expand Down Expand Up @@ -35,7 +36,7 @@
parser.add_argument("--input_file", required=False, type=Path, default=Path("input_files/test_input.json"))
parser.add_argument("--output_file", required=False, type=Path, default=Path("output_files/output.json"))
parser.add_argument("--logs_file", required=False, type=Path,
default=Path("output_files/error_logs.txt"))
default=Path("output_files/error_logs.txt"))
parser.add_argument("--workdir", required=False, type=str, default="workdir")

parser.add_argument("--use_sha1_from_live", required=False, action='store_true')
Expand Down Expand Up @@ -90,11 +91,10 @@

input_json = override_sha1(input_json, args.provider, args.device, args.version)


git_setup(SDK_NAME, args.sdk_ref, SDK_URL, abs_workdir)

output = {}
test_output = []
test_output = {}
build_output = []
logs = ""

Expand Down
22 changes: 17 additions & 5 deletions scripts/build_and_test/scan_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@
from device import Devices, Device
from utils import run_cmd

def scan_variant(target: str, sdk_path: str, variant_param: str, variant_value: str, app_build_path:
Path, extra_flags: str=""):

def scan_variant(target: str,
sdk_path: str,
variant_param: str,
variant_value: str,
app_build_path: Path,
extra_flags: str = ""):
error = run_cmd(f"TARGET={target} BOLOS_SDK={sdk_path} make clean", cwd=app_build_path, no_throw=True)
if variant_param:
error, log = run_cmd(f"TARGET={target} BOLOS_SDK={sdk_path} make {variant_param}={variant_value} -j ENABLE_SDK_WERROR=1 scan-build", cwd=app_build_path, no_throw=True)
error, log = run_cmd(f"TARGET={target} BOLOS_SDK={sdk_path} make {variant_param}={variant_value} "
"-j ENABLE_SDK_WERROR=1 scan-build",
cwd=app_build_path, no_throw=True)
else:
error, log = run_cmd(f"TARGET={target} BOLOS_SDK={sdk_path} make -j ENABLE_SDK_WERROR=1 scan-build", cwd=app_build_path, no_throw=True)
error, log = run_cmd(f"TARGET={target} BOLOS_SDK={sdk_path} make -j ENABLE_SDK_WERROR=1 scan-build",
cwd=app_build_path, no_throw=True)

if error:
print("\t=> KO")
Expand Down Expand Up @@ -44,7 +52,11 @@ def scan_device(device: Device, variant_param: str, app_build_path: Path, sdk_pa
variants = app_json.get(f"variants_{device.model_name}", [])
variant_output = {}
if len(variants) > 0:
variant_output, error_log = scan_all_variants(device.target_name, sdk_path, variant_param, variants, app_build_path)
variant_output, error_log = scan_all_variants(device.target_name,
sdk_path,
variant_param,
variants,
app_build_path)

return variant_output, error_log

Expand Down
25 changes: 14 additions & 11 deletions scripts/build_and_test/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
from device import Devices, Device
from build_app import build_variant
from utils import run_cmd
from typing import Tuple

def test(model: str, app_test_path: Path, app_build_path: Path, test_params: str):
output = {}
error, log = run_cmd(f"pytest {app_test_path}/ --tb=short -v --device {model} {test_params}", cwd=app_build_path, no_throw=True)

def test(model: str, app_test_path: Path, app_build_path: Path, test_params: str) -> Tuple[str, str]:
output: str
error, log = run_cmd(f"pytest {app_test_path}/ --tb=short -v --device {model} {test_params}",
cwd=app_build_path, no_throw=True)

if (error):
output = "Fail"
Expand All @@ -19,9 +22,10 @@ def install_dependencies(app_test_path: Path):
error, log = run_cmd("pip install -r requirements.txt", cwd=app_test_path, no_throw=True)
return error, log


def test_device(device: Device, variant_param: str, app_build_path: Path, app_test_path: Path,
sdk_path: Path, extra_flags: str, blacklist: str, test_params: str):
test_output = {}
sdk_path: Path, extra_flags: str, blacklist: str, test_params: str):
test_output: str
log = ""

if not device.selected:
Expand Down Expand Up @@ -58,24 +62,23 @@ def test_all_devices(devices: Devices, sdk_path: Path, app_json: dict, workdir:
}
output["test"] = {}

blacklist = app_json.get(f"test_blacklist", [])
blacklist = app_json.get("test_blacklist", [])

test_params = app_json.get("test_param_nanos", "")
nanos_output, nanos_log = test_device(devices.nanos, variant_param, app_build_path, app_test_path,
sdk_path, extra_flags, blacklist, test_params)
sdk_path, extra_flags, blacklist, test_params)

test_params = app_json.get("test_param_nanosp", "")
nanosp_output, nanosp_log = test_device(devices.nanosp, variant_param, app_build_path, app_test_path,
sdk_path, extra_flags, blacklist, test_params)

sdk_path, extra_flags, blacklist, test_params)

test_params = app_json.get("test_param_nanox", "")
nanox_output, nanox_log = test_device(devices.nanox, variant_param, app_build_path, app_test_path,
sdk_path, extra_flags, blacklist, test_params)
sdk_path, extra_flags, blacklist, test_params)

test_params = app_json.get("test_param_stax", "")
stax_output, stax_log = test_device(devices.stax, variant_param, app_build_path, app_test_path,
sdk_path, extra_flags, blacklist, test_params)
sdk_path, extra_flags, blacklist, test_params)

if nanos_output:
output["test"]["nanos"] = nanos_output
Expand Down
9 changes: 6 additions & 3 deletions scripts/build_and_test/utils.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import subprocess
import shutil
from pathlib import Path
from typing import Tuple


def run_cmd(cmd: str,
cwd: Path,
print_output: bool = True,
no_throw: bool = False) -> str:
no_throw: bool = False) -> Tuple[int, str]:
error_log = ""
print(f"[run_cmd] Running: {cmd} from {cwd}")

Expand Down Expand Up @@ -40,15 +41,17 @@ def git_setup(repo_name: str, repo_ref: str, repo_url: str, workdir: Path):
if not Path.exists(workdir/Path(repo_name)):
run_cmd(f"git {GIT_CONFIG} clone {repo_url} {repo_name}", cwd=workdir)
else:
run_cmd(f"git fetch", cwd=workdir/Path(repo_name))
run_cmd("git fetch", cwd=workdir/Path(repo_name))

error, _ = run_cmd(f"git checkout {repo_ref}", cwd=workdir/Path(repo_name), no_throw=True)
if error:
print("Error: removing folder")
shutil.rmtree(workdir/Path(repo_name))
return

error, _ = run_cmd(f"git {GIT_CONFIG} submodule update --init --recursive", cwd=workdir/Path(repo_name), no_throw=True)
error, _ = run_cmd(f"git {GIT_CONFIG} submodule update --init --recursive",
cwd=workdir/Path(repo_name),
no_throw=True)
if error:
print("Error: removing folder")
shutil.rmtree(workdir/Path(repo_name))
Expand Down
8 changes: 5 additions & 3 deletions scripts/create_app_list/app_load_params_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def parse_listapploadparams(app_load_params_str: str) -> Dict:
return dict(app_load_params)


def check_manifest(manifest: dict, database: dict) -> None:
def check_manifest(manifest: dict, database: dict) -> int:
ret = 0

for variant, data in manifest["VARIANTS"].items():
Expand Down Expand Up @@ -103,7 +103,8 @@ def check_manifest(manifest: dict, database: dict) -> None:
app_load_params_value = app_load_params.get(key)
if key == "appName":
if len(app_load_params_value) != 1:
print(f"[ERROR] Expected a single value for 'appName' ({app_load_params_value} vs {app_params_ref_value})")
print("[ERROR] Expected a single value for 'appName' "
f"({app_load_params_value} vs {app_params_ref_value})")
ret = -1
continue
app_load_params_value = app_load_params_value[0]
Expand All @@ -112,7 +113,8 @@ def check_manifest(manifest: dict, database: dict) -> None:
app_load_params_value = ["0x000"]

if len(app_load_params_value) != 1:
print(f"[ERROR] Expected a single value for 'appFlags' ({app_load_params_value} vs {app_params_ref_value})")
print("[ERROR] Expected a single value for 'appFlags' "
f"({app_load_params_value} vs {app_params_ref_value})")
ret = -1
continue

Expand Down
6 changes: 3 additions & 3 deletions scripts/create_app_list/app_load_params_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env python3

from pathlib import Path
import json
from pathlib import Path
from typing import Dict


def format_database(database: dict) -> str:
Expand All @@ -20,15 +21,14 @@ def format_database(database: dict) -> str:
return database_str


def load_database(database_path: Path):
def load_database(database_path: Path) -> Dict:
database = {}
if database_path.exists():
with open(database_path, 'r') as f:
database = json.load(f)
else:
with open(database_path, 'w') as f:
print("File created:", database_path)
database = []
return database


Expand Down
21 changes: 13 additions & 8 deletions scripts/create_app_list/gen_variant.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,35 @@
#!/usr/bin/env python3

from pathlib import Path
from makefile_dump import get_app_listvariants
from collections import namedtuple
from typing import Dict, List, Union

from makefile_dump import get_app_listvariants

Models = namedtuple('Models', ['sdk_value', 'device_name'])

MODELS = [Models("$NANOS_SDK", "nanos"),
Models("$NANOX_SDK", "nanox"),
Models("$NANOSP_SDK", "nanosp"),
Models("$STAX_SDK", "stax")]
Models("$NANOX_SDK", "nanox"),
Models("$NANOSP_SDK", "nanosp"),
Models("$STAX_SDK", "stax")]


def gen_variant(app_name: str, build_path: str, output_file: Path = "", workdir: Path = "") -> dict:
def gen_variant(app_name: str,
build_path: Path,
output_file: Path = Path(),
workdir: Path = Path()) -> dict:
print(f"Generating for {app_name}")

database_params = {
database_params: Dict[str, Union[str, List]] = {
"name": app_name,
}

# Retrieve available variants
for model in MODELS:
try:
variant_param_name, variants = get_app_listvariants(build_path, model.sdk_value, allow_failure=True)
except:
print("Skipping generation due to error")
except Exception as e:
print(f"Skipping generation due to error ({e})")
continue

database_params["variant_param"] = variant_param_name
Expand Down
4 changes: 1 addition & 3 deletions scripts/create_app_list/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import json

from parse_github import parse_github
import sys
sys.path.append('..')

from gen_variant import gen_variant
from utils import git_setup, merge_json

Expand Down Expand Up @@ -69,4 +68,3 @@

with open(args.full_output_file, 'w') as json_file:
json.dump(full_output, json_file, indent=1)

5 changes: 4 additions & 1 deletion scripts/create_app_list/makefile_dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
from pathlib import Path
from typing import Tuple, List

def get_app_listvariants(app_build_path: Path, sdk: str = "$NANOS_SDK", allow_failure: bool = False) -> Tuple[str, List[str]]:

def get_app_listvariants(app_build_path: Path,
sdk: str = "$NANOS_SDK",
allow_failure: bool = False) -> Tuple[str, List[str]]:
# Using listvariants Makefile target
listvariants = run_cmd(f"make BOLOS_SDK={sdk} listvariants", cwd=app_build_path, no_throw=allow_failure)
if "VARIANTS" not in listvariants:
Expand Down
7 changes: 3 additions & 4 deletions scripts/create_app_list/parse_github.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import requests
import json
from pathlib import Path
from typing import Dict, List, Union

base_url = "https://api.github.com"
org_name = "LedgerHQ"

repos_endpoint = f"{base_url}/orgs/{org_name}/repos"

params = {
params: Dict[str, Union[str, int]] = {
"type": "public",
"archived": "false",
"sort": "full_name",
Expand All @@ -16,7 +15,7 @@
}


def parse_github(access_token: str = "") -> str:
def parse_github(access_token: str = "") -> List[Dict]:
repos = []
headers = {
"Authorization": f"Bearer {access_token}",
Expand Down
Loading

0 comments on commit f9b9ffa

Please sign in to comment.