File: arch_test.sh

package info (click to toggle)
kworkflow 1%3A0.10-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 5,212 kB
  • sloc: sh: 31,869; perl: 2,172; sql: 268; ansic: 114; xml: 84; python: 76; makefile: 27
file content (287 lines) | stat: -rwxr-xr-x 7,578 bytes parent folder | download
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
#!/usr/bin/env bash

include './src/plugins/kernel_install/utils.sh'
include './src/plugins/kernel_install/arch.sh'
include './src/lib/kwio.sh'
include './src/lib/kwlib.sh'
include './tests/unit/utils.sh'

function setUp()
{
  export ORIGINAL_PATH="$PWD"
  mk_fake_boot "$SHUNIT_TMPDIR"

  export kw_path='/fake/remote/path'
  export KW_ETC_DIR='/fake/local/path'
  export REMOTE_KW_DEPLOY='/fake/run/kw/etc'

  cp "tests/unit/samples/mkinitcpio_output/mkinitcpio_log_with_errors" "$SHUNIT_TMPDIR"
  cp "tests/unit/samples/mkinitcpio_output/mkinitcpio_log_only_warnings" "$SHUNIT_TMPDIR"

  cd "$SHUNIT_TMPDIR" || {
    fail "(${LINENO}) It was not possible to move to temporary directory"
    return
  }
}

function tearDown()
{
  cd "$ORIGINAL_PATH" || {
    fail "(${LINENO}) It was not possible to move to the kw folder"
    return
  }
  rm -rf "$SHUNIT_TMPDIR"
}

function test_generate_arch_temporary_root_file_system_local_and_mkinitcpio()
{
  local name='xpto'
  local path_prefix=''
  local cmd=
  local sudo_cmd=''
  local qemu_mock_img="${SHUNIT_TMPDIR}/mock_image"
  local ret

  # Local
  sudo_cmd='sudo --preserve-env'
  declare -a cmd_sequence=(
    "${sudo_cmd} depmod --all ${name}"
    "${sudo_cmd} mkinitcpio --generate /boot/initramfs-${name}.img --kernel ${name}"
  )

  # Create fake initramfs
  touch "initramfs-${name}.img"

  output="$(
    boot_prefix="${SHUNIT_TMPDIR}"
    function command_exists()
    {
      return 0
    }
    generate_arch_temporary_root_file_system 'TEST_MODE' "${name}" 'local' 'GRUB'
  )"
  ret="$?"

  compare_command_sequence '' "$LINENO" 'cmd_sequence' "$output"
  assert_equals_helper 'Expected error code' "(${LINENO})" 0 "$ret"
}

function test_generate_arch_temporary_root_file_system_local_and_mkinitcpio_fail_to_generate_initramfs()
{
  local name='xpto'
  local path_prefix=''
  local cmd=
  local sudo_cmd=''
  local qemu_mock_img="${SHUNIT_TMPDIR}/mock_image"
  local ret

  output="$(
    function command_exists()
    {
      return 0
    }
    generate_arch_temporary_root_file_system 'TEST_MODE' "${name}" 'local' 'GRUB'
  )"
  ret="$?"

  assert_equals_helper 'Expected error code' "(${LINENO})" 2 "$ret"
}

function test_generate_arch_temporary_root_file_system_remote_and_mkinitcpio()
{
  local name='xpto'
  local path_prefix=''
  local cmd=
  local sudo_cmd=''
  local qemu_mock_img="${SHUNIT_TMPDIR}/mock_image"

  # Remote
  declare -a cmd_sequence=(
    "depmod --all ${name}"
    "mkinitcpio --generate /boot/initramfs-${name}.img --kernel ${name}"
  )

  output="$(
    function command_exists()
    {
      return 0
    }
    generate_arch_temporary_root_file_system 'TEST_MODE' "${name}" 'remote' 'GRUB'
  )"
  compare_command_sequence '' "$LINENO" 'cmd_sequence' "$output"
}

function test_generate_arch_temporary_root_file_system_remote_and_dracut()
{
  local name='xpto'
  local path_prefix=''
  local cmd=
  local sudo_cmd=''
  local qemu_mock_img="${SHUNIT_TMPDIR}/mock_image"

  # Remote
  declare -a cmd_sequence=(
    "depmod --all $name"
    "DRACUT_NO_XATTR=1 dracut --force --persistent-policy by-partuuid --hostonly /boot/initramfs-${name}.img ${name}"
  )

  # We want to force dracut
  output="$(
    function command_exists()
    {
      [[ "$1" == 'mkinitcpio' ]] && return 1
      return 0
    }
    generate_arch_temporary_root_file_system 'TEST_MODE' "$name" 'remote' 'GRUB'
  )"
  compare_command_sequence '' "$LINENO" 'cmd_sequence' "$output"
}

