diff --git a/bin/cros_run_vm_test b/bin/cros_run_vm_test index 6981745ac4..8036b230b1 100755 --- a/bin/cros_run_vm_test +++ b/bin/cros_run_vm_test @@ -8,6 +8,7 @@ . "$(dirname $0)/../common.sh" . "$(dirname $0)/../lib/cros_vm_lib.sh" +. "$(dirname "$0")/../lib/cros_vm_constants.sh" DEFINE_string image_path "" "Full path of the VM image" DEFINE_string test_case "" "Name of the test case to run" @@ -18,8 +19,16 @@ set -e FLAGS "$@" || exit 1 eval set -- "${FLAGS_ARGV}" -[ -n "${FLAGS_image_path}" ] || die "You must specify a path to an image" -[ -n "${FLAGS_test_case}" ] || die "You must specify a test case" +# Use latest if not specified. +if [ -z "${FLAGS_image_path}" ]; then + LATEST_IMAGE="$(${SCRIPTS_DIR}/get_latest_image.sh)/${DEFAULT_QEMU_IMAGE}" + info "Using latest vm image ${LATEST_IMAGE}" + FLAGS_image_path=${LATEST_IMAGE} +fi + +[ -e "${FLAGS_image_path}" ] || die "Image ${FLAGS_image_path} does not exist." + +[ -n "${FLAGS_test_case}" ] || die "You must specify a test case." trap stop_kvm EXIT start_kvm "${FLAGS_image_path}" diff --git a/image_to_vm.sh b/image_to_vm.sh index 3807269856..c2fb82b748 100755 --- a/image_to_vm.sh +++ b/image_to_vm.sh @@ -11,22 +11,11 @@ # The path to common.sh should be relative to your script's location. . "$(dirname "$0")/common.sh" . "$(dirname "$0")/chromeos-common.sh" +. "$(dirname "$0")/lib/cros_vm_constants.sh" get_default_board assert_inside_chroot -DEFAULT_MEM="1024" -DEFAULT_VMDK="ide.vmdk" -DEFAULT_VMX="chromiumos.vmx" -DEFAULT_VBOX_DISK="os.vdi" -DEFAULT_QEMU_IMAGE="chromiumos_qemu_image.bin" - -# Minimum sizes for full size vm images -- needed for update. -MIN_VDISK_SIZE_FULL=6072 -MIN_STATEFUL_FS_SIZE_FULL=2048 - -MOD_SCRIPTS_ROOT="${GCLIENT_ROOT}/src/scripts/mod_for_test_scripts" - # Flags DEFINE_string board "${DEFAULT_BOARD}" \ "Board for which the image was built" @@ -85,7 +74,7 @@ fi IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${FLAGS_board}" # Default to the most recent image if [ -z "${FLAGS_from}" ] ; then - FLAGS_from="${IMAGES_DIR}/$(ls -t $IMAGES_DIR | head -1)" + FLAGS_from="$(./get_latest_image.sh)" else pushd "${FLAGS_from}" && FLAGS_from=`pwd` && popd fi diff --git a/lib/cros_vm_constants.sh b/lib/cros_vm_constants.sh new file mode 100644 index 0000000000..124d158eb5 --- /dev/null +++ b/lib/cros_vm_constants.sh @@ -0,0 +1,16 @@ +# Copyright (c) 2010 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. + +# Common constants for vm scripts. + +# Default values for creating VM's. +DEFAULT_MEM="1024" +DEFAULT_VMDK="ide.vmdk" +DEFAULT_VMX="chromiumos.vmx" +DEFAULT_VBOX_DISK="os.vdi" +DEFAULT_QEMU_IMAGE="chromiumos_qemu_image.bin" + +# Minimum sizes for full size vm images -- needed for update. +MIN_VDISK_SIZE_FULL=6072 +MIN_STATEFUL_FS_SIZE_FULL=2048 \ No newline at end of file diff --git a/lib/cros_vm_lib.sh b/lib/cros_vm_lib.sh index 61d575bfff..c47d11de33 100644 --- a/lib/cros_vm_lib.sh +++ b/lib/cros_vm_lib.sh @@ -4,6 +4,8 @@ # # Common vm functions for use in crosutils. +. "$(dirname "$0")/cros_vm_constants.sh" + DEFINE_string kvm_pid "" \ "Use this pid file. If it exists and is set, use the vm specified by pid." DEFINE_boolean no_graphics ${FLAGS_FALSE} "Runs the KVM instance silently." @@ -11,7 +13,6 @@ DEFINE_boolean persist "${FLAGS_FALSE}" "Persist vm." DEFINE_boolean snapshot ${FLAGS_FALSE} "Don't commit changes to image." DEFINE_integer ssh_port 9222 "Port to tunnel ssh traffic over." - KVM_PID_FILE=/tmp/kvm.$$.pid function get_pid() { @@ -47,7 +48,7 @@ function start_kvm() { snapshot="-snapshot" fi - sudo kvm -m 1024 \ + sudo kvm -m ${DEFAULT_MEM} \ -vga std \ -pidfile "${KVM_PID_FILE}" \ -daemonize \