Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
546e161
update optee jobs and scripts
stanley31huang Mar 19, 2025
e80ec67
update test case and test script
stanley31huang Mar 21, 2025
a5f201d
update snapcraft yaml
stanley31huang Mar 21, 2025
e2ccf45
fixed bug
stanley31huang Mar 21, 2025
587bd77
Update contrib/checkbox-ce-oem/checkbox-provider-ce-oem/data/xtest_su…
stanley31huang Mar 25, 2025
c1fd1c7
Update contrib/checkbox-ce-oem/checkbox-provider-ce-oem/bin/optee_hel…
stanley31huang Mar 25, 2025
53a2e85
update optee_helper
stanley31huang Mar 25, 2025
ae5e822
fixed coding style issue
stanley31huang Mar 25, 2025
0321457
update snapcraft yaml
stanley31huang Mar 25, 2025
f02b61d
Update contrib/checkbox-ce-oem/checkbox-ce-oem-snap/series_classic20/…
stanley31huang Mar 25, 2025
45f28c3
Update contrib/checkbox-ce-oem/checkbox-ce-oem-snap/series_classic24/…
stanley31huang Mar 25, 2025
98d52c0
Update contrib/checkbox-ce-oem/checkbox-ce-oem-snap/series_classic22/…
stanley31huang Mar 25, 2025
fe415d4
Update contrib/checkbox-ce-oem/checkbox-ce-oem-snap/series_uc20/snap/…
stanley31huang Mar 25, 2025
4a4cf6c
Update contrib/checkbox-ce-oem/checkbox-ce-oem-snap/series_uc22/snap/…
stanley31huang Mar 25, 2025
089dfe1
Update contrib/checkbox-ce-oem/checkbox-ce-oem-snap/series_uc24/snap/…
stanley31huang Mar 25, 2025
9ebc726
Update contrib/checkbox-ce-oem/checkbox-provider-ce-oem/bin/optee_hel…
stanley31huang Mar 25, 2025
4212e17
fix subprocess run
stanley31huang Mar 25, 2025
3f6e3c1
fix coding style issue
stanley31huang Mar 25, 2025
1e51e60
fix format string issue on py3.5
stanley31huang Mar 26, 2025
8fd71cf
fix python code style issue
stanley31huang Mar 26, 2025
a114a46
fix string format issue
stanley31huang Mar 26, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,29 @@ parts:
PART_SRC=${SNAPCRAFT_PROJECT_DIR}/parts/checkbox-provider-ce-oem/src
gcc ${PART_SRC}/src/input-pcspkr.c -o ${PART_SRC}/src/beep
cp -v ${PART_SRC}/src/beep ${SNAPCRAFT_PART_INSTALL}/usr/bin/
xtest:
plugin: dump
source: https://github.com/OP-TEE/optee_test.git
source-type: git
build-snaps:
- checkbox20
build-packages:
- jq
build-environment:
- PART_DEST: ${SNAPCRAFT_PART_INSTALL}/providers/checkbox-provider-ce-oem/data/
- PROVIDER_SRC: ${SNAPCRAFT_PROJECT_DIR}/../../checkbox-provider-ce-oem
- PYTHONPATH: /snap/checkbox20/current/lib/python3.8/site-packages/
override-pull: |
snapcraftctl pull
cp ${PROVIDER_SRC}/data/xtest_supported_version.json .
cp ${PROVIDER_SRC}/bin/optee_helper.py .
cp ${PROVIDER_SRC}/bin/look_up_xtest.py .
override-build: |
for ver in `cat xtest_supported_version.json | jq -r .xtest_suite_tag[]`; do
git checkout $ver
python3 optee_helper.py parse_xtest_src $ver
done
cp -v optee-test-*.json ${PART_DEST}
spidev-test:
plugin: make
source: https://github.com/torvalds/linux.git
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,29 @@ parts:
PART_SRC=${SNAPCRAFT_PROJECT_DIR}/parts/checkbox-provider-ce-oem/src
gcc ${PART_SRC}/src/input-pcspkr.c -o ${PART_SRC}/src/beep
cp -v ${PART_SRC}/src/beep ${SNAPCRAFT_PART_INSTALL}/usr/bin/
xtest:
plugin: dump
source: https://github.com/OP-TEE/optee_test.git
source-type: git
build-snaps:
- checkbox22
build-packages:
- jq
build-environment:
- PART_DEST: ${SNAPCRAFT_PART_INSTALL}/providers/checkbox-provider-ce-oem/data/
- PROVIDER_SRC: ${SNAPCRAFT_PROJECT_DIR}/../../checkbox-provider-ce-oem
- PYTHONPATH: /snap/checkbox22/current/lib/python3.10/site-packages/
override-pull: |
snapcraftctl pull
cp ${PROVIDER_SRC}/data/xtest_supported_version.json .
cp ${PROVIDER_SRC}/bin/optee_helper.py .
cp ${PROVIDER_SRC}/bin/look_up_xtest.py .
override-build: |
for ver in `cat xtest_supported_version.json | jq -r .xtest_suite_tag[]`; do
git checkout $ver
python3 optee_helper.py parse_xtest_src $ver
done
cp -v optee-test-*.json ${PART_DEST}
spidev-test:
plugin: make
source: https://github.com/torvalds/linux.git
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,29 @@ parts:
PART_SRC=${CRAFT_PROJECT_DIR}/parts/checkbox-provider-ce-oem/src
gcc ${PART_SRC}/src/input-pcspkr.c -o ${PART_SRC}/src/beep
cp -v ${PART_SRC}/src/beep ${CRAFT_PART_INSTALL}/usr/bin/
xtest:
plugin: dump
source: https://github.com/OP-TEE/optee_test.git
source-type: git
build-snaps:
- checkbox24
build-packages:
- jq
build-environment:
- PART_DEST: ${CRAFT_PART_INSTALL}/providers/checkbox-provider-ce-oem/data/
- PROVIDER_SRC: ${CRAFT_PROJECT_DIR}/../../checkbox-provider-ce-oem
- PYTHONPATH: /snap/checkbox24/current/lib/python3.12/site-packages/
override-pull: |
snapcraftctl pull
cp ${PROVIDER_SRC}/data/xtest_supported_version.json .
cp ${PROVIDER_SRC}/bin/optee_helper.py .
cp ${PROVIDER_SRC}/bin/look_up_xtest.py .
override-build: |
for ver in `cat xtest_supported_version.json | jq -r .xtest_suite_tag[]`; do
git checkout $ver
python3 optee_helper.py parse_xtest_src $ver
done
cp -v optee-test-*.json ${PART_DEST}
spidev-test:
plugin: make
source: https://github.com/torvalds/linux.git
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,29 @@ parts:
PART_SRC=${SNAPCRAFT_PROJECT_DIR}/parts/checkbox-provider-ce-oem/src
gcc ${PART_SRC}/src/input-pcspkr.c -o ${PART_SRC}/src/beep
cp -v ${PART_SRC}/src/beep ${SNAPCRAFT_PART_INSTALL}/usr/bin/
xtest:
plugin: dump
source: https://github.com/OP-TEE/optee_test.git
source-type: git
build-snaps:
- checkbox20
build-packages:
- jq
build-environment:
- PART_DEST: ${SNAPCRAFT_PART_INSTALL}/providers/checkbox-provider-ce-oem/data/
- PROVIDER_SRC: ${SNAPCRAFT_PROJECT_DIR}/../../checkbox-provider-ce-oem
- PYTHONPATH: /snap/checkbox20/current/lib/python3.8/site-packages/
override-pull: |
snapcraftctl pull
cp ${PROVIDER_SRC}/data/xtest_supported_version.json .
cp ${PROVIDER_SRC}/bin/optee_helper.py .
cp ${PROVIDER_SRC}/bin/look_up_xtest.py .
override-build: |
for ver in `cat xtest_supported_version.json | jq -r .xtest_suite_tag[]`; do
git checkout $ver
python3 optee_helper.py parse_xtest_src $ver
done
cp -v optee-test-*.json ${PART_DEST}
spidev-test:
plugin: make
source: https://github.com/torvalds/linux.git
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,29 @@ parts:
PART_SRC=${SNAPCRAFT_PROJECT_DIR}/parts/checkbox-provider-ce-oem/src
gcc ${PART_SRC}/src/input-pcspkr.c -o ${PART_SRC}/src/beep
cp -v ${PART_SRC}/src/beep ${SNAPCRAFT_PART_INSTALL}/usr/bin/
xtest:
plugin: dump
source: https://github.com/OP-TEE/optee_test.git
source-type: git
build-snaps:
- checkbox22
build-packages:
- jq
build-environment:
- PART_DEST: ${SNAPCRAFT_PART_INSTALL}/providers/checkbox-provider-ce-oem/data/
- PROVIDER_SRC: ${SNAPCRAFT_PROJECT_DIR}/../../checkbox-provider-ce-oem
- PYTHONPATH: /snap/checkbox22/current/lib/python3.10/site-packages/
override-pull: |
snapcraftctl pull
cp ${PROVIDER_SRC}/data/xtest_supported_version.json .
cp ${PROVIDER_SRC}/bin/optee_helper.py .
cp ${PROVIDER_SRC}/bin/look_up_xtest.py .
override-build: |
for ver in `cat xtest_supported_version.json | jq -r .xtest_suite_tag[]`; do
git checkout $ver
python3 optee_helper.py parse_xtest_src $ver
done
cp -v optee-test-*.json ${PART_DEST}
spidev-test:
plugin: make
source: https://github.com/torvalds/linux.git
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,29 @@ parts:
PART_SRC=${CRAFT_PROJECT_DIR}/parts/checkbox-provider-ce-oem/src
gcc ${PART_SRC}/src/input-pcspkr.c -o ${PART_SRC}/src/beep
cp -v ${PART_SRC}/src/beep ${CRAFT_PART_INSTALL}/usr/bin/
xtest:
plugin: dump
source: https://github.com/OP-TEE/optee_test.git
source-type: git
build-snaps:
- checkbox24
build-packages:
- jq
build-environment:
- PART_DEST: ${CRAFT_PART_INSTALL}/providers/checkbox-provider-ce-oem/data/
- PROVIDER_SRC: ${CRAFT_PROJECT_DIR}/../../checkbox-provider-ce-oem
- PYTHONPATH: /snap/checkbox24/current/lib/python3.12/site-packages/
override-pull: |
snapcraftctl pull
cp ${PROVIDER_SRC}/data/xtest_supported_version.json .
cp ${PROVIDER_SRC}/bin/optee_helper.py .
cp ${PROVIDER_SRC}/bin/look_up_xtest.py .
override-build: |
for ver in `cat xtest_supported_version.json | jq -r .xtest_suite_tag[]`; do
git checkout $ver
python3 optee_helper.py parse_xtest_src $ver
done
cp -v optee-test-*.json ${PART_DEST}
spidev-test:
plugin: make
source: https://github.com/torvalds/linux.git
Expand Down
207 changes: 207 additions & 0 deletions contrib/checkbox-ce-oem/checkbox-provider-ce-oem/bin/optee_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
#!/usr/bin/env python3
import argparse
import glob
import json
import os
import re
import shlex
import subprocess

