blob: 8aaaade5a0fba7317f1e93c586be6dac34b0a1e6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
#!/bin/bash
#
# Written by Guilherme Maciel Ferreira <guilherme.maciel.ferreira@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
SRCDIR=${BASEDIR}/boot
IMAGE_NAME="v1.0-test"
IMAGE_MULTI=linux.img
DATAFILE0=vmlinuz
DATAFILE1=initrd.img
DATAFILE2=System.map
DATAFILES="${DATAFILE0} ${DATAFILE1} ${DATAFILE2}"
TEST_OUT=test_output
MKIMAGE=${BASEDIR}/tools/mkimage
DUMPIMAGE=${BASEDIR}/tools/dumpimage
MKIMAGE_LIST=mkimage.list
DUMPIMAGE_LIST=dumpimage.list
# Remove all the files we created
cleanup()
{
local file
for file in ${DATAFILES}; do
rm -f ${file} ${SRCDIR}/${file}
done
rm -f ${IMAGE_MULTI} ${DUMPIMAGE_LIST} ${MKIMAGE_LIST} ${TEST_OUT}
rmdir ${SRCDIR}
}
# Check that two files are the same
assert_equal()
{
if ! diff -u $1 $2; then
echo "Failed."
cleanup
exit 1
fi
}
# Create some test files
create_files()
{
local file
mkdir -p ${SRCDIR}
for file in ${DATAFILES}; do
head -c $RANDOM /dev/urandom >${SRCDIR}/${file}
done
}
# Run a command, echoing it first
do_cmd()
{
local cmd="$@"
echo "# ${cmd}"
${cmd} 2>&1
}
# Run a command, redirecting output
# Args:
# redirect_file
# command...
do_cmd_redir()
{
local redir="$1"
shift
local cmd="$@"
echo "# ${cmd}"
${cmd} >${redir}
}
# Write files into an multi-file image
create_multi_image()
{
local files="${SRCDIR}/${DATAFILE0}:${SRCDIR}/${DATAFILE1}"
files+=":${SRCDIR}/${DATAFILE2}"
echo -e "\nBuilding multi-file image..."
do_cmd ${MKIMAGE} -A x86 -O linux -T multi -n \"${IMAGE_NAME}\" \
-d ${files} ${IMAGE_MULTI}
echo "done."
}
# Extract files from an multi-file image
extract_multi_image()
{
echo -e "\nExtracting multi-file image contents..."
do_cmd ${DUMPIMAGE} -T multi -i ${IMAGE_MULTI} -p 0 ${DATAFILE0}
do_cmd ${DUMPIMAGE} -T multi -i ${IMAGE_MULTI} -p 1 ${DATAFILE1}
do_cmd ${DUMPIMAGE} -T multi -i ${IMAGE_MULTI} -p 2 ${DATAFILE2}
do_cmd ${DUMPIMAGE} -T multi -i ${IMAGE_MULTI} -p 2 ${DATAFILE2} -o ${TEST_OUT}
echo "done."
}
# List the contents of a file
# Args:
# image filename
list_image()
{
local image="$1"
echo -e "\nListing image contents..."
do_cmd_redir ${MKIMAGE_LIST} ${MKIMAGE} -l ${image}
do_cmd_redir ${DUMPIMAGE_LIST} ${DUMPIMAGE} -l ${image}
echo "done."
}
main()
{
local file
create_files
# Compress and extract multi-file images, compare the result
create_multi_image
extract_multi_image
for file in ${DATAFILES}; do
assert_equal ${file} ${SRCDIR}/${file}
done
assert_equal ${TEST_OUT} ${DATAFILE2}
# List contents of multi-file image and compares output from tools
list_image ${IMAGE_MULTI}
assert_equal ${DUMPIMAGE_LIST} ${MKIMAGE_LIST}
# Remove files created
cleanup
echo "Tests passed."
}
main
|