xref: /openbmc/qemu/tests/avocado/replay_kernel.py (revision fb6051e7)
1# Record/replay test that boots a Linux kernel
2#
3# Copyright (c) 2020 ISP RAS
4#
5# Author:
6#  Pavel Dovgalyuk <Pavel.Dovgaluk@ispras.ru>
7#
8# This work is licensed under the terms of the GNU GPL, version 2 or
9# later.  See the COPYING file in the top-level directory.
10
11import os
12import lzma
13import shutil
14import logging
15import time
16import subprocess
17
18from avocado import skip
19from avocado import skipUnless
20from avocado import skipUnless
21from avocado_qemu import wait_for_console_pattern
22from avocado.utils import archive
23from avocado.utils import process
24from boot_linux_console import LinuxKernelTest
25
26class ReplayKernelBase(LinuxKernelTest):
27    """
28    Boots a Linux kernel in record mode and checks that the console
29    is operational and the kernel command line is properly passed
30    from QEMU to the kernel.
31    Then replays the same scenario and verifies, that QEMU correctly
32    terminates.
33    """
34
35    timeout = 180
36    KERNEL_COMMON_COMMAND_LINE = 'printk.time=1 panic=-1 '
37
38    def run_vm(self, kernel_path, kernel_command_line, console_pattern,
39               record, shift, args, replay_path):
40        # icount requires TCG to be available
41        self.require_accelerator('tcg')
42
43        logger = logging.getLogger('replay')
44        start_time = time.time()
45        vm = self.get_vm()
46        vm.set_console()
47        if record:
48            logger.info('recording the execution...')
49            mode = 'record'
50        else:
51            logger.info('replaying the execution...')
52            mode = 'replay'
53        vm.add_args('-icount', 'shift=%s,rr=%s,rrfile=%s' %
54                    (shift, mode, replay_path),
55                    '-kernel', kernel_path,
56                    '-append', kernel_command_line,
57                    '-net', 'none',
58                    '-no-reboot')
59        if args:
60            vm.add_args(*args)
61        vm.launch()
62        self.wait_for_console_pattern(console_pattern, vm)
63        if record:
64            vm.shutdown()
65            logger.info('finished the recording with log size %s bytes'
66                        % os.path.getsize(replay_path))
67            self.run_replay_dump(replay_path)
68            logger.info('successfully tested replay-dump.py')
69        else:
70            vm.wait()
71            logger.info('successfully finished the replay')
72        elapsed = time.time() - start_time
73        logger.info('elapsed time %.2f sec' % elapsed)
74        return elapsed
75
76    def run_replay_dump(self, replay_path):
77        try:
78            subprocess.check_call(["./scripts/replay-dump.py",
79                                   "-f", replay_path],
80                                  stdout=subprocess.DEVNULL)
81        except subprocess.CalledProcessError:
82            self.fail('replay-dump.py failed')
83
84    def run_rr(self, kernel_path, kernel_command_line, console_pattern,
85               shift=7, args=None):
86        replay_path = os.path.join(self.workdir, 'replay.bin')
87        t1 = self.run_vm(kernel_path, kernel_command_line, console_pattern,
88                         True, shift, args, replay_path)
89        t2 = self.run_vm(kernel_path, kernel_command_line, console_pattern,
90                         False, shift, args, replay_path)
91        logger = logging.getLogger('replay')
92        logger.info('replay overhead {:.2%}'.format(t2 / t1 - 1))
93
94class ReplayKernelNormal(ReplayKernelBase):
95
96    def test_i386_pc(self):
97        """
98        :avocado: tags=arch:i386
99        :avocado: tags=machine:pc
100        """
101        kernel_url = ('https://storage.tuxboot.com/20230331/i386/bzImage')
102        kernel_hash = 'a3e5b32a354729e65910f5a1ffcda7c14a6c12a55e8213fb86e277f1b76ed956'
103        kernel_path = self.fetch_asset(kernel_url,
104                                       asset_hash=kernel_hash,
105                                       algorithm = "sha256")
106
107        kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
108        console_pattern = 'VFS: Cannot open root device'
109
110        self.run_rr(kernel_path, kernel_command_line, console_pattern, shift=5)
111
112    # See https://gitlab.com/qemu-project/qemu/-/issues/2094
113    @skipUnless(os.getenv('QEMU_TEST_FLAKY_TESTS'), 'pc machine is unstable with replay')
114    def test_x86_64_pc(self):
115        """
116        :avocado: tags=arch:x86_64
117        :avocado: tags=machine:pc
118        :avocado: tags=flaky
119        """
120        kernel_url = ('https://archives.fedoraproject.org/pub/archive/fedora'
121                      '/linux/releases/29/Everything/x86_64/os/images/pxeboot'
122                      '/vmlinuz')
123        kernel_hash = '23bebd2680757891cf7adedb033532163a792495'
124        kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
125
126        kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
127        console_pattern = 'VFS: Cannot open root device'
128
129        self.run_rr(kernel_path, kernel_command_line, console_pattern, shift=5)
130
131    def test_x86_64_q35(self):
132        """
133        :avocado: tags=arch:x86_64
134        :avocado: tags=machine:q35
135        """
136        kernel_url = ('https://archives.fedoraproject.org/pub/archive/fedora'
137                      '/linux/releases/29/Everything/x86_64/os/images/pxeboot'
138                      '/vmlinuz')
139        kernel_hash = '23bebd2680757891cf7adedb033532163a792495'
140        kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
141
142        kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
143        console_pattern = 'VFS: Cannot open root device'
144
145        self.run_rr(kernel_path, kernel_command_line, console_pattern, shift=5)
146
147    def test_mips_malta(self):
148        """
149        :avocado: tags=arch:mips
150        :avocado: tags=machine:malta
151        :avocado: tags=endian:big
152        """
153        deb_url = ('http://snapshot.debian.org/archive/debian/'
154                   '20130217T032700Z/pool/main/l/linux-2.6/'
155                   'linux-image-2.6.32-5-4kc-malta_2.6.32-48_mips.deb')
156        deb_hash = 'a8cfc28ad8f45f54811fc6cf74fc43ffcfe0ba04'
157        deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
158        kernel_path = self.extract_from_deb(deb_path,
159                                            '/boot/vmlinux-2.6.32-5-4kc-malta')
160        kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
161        console_pattern = 'Kernel command line: %s' % kernel_command_line
162
163        self.run_rr(kernel_path, kernel_command_line, console_pattern, shift=5)
164
165    def test_mips64el_malta(self):
166        """
167        This test requires the ar tool to extract "data.tar.gz" from
168        the Debian package.
169
170        The kernel can be rebuilt using this Debian kernel source [1] and
171        following the instructions on [2].
172
173        [1] http://snapshot.debian.org/package/linux-2.6/2.6.32-48/
174            #linux-source-2.6.32_2.6.32-48
175        [2] https://kernel-team.pages.debian.net/kernel-handbook/
176            ch-common-tasks.html#s-common-official
177
178        :avocado: tags=arch:mips64el
179        :avocado: tags=machine:malta
180        """
181        deb_url = ('http://snapshot.debian.org/archive/debian/'
182                   '20130217T032700Z/pool/main/l/linux-2.6/'
183                   'linux-image-2.6.32-5-5kc-malta_2.6.32-48_mipsel.deb')
184        deb_hash = '1aaec92083bf22fda31e0d27fa8d9a388e5fc3d5'
185        deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
186        kernel_path = self.extract_from_deb(deb_path,
187                                            '/boot/vmlinux-2.6.32-5-5kc-malta')
188        kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
189        console_pattern = 'Kernel command line: %s' % kernel_command_line
190        self.run_rr(kernel_path, kernel_command_line, console_pattern, shift=5)
191
192    def test_aarch64_virt(self):
193        """
194        :avocado: tags=arch:aarch64
195        :avocado: tags=machine:virt
196        :avocado: tags=cpu:cortex-a53
197        """
198        kernel_url = ('https://archives.fedoraproject.org/pub/archive/fedora'
199                      '/linux/releases/29/Everything/aarch64/os/images/pxeboot'
200                      '/vmlinuz')
201        kernel_hash = '8c73e469fc6ea06a58dc83a628fc695b693b8493'
202        kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
203
204        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
205                               'console=ttyAMA0')
206        console_pattern = 'VFS: Cannot open root device'
207
208        self.run_rr(kernel_path, kernel_command_line, console_pattern)
209
210    def test_arm_virt(self):
211        """
212        :avocado: tags=arch:arm
213        :avocado: tags=machine:virt
214        """
215        kernel_url = ('https://archives.fedoraproject.org/pub/archive/fedora'
216                      '/linux/releases/29/Everything/armhfp/os/images/pxeboot'
217                      '/vmlinuz')
218        kernel_hash = 'e9826d741b4fb04cadba8d4824d1ed3b7fb8b4d4'
219        kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
220
221        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
222                               'console=ttyAMA0')
223        console_pattern = 'VFS: Cannot open root device'
224
225        self.run_rr(kernel_path, kernel_command_line, console_pattern, shift=1)
226
227    def test_arm_cubieboard_initrd(self):
228        """
229        :avocado: tags=arch:arm
230        :avocado: tags=machine:cubieboard
231        """
232        deb_url = ('https://apt.armbian.com/pool/main/l/'
233                   'linux-6.6.16/linux-image-current-sunxi_24.2.1_armhf__6.6.16-Seb3e-D6b4a-P2359-Ce96bHfe66-HK01ba-V014b-B067e-R448a.deb')
234        deb_hash = 'f7c3c8c5432f765445dc6e7eab02f3bbe668256b'
235        deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
236        kernel_path = self.extract_from_deb(deb_path,
237                                            '/boot/vmlinuz-6.6.16-current-sunxi')
238        dtb_path = '/usr/lib/linux-image-6.6.16-current-sunxi/sun4i-a10-cubieboard.dtb'
239        dtb_path = self.extract_from_deb(deb_path, dtb_path)
240        initrd_url = ('https://github.com/groeck/linux-build-test/raw/'
241                      '2eb0a73b5d5a28df3170c546ddaaa9757e1e0848/rootfs/'
242                      'arm/rootfs-armv5.cpio.gz')
243        initrd_hash = '2b50f1873e113523967806f4da2afe385462ff9b'
244        initrd_path_gz = self.fetch_asset(initrd_url, asset_hash=initrd_hash)
245        initrd_path = os.path.join(self.workdir, 'rootfs.cpio')
246        archive.gzip_uncompress(initrd_path_gz, initrd_path)
247
248        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
249                               'console=ttyS0,115200 '
250                               'usbcore.nousb '
251                               'panic=-1 noreboot')
252        console_pattern = 'Boot successful.'
253        self.run_rr(kernel_path, kernel_command_line, console_pattern, shift=1,
254                    args=('-dtb', dtb_path,
255                          '-initrd', initrd_path,
256                          '-no-reboot'))
257
258    def test_s390x_s390_ccw_virtio(self):
259        """
260        :avocado: tags=arch:s390x
261        :avocado: tags=machine:s390-ccw-virtio
262        """
263        kernel_url = ('https://archives.fedoraproject.org/pub/archive'
264                      '/fedora-secondary/releases/29/Everything/s390x/os/images'
265                      '/kernel.img')
266        kernel_hash = 'e8e8439103ef8053418ef062644ffd46a7919313'
267        kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
268
269        kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=sclp0'
270        console_pattern = 'Kernel command line: %s' % kernel_command_line
271        self.run_rr(kernel_path, kernel_command_line, console_pattern, shift=9)
272
273    def test_alpha_clipper(self):
274        """
275        :avocado: tags=arch:alpha
276        :avocado: tags=machine:clipper
277        """
278        kernel_url = ('http://archive.debian.org/debian/dists/lenny/main/'
279                      'installer-alpha/20090123lenny10/images/cdrom/vmlinuz')
280        kernel_hash = '3a943149335529e2ed3e74d0d787b85fb5671ba3'
281        kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
282
283        uncompressed_kernel = archive.uncompress(kernel_path, self.workdir)
284
285        kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
286        console_pattern = 'Kernel command line: %s' % kernel_command_line
287        self.run_rr(uncompressed_kernel, kernel_command_line, console_pattern, shift=9,
288            args=('-nodefaults', ))
289
290    def test_ppc64_pseries(self):
291        """
292        :avocado: tags=arch:ppc64
293        :avocado: tags=machine:pseries
294        :avocado: tags=accel:tcg
295        """
296        kernel_url = ('https://archives.fedoraproject.org/pub/archive'
297                      '/fedora-secondary/releases/29/Everything/ppc64le/os'
298                      '/ppc/ppc64/vmlinuz')
299        kernel_hash = '3fe04abfc852b66653b8c3c897a59a689270bc77'
300        kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
301
302        kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=hvc0'
303        console_pattern = 'VFS: Cannot open root device'
304        self.run_rr(kernel_path, kernel_command_line, console_pattern)
305
306    def test_ppc64_powernv(self):
307        """
308        :avocado: tags=arch:ppc64
309        :avocado: tags=machine:powernv
310        :avocado: tags=accel:tcg
311        """
312        kernel_url = ('https://archives.fedoraproject.org/pub/archive'
313                      '/fedora-secondary/releases/29/Everything/ppc64le/os'
314                      '/ppc/ppc64/vmlinuz')
315        kernel_hash = '3fe04abfc852b66653b8c3c897a59a689270bc77'
316        kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
317
318        kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + \
319                              'console=tty0 console=hvc0'
320        console_pattern = 'VFS: Cannot open root device'
321        self.run_rr(kernel_path, kernel_command_line, console_pattern)
322
323    def test_m68k_q800(self):
324        """
325        :avocado: tags=arch:m68k
326        :avocado: tags=machine:q800
327        """
328        deb_url = ('https://snapshot.debian.org/archive/debian-ports'
329                   '/20191021T083923Z/pool-m68k/main'
330                   '/l/linux/kernel-image-5.3.0-1-m68k-di_5.3.7-1_m68k.udeb')
331        deb_hash = '044954bb9be4160a3ce81f8bc1b5e856b75cccd1'
332        deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
333        kernel_path = self.extract_from_deb(deb_path,
334                                            '/boot/vmlinux-5.3.0-1-m68k')
335
336        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
337                               'console=ttyS0 vga=off')
338        console_pattern = 'No filesystem could mount root'
339        self.run_rr(kernel_path, kernel_command_line, console_pattern)
340
341    def do_test_advcal_2018(self, file_path, kernel_name, args=None):
342        archive.extract(file_path, self.workdir)
343
344        for entry in os.scandir(self.workdir):
345            if entry.name.startswith('day') and entry.is_dir():
346                kernel_path = os.path.join(entry.path, kernel_name)
347                break
348
349        kernel_command_line = ''
350        console_pattern = 'QEMU advent calendar'
351        self.run_rr(kernel_path, kernel_command_line, console_pattern,
352                    args=args)
353
354    def test_arm_vexpressa9(self):
355        """
356        :avocado: tags=arch:arm
357        :avocado: tags=machine:vexpress-a9
358        """
359        tar_hash = '32b7677ce8b6f1471fb0059865f451169934245b'
360        tar_url = ('https://qemu-advcal.gitlab.io'
361                   '/qac-best-of-multiarch/download/day16.tar.xz')
362        file_path = self.fetch_asset(tar_url, asset_hash=tar_hash)
363        dtb_path = self.workdir + '/day16/vexpress-v2p-ca9.dtb'
364        self.do_test_advcal_2018(file_path, 'winter.zImage',
365                                 args=('-dtb', dtb_path))
366
367    def test_m68k_mcf5208evb(self):
368        """
369        :avocado: tags=arch:m68k
370        :avocado: tags=machine:mcf5208evb
371        """
372        tar_hash = 'ac688fd00561a2b6ce1359f9ff6aa2b98c9a570c'
373        tar_url = ('https://qemu-advcal.gitlab.io'
374                   '/qac-best-of-multiarch/download/day07.tar.xz')
375        file_path = self.fetch_asset(tar_url, asset_hash=tar_hash)
376        self.do_test_advcal_2018(file_path, 'sanity-clause.elf')
377
378    def test_microblaze_s3adsp1800(self):
379        """
380        :avocado: tags=arch:microblaze
381        :avocado: tags=machine:petalogix-s3adsp1800
382        """
383        tar_hash = '08bf3e3bfb6b6c7ce1e54ab65d54e189f2caf13f'
384        tar_url = ('https://qemu-advcal.gitlab.io'
385                   '/qac-best-of-multiarch/download/day17.tar.xz')
386        file_path = self.fetch_asset(tar_url, asset_hash=tar_hash)
387        self.do_test_advcal_2018(file_path, 'ballerina.bin')
388
389    def test_ppc64_e500(self):
390        """
391        :avocado: tags=arch:ppc64
392        :avocado: tags=machine:ppce500
393        :avocado: tags=cpu:e5500
394        """
395        tar_hash = '6951d86d644b302898da2fd701739c9406527fe1'
396        tar_url = ('https://qemu-advcal.gitlab.io'
397                   '/qac-best-of-multiarch/download/day19.tar.xz')
398        file_path = self.fetch_asset(tar_url, asset_hash=tar_hash)
399        self.do_test_advcal_2018(file_path, 'uImage')
400
401    def test_or1k_sim(self):
402        """
403        :avocado: tags=arch:or1k
404        :avocado: tags=machine:or1k-sim
405        """
406        tar_hash = '20334cdaf386108c530ff0badaecc955693027dd'
407        tar_url = ('https://qemu-advcal.gitlab.io'
408                   '/qac-best-of-multiarch/download/day20.tar.xz')
409        file_path = self.fetch_asset(tar_url, asset_hash=tar_hash)
410        self.do_test_advcal_2018(file_path, 'vmlinux')
411
412    def test_ppc_g3beige(self):
413        """
414        :avocado: tags=arch:ppc
415        :avocado: tags=machine:g3beige
416        """
417        tar_hash = 'e0b872a5eb8fdc5bed19bd43ffe863900ebcedfc'
418        tar_url = ('https://qemu-advcal.gitlab.io'
419                   '/qac-best-of-multiarch/download/day15.tar.xz')
420        file_path = self.fetch_asset(tar_url, asset_hash=tar_hash)
421        self.do_test_advcal_2018(file_path, 'invaders.elf',
422                                 args=('-M', 'graphics=off'))
423
424    def test_ppc_mac99(self):
425        """
426        :avocado: tags=arch:ppc
427        :avocado: tags=machine:mac99
428        """
429        tar_hash = 'e0b872a5eb8fdc5bed19bd43ffe863900ebcedfc'
430        tar_url = ('https://qemu-advcal.gitlab.io'
431                   '/qac-best-of-multiarch/download/day15.tar.xz')
432        file_path = self.fetch_asset(tar_url, asset_hash=tar_hash)
433        self.do_test_advcal_2018(file_path, 'invaders.elf',
434                                 args=('-M', 'graphics=off'))
435
436    def test_sparc_ss20(self):
437        """
438        :avocado: tags=arch:sparc
439        :avocado: tags=machine:SS-20
440        """
441        tar_hash = 'b18550d5d61c7615d989a06edace051017726a9f'
442        tar_url = ('https://qemu-advcal.gitlab.io'
443                   '/qac-best-of-multiarch/download/day11.tar.xz')
444        file_path = self.fetch_asset(tar_url, asset_hash=tar_hash)
445        self.do_test_advcal_2018(file_path, 'zImage.elf')
446
447    def test_xtensa_lx60(self):
448        """
449        :avocado: tags=arch:xtensa
450        :avocado: tags=machine:lx60
451        :avocado: tags=cpu:dc233c
452        """
453        tar_hash = '49e88d9933742f0164b60839886c9739cb7a0d34'
454        tar_url = ('https://qemu-advcal.gitlab.io'
455                   '/qac-best-of-multiarch/download/day02.tar.xz')
456        file_path = self.fetch_asset(tar_url, asset_hash=tar_hash)
457        self.do_test_advcal_2018(file_path, 'santas-sleigh-ride.elf')
458
459@skipUnless(os.getenv('AVOCADO_TIMEOUT_EXPECTED'), 'Test might timeout')
460class ReplayKernelSlow(ReplayKernelBase):
461    # Override the timeout, because this kernel includes an inner
462    # loop which is executed with TB recompilings during replay,
463    # making it very slow.
464    timeout = 180
465
466    def test_mips_malta_cpio(self):
467        """
468        :avocado: tags=arch:mips
469        :avocado: tags=machine:malta
470        :avocado: tags=endian:big
471        :avocado: tags=slowness:high
472        """
473        deb_url = ('http://snapshot.debian.org/archive/debian/'
474                   '20160601T041800Z/pool/main/l/linux/'
475                   'linux-image-4.5.0-2-4kc-malta_4.5.5-1_mips.deb')
476        deb_hash = 'a3c84f3e88b54e06107d65a410d1d1e8e0f340f8'
477        deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
478        kernel_path = self.extract_from_deb(deb_path,
479                                            '/boot/vmlinux-4.5.0-2-4kc-malta')
480        initrd_url = ('https://github.com/groeck/linux-build-test/raw/'
481                      '8584a59ed9e5eb5ee7ca91f6d74bbb06619205b8/rootfs/'
482                      'mips/rootfs.cpio.gz')
483        initrd_hash = 'bf806e17009360a866bf537f6de66590de349a99'
484        initrd_path_gz = self.fetch_asset(initrd_url, asset_hash=initrd_hash)
485        initrd_path = self.workdir + "rootfs.cpio"
486        archive.gzip_uncompress(initrd_path_gz, initrd_path)
487
488        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
489                               'console=ttyS0 console=tty '
490                               'rdinit=/sbin/init noreboot')
491        console_pattern = 'Boot successful.'
492        self.run_rr(kernel_path, kernel_command_line, console_pattern, shift=5,
493                    args=('-initrd', initrd_path))
494
495    @skipUnless(os.getenv('AVOCADO_ALLOW_UNTRUSTED_CODE'), 'untrusted code')
496    def test_mips64el_malta_5KEc_cpio(self):
497        """
498        :avocado: tags=arch:mips64el
499        :avocado: tags=machine:malta
500        :avocado: tags=endian:little
501        :avocado: tags=slowness:high
502        :avocado: tags=cpu:5KEc
503        """
504        kernel_url = ('https://github.com/philmd/qemu-testing-blob/'
505                      'raw/9ad2df38/mips/malta/mips64el/'
506                      'vmlinux-3.19.3.mtoman.20150408')
507        kernel_hash = '00d1d268fb9f7d8beda1de6bebcc46e884d71754'
508        kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
509        initrd_url = ('https://github.com/groeck/linux-build-test/'
510                      'raw/8584a59e/rootfs/'
511                      'mipsel64/rootfs.mipsel64r1.cpio.gz')
512        initrd_hash = '1dbb8a396e916847325284dbe2151167'
513        initrd_path_gz = self.fetch_asset(initrd_url, algorithm='md5',
514                                          asset_hash=initrd_hash)
515        initrd_path = self.workdir + "rootfs.cpio"
516        archive.gzip_uncompress(initrd_path_gz, initrd_path)
517
518        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
519                               'console=ttyS0 console=tty '
520                               'rdinit=/sbin/init noreboot')
521        console_pattern = 'Boot successful.'
522        self.run_rr(kernel_path, kernel_command_line, console_pattern, shift=5,
523                    args=('-initrd', initrd_path))
524
525    def do_test_mips_malta32el_nanomips(self, kernel_path_xz):
526        kernel_path = self.workdir + "kernel"
527        with lzma.open(kernel_path_xz, 'rb') as f_in:
528            with open(kernel_path, 'wb') as f_out:
529                shutil.copyfileobj(f_in, f_out)
530
531        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
532                               'mem=256m@@0x0 '
533                               'console=ttyS0')
534        console_pattern = 'Kernel command line: %s' % kernel_command_line
535        self.run_rr(kernel_path, kernel_command_line, console_pattern, shift=5)
536
537    def test_mips_malta32el_nanomips_4k(self):
538        """
539        :avocado: tags=arch:mipsel
540        :avocado: tags=machine:malta
541        :avocado: tags=endian:little
542        :avocado: tags=cpu:I7200
543        """
544        kernel_url = ('http://mipsdistros.mips.com/LinuxDistro/nanomips/'
545                      'kernels/v4.15.18-432-gb2eb9a8b07a1-20180627102142/'
546                      'generic_nano32r6el_page4k.xz')
547        kernel_hash = '477456aafd2a0f1ddc9482727f20fe9575565dd6'
548        kernel_path_xz = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
549        self.do_test_mips_malta32el_nanomips(kernel_path_xz)
550
551    def test_mips_malta32el_nanomips_16k_up(self):
552        """
553        :avocado: tags=arch:mipsel
554        :avocado: tags=machine:malta
555        :avocado: tags=endian:little
556        :avocado: tags=cpu:I7200
557        """
558        kernel_url = ('http://mipsdistros.mips.com/LinuxDistro/nanomips/'
559                      'kernels/v4.15.18-432-gb2eb9a8b07a1-20180627102142/'
560                      'generic_nano32r6el_page16k_up.xz')
561        kernel_hash = 'e882868f944c71c816e832e2303b7874d044a7bc'
562        kernel_path_xz = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
563        self.do_test_mips_malta32el_nanomips(kernel_path_xz)
564
565    def test_mips_malta32el_nanomips_64k_dbg(self):
566        """
567        :avocado: tags=arch:mipsel
568        :avocado: tags=machine:malta
569        :avocado: tags=endian:little
570        :avocado: tags=cpu:I7200
571        """
572        kernel_url = ('http://mipsdistros.mips.com/LinuxDistro/nanomips/'
573                      'kernels/v4.15.18-432-gb2eb9a8b07a1-20180627102142/'
574                      'generic_nano32r6el_page64k_dbg.xz')
575        kernel_hash = '18d1c68f2e23429e266ca39ba5349ccd0aeb7180'
576        kernel_path_xz = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
577        self.do_test_mips_malta32el_nanomips(kernel_path_xz)
578