blob: decdb3dde3b5d15814460b1fd8fed31eedc398e9 [file] [log] [blame]
# -*- coding: utf-8 -*-
# Copyright (c) 2014 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.
"""Integration VM test for cros commands.
To run this command, first build a test image. e.g.
(host)$ cros_sdk
(sdk)$ ./build_packages --board=betty
(sdk)$ ./build_image --board=betty test
(sdk)$ ./image_to_vm.sh --board=betty --test_image
(sdk)$ cd ../../chromite/cli/cros/tests/
(sdk)$ ./cros_vm_test --board=betty --image_path \
~/trunk/src/build/images/betty/latest/chromiumos_qemu_image.bin
"""
from __future__ import print_function
from chromite.cli import command_vm_test
from chromite.lib import commandline
class CrosVMTest(command_vm_test.CommandVMTest):
"""Test class for cros commands."""
def BuildCommand(self, command, device=None, pos_args=None, opt_args=None):
"""Builds a cros command.
Args:
command: The subcommand to build on (e.g. 'flash', 'deploy').
device: The device's address for the command.
pos_args: A list of positional arguments for the command.
opt_args: A list of optional arguments for the command.
Returns:
A full cros command as a list.
"""
cmd = ['cros', command]
if opt_args:
cmd.extend(opt_args)
if device:
if command == 'devices':
# The device argument is optional for 'cros devices' command.
cmd.extend(['--device', device])
else:
cmd.append(device)
if pos_args:
cmd.extend(pos_args)
return cmd
def _ParseArguments(argv):
"""Parses command-line arguments."""
parser = commandline.ArgumentParser(description=__doc__, caching=True)
parser.add_argument(
'--board', required=True, help='Board for the VM to run tests.')
parser.add_argument(
'--image_path', required=True, type='path',
help='Path to the image for the VM to run tests.')
return parser.parse_args(argv)
def main(argv):
"""Main function of the script."""
options = _ParseArguments(argv)
options.Freeze()
test = CrosVMTest(options.board, options.image_path)
test.Run()