Skip to content

Commit

Permalink
[Checkbox-ce-oem] Modify job and script to support use x-test tool(Bu…
Browse files Browse the repository at this point in the history
…gfix) (#1075)

* Modify job and script too support use x-test tool

* Modify the logic to prioritize the x-test snap

* Modify the method to get xtest in gadget snap

Modify the method to call python script

* Separate look_up_xtest to another script
  • Loading branch information
rickwu666666 authored Mar 20, 2024
1 parent 07f2985 commit 873cccb
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 51 deletions.
31 changes: 31 additions & 0 deletions contrib/checkbox-provider-ce-oem/bin/look_up_xtest.py
Original file line number Diff line number Diff line change
@@ -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()
33 changes: 23 additions & 10 deletions contrib/checkbox-provider-ce-oem/bin/parse_optee_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down
54 changes: 13 additions & 41 deletions contrib/checkbox-provider-ce-oem/units/optee/jobs.pxu
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 }}

0 comments on commit 873cccb

Please sign in to comment.