[U-Boot] [PATCH 4/4] sandbox: dumpimage: Test dumpimage

guilherme.maciel.ferreira at gmail.com guilherme.maciel.ferreira at gmail.com
Wed Sep 18 02:42:41 CEST 2013


From: Guilherme Maciel Ferreira <guilherme.maciel.ferreira at gmail.com>

Signed-off-by: Guilherme Maciel Ferreira <guilherme.maciel.ferreira at gmail.com>
---
 test/image/test-imagetools.sh |  107 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 107 insertions(+), 0 deletions(-)
 create mode 100755 test/image/test-imagetools.sh

diff --git a/test/image/test-imagetools.sh b/test/image/test-imagetools.sh
new file mode 100755
index 0000000..b243794
--- /dev/null
+++ b/test/image/test-imagetools.sh
@@ -0,0 +1,107 @@
+#!/bin/bash
+#
+# Written by Guilherme Maciel Ferreira <guilherme.maciel.ferreira at gmail.com>
+#
+# Sanity check for mkimage and dumpimage tools
+#
+# SPDX-License-Identifier:	GPL-2.0+
+#
+# To run this:
+#
+# make O=sandbox sandbox_config
+# make O=sandbox
+# ./test/image/test-imagetools.sh
+
+
+BASEDIR=sandbox
+
+LINUX_VERSION=`uname -r`
+IMAGE=linux-${LINUX_VERSION}.img
+DATAFILE0=vmlinuz-${LINUX_VERSION}
+DATAFILE1=initrd.img-${LINUX_VERSION}
+DATAFILE2=System.map-${LINUX_VERSION}
+
+MKIMAGE=${BASEDIR}/tools/mkimage
+DUMPIMAGE=${BASEDIR}/tools/dumpimage
+MKIMAGE_LIST=mkimage.list
+DUMPIMAGE_LIST=dumpimage.list
+
+cleanup()
+{
+	rm -f ${DATAFILE0}
+	rm -f ${DATAFILE1}
+	rm -f ${DATAFILE2}
+	rm -f ${IMAGE}
+	rm -f ${DUMPIMAGE_LIST}
+	rm -f ${MKIMAGE_LIST}
+}
+
+assert_equal()
+{
+	FILE_1=$1
+	FILE_2=$2
+	diff ${FILE_1} ${FILE_2}
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		echo "Failed."
+		cleanup
+		exit $ret
+	fi
+}
+
+compress_image()
+{
+	BOOTDIR=$1
+	DATAFILES=${BOOTDIR}/${DATAFILE0}:${BOOTDIR}/${DATAFILE1}:${BOOTDIR}/${DATAFILE2}
+
+	echo -e "\nBuilding image..."
+	echo "# ${MKIMAGE} -A x86 -O linux -T multi -n \"${LINUX_VERSION}\" -d ${DATAFILES} ${IMAGE}"
+	./${MKIMAGE} -A x86 -O linux -T multi -n "${LINUX_VERSION}" -d ${DATAFILES} ${IMAGE}
+	echo -e "done.\n"
+}
+
+extract_image()
+{
+	echo -e "\nExtracting image contents..."
+	echo "# ${DUMPIMAGE} -i ${IMAGE} -p 0 ${DATAFILE0}"
+	./${DUMPIMAGE} -i ${IMAGE} -p 0 ${DATAFILE0}
+	echo "# ${DUMPIMAGE} -i ${IMAGE} -p 1 ${DATAFILE1}"
+	./${DUMPIMAGE} -i ${IMAGE} -p 1 ${DATAFILE1}
+	echo "# ${DUMPIMAGE} -i ${IMAGE} -p 2 ${DATAFILE2}"
+	./${DUMPIMAGE} -i ${IMAGE} -p 2 ${DATAFILE2}
+	echo -e "done.\n"
+}
+
+list_image()
+{
+	echo -e "\nListing image contents..."
+	echo "# ${MKIMAGE} -l ${IMAGE}"
+	./${MKIMAGE} -l ${IMAGE} > ${MKIMAGE_LIST} 2>&1
+	echo "# ${DUMPIMAGE} -l ${IMAGE}"
+	./${DUMPIMAGE} -l ${IMAGE} > ${DUMPIMAGE_LIST} 2>&1
+	echo -e "done.\n"
+}
+
+main()
+{
+	# Assume kernel images lie in /boot dir
+	BOOTDIR=/boot
+
+	# Compress and extract multifile images, compare the result
+	compress_image ${BOOTDIR}
+	extract_image
+	assert_equal ${DATAFILE0} ${BOOTDIR}/${DATAFILE0}
+	assert_equal ${DATAFILE1} ${BOOTDIR}/${DATAFILE1}
+	assert_equal ${DATAFILE2} ${BOOTDIR}/${DATAFILE2}
+
+	# List contents and compares output fro tools
+	list_image
+	assert_equal ${DUMPIMAGE_LIST} ${MKIMAGE_LIST}
+
+	# Remove files created
+	cleanup
+
+	echo "Success."
+}
+
+main
-- 
1.7.0.4



More information about the U-Boot mailing list