function test_generate_arch_temporary_root_file_system_remote_and_not_supported()
{
  local name='xpto'
  local path_prefix=''
  local cmd=
  local sudo_cmd=''
  local qemu_mock_img="${SHUNIT_TMPDIR}/mock_image"

  # Remote
  declare -a cmd_sequence=(
    "depmod --all $name"
    "DRACUT_NO_XATTR=1 dracut --force --persistent-policy by-partuuid --hostonly /boot/initramfs-${name}.img ${name}"
  )

  # We want to force an unsupported tool
  output="$(
    function command_exists()
    {
      [[ "${1}" == 'mkinitcpio' ]] && return 1
      [[ "${1}" == 'dracut' ]] && return 1
    }
    generate_arch_temporary_root_file_system 'TEST_MODE' "${name}" 'remote' 'GRUB'
  )"

  assertEquals "(${LINENO})" 22 "$?"
}

function test_generate_arch_temporary_root_file_system_remote_preferred_root_fs()
{
  local name='xpto'
  local path_prefix=''
  local cmd=
  local sudo_cmd=''
  local qemu_mock_img="${SHUNIT_TMPDIR}/mock_image"

  # Remote
  declare -a cmd_sequence=(
    "depmod --all ${name}"
    "DRACUT_NO_XATTR=1 dracut --force --persistent-policy by-partuuid --hostonly /boot/initramfs-${name}.img ${name}"
  )

  # We want to force an the prefered option
  output="$(
    function command_exists()
    {
      return 0
    }
    generate_arch_temporary_root_file_system 'TEST_MODE' "$name" 'remote' 'GRUB' '' 'dracut'
  )"

  compare_command_sequence '' "$LINENO" 'cmd_sequence' "$output"
}

function test_generate_arch_temporary_root_file_system_remote_preferred_root_fs_invalid()
{
  local name='xpto'
  local path_prefix=''
  local cmd=
  local sudo_cmd=''
  local qemu_mock_img="${SHUNIT_TMPDIR}/mock_image"
  local expected_output='It looks like that "xpto" does not exists'
  local output

  # We want to force an the prefered option
  output="$(
    function command_exists()
    {
      return 1
    }
    generate_arch_temporary_root_file_system 'TEST_MODE' "${name}" 'remote' 'GRUB' '' 'xpto'
  )"

  assert_equals_helper "Expected error message" "(${LINENO})" "$expected_output" "$output"
}

function test_process_mkinitcpio_message_check_errors_return()
{
  local log_from_file
  local output
  local ret

  log_from_file=$(< "mkinitcpio_log_with_errors")

  output=$(process_mkinitcpio_message "$log_from_file")
  ret="$?"

  assert_equals_helper 'Expected error code' "(${LINENO})" 68 "$ret"
}

function test_process_mkinitcpio_message_check_warnings_return()
{
  local log_from_file
  local output
  local ret

  log_from_file=$(< "mkinitcpio_log_only_warnings")

  output=$(process_mkinitcpio_message "$log_from_file")
  ret="$?"

  assert_equals_helper 'Expected error code' "(${LINENO})" 42 "$ret"
}

function test_process_mkinitcpio_message_check_warning_message()
{
  local log_from_file
  local output
  local ret

  declare -a output_sequence=(
    "==> WARNING: Possibly missing firmware for module: 'xhci_pci'"
    "==> WARNING: Possibly missing '/bin/bash' for script: /usr/bin/mount.steamos"
    "==> WARNING: errors were encountered during the build. The image may not be complete."
  )

  log_from_file=$(< "mkinitcpio_log_only_warnings")

  output=$(process_mkinitcpio_message "$log_from_file")

  compare_command_sequence '' "$LINENO" 'output_sequence' "$output"
}

function test_process_mkinitcpio_message_check_error_warning_message()
{
  local log_from_file
  local output
  local ret

  declare -a output_sequence=(
    "==> ERROR: binary not found: 'plymouth'"
    "==> ERROR: module not found: 'steamdeck'"
    "==> ERROR: module not found: 'steamdeck_hwmon'"
    "==> ERROR: module not found: 'leds_steamdeck'"
    "==> ERROR: module not found: 'extcon_steamdeck'"
    "==> ERROR: module not found: 'ulpi'"
    "==> ERROR: module not found: 'uas'"
    "==> WARNING: Possibly missing firmware for module: 'xhci_pci'"
    "==> WARNING: Possibly missing '/bin/bash' for script: /usr/bin/mount.steamos"
    "==> WARNING: errors were encountered during the build. The image may not be complete."
  )

  log_from_file=$(< "mkinitcpio_log_with_errors")
  output=$(process_mkinitcpio_message "$log_from_file")

  compare_command_sequence '' "$LINENO" 'output_sequence' "$output"
}

invoke_shunit