1438eff63SJamin Lin# Functional test that boots the ASPEED SoCs with firmware
2438eff63SJamin Lin#
3438eff63SJamin Lin# Copyright (C) 2022 ASPEED Technology Inc
4438eff63SJamin Lin#
5438eff63SJamin Lin# This work is licensed under the terms of the GNU GPL, version 2 or
6438eff63SJamin Lin# later.  See the COPYING file in the top-level directory.
7438eff63SJamin Lin
8f7bc7da0SCédric Le Goaterimport time
992f8e8e2SAlex Bennéeimport os
10f7bc7da0SCédric Le Goater
11438eff63SJamin Linfrom avocado_qemu import QemuSystemTest
12438eff63SJamin Linfrom avocado_qemu import wait_for_console_pattern
13f7bc7da0SCédric Le Goaterfrom avocado_qemu import exec_command
14438eff63SJamin Linfrom avocado_qemu import exec_command_and_wait_for_pattern
15a4b14b46SCédric Le Goaterfrom avocado_qemu import interrupt_interactive_console_until_pattern
16438eff63SJamin Linfrom avocado.utils import archive
1792f8e8e2SAlex Bennéefrom avocado import skipIf
18438eff63SJamin Lin
19438eff63SJamin Lin
20438eff63SJamin Linclass AST1030Machine(QemuSystemTest):
21438eff63SJamin Lin    """Boots the zephyr os and checks that the console is operational"""
22438eff63SJamin Lin
23438eff63SJamin Lin    timeout = 10
24438eff63SJamin Lin
25438eff63SJamin Lin    def test_ast1030_zephyros(self):
26438eff63SJamin Lin        """
27438eff63SJamin Lin        :avocado: tags=arch:arm
28438eff63SJamin Lin        :avocado: tags=machine:ast1030-evb
29438eff63SJamin Lin        """
30438eff63SJamin Lin        tar_url = ('https://github.com/AspeedTech-BMC'
31438eff63SJamin Lin                   '/zephyr/releases/download/v00.01.04/ast1030-evb-demo.zip')
32438eff63SJamin Lin        tar_hash = '4c6a8ce3a8ba76ef1a65dae419ae3409343c4b20'
33438eff63SJamin Lin        tar_path = self.fetch_asset(tar_url, asset_hash=tar_hash)
34438eff63SJamin Lin        archive.extract(tar_path, self.workdir)
35438eff63SJamin Lin        kernel_file = self.workdir + "/ast1030-evb-demo/zephyr.elf"
36438eff63SJamin Lin        self.vm.set_console()
37438eff63SJamin Lin        self.vm.add_args('-kernel', kernel_file,
38438eff63SJamin Lin                         '-nographic')
39438eff63SJamin Lin        self.vm.launch()
40438eff63SJamin Lin        wait_for_console_pattern(self, "Booting Zephyr OS")
41438eff63SJamin Lin        exec_command_and_wait_for_pattern(self, "help",
42438eff63SJamin Lin                                          "Available commands")
43341e21faSCédric Le Goater
44341e21faSCédric Le Goaterclass AST2x00Machine(QemuSystemTest):
45341e21faSCédric Le Goater
46b1ceae2fSAlex Bennée    timeout = 90
47b1ceae2fSAlex Bennée
48341e21faSCédric Le Goater    def wait_for_console_pattern(self, success_message, vm=None):
49341e21faSCédric Le Goater        wait_for_console_pattern(self, success_message,
50341e21faSCédric Le Goater                                 failure_message='Kernel panic - not syncing',
51341e21faSCédric Le Goater                                 vm=vm)
52341e21faSCédric Le Goater
53341e21faSCédric Le Goater    def do_test_arm_aspeed(self, image):
54341e21faSCédric Le Goater        self.vm.set_console()
55341e21faSCédric Le Goater        self.vm.add_args('-drive', 'file=' + image + ',if=mtd,format=raw',
56341e21faSCédric Le Goater                         '-net', 'nic')
57341e21faSCédric Le Goater        self.vm.launch()
58341e21faSCédric Le Goater
59341e21faSCédric Le Goater        self.wait_for_console_pattern("U-Boot 2016.07")
60341e21faSCédric Le Goater        self.wait_for_console_pattern("## Loading kernel from FIT Image at 20080000")
61341e21faSCédric Le Goater        self.wait_for_console_pattern("Starting kernel ...")
62341e21faSCédric Le Goater        self.wait_for_console_pattern("Booting Linux on physical CPU 0x0")
63341e21faSCédric Le Goater        wait_for_console_pattern(self,
64341e21faSCédric Le Goater                "aspeed-smc 1e620000.spi: read control register: 203b0641")
65341e21faSCédric Le Goater        self.wait_for_console_pattern("ftgmac100 1e660000.ethernet eth0: irq ")
66341e21faSCédric Le Goater        self.wait_for_console_pattern("systemd[1]: Set hostname to")
67341e21faSCédric Le Goater
68341e21faSCédric Le Goater    def test_arm_ast2400_palmetto_openbmc_v2_9_0(self):
69341e21faSCédric Le Goater        """
70341e21faSCédric Le Goater        :avocado: tags=arch:arm
71341e21faSCédric Le Goater        :avocado: tags=machine:palmetto-bmc
72341e21faSCédric Le Goater        """
73341e21faSCédric Le Goater
74341e21faSCédric Le Goater        image_url = ('https://github.com/openbmc/openbmc/releases/download/2.9.0/'
75341e21faSCédric Le Goater                     'obmc-phosphor-image-palmetto.static.mtd')
76341e21faSCédric Le Goater        image_hash = ('3e13bbbc28e424865dc42f35ad672b10f2e82cdb11846bb28fa625b48beafd0d')
77341e21faSCédric Le Goater        image_path = self.fetch_asset(image_url, asset_hash=image_hash,
78341e21faSCédric Le Goater                                      algorithm='sha256')
79341e21faSCédric Le Goater
80341e21faSCédric Le Goater        self.do_test_arm_aspeed(image_path)
81341e21faSCédric Le Goater
82341e21faSCédric Le Goater    def test_arm_ast2500_romulus_openbmc_v2_9_0(self):
83341e21faSCédric Le Goater        """
84341e21faSCédric Le Goater        :avocado: tags=arch:arm
85341e21faSCédric Le Goater        :avocado: tags=machine:romulus-bmc
86341e21faSCédric Le Goater        """
87341e21faSCédric Le Goater
88341e21faSCédric Le Goater        image_url = ('https://github.com/openbmc/openbmc/releases/download/2.9.0/'
89341e21faSCédric Le Goater                     'obmc-phosphor-image-romulus.static.mtd')
90341e21faSCédric Le Goater        image_hash = ('820341076803f1955bc31e647a512c79f9add4f5233d0697678bab4604c7bb25')
91341e21faSCédric Le Goater        image_path = self.fetch_asset(image_url, asset_hash=image_hash,
92341e21faSCédric Le Goater                                      algorithm='sha256')
93341e21faSCédric Le Goater
94341e21faSCédric Le Goater        self.do_test_arm_aspeed(image_path)
95f7bc7da0SCédric Le Goater
967b5093b8SCédric Le Goater    def do_test_arm_aspeed_buildroot_start(self, image, cpu_id):
970793fe01SPeter Maydell        self.require_netdev('user')
980793fe01SPeter Maydell
99f7bc7da0SCédric Le Goater        self.vm.set_console()
100f7bc7da0SCédric Le Goater        self.vm.add_args('-drive', 'file=' + image + ',if=mtd,format=raw',
101f7bc7da0SCédric Le Goater                         '-net', 'nic', '-net', 'user')
102f7bc7da0SCédric Le Goater        self.vm.launch()
103f7bc7da0SCédric Le Goater
104f7bc7da0SCédric Le Goater        self.wait_for_console_pattern('U-Boot 2019.04')
105f7bc7da0SCédric Le Goater        self.wait_for_console_pattern('## Loading kernel from FIT Image')
106f7bc7da0SCédric Le Goater        self.wait_for_console_pattern('Starting kernel ...')
107f7bc7da0SCédric Le Goater        self.wait_for_console_pattern('Booting Linux on physical CPU ' + cpu_id)
108f7bc7da0SCédric Le Goater        self.wait_for_console_pattern('lease of 10.0.2.15')
10965711f9aSAlex Bennée        # the line before login:
110f7bc7da0SCédric Le Goater        self.wait_for_console_pattern('Aspeed EVB')
11165711f9aSAlex Bennée        time.sleep(0.1)
112f7bc7da0SCédric Le Goater        exec_command(self, 'root')
113f7bc7da0SCédric Le Goater        time.sleep(0.1)
114f7bc7da0SCédric Le Goater
1157b5093b8SCédric Le Goater    def do_test_arm_aspeed_buildroot_poweroff(self):
116f7bc7da0SCédric Le Goater        exec_command_and_wait_for_pattern(self, 'poweroff',
117f7bc7da0SCédric Le Goater                                          'reboot: System halted');
118f7bc7da0SCédric Le Goater
1197b5093b8SCédric Le Goater    def test_arm_ast2500_evb_buildroot(self):
120f7bc7da0SCédric Le Goater        """
121f7bc7da0SCédric Le Goater        :avocado: tags=arch:arm
122f7bc7da0SCédric Le Goater        :avocado: tags=machine:ast2500-evb
123f7bc7da0SCédric Le Goater        """
124f7bc7da0SCédric Le Goater
125f7bc7da0SCédric Le Goater        image_url = ('https://github.com/legoater/qemu-aspeed-boot/raw/master/'
126ed1f5ff8SCédric Le Goater                     'images/ast2500-evb/buildroot-2022.11-2-g15d3648df9/flash.img')
127ed1f5ff8SCédric Le Goater        image_hash = ('f96d11db521fe7a2787745e9e391225deeeec3318ee0fc07c8b799b8833dd474')
128f7bc7da0SCédric Le Goater        image_path = self.fetch_asset(image_url, asset_hash=image_hash,
129f7bc7da0SCédric Le Goater                                      algorithm='sha256')
130f7bc7da0SCédric Le Goater
1317a7308eaSCédric Le Goater        self.vm.add_args('-device',
1327a7308eaSCédric Le Goater                         'tmp105,bus=aspeed.i2c.bus.3,address=0x4d,id=tmp-test');
1337b5093b8SCédric Le Goater        self.do_test_arm_aspeed_buildroot_start(image_path, '0x0')
1347a7308eaSCédric Le Goater
1357a7308eaSCédric Le Goater        exec_command_and_wait_for_pattern(self,
1367a7308eaSCédric Le Goater             'echo lm75 0x4d > /sys/class/i2c-dev/i2c-3/device/new_device',
1377a7308eaSCédric Le Goater             'i2c i2c-3: new_device: Instantiated device lm75 at 0x4d');
1387a7308eaSCédric Le Goater        exec_command_and_wait_for_pattern(self,
1397a7308eaSCédric Le Goater                             'cat /sys/class/hwmon/hwmon1/temp1_input', '0')
1407a7308eaSCédric Le Goater        self.vm.command('qom-set', path='/machine/peripheral/tmp-test',
1417a7308eaSCédric Le Goater                        property='temperature', value=18000);
1427a7308eaSCédric Le Goater        exec_command_and_wait_for_pattern(self,
1437a7308eaSCédric Le Goater                             'cat /sys/class/hwmon/hwmon1/temp1_input', '18000')
1447a7308eaSCédric Le Goater
1457b5093b8SCédric Le Goater        self.do_test_arm_aspeed_buildroot_poweroff()
146f7bc7da0SCédric Le Goater
1477b5093b8SCédric Le Goater    def test_arm_ast2600_evb_buildroot(self):
148f7bc7da0SCédric Le Goater        """
149f7bc7da0SCédric Le Goater        :avocado: tags=arch:arm
150f7bc7da0SCédric Le Goater        :avocado: tags=machine:ast2600-evb
151f7bc7da0SCédric Le Goater        """
152f7bc7da0SCédric Le Goater
153f7bc7da0SCédric Le Goater        image_url = ('https://github.com/legoater/qemu-aspeed-boot/raw/master/'
154ed1f5ff8SCédric Le Goater                     'images/ast2600-evb/buildroot-2022.11-2-g15d3648df9/flash.img')
155ed1f5ff8SCédric Le Goater        image_hash = ('e598d86e5ea79671ca8b59212a326c911bc8bea728dec1a1f5390d717a28bb8b')
156f7bc7da0SCédric Le Goater        image_path = self.fetch_asset(image_url, asset_hash=image_hash,
157f7bc7da0SCédric Le Goater                                      algorithm='sha256')
158f7bc7da0SCédric Le Goater
15961cf757dSCédric Le Goater        self.vm.add_args('-device',
16061cf757dSCédric Le Goater                         'tmp105,bus=aspeed.i2c.bus.3,address=0x4d,id=tmp-test');
1613302184fSCédric Le Goater        self.vm.add_args('-device',
1623302184fSCédric Le Goater                         'ds1338,bus=aspeed.i2c.bus.3,address=0x32');
1637b5093b8SCédric Le Goater        self.do_test_arm_aspeed_buildroot_start(image_path, '0xf00')
16461cf757dSCédric Le Goater
16561cf757dSCédric Le Goater        exec_command_and_wait_for_pattern(self,
16661cf757dSCédric Le Goater             'echo lm75 0x4d > /sys/class/i2c-dev/i2c-3/device/new_device',
16761cf757dSCédric Le Goater             'i2c i2c-3: new_device: Instantiated device lm75 at 0x4d');
16861cf757dSCédric Le Goater        exec_command_and_wait_for_pattern(self,
16961cf757dSCédric Le Goater                             'cat /sys/class/hwmon/hwmon0/temp1_input', '0')
17061cf757dSCédric Le Goater        self.vm.command('qom-set', path='/machine/peripheral/tmp-test',
17161cf757dSCédric Le Goater                        property='temperature', value=18000);
17261cf757dSCédric Le Goater        exec_command_and_wait_for_pattern(self,
17361cf757dSCédric Le Goater                             'cat /sys/class/hwmon/hwmon0/temp1_input', '18000')
17461cf757dSCédric Le Goater
1753302184fSCédric Le Goater        exec_command_and_wait_for_pattern(self,
1763302184fSCédric Le Goater             'echo ds1307 0x32 > /sys/class/i2c-dev/i2c-3/device/new_device',
1773302184fSCédric Le Goater             'i2c i2c-3: new_device: Instantiated device ds1307 at 0x32');
1783302184fSCédric Le Goater        year = time.strftime("%Y")
1793302184fSCédric Le Goater        exec_command_and_wait_for_pattern(self, 'hwclock -f /dev/rtc1', year);
1803302184fSCédric Le Goater
1817b5093b8SCédric Le Goater        self.do_test_arm_aspeed_buildroot_poweroff()
182bceb4d99SCédric Le Goater
183bceb4d99SCédric Le Goater
18492f8e8e2SAlex Bennéeclass AST2x00MachineSDK(QemuSystemTest):
18592f8e8e2SAlex Bennée
186*30d7aac4SCédric Le Goater    EXTRA_BOOTARGS = (
187*30d7aac4SCédric Le Goater        'quiet '
188*30d7aac4SCédric Le Goater        'systemd.mask=org.openbmc.HostIpmi.service '
189*30d7aac4SCédric Le Goater        'systemd.mask=xyz.openbmc_project.Chassis.Control.Power@0.service '
190*30d7aac4SCédric Le Goater        'systemd.mask=modprobe@fuse.service '
191*30d7aac4SCédric Le Goater        'systemd.mask=rngd.service '
192*30d7aac4SCédric Le Goater        'systemd.mask=obmc-console@ttyS2.service '
193*30d7aac4SCédric Le Goater    )
194a4b14b46SCédric Le Goater
19592f8e8e2SAlex Bennée    # FIXME: Although these tests boot a whole distro they are still
19692f8e8e2SAlex Bennée    # slower than comparable machine models. There may be some
19792f8e8e2SAlex Bennée    # optimisations which bring down the runtime. In the meantime they
19892f8e8e2SAlex Bennée    # have generous timeouts and are disable for CI which aims for all
19992f8e8e2SAlex Bennée    # tests to run in less than 60 seconds.
20092f8e8e2SAlex Bennée    timeout = 240
20192f8e8e2SAlex Bennée
20292f8e8e2SAlex Bennée    def wait_for_console_pattern(self, success_message, vm=None):
20392f8e8e2SAlex Bennée        wait_for_console_pattern(self, success_message,
20492f8e8e2SAlex Bennée                                 failure_message='Kernel panic - not syncing',
20592f8e8e2SAlex Bennée                                 vm=vm)
20692f8e8e2SAlex Bennée
207a4b14b46SCédric Le Goater    def do_test_arm_aspeed_sdk_start(self, image):
2080793fe01SPeter Maydell        self.require_netdev('user')
209bceb4d99SCédric Le Goater        self.vm.set_console()
210bceb4d99SCédric Le Goater        self.vm.add_args('-drive', 'file=' + image + ',if=mtd,format=raw',
211bceb4d99SCédric Le Goater                         '-net', 'nic', '-net', 'user')
212bceb4d99SCédric Le Goater        self.vm.launch()
213bceb4d99SCédric Le Goater
214bceb4d99SCédric Le Goater        self.wait_for_console_pattern('U-Boot 2019.04')
215a4b14b46SCédric Le Goater        interrupt_interactive_console_until_pattern(
216a4b14b46SCédric Le Goater            self, 'Hit any key to stop autoboot:', 'ast#')
217a4b14b46SCédric Le Goater        exec_command_and_wait_for_pattern(
218a4b14b46SCédric Le Goater            self, 'setenv bootargs ${bootargs} ' + self.EXTRA_BOOTARGS, 'ast#')
219a4b14b46SCédric Le Goater        exec_command_and_wait_for_pattern(
220a4b14b46SCédric Le Goater            self, 'boot', '## Loading kernel from FIT Image')
221bceb4d99SCédric Le Goater        self.wait_for_console_pattern('Starting kernel ...')
222bceb4d99SCédric Le Goater
22392f8e8e2SAlex Bennée    @skipIf(os.getenv('GITLAB_CI'), 'Running on GitLab')
224bceb4d99SCédric Le Goater    def test_arm_ast2500_evb_sdk(self):
225bceb4d99SCédric Le Goater        """
226bceb4d99SCédric Le Goater        :avocado: tags=arch:arm
227bceb4d99SCédric Le Goater        :avocado: tags=machine:ast2500-evb
228bceb4d99SCédric Le Goater        """
229bceb4d99SCédric Le Goater
230bceb4d99SCédric Le Goater        image_url = ('https://github.com/AspeedTech-BMC/openbmc/releases/'
231bceb4d99SCédric Le Goater                     'download/v08.01/ast2500-default-obmc.tar.gz')
232bceb4d99SCédric Le Goater        image_hash = ('5375f82b4c43a79427909342a1e18b4e48bd663e38466862145d27bb358796fd')
233bceb4d99SCédric Le Goater        image_path = self.fetch_asset(image_url, asset_hash=image_hash,
234bceb4d99SCédric Le Goater                                      algorithm='sha256')
235bceb4d99SCédric Le Goater        archive.extract(image_path, self.workdir)
236bceb4d99SCédric Le Goater
237bceb4d99SCédric Le Goater        self.do_test_arm_aspeed_sdk_start(
238a4b14b46SCédric Le Goater            self.workdir + '/ast2500-default/image-bmc')
239bceb4d99SCédric Le Goater        self.wait_for_console_pattern('ast2500-default login:')
240bceb4d99SCédric Le Goater
24192f8e8e2SAlex Bennée    @skipIf(os.getenv('GITLAB_CI'), 'Running on GitLab')
242bceb4d99SCédric Le Goater    def test_arm_ast2600_evb_sdk(self):
243bceb4d99SCédric Le Goater        """
244bceb4d99SCédric Le Goater        :avocado: tags=arch:arm
245bceb4d99SCédric Le Goater        :avocado: tags=machine:ast2600-evb
246bceb4d99SCédric Le Goater        """
247bceb4d99SCédric Le Goater
248bceb4d99SCédric Le Goater        image_url = ('https://github.com/AspeedTech-BMC/openbmc/releases/'
249bceb4d99SCédric Le Goater                     'download/v08.01/ast2600-default-obmc.tar.gz')
250bceb4d99SCédric Le Goater        image_hash = ('f12ef15e8c1f03a214df3b91c814515c5e2b2f56119021398c1dbdd626817d15')
251bceb4d99SCédric Le Goater        image_path = self.fetch_asset(image_url, asset_hash=image_hash,
252bceb4d99SCédric Le Goater                                      algorithm='sha256')
253bceb4d99SCédric Le Goater        archive.extract(image_path, self.workdir)
254bceb4d99SCédric Le Goater
255bceb4d99SCédric Le Goater        self.vm.add_args('-device',
256bceb4d99SCédric Le Goater                         'tmp105,bus=aspeed.i2c.bus.5,address=0x4d,id=tmp-test');
257bceb4d99SCédric Le Goater        self.vm.add_args('-device',
258bceb4d99SCédric Le Goater                         'ds1338,bus=aspeed.i2c.bus.5,address=0x32');
259bceb4d99SCédric Le Goater        self.do_test_arm_aspeed_sdk_start(
260a4b14b46SCédric Le Goater            self.workdir + '/ast2600-default/image-bmc')
261bceb4d99SCédric Le Goater        self.wait_for_console_pattern('ast2600-default login:')
262bceb4d99SCédric Le Goater        exec_command_and_wait_for_pattern(self, 'root', 'Password:')
263bceb4d99SCédric Le Goater        exec_command_and_wait_for_pattern(self, '0penBmc', 'root@ast2600-default:~#')
264bceb4d99SCédric Le Goater
265bceb4d99SCédric Le Goater        exec_command_and_wait_for_pattern(self,
266bceb4d99SCédric Le Goater             'echo lm75 0x4d > /sys/class/i2c-dev/i2c-5/device/new_device',
267bceb4d99SCédric Le Goater             'i2c i2c-5: new_device: Instantiated device lm75 at 0x4d');
268bceb4d99SCédric Le Goater        exec_command_and_wait_for_pattern(self,
269bceb4d99SCédric Le Goater                             'cat /sys/class/hwmon/hwmon19/temp1_input', '0')
270bceb4d99SCédric Le Goater        self.vm.command('qom-set', path='/machine/peripheral/tmp-test',
271bceb4d99SCédric Le Goater                        property='temperature', value=18000);
272bceb4d99SCédric Le Goater        exec_command_and_wait_for_pattern(self,
273bceb4d99SCédric Le Goater                             'cat /sys/class/hwmon/hwmon19/temp1_input', '18000')
274bceb4d99SCédric Le Goater
275bceb4d99SCédric Le Goater        exec_command_and_wait_for_pattern(self,
276bceb4d99SCédric Le Goater             'echo ds1307 0x32 > /sys/class/i2c-dev/i2c-5/device/new_device',
277bceb4d99SCédric Le Goater             'i2c i2c-5: new_device: Instantiated device ds1307 at 0x32');
278bceb4d99SCédric Le Goater        year = time.strftime("%Y")
279bceb4d99SCédric Le Goater        exec_command_and_wait_for_pattern(self, 'hwclock -f /dev/rtc1', year);
280