support disk snapshots with emulator

Bug #1253802 reported by Jamie Strandboge
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
android (Ubuntu)
Fix Released
High
Ricardo Salveti

Bug Description

Being able to create a snapshot and roll back to it is very useful for developers. Eg, developers can
 * develop features, etc on the image, then package them up, roll back the image and test on a pristine image
 * save time on system-image upgrade testing
 * do multiple test runs, reverting to the pristine image between runs to cut down on variances
 * verify bugs in the image easily
 * etc

Snapshotting can be complicated, but most of the time you just want to have a pristine snapshot that you can rollback to with the option of committing changes. Attached is an updated run-emulator.sh script to achieve this:
$ ./run-emulator.sh help

Usage: run-emulator.sh
       run-emulator.sh [COMMAND]

Commands:
 use-disk-snapshots Convert images to qcow2 and create 'pristine' snapshot
 convert-disk DISK Convert DISK to qcow2 and create 'pristine' snapshot
 snapshot-disks Update 'pristine' snapshot to current state
 revert-disks Revert current images to 'pristine' snapshot
 info-disks Show disk information for current images

Without arguments, run the emulated image.

Note: these commands only manipulate the qemu qcow2 disk images and are
      unrelated to the -snapshot* and -no-snapshot* emulator command line
      options

Basic workflow is:
$ ./build-emulator-sdcard.sh # create image like normal, skip if already have image
$ ./run-emulator.sh use-disk-snapshots
$ ./run-emulator.sh
<do work>
$ ./run-emulator.sh revert-disks
$ ./run-emulator.sh
<perform tests in pristine environment>
$ ./run-emulator.sh revert-disks

Once system-image is supported, can update the image like so:
$ ./run-emulator.sh revert-disks
$ ./run-emulator.sh
<run system-image>
$ ./run-emulator.sh snapshot-disks

The emulator is based on qemu 0.12 and the default disk compatibility option for qcow2 images is 0.10 (though I explicitly use compat=0.10 in the script). The script continues to run as before with raw images and snapshotting is only usable after running 'use-disk-snapshots'. When using this command to run-emulator.sh, disks specified with '-system', 'data', '-cache' and '-sdcard' are all converted to qcow2 and updated to have a 'pristine' snapshot. 'convert-disk DISK' can be used to convert a single disk, which might be useful when rerunning build-emulator-sdcard.sh.

Note that this script only deals with the disk files themselves and adds a dependency on qemu-utils. It does not require advanced functionality with the emulator and is lightly tested. The emulator itself has other snapshot commands that might be interesting to expose to users (eg, /usr/share/android/emulator/out/host/linux-x86/bin/emulator -help|grep snap). This page could provide inspiration for further enhancements: http://stackoverflow.com/questions/4842612/how-do-you-save-android-emulator-snapshot/5980578#5980578. I believe the above simple disk commands are complementary to the emulator snapshot commands and possibly more desirable for the simple use cases I outlined above.

Feel free to adjust as desired.

Revision history for this message
Jamie Strandboge (jdstrand) wrote :
Revision history for this message
Jamie Strandboge (jdstrand) wrote :

Updated run_emulator.sh to add 'convert-disk'.

description: updated
Changed in android (Ubuntu):
status: New → In Progress
importance: Undecided → High
assignee: nobody → Ricardo Salveti (rsalveti)
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package android - 20131126-0210-0ubuntu1

---------------
android (20131126-0210-0ubuntu1) trusty; urgency=low

  * New upstream release:
    - run-emulator.sh: adding support for disk snapshots (LP: #1253802)
    - goldfish: reducing system and userdata image sizes
  * debian/android.install.in: adding the emulator images to the android
    package
 -- Ricardo Salveti de Araujo <email address hidden> Tue, 26 Nov 2013 00:31:04 -0200

Changed in android (Ubuntu):
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.