update_engine: Upload sample images for testing.
This patch includes the sample images as a compressed .tar.bz2 file in
the source code. The images are generated with the generate_images.sh
script, but the output is also included here. The script requires
root access to create, mount and populate the images with the different
files, which is not reliable enough to run in the builders. Instead,
the images are unpacked from tha .tar.bz2 file when building the
unittests.
These images are not expected to change frequently and the current size
of the .tar.bz2 file is about 3 kB.
BUG=chromium:503145
TEST=`FEATURES=test cros_workon_make update_engine` unpacks the files only when the .tar.bz2 is updated.
TEST=Unit tests still pass.
Change-Id: Ie2be2afdf7a11a7d04b0477767d00b1daa99f1b0
Reviewed-on: https://chromium-review.googlesource.com/292949
Trybot-Ready: Alex Deymo <deymo@chromium.org>
Tested-by: Alex Deymo <deymo@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Commit-Queue: Alex Deymo <deymo@chromium.org>
diff --git a/generate_image.gypi b/generate_image.gypi
deleted file mode 100644
index 025e925..0000000
--- a/generate_image.gypi
+++ /dev/null
@@ -1,27 +0,0 @@
-{
- 'variables': {
- 'out_dir': '<(SHARED_INTERMEDIATE_DIR)/<(image_out_dir)',
- 'generator': 'sample_images/generate_image.sh',
- },
- 'rules': [
- {
- 'rule_name': 'generate_image',
- 'extension': 'txt',
- 'inputs': [
- '<(generator)',
- '<(RULE_INPUT_PATH)',
- ],
- 'outputs': [
- '<(out_dir)/<(RULE_INPUT_ROOT).img',
- ],
- 'action': [
- '<(generator)',
- '<(RULE_INPUT_PATH)',
- '<(out_dir)',
- ],
- 'msvs_cygwin_shell': 0,
- 'message': 'Generating image from <(RULE_INPUT_PATH)',
- 'process_outputs_as_sources': 1,
- },
- ],
-}
diff --git a/sample_images/disk_ext2_1k.txt b/sample_images/disk_ext2_1k.txt
deleted file mode 100644
index 1494535..0000000
--- a/sample_images/disk_ext2_1k.txt
+++ /dev/null
@@ -1 +0,0 @@
-default 16777216 1024
diff --git a/sample_images/disk_ext2_4k.txt b/sample_images/disk_ext2_4k.txt
deleted file mode 100644
index cac718f..0000000
--- a/sample_images/disk_ext2_4k.txt
+++ /dev/null
@@ -1 +0,0 @@
-default 16777216 4096
diff --git a/sample_images/disk_ext2_ue_settings.txt b/sample_images/disk_ext2_ue_settings.txt
deleted file mode 100644
index 554f7da..0000000
--- a/sample_images/disk_ext2_ue_settings.txt
+++ /dev/null
@@ -1 +0,0 @@
-ue_settings 16777216 4096
diff --git a/sample_images/generate_image.sh b/sample_images/generate_images.sh
similarity index 83%
rename from sample_images/generate_image.sh
rename to sample_images/generate_images.sh
index c4f132a..d8d92f5 100755
--- a/sample_images/generate_image.sh
+++ b/sample_images/generate_images.sh
@@ -4,6 +4,11 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+# This script generates some sample images used in unittests and packages them
+# in the sample_images.tar.bz2 file. The list of generated images and their
+# options are described in the main() function. You need to manually run this
+# script to update the generated images whenever you modify this script.
+
set -e
# cleanup <path>
@@ -145,14 +150,28 @@
trap - INT TERM EXIT
}
-image_desc="${1:-}"
-output_dir="${2:-}"
+OUTPUT_DIR=$(dirname "$0")
+IMAGES=()
-if [[ ! -e "${image_desc}" || ! -d "${output_dir}" ]]; then
- echo "Use: $0 <image_description.txt> <output_dir>" >&2
- exit 1
-fi
+# generate_image <image_name> [<image args> ...]
+generate_image() {
+ echo "Generating image $1.img"
+ IMAGES+=( "$1.img" )
+ generate_fs "${OUTPUT_DIR}/$1.img" "${@:2}"
+}
-args=( $(cat ${image_desc}) )
-dest_image="${output_dir}/$(basename ${image_desc} .txt).img"
-generate_fs "${dest_image}" "${args[@]}"
+main() {
+ # Add more sample images here.
+ generate_image disk_ext2_1k default 16777216 1024
+ generate_image disk_ext2_4k default 16777216 4096
+ generate_image disk_ext2_ue_settings ue_settings 16777216 4096
+
+ # Generate the tarball and delete temporary images.
+ echo "Packing tar file sample_images.tar.bz2"
+ tar -jcf "${OUTPUT_DIR}/sample_images.tar.bz2" -C "${OUTPUT_DIR}" \
+ "${IMAGES[@]}"
+ cd "${OUTPUT_DIR}"
+ rm "${IMAGES[@]}"
+}
+
+main
diff --git a/sample_images/sample_images.tar.bz2 b/sample_images/sample_images.tar.bz2
new file mode 100644
index 0000000..0982271
--- /dev/null
+++ b/sample_images/sample_images.tar.bz2
Binary files differ
diff --git a/tar_bunzip2.gypi b/tar_bunzip2.gypi
new file mode 100644
index 0000000..4ba7528
--- /dev/null
+++ b/tar_bunzip2.gypi
@@ -0,0 +1,27 @@
+{
+ 'variables': {
+ 'out_dir': '<(SHARED_INTERMEDIATE_DIR)/<(image_out_dir)',
+ },
+ 'rules': [
+ {
+ 'rule_name': 'tar-bunzip2',
+ 'extension': 'bz2',
+ 'inputs': [
+ '<(RULE_INPUT_PATH)',
+ ],
+ 'outputs': [
+ # The .flag file is used to mark the timestamp of the file extraction
+ # and re-run this action if a new .bz2 file is generated.
+ '<(out_dir)/<(RULE_INPUT_ROOT).flag',
+ ],
+ 'action': [
+ 'sh',
+ '-c',
+ 'tar -xvf "<(RULE_INPUT_PATH)" -C "<(out_dir)" && touch <(out_dir)/<(RULE_INPUT_ROOT).flag',
+ ],
+ 'msvs_cygwin_shell': 0,
+ 'process_outputs_as_sources': 1,
+ 'message': 'Unpacking file <(RULE_INPUT_PATH)',
+ },
+ ],
+}
diff --git a/update_engine.gyp b/update_engine.gyp
index e339a4c..3a6714f 100644
--- a/update_engine.gyp
+++ b/update_engine.gyp
@@ -338,7 +338,7 @@
],
'includes': ['../common-mk/openssl_pem.gypi'],
},
- # Sample images used for testing.
+ # Unpacks sample images used for testing.
{
'target_name': 'update_engine-test_images',
'type': 'none',
@@ -346,11 +346,9 @@
'image_out_dir': '.',
},
'sources': [
- 'sample_images/disk_ext2_1k.txt',
- 'sample_images/disk_ext2_4k.txt',
- 'sample_images/disk_ext2_ue_settings.txt',
+ 'sample_images/sample_images.tar.bz2',
],
- 'includes': ['generate_image.gypi'],
+ 'includes': ['tar_bunzip2.gypi'],
},
# Test HTTP Server.
{