from look_up_xtest import look_up_app
from pathlib import Path
from systemd import journal
from xtest_install_ta import find_ta_path, install_ta


TEST_FILE_PREFIX = "optee-test-"


def _run_command(cmd, **kwargs):
"""Helper function to run commands and print out the command and output"""
print("Running command: {}".format(cmd), flush=True)
try:
return subprocess.run(shlex.split(cmd), **kwargs)
except subprocess.CalledProcessError as e:
print(
"Command failed with return code {}".format(e.returncode),
flush=True,
)
print("Error output: {}".format(e.stderr), flush=True)
raise e
except Exception as e:
print(
"Unexpected error running command: {}".format(str(e)), flush=True
)
raise e


def launch_xtest(test_suite, test_id):
test_utility = look_up_app("xtest", os.environ.get("XTEST"))

print("Looking for PID of tee-supplicant..", flush=True)
_run_command("pgrep tee-supplicant", check=True)

optee_fw = _lookup_optee_version()

if optee_fw is None:
print(
"OPTEE firmware version unavailable in journal log"
", check OPTEE OS is activate",
flush=True,
)
return 2
elif optee_fw < "4.0":
ta_path = find_ta_path()
install_ta(test_utility, ta_path)

ret = _run_command(
"{} -t {} {}".format(test_utility, test_suite, test_id), check=False
)
return ret.returncode


