diff options
author | Alex Deymo <deymo@google.com> | 2016-03-04 17:53:02 -0800 |
---|---|---|
committer | Alex Deymo <deymo@google.com> | 2016-03-12 01:00:07 +0000 |
commit | cbc2274c4160805bf726df872390112654816ca7 (patch) | |
tree | 0cf6a2bebee169ae0316cec2b2209501bf19c739 /sample_images/generate_images.sh | |
parent | 788c2d9b4b4da52f0874c391bda59610625e66aa (diff) | |
download | update_engine-cbc2274c4160805bf726df872390112654816ca7.tar.gz |
Rework postinstall unittests to pass on Android.
Postinstall unittests were creating and mounting an image on each test
run. This patch adds several test scripts to one of the pre-generated
images and uses that image during postinstall testing instead.
To workaround problems with mount/umount of loop devices on Android,
this patch rewrites the `losetup` logic to make the appropriate
syscalls and create the loop device with mknod if it doesn't exists.
The tests require some extra SELinux policies to run in enforcing mode.
Bug: 26955860
TEST=Ran all Postinstall unittests.
Change-Id: I47a56b80b97596bc65ffe30cbc8118f05faff0ae
Diffstat (limited to 'sample_images/generate_images.sh')
-rwxr-xr-x | sample_images/generate_images.sh | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/sample_images/generate_images.sh b/sample_images/generate_images.sh index 17bb11cc..c9936c1a 100755 --- a/sample_images/generate_images.sh +++ b/sample_images/generate_images.sh @@ -124,6 +124,49 @@ GOOGLE_RELEASE=6946.63.0 EOF } +add_files_postinstall() { + local mntdir="$1" + + sudo mkdir -p "${mntdir}"/bin >/dev/null + + # A postinstall bash program. + sudo tee "${mntdir}"/bin/postinst_example >/dev/null <<EOF +#!/etc/../bin/sh +echo "I'm a postinstall program and I know how to write to stdout" +echo "My call was $@" +exit 0 +EOF + + # A symlink to another program. This should also work. + sudo ln -s "postinst_example" "${mntdir}"/bin/postinst_link + + sudo tee "${mntdir}"/bin/postinst_fail3 >/dev/null <<EOF +#!/etc/../bin/sh +exit 3 +EOF + + sudo tee "${mntdir}"/bin/postinst_fail1 >/dev/null <<EOF +#!/etc/../bin/sh +exit 1 +EOF + + # A postinstall bash program. + sudo tee "${mntdir}"/bin/self_check_context >/dev/null <<EOF +#!/etc/../bin/sh +echo "This is my context:" +ls -lZ "\$0" | grep -F ' u:object_r:postinstall_file:s0 ' || exit 5 +exit 0 +EOF + + sudo tee "${mntdir}"/postinst >/dev/null <<EOF +#!/etc/../bin/sh +echo "postinst" +exit 0 +EOF + + sudo chmod +x "${mntdir}"/postinst "${mntdir}"/bin/* +} + # generate_fs <filename> <kind> <size> [block_size] [block_groups] generate_fs() { local filename="$1" @@ -152,6 +195,7 @@ generate_fs() { case "${kind}" in ue_settings) add_files_ue_settings "${mntdir}" "${block_size}" + add_files_postinstall "${mntdir}" "${block_size}" ;; default) add_files_default "${mntdir}" "${block_size}" @@ -179,7 +223,7 @@ main() { generate_image disk_ext2_1k default 16777216 1024 generate_image disk_ext2_4k default 16777216 4096 generate_image disk_ext2_4k_empty empty $((1024 * 4096)) 4096 - generate_image disk_ext2_ue_settings ue_settings 16777216 4096 + generate_image disk_ext2_ue_settings ue_settings $((1024 * 4096)) 4096 # Generate the tarball and delete temporary images. echo "Packing tar file sample_images.tar.bz2" |