OLD | NEW |
1 #!/bin/bash | 1 #!/bin/bash |
2 | 2 |
3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 # | 6 # |
7 # Runs a given test case under a VM. | 7 # Runs a given test case under a VM. |
8 | 8 |
9 . "$(dirname $0)/../common.sh" | 9 . "$(dirname $0)/../common.sh" |
| 10 . "$(dirname $0)/../lib/cros_vm_lib.sh" |
10 | 11 |
11 DEFINE_string image_path "" "Full path of the VM image" | 12 DEFINE_string image_path "" "Full path of the VM image" |
12 DEFINE_boolean no_graphics ${FLAGS_FALSE} "Runs the KVM instance silently" | |
13 DEFINE_integer ssh_port 9222 "Port to tunnel ssh traffic over" | |
14 DEFINE_string test_case "" "Name of the test case to run" | 13 DEFINE_string test_case "" "Name of the test case to run" |
15 | 14 |
16 set -e | 15 set -e |
17 | 16 |
18 KVM_PID_FILE=/tmp/kvm.$$.pid | 17 # Parse command line. |
19 | |
20 # TODO(rtc): These flags assume that we'll be using KVM on Lucid and won't work | |
21 # on Hardy. | |
22 function start_kvm { | |
23 echo "Starting the KVM instance" | |
24 local nographics="" | |
25 if [ ${FLAGS_no_graphics} -eq ${FLAGS_TRUE} ]; then | |
26 nographics="-nographic" | |
27 fi | |
28 sudo kvm -m 1024 \ | |
29 -vga std \ | |
30 -pidfile "${KVM_PID_FILE}" \ | |
31 -daemonize \ | |
32 -net nic \ | |
33 ${nographics} \ | |
34 -net user,hostfwd=tcp::${FLAGS_ssh_port}-:22 \ | |
35 -hda "${FLAGS_image_path}" | |
36 } | |
37 | |
38 function stop_kvm { | |
39 echo "Stopping the KVM instance" | |
40 local pid=$(sudo cat "${KVM_PID_FILE}") | |
41 echo "Killing ${pid}" | |
42 sudo kill ${pid} | |
43 sudo rm "${KVM_PID_FILE}" | |
44 } | |
45 | |
46 # Parse command line | |
47 FLAGS "$@" || exit 1 | 18 FLAGS "$@" || exit 1 |
48 eval set -- "${FLAGS_ARGV}" | 19 eval set -- "${FLAGS_ARGV}" |
49 | 20 |
50 [ -n "${FLAGS_image_path}" ] || die "You must specify a path to an image" | 21 [ -n "${FLAGS_image_path}" ] || die "You must specify a path to an image" |
51 [ -n "${FLAGS_test_case}" ] || die "You must specify a test case" | 22 [ -n "${FLAGS_test_case}" ] || die "You must specify a test case" |
52 | 23 |
53 trap stop_kvm EXIT | 24 trap stop_kvm EXIT |
54 start_kvm | 25 start_kvm "${FLAGS_image_path}" |
55 "$(dirname $0)"/../run_remote_tests.sh \ | 26 "$(dirname $0)"/../run_remote_tests.sh \ |
56 --ssh_port=${FLAGS_ssh_port} \ | 27 --ssh_port=${FLAGS_ssh_port} \ |
57 --remote="${HOSTNAME}" \ | 28 --remote="${HOSTNAME}" \ |
58 "${FLAGS_test_case}" | 29 "${FLAGS_test_case}" |
OLD | NEW |