def parse_test_cases():
test_cases = []
pattern = r"ADBG_CASE_DEFINE\((.*?), (.*?), (.*?),\s+\"(.*?)\"\);"

for file in glob.glob("**/*.c", recursive=True):
file_obj = Path(file)
matches = re.findall(pattern, file_obj.read_text(), re.DOTALL)
for match in matches:
suite, test_num, test_name, test_desc = match
test_desc = test_desc.replace(": ", " - ")

if suite.strip() not in ["ffa_spmc", "gp"]:
test_desc = test_desc.strip()
test_cases.append(
{
"suite": suite.strip(),
"test_id": test_num.strip(),
"test_name": test_name.strip(),
"test_description": test_desc,
}
)

return test_cases


def parse_xtest_src(version):
output_file = "{}{}.json".format(TEST_FILE_PREFIX, version)
test_cases = parse_test_cases()
with open(output_file, "w") as fp:
json.dump(test_cases, fp, indent=4)


def _lookup_optee_version():
j_reader = journal.Reader()
j_reader.this_boot()
for entry in j_reader:
match = re.search(
r"optee: (version|revision) (\d+.\d+)", entry["MESSAGE"]
)
if match:
return match.group(2)
return None


def check_version(expected_ver):

optee_version = _lookup_optee_version() or "unknown"
print("optee_firmware: {}".format(optee_version))
print("expected version: {}".format(expected_ver))
if not expected_ver or optee_version != expected_ver:
raise SystemExit("Error: OPTEE firmware version is not expected")
else:
print("Passed: OPTEE firmware version is expected")


