diff --git a/bin/cros_run_vm_test b/bin/cros_run_vm_test index 82b3b8fcd4..6981745ac4 100755 --- a/bin/cros_run_vm_test +++ b/bin/cros_run_vm_test @@ -7,43 +7,14 @@ # Runs a given test case under a VM. . "$(dirname $0)/../common.sh" +. "$(dirname $0)/../lib/cros_vm_lib.sh" DEFINE_string image_path "" "Full path of the VM image" -DEFINE_boolean no_graphics ${FLAGS_FALSE} "Runs the KVM instance silently" -DEFINE_integer ssh_port 9222 "Port to tunnel ssh traffic over" DEFINE_string test_case "" "Name of the test case to run" set -e -KVM_PID_FILE=/tmp/kvm.$$.pid - -# TODO(rtc): These flags assume that we'll be using KVM on Lucid and won't work -# on Hardy. -function start_kvm { - echo "Starting the KVM instance" - local nographics="" - if [ ${FLAGS_no_graphics} -eq ${FLAGS_TRUE} ]; then - nographics="-nographic" - fi - sudo kvm -m 1024 \ - -vga std \ - -pidfile "${KVM_PID_FILE}" \ - -daemonize \ - -net nic \ - ${nographics} \ - -net user,hostfwd=tcp::${FLAGS_ssh_port}-:22 \ - -hda "${FLAGS_image_path}" -} - -function stop_kvm { - echo "Stopping the KVM instance" - local pid=$(sudo cat "${KVM_PID_FILE}") - echo "Killing ${pid}" - sudo kill ${pid} - sudo rm "${KVM_PID_FILE}" -} - -# Parse command line +# Parse command line. FLAGS "$@" || exit 1 eval set -- "${FLAGS_ARGV}" @@ -51,7 +22,7 @@ eval set -- "${FLAGS_ARGV}" [ -n "${FLAGS_test_case}" ] || die "You must specify a test case" trap stop_kvm EXIT -start_kvm +start_kvm "${FLAGS_image_path}" "$(dirname $0)"/../run_remote_tests.sh \ --ssh_port=${FLAGS_ssh_port} \ --remote="${HOSTNAME}" \ diff --git a/bin/cros_run_vm_update b/bin/cros_run_vm_update new file mode 100755 index 0000000000..98ffef0e92 --- /dev/null +++ b/bin/cros_run_vm_update @@ -0,0 +1,34 @@ +#!/bin/bash + +# 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. +# +# Updates an existing vm image with another image. + +. "$(dirname $0)/../common.sh" +. "$(dirname $0)/../lib/cros_vm_lib.sh" + +DEFINE_string stateful_flags "" "Flags to pass to stateful update." s +DEFINE_string update_image_path "" "Path of the image to update to." u +DEFINE_string vm_image_path "" "Path of the VM image to update from." v + +set -e + +# Parse command line. +FLAGS "$@" || exit 1 +eval set -- "${FLAGS_ARGV}" + +[ -n "${FLAGS_update_image_path}" ] || \ + die "You must specify a path to an image to use as an update." +[ -n "${FLAGS_vm_image_path}" ] || \ + die "You must specify a path to a vm image." + +trap stop_kvm EXIT +start_kvm "${FLAGS_vm_image_path}" + +$(dirname $0)/../image_to_live.sh \ + --remote=${HOSTNAME} \ + --ssh_port=${FLAGS_ssh_port} \ + --stateful_update_flag=${stateful_flags} \ + --image=$(readlink -f ${FLAGS_update_image_path}) diff --git a/image_to_live.sh b/image_to_live.sh index 96cb5c60d2..f2b0c0556b 100755 --- a/image_to_live.sh +++ b/image_to_live.sh @@ -131,7 +131,7 @@ function run_stateful_update { info "Starting stateful update using URL ${stateful_url}" # Copy over update script and run update. - local dev_dir="$(dirname $0)/../platform/dev" + local dev_dir="${SCRIPTS_DIR}/../platform/dev" remote_cp_to "${dev_dir}/stateful_update" "/tmp" remote_sh "/tmp/stateful_update ${stateful_update_args} ${stateful_url}" } diff --git a/image_to_vm.sh b/image_to_vm.sh index af08b5bf8d..95715601c6 100755 --- a/image_to_vm.sh +++ b/image_to_vm.sh @@ -13,12 +13,18 @@ . "$(dirname "$0")/chromeos-common.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 @@ -33,6 +39,7 @@ DEFINE_string format "qemu" \ "Output format, either qemu, vmware or virtualbox" DEFINE_string from "" \ "Directory containing rootfs.image and mbr.image" +DEFINE_boolean full "${FLAGS_FALSE}" "Build full image with all partitions." DEFINE_boolean make_vmx ${FLAGS_TRUE} \ "Create a vmx file for use with vmplayer (vmware only)." DEFINE_integer mem "${DEFAULT_MEM}" \ @@ -67,6 +74,14 @@ if [ -z "${FLAGS_board}" ] ; then die "--board is required." fi +if [ "${FLAGS_full}" -eq "${FLAGS_TRUE}" ] && \ + ( [[ ${FLAGS_vdisk_size} < ${MIN_VDISK_SIZE_FULL} ]] || \ + [[ ${FLAGS_statefulfs_size} < ${MIN_STATEFUL_FS_SIZE_FULL} ]]); then + die "Disk is too small for full, please select a vdisk size greater than \ +${MIN_VDISK_SIZE_FULL} and statefulfs size greater than \ +${MIN_STATEFUL_FS_SIZE_FULL}." +fi + IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${FLAGS_board}" # Default to the most recent image if [ -z "${FLAGS_from}" ] ; then @@ -114,7 +129,6 @@ if [ ${FLAGS_test_image} -eq ${FLAGS_TRUE} ] ; then fi # Memory units are in MBs -DEFAULT_MEM="1024" TEMP_IMG="$(dirname ${SRC_IMAGE})/vm_temp_image.bin" # If we're not building for VMWare, don't build the vmx @@ -182,11 +196,13 @@ mkdir -p "${TEMP_ESP_MNT}" sudo mount -o loop "${TEMP_ESP}" "${TEMP_ESP_MNT}" if [ "${FLAGS_format}" = "qemu" ]; then - sudo python ./fixup_image_for_qemu.py --mounted_dir="${TEMP_MNT}" \ - --enable_tablet=true + sudo python "$(dirname $0)/fixup_image_for_qemu.py" \ + --mounted_dir="${TEMP_MNT}" \ + --enable_tablet=true else - sudo python ./fixup_image_for_qemu.py --mounted_dir="${TEMP_MNT}" \ - --enable_tablet=false + sudo python "$(dirname $0)/fixup_image_for_qemu.py" \ + --mounted_dir="${TEMP_MNT}" \ + --enable_tablet=false fi # Modify the unverified usb template which uses a default usb_disk of sdb3 @@ -197,15 +213,17 @@ sync trap - INT TERM EXIT cleanup -# Make 3 GiB output image -# TOOD(adlr): pick a size that will for sure accomodate the partitions +# TOOD(adlr): pick a size that will for sure accomodate the partitions. dd if=/dev/zero of="${TEMP_IMG}" bs=1 count=1 \ seek=$((${FLAGS_vdisk_size} * 1024 * 1024 - 1)) +GPT_FULL="false" +[ "${FLAGS_full}" -eq "${FLAGS_TRUE}" ] && GPT_FULL="true" + # Set up the partition table install_gpt "${TEMP_IMG}" "$(numsectors $TEMP_ROOTFS)" \ "$(numsectors $TEMP_STATE)" "${TEMP_PMBR}" "$(numsectors $TEMP_ESP)" \ - false ${FLAGS_rootfs_partition_size} + "${GPT_FULL}" ${FLAGS_rootfs_partition_size} # Copy into the partition parts of the file dd if="${TEMP_ROOTFS}" of="${TEMP_IMG}" conv=notrunc bs=512 \ seek="${START_ROOTFS_A}" diff --git a/remote_access.sh b/remote_access.sh index 6a5a6d1fb6..092555a5bd 100644 --- a/remote_access.sh +++ b/remote_access.sh @@ -15,7 +15,7 @@ DEFINE_integer ssh_port 22 \ # Copies $1 to $2 on remote host function remote_cp_to() { - REMOTE_OUT=$(scp -o StrictHostKeyChecking=no -o \ + REMOTE_OUT=$(scp -P ${FLAGS_ssh_port} -o StrictHostKeyChecking=no -o \ UserKnownHostsFile=$TMP_KNOWN_HOSTS $1 root@$FLAGS_remote:$2) return ${PIPESTATUS[0]} }