From 9f2461061f0c5554e979075f4ae581b727a73910 Mon Sep 17 00:00:00 2001 From: "James O. D. Hunt" Date: Fri, 7 Sep 2018 17:54:51 +0100 Subject: [PATCH] tests: Show summary of image sizes At the end of the tests, show a summary of the size of all the rootfs's, images and initrd's. Fixes #162. Signed-off-by: James O. D. Hunt --- .ci/setup.sh | 6 ++-- tests/test_images.sh | 85 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 3 deletions(-) diff --git a/.ci/setup.sh b/.ci/setup.sh index 208eaf85..bfa52b6f 100755 --- a/.ci/setup.sh +++ b/.ci/setup.sh @@ -14,13 +14,13 @@ source "${cidir}/lib.sh" source /etc/os-release if [ "$ID" == fedora ];then - sudo -E dnf -y install automake yamllint coreutils moreutils + sudo -E dnf -y install automake yamllint coreutils moreutils bc elif [ "$ID" == centos ];then sudo -E yum -y install epel-release - sudo -E yum -y install automake yamllint coreutils moreutils + sudo -E yum -y install automake yamllint coreutils moreutils bc elif [ "$ID" == ubuntu ];then sudo apt-get -qq update - sudo apt-get install -y -qq make automake qemu-utils python-pip coreutils moreutils + sudo apt-get install -y -qq make automake qemu-utils python-pip coreutils moreutils bc sudo pip install yamllint else echo "Linux distribution not supported" diff --git a/tests/test_images.sh b/tests/test_images.sh index 00498517..e6651533 100755 --- a/tests/test_images.sh +++ b/tests/test_images.sh @@ -33,6 +33,12 @@ readonly docker_build_runtime="runc" test_images_only="false" test_initrds_only="false" +# Hashes used to keep track of image sizes. +# - Key: name of distro. +# - Value: colon-separated roots and image sizes ("${rootfs_size}:${image_size}"). +typeset -A built_images +typeset -A built_initrds + usage() { cat <> "$statsfile" +} + +# Show the sizes of all the generated initrds and images +show_stats() +{ + local name + local sizes + + local tmpfile=$(mktemp) + + # images + for name in "${!built_images[@]}" + do + sizes=${built_images[$name]} + add_to_stats_file "$tmpfile" "$name" "$sizes" 'image' + done + + # initrds + for name in "${!built_initrds[@]}" + do + sizes=${built_initrds[$name]} + add_to_stats_file "$tmpfile" "$name" "$sizes" 'initrd' + done + + info "Image and rootfs sizes (in bytes and MB), smallest image first:" + echo + + printf '%12.12s\t%10.10s\t%12.12s\t%10.10s\t%-8.8s\t%-20.20s\n' \ + "image-bytes" \ + "image-MB" \ + "rootfs-bytes" \ + "rootfs-MB" \ + "Type" \ + "Name" + + sort -k1,1n "$tmpfile" + + rm -f "${tmpfile}" +} + exit_handler() { if [ "$?" -eq 0 ] @@ -270,6 +343,8 @@ handle_options() build_rootfs "${distro}" "${rootfs}" + local rootfs_size=$(du -sb "${rootfs}" | awk '{print $1}') + if [ "$type" = "image" ] then # Images need systemd @@ -278,12 +353,20 @@ handle_options() local image_path="${images_dir}/${type}-${distro}-agent-init-${AGENT_INIT}.img" build_image "${image_path}" "${rootfs}" + local image_size=$(stat -c "%s" "${image_path}") + + built_images["${distro}"]="${rootfs_size}:${image_size}" + install_image_create_container "${image_path}" elif [ "$type" = "initrd" ] then local initrd_path="${images_dir}/${type}-${distro}-agent-init-${AGENT_INIT}.img" build_initrd "${initrd_path}" "${rootfs}" + local initrd_size=$(stat -c "%s" "${initrd_path}") + + built_initrds["${distro}"]="${rootfs_size}:${initrd_size}" + install_initrd_create_container "${initrd_path}" else die "invalid type: '$type' for distro $distro option $opt" @@ -459,6 +542,8 @@ test_all_distros() # previous tests. test_distro_euleros fi + + show_stats } main()