diff --git a/contrib/checkbox-provider-ce-oem/bin/look_up_xtest.py b/contrib/checkbox-provider-ce-oem/bin/look_up_xtest.py new file mode 100755 index 000000000..2b05a4355 --- /dev/null +++ b/contrib/checkbox-provider-ce-oem/bin/look_up_xtest.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python3 + +from checkbox_support.snap_utils.snapd import Snapd +from checkbox_support.snap_utils.system import get_gadget_snap + + +def look_up_xtest(): + if Snapd().list("x-test"): + return "x-test.xtest" + elif look_up_gadget() is not False: + return look_up_gadget() + else: + raise SystemExit(1) + + +def look_up_gadget(): + gadget = get_gadget_snap() + snap = Snapd().list(gadget) + if "apps" in snap.keys(): + for app in snap["apps"]: + if app["name"] == "xtest": + return ".".join([app["snap"], app["name"]]) + return False + + +def main(): + print(look_up_xtest()) + + +if __name__ == "__main__": + main() diff --git a/contrib/checkbox-provider-ce-oem/bin/parse_optee_test.py b/contrib/checkbox-provider-ce-oem/bin/parse_optee_test.py index d7778aec0..9c9c307e2 100755 --- a/contrib/checkbox-provider-ce-oem/bin/parse_optee_test.py +++ b/contrib/checkbox-provider-ce-oem/bin/parse_optee_test.py @@ -2,32 +2,45 @@ import json import argparse +from look_up_xtest import look_up_xtest -def parse_json_file(filename, filter=False): - with open(filename, 'r') as file: +def parse_json_file(filepath, filter=False, xtest=None): + with open(filepath, 'r') as file: data = json.load(file) for test in data: - if (filter and test['suite'] == 'pkcs11') or \ - (not filter and test['suite'] not in ['pkcs11']): - print_test_info(test) + if check_suite(test['suite'], filter): + print_test_info(test, xtest) -def print_test_info(test): +def check_suite(suite, filter): + if filter: + return suite == 'pkcs11' + else: + return suite != 'pkcs11' + + +def print_test_info(test, xtest): print("suite: {}".format(test['suite'])) print("test_id: {}".format(test['test_id'])) - print("description: {}\n".format(test['test_description'])) + print("description: {}".format(test['test_description'])) + print("tool: {}\n".format(xtest)) def main(): parser = argparse.ArgumentParser(description='Parse a JSON file.') - parser.add_argument('filename', help='The name of the file to parse.') + parser.add_argument('filepath', + help='The path of the file to parse.') parser.add_argument('-p', '--pkcs11', - help='To filter out PKCS11 for the suite' + help='To filter out PKCS11 for the suite.' 'field in JSON.', action='store_true') args = parser.parse_args() - parse_json_file(args.filename, args.pkcs11) + try: + xtest = look_up_xtest() + except SystemExit: + xtest = None + parse_json_file(args.filepath, args.pkcs11, xtest) if __name__ == "__main__": diff --git a/contrib/checkbox-provider-ce-oem/units/optee/jobs.pxu b/contrib/checkbox-provider-ce-oem/units/optee/jobs.pxu index b2a2cfbdd..ede04a236 100644 --- a/contrib/checkbox-provider-ce-oem/units/optee/jobs.pxu +++ b/contrib/checkbox-provider-ce-oem/units/optee/jobs.pxu @@ -21,26 +21,18 @@ command: id: ce-oem-optee/xtest-check category_id: optee -_summary: Check if xtest is in the gedget snap. +_summary: Check if xtest is in the system. plugin: shell user: root estimated_duration: 20.0 -environ: OPTEE_TOOL command: - if [[ -z "$OPTEE_TOOL" ]]; then - gadget=$(snap list | awk '$NF == "gadget" {print $1}') - xtest=$(snap info "$gadget"|grep xtest) - if [[ "$xtest" ]]; then - echo -e "\nInfo: Gadget snap support xtest command!" - echo -e "$xtest" - exit 0 - else - echo -e "\nError: Gadget snap not support xtest command!" - echo -e "\nError: Please identify the tool name if needed!" - exit 1 - fi + tool=$(look_up_xtest.py) + exit_status=$? + if [[ "$exit_status" -eq 0 ]]; then + echo "Info: Found xtest runnable $tool" else - echo -e "\nInfo: Using $OPTEE_TOOL to excute OP-TEE test" + echo "Error: Not able to found xtest runnable tool" + exit 1 fi depends: ce-oem-optee/device-node @@ -51,18 +43,13 @@ plugin: shell user: root estimated_duration: 20.0 depends: ce-oem-optee/xtest-check -environ: OPTEE_TOOL command: - tool="" + tool=$(look_up_xtest.py) ta_path="" - if [[ -n "$OPTEE_TOOL" ]]; then - tool="$OPTEE_TOOL" - ta_path="/lib/optee_armtz/" + if [[ "$tool" == "x-test.xtest" ]]; then + ta_path="$(find /var/snap -wholename */lib/optee_armtz)" else - gadget=$(snap list | awk '$NF == "gadget" {print $1}') - # TA will be copied into this path once interface tee-tas connected. - # optee-test snap need to be installed in devmode - tool="$gadget.xtest" + gadget=$(awk -F"." '{ print $1}' <<< "$tool") ta_path="/snap/$gadget/current/lib/optee_armtz/" fi if [[ -z "$(find "$ta_path" -mindepth 1 -type f -o -type d)" ]]; then @@ -121,16 +108,8 @@ category_id: optee estimated_duration: 30 flags: also-after-suspend depends: ce-oem-optee/ta-install -environ: OPTEE_TOOL command: - tool="" - if [[ -n "$OPTEE_TOOL" ]]; then - tool="$OPTEE_TOOL" - else - gadget=$(snap list | awk '$NF == "gadget" {print $1}') - tool="$gadget.xtest" - fi - "$tool" -t {{ suite }} {{ test_id }} + {{ tool }} -t {{ suite }} {{ test_id }} unit: template template-resource: ce-oem-optee-test-list-pkcs11 @@ -146,11 +125,4 @@ estimated_duration: 30 depends: ce-oem-optee/xtest-check flags: also-after-suspend command: - tool="" - if [[ -n "$OPTEE_TOOL" ]]; then - tool="$OPTEE_TOOL" - else - gadget=$(snap list | awk '$NF == "gadget" {print $1}') - tool="$gadget.xtest" - fi - "$tool" -t {{ suite }} {{ test_id }} + {{ tool }} -t {{ suite }} {{ test_id }}