blob: f3d70a87f6990cf92349fd2a9bee79e05914b5f7 [file] [log] [blame]
# Lint as: python2, python3
# Copyright 2018 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import contextlib
import json
import logging
import os
import time
from autotest_lib.client.common_lib import error, utils
class ChartFixture:
"""Sets up chart tablet to display placeholder scene image."""
DISPLAY_SCRIPT = '/usr/local/autotest/bin/'
OUTPUT_LOG = '/tmp/chart_service.log'
def __init__(self, chart_host, scene_uri): = chart_host
self.scene_uri = scene_uri
self.display_pid = None['rm', '-f', self.OUTPUT_LOG])
def initialize(self):
"""Prepare scene file and display it on chart host."""'Prepare scene file')
if utils.is_in_container():
# Reboot chart to clean the dirty state from last test. See
# b/201032899.
tmpdir =
scene_path = os.path.join(
tmpdir, self.scene_uri[self.scene_uri.rfind('/') + 1:])'wget', args=('-O', scene_path, self.scene_uri))'Display scene file')
self.display_pid =
'python2 {script} {scene} >{log} 2>&1'.format(
'Poll for "is ready" message for ensuring chart is ready.')
timeout = 60
poll_time_step = 0.1
while timeout > 0:
args=('-q', 'Chart is ready.', self.OUTPUT_LOG),
ignore_status=True).exit_status == 0:
timeout -= poll_time_step
raise error.TestError('Timeout waiting for chart ready')
def cleanup(self):
"""Cleanup display script."""
if self.display_pid is not None:
args=('-2', str(self.display_pid)),
ignore_status=True), '.')
def get_chart_address(host_address, args):
"""Get address of chart tablet from commandline args or mapping logic in
test lab.
@param host_address: a list of hostname strings.
@param args: a dict parse from commandline args.
A list of strings for chart tablet addresses.
address = utils.args_to_dict(args).get('chart')
if address is not None:
return address.split(',')
elif utils.is_in_container():
return [utils.get_lab_chart_address(host) for host in host_address]
return None
class DUTFixture:
"""Sets up camera filter for target camera facing on DUT."""
TEST_CONFIG_PATH = '/var/cache/camera/test_config.json'
CAMERA_SCENE_LOG = '/tmp/scene.jpg'
def __init__(self, test, host, facing):
self.test = test = host
self.facing = facing
def _set_selinux_permissive(self):
selinux_mode ='getenforce')'setenforce 0')
yield'setenforce', args=(selinux_mode, ))
def _write_file(self, filepath, content, permission=None, owner=None):
"""Write content to filepath on remote host.
@param permission: set permission to 0xxx octal number of remote file.
@param owner: set owner of remote file.
tmp_path = os.path.join(self.test.tmpdir, os.path.basename(filepath))
with open(tmp_path, 'w') as f:
if permission is not None:
os.chmod(tmp_path, permission), filepath, delete_dest=True)
if owner is not None:'chown', args=(owner, filepath))
def initialize(self):
"""Filter out camera other than target facing on DUT."""
'enable_back_camera': self.facing == 'back',
'enable_front_camera': self.facing == 'front',
'enable_external_camera': False
# cros_camera_service will reference the test config to filter out
# undesired cameras.'Restart camera service with filter option')'cros-camera')
# arc_setup will reference the test config to filter out the media
# profile of undesired cameras.'Restart ARC++ container with camera test config')'restart ui')
def _stop_camera_service(self):
# Ensure camera service is running or the
# upstart_stop()/upstart_restart() may failed due to in
# "start|post-stop" sleep for respawning state. See b/183904344 for
# detail.'Wait for presence of camera service')'cros-camera')'cros-camera')
def log_camera_scene(self):
"""Capture an image from camera as the log for debugging scene related
gtest_filter = (
with self._stop_camera_service():
args=('--user=arc-camera', 'cros_camera_test',
'--gtest_filter=' + gtest_filter,
'--camera_facing=' + self.facing,
'--dump_still_capture_path=' +
self.CAMERA_SCENE_LOG)), '.')
def cleanup(self):
"""Cleanup camera filter."""'Remove filter option and restore camera service')
with self._stop_camera_service():'rm', args=('-f', self.TEST_CONFIG_PATH))'Restore camera profile in ARC++ container')'restart ui')