1# Functional test that boots a microblaze Linux kernel and checks the console
2#
3# Copyright (c) 2018, 2021 Red Hat, Inc.
4#
5# This work is licensed under the terms of the GNU GPL, version 2 or
6# later. See the COPYING file in the top-level directory.
7
8import time
9from avocado_qemu import exec_command, exec_command_and_wait_for_pattern
10from avocado_qemu import QemuSystemTest
11from avocado_qemu import wait_for_console_pattern
12from avocado.utils import archive
13
14class MicroblazeMachine(QemuSystemTest):
15
16    timeout = 90
17
18    def test_microblaze_s3adsp1800(self):
19        """
20        :avocado: tags=arch:microblaze
21        :avocado: tags=machine:petalogix-s3adsp1800
22        """
23
24        tar_url = ('https://qemu-advcal.gitlab.io'
25                   '/qac-best-of-multiarch/download/day17.tar.xz')
26        tar_hash = '08bf3e3bfb6b6c7ce1e54ab65d54e189f2caf13f'
27        file_path = self.fetch_asset(tar_url, asset_hash=tar_hash)
28        archive.extract(file_path, self.workdir)
29        self.vm.set_console()
30        self.vm.add_args('-kernel', self.workdir + '/day17/ballerina.bin')
31        self.vm.launch()
32        wait_for_console_pattern(self, 'This architecture does not have '
33                                       'kernel memory protection')
34        # Note:
35        # The kernel sometimes gets stuck after the "This architecture ..."
36        # message, that's why we don't test for a later string here. This
37        # needs some investigation by a microblaze wizard one day...
38
39    def test_microblazeel_s3adsp1800(self):
40        """
41        :avocado: tags=arch:microblazeel
42        :avocado: tags=machine:petalogix-s3adsp1800
43        """
44
45        self.require_netdev('user')
46        tar_url = ('http://www.qemu-advent-calendar.org/2023/download/'
47                   'day13.tar.gz')
48        tar_hash = '6623d5fff5f84cfa8f34e286f32eff6a26546f44'
49        file_path = self.fetch_asset(tar_url, asset_hash=tar_hash)
50        archive.extract(file_path, self.workdir)
51        self.vm.set_console()
52        self.vm.add_args('-kernel', self.workdir + '/day13/xmaton.bin')
53        self.vm.add_args('-nic', 'user,tftp=' + self.workdir + '/day13/')
54        self.vm.launch()
55        wait_for_console_pattern(self, 'QEMU Advent Calendar 2023')
56        time.sleep(0.1)
57        exec_command(self, 'root')
58        time.sleep(0.1)
59        exec_command_and_wait_for_pattern(self,
60                'tftp -g -r xmaton.png 10.0.2.2 ; md5sum xmaton.png',
61                '821cd3cab8efd16ad6ee5acc3642a8ea')
62