-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_boot_deploy_functions.sh
More file actions
executable file
·168 lines (133 loc) · 3.78 KB
/
test_boot_deploy_functions.sh
File metadata and controls
executable file
·168 lines (133 loc) · 3.78 KB
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/bin/sh -e
# shellcheck disable=SC1091
. boot-deploy-functions.sh
wdir="$(mktemp -d /tmp/boot-deploy-test.XXXXXX)"
trap 'rm -rf $wdir; exit 1' INT EXIT TERM
test_get_size_of_files() {
for _f in f1 f2 f3 f4 f5; do
dd if=/dev/zero of="$wdir/$_f" bs=1K count=37 >/dev/null 2>&1
done
local _size
# shellcheck disable=SC2086
_size=$(get_size_of_files $wdir/f1 $wdir/f2 $wdir/f3 $wdir/f4 $wdir/f5:/foo/f5)
local _ret=0
# exact size depends on the filesystem, so just make sure it's roughly in the same ballpark
if [ "$_size" -ge 225 ] || [ "$_size" -le 150 ]; then
echo "test_get_size_of_files: failed, expected: ~150-225 kilobytes, got: $_size kilobytes"
_ret=1
fi
[ $_ret -eq 0 ] && echo "test_get_size_of_files: pass"
return $_ret
}
test_copy_files() {
output_dir="$wdir/out"
local _in="$wdir/in"
mkdir -p "$_in"
mkdir -p "$output_dir"
touch "$_in/foo"
touch "$_in/bar"
touch "$_in/has space"
# shellcheck disable=SC2086
copy_files $_in/foo:/usr/bin/foo $_in/bar "$_in/has space"
local _ret=0
if [ ! -e "$output_dir/usr/bin/foo" ]; then
echo "test_copy_files: fail - expected to copy a file with src:dest format!"
_ret=1
elif [ ! -e "$output_dir/bar" ]; then
echo "test_copy_files: fail - expected to copy a file!"
_ret=1
elif [ ! -e "$output_dir/has space" ]; then
echo "test_copy_files: fail - expected to copy a file with a space in the path!"
_ret=1
fi
[ $_ret -eq 0 ] && echo "test_copy_files: pass"
return $_ret
}
test_invalid_dtb() {
# shellcheck disable=SC2091
if $(find_dtb "bogus_dts") ; then
echo "test_invalid_dtb: find_dtb should've failed"
return 1
fi
echo "test_invalid_dtb: pass"
return 0
}
test_extlinux_config() {
work_dir="./"
# shellcheck disable=SC2034
deviceinfo_generate_extlinux_config="true"
# shellcheck disable=SC2034
distro_name="postmarketOS"
# shellcheck disable=SC2034
kernel_filename="vmlinuz"
# shellcheck disable=SC2034
initfs_filename="initramfs"
# shellcheck disable=SC2034
additional_files=""
local _ret=0
local _result
local _expected_result
# A dumb replacement for find_all_dtbs which doesn't work with globs
unset -f find_all_dtbs
find_all_dtbs() {
echo "$deviceinfo_dtb"
}
# cmdline + 1 dtb
# shellcheck disable=SC2034
deviceinfo_dtb="mediatek/mt8173-elm-hana"
unset -f get_cmdline
get_cmdline() {
# shellcheck disable=SC2317
echo "test test test"
}
create_extlinux_config
_expected_result="$(cat extlinux-examples/extlinux.conf.1)"
_result="$(cat $work_dir/extlinux.conf)"
if [ ! "$_result" = "$_expected_result" ]; then
_ret=1
echo "test_extlinux_config (cmdline + 1 dtb): fail"
else
echo "test_extlinux_config (cmdline + 1 dtb): pass"
fi
# cmdline + multiple dtbs
# shellcheck disable=SC2034
deviceinfo_dtb="mediatek/mt8173-elm-hana mediatek/mt8173-elm-hana-rev7"
unset -f get_cmdline
get_cmdline() {
# shellcheck disable=SC2317
echo "test test test"
}
create_extlinux_config
_expected_result="$(cat extlinux-examples/extlinux.conf.2)"
_result="$(cat $work_dir/extlinux.conf)"
if [ ! "$_result" = "$_expected_result" ]; then
_ret=1
echo "test_extlinux_config (cmdline + multiple dtbs): fail"
else
echo "test_extlinux_config (cmdline + multiple dtbs): pass"
fi
# no cmdline + 1 dtb
# shellcheck disable=SC2034
deviceinfo_dtb="mediatek/mt8173-elm-hana"
unset -f get_cmdline
get_cmdline() {
# shellcheck disable=SC2317
echo " "
}
create_extlinux_config
_expected_result="$(cat extlinux-examples/extlinux.conf.3)"
_result="$(cat $work_dir/extlinux.conf)"
if [ ! "$_result" = "$_expected_result" ]; then
_ret=1
echo "test_extlinux_config (no cmdline + 1 dtb): fail"
else
echo "test_extlinux_config (no cmdline + 1 dtb)): pass"
fi
return $_ret
}
test_get_size_of_files
test_copy_files
test_invalid_dtb
test_extlinux_config
rm -rf "$wdir"
trap - INT EXIT TERM