def parse_json_file(filepath, filter_pkcs11=False):

if not filepath:
default_provider_path = (
"/snap/checkbox-ce-oem/current/providers"
"/checkbox-provider-ce-oem/data/"
)
fw_ver = _lookup_optee_version()
if not fw_ver:
print("error: failed to retrieve the version of optee")
return
# append 0 when the version is not fit
if len(fw_ver.split(".")) == 2:
filepath = "{}{}{}.0.json".format(
default_provider_path, TEST_FILE_PREFIX, fw_ver
)
else:
filepath = "{}{}{}.json".format(
default_provider_path, TEST_FILE_PREFIX, fw_ver
)

fp = Path(filepath)
if not fp.exists():
print("error: {} is not available".format(filepath))
else:
for test in json.loads(fp.read_text()):
if (filter_pkcs11 and test["suite"] == "pkcs11") or (
not filter_pkcs11 and test["suite"] != "pkcs11"
):
print_test_info(test)


def print_test_info(test):
print("suite: {}".format(test["suite"]))
print("test_id: {}".format(test["test_id"]))
print("test_name: {}".format(test["test_name"]))
print("description: {}".format(test["test_description"]))
print()


def register_arguments():
parser = argparse.ArgumentParser(description="OPTEE helper scripts")
sub_parsers = parser.add_subparsers(dest="action", required=True)

gen_tests_parser = sub_parsers.add_parser(
"generate", description="Parse an OPTEE JSON file"
)
gen_tests_parser.add_argument(
"-p",
"--pkcs11",
help="To filter out PKCS11 for the suite." "field in JSON.",
action="store_true",
)

parse_src_parser = sub_parsers.add_parser(
"parse_xtest_src",
description="Parse xtest source code and dump a JSON file",
)
parse_src_parser.add_argument("file_suffix")

check_parser = sub_parsers.add_parser(
"check_firmware_version", description="check OPTEE firmware"
)
check_parser.add_argument(
"expected_version", help="OPTEE firmware version"
)

test_parser = sub_parsers.add_parser(
"xtest", description="perform xtest case"
)
test_parser.add_argument("test_suite", type=str)
test_parser.add_argument("test_id", type=str)

return parser.parse_args()


def main():
args = register_arguments()
if args.action == "generate":
parse_json_file(os.environ.get("OPTEE_CASES"), args.pkcs11)
elif args.action == "check_firmware_version":
check_version(args.expected_version)
elif args.action == "parse_xtest_src":
parse_xtest_src(args.file_suffix)
elif args.action == "xtest":
raise SystemExit(launch_xtest(args.test_suite, args.test_id))


if __name__ == "__main__":
main()
Loading
Loading