Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test Jobs for V4L2 Compliance (New) #1653

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
74 changes: 74 additions & 0 deletions providers/base/bin/v4l2_compliance_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#! /usr/bin/python3

import argparse
import sys
from checkbox_support.parsers.v4l2_compliance import parse_v4l2_compliance

Check warning on line 5 in providers/base/bin/v4l2_compliance_test.py

View check run for this annotation

Codecov / codecov/patch

providers/base/bin/v4l2_compliance_test.py#L3-L5

Added lines #L3 - L5 were not covered by tests

"""

Check warning on line 7 in providers/base/bin/v4l2_compliance_test.py

View check run for this annotation

Codecov / codecov/patch

providers/base/bin/v4l2_compliance_test.py#L7

Added line #L7 was not covered by tests
class Input:
ioctl: T.List[str]
device: str
"""


def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument(

Check warning on line 16 in providers/base/bin/v4l2_compliance_test.py

View check run for this annotation

Codecov / codecov/patch

providers/base/bin/v4l2_compliance_test.py#L14-L16

Added lines #L14 - L16 were not covered by tests
"--device",
help="The device to test, if not specified, "
"we will let v4l2-compliance infer the default device "
"(usually /dev/video0)",
type=str,
)
parser.add_argument(

Check warning on line 23 in providers/base/bin/v4l2_compliance_test.py

View check run for this annotation

Codecov / codecov/patch

providers/base/bin/v4l2_compliance_test.py#L23

Added line #L23 was not covered by tests
"--ioctl",
nargs="+",
help=(
"List of ioctl requests. "
"If any of them is listed under FAIL in v4l2-compliance, "
"the entire test cases fails. "
"ioctl requests should start with VIDIOC_, "
"for example VIDIOC_ENUM_FMT "
"NOTE: VIDIOC_QUERYCAP is always required"
),
default=["VIDIOC_QUERYCAP"],
)
parser.add_argument(

Check warning on line 36 in providers/base/bin/v4l2_compliance_test.py

View check run for this annotation

Codecov / codecov/patch

providers/base/bin/v4l2_compliance_test.py#L36

Added line #L36 was not covered by tests
"--treat-unsupported-as-fail",
action="store_true",
help="If specified, and if any of the ioctls are in unsupported, "
"they are treated as fail and will fail the test case",
default=False,
)
return parser.parse_args() # type: ignore

Check warning on line 43 in providers/base/bin/v4l2_compliance_test.py

View check run for this annotation

Codecov / codecov/patch

providers/base/bin/v4l2_compliance_test.py#L43

Added line #L43 was not covered by tests


def main():
args = parse_args()
print(

Check warning on line 48 in providers/base/bin/v4l2_compliance_test.py

View check run for this annotation

Codecov / codecov/patch

providers/base/bin/v4l2_compliance_test.py#L46-L48

Added lines #L46 - L48 were not covered by tests
"Testing if all of the following ioctl requests",
args.ioctl,
"are supported on",
args.device or "/dev/video0",
)

_, details = parse_v4l2_compliance(args.device)

Check warning on line 55 in providers/base/bin/v4l2_compliance_test.py

View check run for this annotation

Codecov / codecov/patch

providers/base/bin/v4l2_compliance_test.py#L55

Added line #L55 was not covered by tests

return_code = 0

Check warning on line 57 in providers/base/bin/v4l2_compliance_test.py

View check run for this annotation

Codecov / codecov/patch

providers/base/bin/v4l2_compliance_test.py#L57

Added line #L57 was not covered by tests

if "VIDIOC_QUERYCAP" in details["failed"]:
return_code = 1

Check warning on line 60 in providers/base/bin/v4l2_compliance_test.py

View check run for this annotation

Codecov / codecov/patch

providers/base/bin/v4l2_compliance_test.py#L60

Added line #L60 was not covered by tests
for ioctl_request in args.ioctl:
if ioctl_request in details["failed"]:
print(ioctl_request, "failed the test", file=sys.stderr)
return_code = 1

Check warning on line 64 in providers/base/bin/v4l2_compliance_test.py

View check run for this annotation

Codecov / codecov/patch

providers/base/bin/v4l2_compliance_test.py#L63-L64

