1# Functional test that boots the ASPEED SoCs with firmware 2# 3# Copyright (C) 2022 ASPEED Technology 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 9import os 10 11from avocado_qemu import QemuSystemTest 12from avocado_qemu import wait_for_console_pattern 13from avocado_qemu import exec_command 14from avocado_qemu import exec_command_and_wait_for_pattern 15from avocado.utils import archive 16from avocado import skipIf 17 18 19class AST1030Machine(QemuSystemTest): 20 """Boots the zephyr os and checks that the console is operational""" 21 22 timeout = 10 23 24 def test_ast1030_zephyros(self): 25 """ 26 :avocado: tags=arch:arm 27 :avocado: tags=machine:ast1030-evb 28 """ 29 tar_url = ('https://github.com/AspeedTech-BMC' 30 '/zephyr/releases/download/v00.01.04/ast1030-evb-demo.zip') 31 tar_hash = '4c6a8ce3a8ba76ef1a65dae419ae3409343c4b20' 32 tar_path = self.fetch_asset(tar_url, asset_hash=tar_hash) 33 archive.extract(tar_path, self.workdir) 34 kernel_file = self.workdir + "/ast1030-evb-demo/zephyr.elf" 35 self.vm.set_console() 36 self.vm.add_args('-kernel', kernel_file, 37 '-nographic') 38 self.vm.launch() 39 wait_for_console_pattern(self, "Booting Zephyr OS") 40 exec_command_and_wait_for_pattern(self, "help", 41 "Available commands") 42 43class AST2x00Machine(QemuSystemTest): 44 45 timeout = 90 46 47 def wait_for_console_pattern(self, success_message, vm=None): 48 wait_for_console_pattern(self, success_message, 49 failure_message='Kernel panic - not syncing', 50 vm=vm) 51 52 def do_test_arm_aspeed(self, image): 53 self.vm.set_console() 54 self.vm.add_args('-drive', 'file=' + image + ',if=mtd,format=raw', 55 '-net', 'nic') 56 self.vm.launch() 57 58 self.wait_for_console_pattern("U-Boot 2016.07") 59 self.wait_for_console_pattern("## Loading kernel from FIT Image at 20080000") 60 self.wait_for_console_pattern("Starting kernel ...") 61 self.wait_for_console_pattern("Booting Linux on physical CPU 0x0") 62 wait_for_console_pattern(self, 63 "aspeed-smc 1e620000.spi: read control register: 203b0641") 64 self.wait_for_console_pattern("ftgmac100 1e660000.ethernet eth0: irq ") 65 self.wait_for_console_pattern("systemd[1]: Set hostname to") 66 67 def test_arm_ast2400_palmetto_openbmc_v2_9_0(self): 68 """ 69 :avocado: tags=arch:arm 70 :avocado: tags=machine:palmetto-bmc 71 """ 72 73 image_url = ('https://github.com/openbmc/openbmc/releases/download/2.9.0/' 74 'obmc-phosphor-image-palmetto.static.mtd') 75 image_hash = ('3e13bbbc28e424865dc42f35ad672b10f2e82cdb11846bb28fa625b48beafd0d') 76 image_path = self.fetch_asset(image_url, asset_hash=image_hash, 77 algorithm='sha256') 78 79 self.do_test_arm_aspeed(image_path) 80 81 def test_arm_ast2500_romulus_openbmc_v2_9_0(self): 82 """ 83 :avocado: tags=arch:arm 84 :avocado: tags=machine:romulus-bmc 85 """ 86 87 image_url = ('https://github.com/openbmc/openbmc/releases/download/2.9.0/' 88 'obmc-phosphor-image-romulus.static.mtd') 89 image_hash = ('820341076803f1955bc31e647a512c79f9add4f5233d0697678bab4604c7bb25') 90 image_path = self.fetch_asset(image_url, asset_hash=image_hash, 91 algorithm='sha256') 92 93 self.do_test_arm_aspeed(image_path) 94 95 def do_test_arm_aspeed_buidroot_start(self, image, cpu_id): 96 self.vm.set_console() 97 self.vm.add_args('-drive', 'file=' + image + ',if=mtd,format=raw', 98 '-net', 'nic', '-net', 'user') 99 self.vm.launch() 100 101 self.wait_for_console_pattern('U-Boot 2019.04') 102 self.wait_for_console_pattern('## Loading kernel from FIT Image') 103 self.wait_for_console_pattern('Starting kernel ...') 104 self.wait_for_console_pattern('Booting Linux on physical CPU ' + cpu_id) 105 self.wait_for_console_pattern('lease of 10.0.2.15') 106 # the line before login: 107 self.wait_for_console_pattern('Aspeed EVB') 108 time.sleep(0.1) 109 exec_command(self, 'root') 110 time.sleep(0.1) 111 112 def do_test_arm_aspeed_buidroot_poweroff(self): 113 exec_command_and_wait_for_pattern(self, 'poweroff', 114 'reboot: System halted'); 115 116 def test_arm_ast2500_evb_builroot(self): 117 """ 118 :avocado: tags=arch:arm 119 :avocado: tags=machine:ast2500-evb 120 """ 121 122 image_url = ('https://github.com/legoater/qemu-aspeed-boot/raw/master/' 123 'images/ast2500-evb/buildroot-2022.05/flash.img') 124 image_hash = ('549db6e9d8cdaf4367af21c36385a68bb465779c18b5e37094fc7343decccd3f') 125 image_path = self.fetch_asset(image_url, asset_hash=image_hash, 126 algorithm='sha256') 127 128 self.vm.add_args('-device', 129 'tmp105,bus=aspeed.i2c.bus.3,address=0x4d,id=tmp-test'); 130 self.do_test_arm_aspeed_buidroot_start(image_path, '0x0') 131 132 exec_command_and_wait_for_pattern(self, 133 'echo lm75 0x4d > /sys/class/i2c-dev/i2c-3/device/new_device', 134 'i2c i2c-3: new_device: Instantiated device lm75 at 0x4d'); 135 exec_command_and_wait_for_pattern(self, 136 'cat /sys/class/hwmon/hwmon1/temp1_input', '0') 137 self.vm.command('qom-set', path='/machine/peripheral/tmp-test', 138 property='temperature', value=18000); 139 exec_command_and_wait_for_pattern(self, 140 'cat /sys/class/hwmon/hwmon1/temp1_input', '18000') 141 142 self.do_test_arm_aspeed_buidroot_poweroff() 143 144 def test_arm_ast2600_evb_builroot(self): 145 """ 146 :avocado: tags=arch:arm 147 :avocado: tags=machine:ast2600-evb 148 """ 149 150 image_url = ('https://github.com/legoater/qemu-aspeed-boot/raw/master/' 151 'images/ast2600-evb/buildroot-2022.05/flash.img') 152 image_hash = ('6cc9e7d128fd4fa1fd01c883af67593cae8072c3239a0b8b6ace857f3538a92d') 153 image_path = self.fetch_asset(image_url, asset_hash=image_hash, 154 algorithm='sha256') 155 156 self.vm.add_args('-device', 157 'tmp105,bus=aspeed.i2c.bus.3,address=0x4d,id=tmp-test'); 158 self.vm.add_args('-device', 159 'ds1338,bus=aspeed.i2c.bus.3,address=0x32'); 160 self.do_test_arm_aspeed_buidroot_start(image_path, '0xf00') 161 162 exec_command_and_wait_for_pattern(self, 163 'echo lm75 0x4d > /sys/class/i2c-dev/i2c-3/device/new_device', 164 'i2c i2c-3: new_device: Instantiated device lm75 at 0x4d'); 165 exec_command_and_wait_for_pattern(self, 166 'cat /sys/class/hwmon/hwmon0/temp1_input', '0') 167 self.vm.command('qom-set', path='/machine/peripheral/tmp-test', 168 property='temperature', value=18000); 169 exec_command_and_wait_for_pattern(self, 170 'cat /sys/class/hwmon/hwmon0/temp1_input', '18000') 171 172 exec_command_and_wait_for_pattern(self, 173 'echo ds1307 0x32 > /sys/class/i2c-dev/i2c-3/device/new_device', 174 'i2c i2c-3: new_device: Instantiated device ds1307 at 0x32'); 175 year = time.strftime("%Y") 176 exec_command_and_wait_for_pattern(self, 'hwclock -f /dev/rtc1', year); 177 178 self.do_test_arm_aspeed_buidroot_poweroff() 179 180 181class AST2x00MachineSDK(QemuSystemTest): 182 183 # FIXME: Although these tests boot a whole distro they are still 184 # slower than comparable machine models. There may be some 185 # optimisations which bring down the runtime. In the meantime they 186 # have generous timeouts and are disable for CI which aims for all 187 # tests to run in less than 60 seconds. 188 timeout = 240 189 190 def wait_for_console_pattern(self, success_message, vm=None): 191 wait_for_console_pattern(self, success_message, 192 failure_message='Kernel panic - not syncing', 193 vm=vm) 194 195 def do_test_arm_aspeed_sdk_start(self, image, cpu_id): 196 self.vm.set_console() 197 self.vm.add_args('-drive', 'file=' + image + ',if=mtd,format=raw', 198 '-net', 'nic', '-net', 'user') 199 self.vm.launch() 200 201 self.wait_for_console_pattern('U-Boot 2019.04') 202 self.wait_for_console_pattern('## Loading kernel from FIT Image') 203 self.wait_for_console_pattern('Starting kernel ...') 204 self.wait_for_console_pattern('Booting Linux on physical CPU ' + cpu_id) 205 206 @skipIf(os.getenv('GITLAB_CI'), 'Running on GitLab') 207 def test_arm_ast2500_evb_sdk(self): 208 """ 209 :avocado: tags=arch:arm 210 :avocado: tags=machine:ast2500-evb 211 """ 212 213 image_url = ('https://github.com/AspeedTech-BMC/openbmc/releases/' 214 'download/v08.01/ast2500-default-obmc.tar.gz') 215 image_hash = ('5375f82b4c43a79427909342a1e18b4e48bd663e38466862145d27bb358796fd') 216 image_path = self.fetch_asset(image_url, asset_hash=image_hash, 217 algorithm='sha256') 218 archive.extract(image_path, self.workdir) 219 220 self.do_test_arm_aspeed_sdk_start( 221 self.workdir + '/ast2500-default/image-bmc', '0x0') 222 self.wait_for_console_pattern('ast2500-default login:') 223 224 @skipIf(os.getenv('GITLAB_CI'), 'Running on GitLab') 225 def test_arm_ast2600_evb_sdk(self): 226 """ 227 :avocado: tags=arch:arm 228 :avocado: tags=machine:ast2600-evb 229 """ 230 231 image_url = ('https://github.com/AspeedTech-BMC/openbmc/releases/' 232 'download/v08.01/ast2600-default-obmc.tar.gz') 233 image_hash = ('f12ef15e8c1f03a214df3b91c814515c5e2b2f56119021398c1dbdd626817d15') 234 image_path = self.fetch_asset(image_url, asset_hash=image_hash, 235 algorithm='sha256') 236 archive.extract(image_path, self.workdir) 237 238 self.vm.add_args('-device', 239 'tmp105,bus=aspeed.i2c.bus.5,address=0x4d,id=tmp-test'); 240 self.vm.add_args('-device', 241 'ds1338,bus=aspeed.i2c.bus.5,address=0x32'); 242 self.do_test_arm_aspeed_sdk_start( 243 self.workdir + '/ast2600-default/image-bmc', '0xf00') 244 self.wait_for_console_pattern('ast2600-default login:') 245 exec_command_and_wait_for_pattern(self, 'root', 'Password:') 246 exec_command_and_wait_for_pattern(self, '0penBmc', 'root@ast2600-default:~#') 247 248 exec_command_and_wait_for_pattern(self, 249 'echo lm75 0x4d > /sys/class/i2c-dev/i2c-5/device/new_device', 250 'i2c i2c-5: new_device: Instantiated device lm75 at 0x4d'); 251 exec_command_and_wait_for_pattern(self, 252 'cat /sys/class/hwmon/hwmon19/temp1_input', '0') 253 self.vm.command('qom-set', path='/machine/peripheral/tmp-test', 254 property='temperature', value=18000); 255 exec_command_and_wait_for_pattern(self, 256 'cat /sys/class/hwmon/hwmon19/temp1_input', '18000') 257 258 exec_command_and_wait_for_pattern(self, 259 'echo ds1307 0x32 > /sys/class/i2c-dev/i2c-5/device/new_device', 260 'i2c i2c-5: new_device: Instantiated device ds1307 at 0x32'); 261 year = time.strftime("%Y") 262 exec_command_and_wait_for_pattern(self, 'hwclock -f /dev/rtc1', year); 263