Added lines #L63 - L64 were not covered by tests

if return_code == 0:
print(args.ioctl, "are all supported")

Check warning on line 67 in providers/base/bin/v4l2_compliance_test.py

View check run for this annotation

Codecov / codecov/patch

providers/base/bin/v4l2_compliance_test.py#L67

Added line #L67 was not covered by tests

return return_code

Check warning on line 69 in providers/base/bin/v4l2_compliance_test.py

View check run for this annotation

Codecov / codecov/patch

providers/base/bin/v4l2_compliance_test.py#L69

Added line #L69 was not covered by tests


if __name__ == "__main__":
return_code = main()
exit(return_code)
21 changes: 21 additions & 0 deletions providers/base/units/camera/jobs.pxu
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,27 @@ command:
udev_resource.py -f MMAL | grep "category: MMAL"
_summary: Detect presence of a MMAL camera.

id: camera/v4l2-ioctl_resource
_summary: Generates ioctl names for v4l2 compliance test
_description: Generates ioctl names for v4l2 compliance test
estimated_duration: 0.02
category_id: com.canonical.plainbox::camera
plugin: resource
command:
v4l2_ioctl_resource.py

unit: template
category_id: com.canonical.plainbox::camera
template-resource: camera/v4l2-ioctl_resource
template-unit: job
template-id: camera/v4l2-compliance_ioctl_name
_template-summary: To check if {ioctl_name} works on {name}
id: camera/v4l2-compliance_{ioctl_name}
_summary: v4l2 compliance for {ioctl_name} on {name}
plugin: shell
command:
v4l2_compliance_test.py --device /dev/{name} --ioctl {ioctl_name}

unit: template
template-resource: device
template-filter: device.category == 'CAPTURE' and device.name != ''
Expand Down
2 changes: 2 additions & 0 deletions providers/base/units/camera/test-plan.pxu
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ _description: Camera tests (automated)
include:
camera/detect certification-status=blocker
camera/multiple-resolution-images_.* certification-status=blocker
camera/v4l2-compliance_.* certification-status=blocker
camera/multiple-resolution-images-attachment_.* certification-status=non-blocker
camera/camera-quality_.* certification-status=non-blocker
camera/camera-quality-image_.* certification-status=non-blocker
bootstrap_include:
device
camera/v4l2-ioctl_resource

id: camera-cert-blockers
unit: test plan
Expand Down
26 changes: 26 additions & 0 deletions providers/resource/bin/v4l2_ioctl_resource.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#! /usr/bin/python3

from checkbox_support.parsers.v4l2_compliance import TEST_NAME_TO_IOCTL_MAP
import subprocess as sp

Check warning on line 4 in providers/resource/bin/v4l2_ioctl_resource.py

View check run for this annotation

Codecov / codecov/patch

providers/resource/bin/v4l2_ioctl_resource.py#L3-L4

Added lines #L3 - L4 were not covered by tests


def main():
try:
udev_out = sp.check_output(

Check warning on line 9 in providers/resource/bin/v4l2_ioctl_resource.py

View check run for this annotation

Codecov / codecov/patch

providers/resource/bin/v4l2_ioctl_resource.py#L7-L9

Added lines #L7 - L9 were not covered by tests
"udev_resource.py -f CAPTURE", universal_newlines=True, shell=True
)
lines = udev_out.splitlines()
except Exception as e:
lines = [f"name: broken {str(e)}"]

Check warning on line 14 in providers/resource/bin/v4l2_ioctl_resource.py

View check run for this annotation

Codecov / codecov/patch

providers/resource/bin/v4l2_ioctl_resource.py#L12-L14

Added lines #L12 - L14 were not covered by tests

for line in lines:
if line.startswith("name:"):
for ioctl_names in TEST_NAME_TO_IOCTL_MAP.values():
for name in ioctl_names:
print(line)
print("ioctl_name:", format(name))
print() # empty line to mark end of list item

Check warning on line 22 in providers/resource/bin/v4l2_ioctl_resource.py

View check run for this annotation

Codecov / codecov/patch

providers/resource/bin/v4l2_ioctl_resource.py#L20-L22

Added lines #L20 - L22 were not covered by tests


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