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 9*92f8e8e2SAlex 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 15438eff63SJamin Linfrom avocado.utils import archive 16*92f8e8e2SAlex Bennéefrom avocado import skipIf 17438eff63SJamin Lin 18438eff63SJamin Lin 19438eff63SJamin Linclass AST1030Machine(QemuSystemTest): 20438eff63SJamin Lin """Boots the zephyr os and checks that the console is operational""" 21438eff63SJamin Lin 22438eff63SJamin Lin timeout = 10 23438eff63SJamin Lin 24438eff63SJamin Lin def test_ast1030_zephyros(self): 25438eff63SJamin Lin """ 26438eff63SJamin Lin :avocado: tags=arch:arm 27438eff63SJamin Lin :avocado: tags=machine:ast1030-evb 28438eff63SJamin Lin """ 29438eff63SJamin Lin tar_url = ('https://github.com/AspeedTech-BMC' 30438eff63SJamin Lin '/zephyr/releases/download/v00.01.04/ast1030-evb-demo.zip') 31438eff63SJamin Lin tar_hash = '4c6a8ce3a8ba76ef1a65dae419ae3409343c4b20' 32438eff63SJamin Lin tar_path = self.fetch_asset(tar_url, asset_hash=tar_hash) 33438eff63SJamin Lin archive.extract(tar_path, self.workdir) 34438eff63SJamin Lin kernel_file = self.workdir + "/ast1030-evb-demo/zephyr.elf" 35438eff63SJamin Lin self.vm.set_console() 36438eff63SJamin Lin self.vm.add_args('-kernel', kernel_file, 37438eff63SJamin Lin '-nographic') 38438eff63SJamin Lin self.vm.launch() 39438eff63SJamin Lin wait_for_console_pattern(self, "Booting Zephyr OS") 40438eff63SJamin Lin exec_command_and_wait_for_pattern(self, "help", 41438eff63SJamin Lin "Available commands") 42341e21faSCédric Le Goater 43341e21faSCédric Le Goaterclass AST2x00Machine(QemuSystemTest): 44341e21faSCédric Le Goater 45b1ceae2fSAlex Bennée timeout = 90 46b1ceae2fSAlex Bennée 47341e21faSCédric Le Goater def wait_for_console_pattern(self, success_message, vm=None): 48341e21faSCédric Le Goater wait_for_console_pattern(self, success_message, 49341e21faSCédric Le Goater failure_message='Kernel panic - not syncing', 50341e21faSCédric Le Goater vm=vm) 51341e21faSCédric Le Goater 52341e21faSCédric Le Goater def do_test_arm_aspeed(self, image): 53341e21faSCédric Le Goater self.vm.set_console() 54341e21faSCédric Le Goater self.vm.add_args('-drive', 'file=' + image + ',if=mtd,format=raw', 55341e21faSCédric Le Goater '-net', 'nic') 56341e21faSCédric Le Goater self.vm.launch() 57341e21faSCédric Le Goater 58341e21faSCédric Le Goater self.wait_for_console_pattern("U-Boot 2016.07") 59341e21faSCédric Le Goater self.wait_for_console_pattern("## Loading kernel from FIT Image at 20080000") 60341e21faSCédric Le Goater self.wait_for_console_pattern("Starting kernel ...") 61341e21faSCédric Le Goater self.wait_for_console_pattern("Booting Linux on physical CPU 0x0") 62341e21faSCédric Le Goater wait_for_console_pattern(self, 63341e21faSCédric Le Goater "aspeed-smc 1e620000.spi: read control register: 203b0641") 64341e21faSCédric Le Goater self.wait_for_console_pattern("ftgmac100 1e660000.ethernet eth0: irq ") 65341e21faSCédric Le Goater self.wait_for_console_pattern("systemd[1]: Set hostname to") 66341e21faSCédric Le Goater 67341e21faSCédric Le Goater def test_arm_ast2400_palmetto_openbmc_v2_9_0(self): 68341e21faSCédric Le Goater """ 69341e21faSCédric Le Goater :avocado: tags=arch:arm 70341e21faSCédric Le Goater :avocado: tags=machine:palmetto-bmc 71341e21faSCédric Le Goater """ 72341e21faSCédric Le Goater 73341e21faSCédric Le Goater image_url = ('https://github.com/openbmc/openbmc/releases/download/2.9.0/' 74341e21faSCédric Le Goater 'obmc-phosphor-image-palmetto.static.mtd') 75341e21faSCédric Le Goater image_hash = ('3e13bbbc28e424865dc42f35ad672b10f2e82cdb11846bb28fa625b48beafd0d') 76341e21faSCédric Le Goater image_path = self.fetch_asset(image_url, asset_hash=image_hash, 77341e21faSCédric Le Goater algorithm='sha256') 78341e21faSCédric Le Goater 79341e21faSCédric Le Goater self.do_test_arm_aspeed(image_path) 80341e21faSCédric Le Goater 81341e21faSCédric Le Goater def test_arm_ast2500_romulus_openbmc_v2_9_0(self): 82341e21faSCédric Le Goater """ 83341e21faSCédric Le Goater :avocado: tags=arch:arm 84341e21faSCédric Le Goater :avocado: tags=machine:romulus-bmc 85341e21faSCédric Le Goater """ 86341e21faSCédric Le Goater 87341e21faSCédric Le Goater image_url = ('https://github.com/openbmc/openbmc/releases/download/2.9.0/' 88341e21faSCédric Le Goater 'obmc-phosphor-image-romulus.static.mtd') 89341e21faSCédric Le Goater image_hash = ('820341076803f1955bc31e647a512c79f9add4f5233d0697678bab4604c7bb25') 90341e21faSCédric Le Goater image_path = self.fetch_asset(image_url, asset_hash=image_hash, 91341e21faSCédric Le Goater algorithm='sha256') 92341e21faSCédric Le Goater 93341e21faSCédric Le Goater self.do_test_arm_aspeed(image_path) 94f7bc7da0SCédric Le Goater 95f7bc7da0SCédric Le Goater def do_test_arm_aspeed_buidroot_start(self, image, cpu_id): 96f7bc7da0SCédric Le Goater self.vm.set_console() 97f7bc7da0SCédric Le Goater self.vm.add_args('-drive', 'file=' + image + ',if=mtd,format=raw', 98f7bc7da0SCédric Le Goater '-net', 'nic', '-net', 'user') 99f7bc7da0SCédric Le Goater self.vm.launch() 100f7bc7da0SCédric Le Goater 101f7bc7da0SCédric Le Goater self.wait_for_console_pattern('U-Boot 2019.04') 102f7bc7da0SCédric Le Goater self.wait_for_console_pattern('## Loading kernel from FIT Image') 103f7bc7da0SCédric Le Goater self.wait_for_console_pattern('Starting kernel ...') 104f7bc7da0SCédric Le Goater self.wait_for_console_pattern('Booting Linux on physical CPU ' + cpu_id) 105f7bc7da0SCédric Le Goater self.wait_for_console_pattern('lease of 10.0.2.15') 10665711f9aSAlex Bennée # the line before login: 107f7bc7da0SCédric Le Goater self.wait_for_console_pattern('Aspeed EVB') 10865711f9aSAlex Bennée time.sleep(0.1) 109f7bc7da0SCédric Le Goater exec_command(self, 'root') 110f7bc7da0SCédric Le Goater time.sleep(0.1) 111f7bc7da0SCédric Le Goater 112f7bc7da0SCédric Le Goater def do_test_arm_aspeed_buidroot_poweroff(self): 113f7bc7da0SCédric Le Goater exec_command_and_wait_for_pattern(self, 'poweroff', 114f7bc7da0SCédric Le Goater 'reboot: System halted'); 115f7bc7da0SCédric Le Goater 116f7bc7da0SCédric Le Goater def test_arm_ast2500_evb_builroot(self): 117f7bc7da0SCédric Le Goater """ 118f7bc7da0SCédric Le Goater :avocado: tags=arch:arm 119f7bc7da0SCédric Le Goater :avocado: tags=machine:ast2500-evb 120f7bc7da0SCédric Le Goater """ 121f7bc7da0SCédric Le Goater 122f7bc7da0SCédric Le Goater image_url = ('https://github.com/legoater/qemu-aspeed-boot/raw/master/' 123f7bc7da0SCédric Le Goater 'images/ast2500-evb/buildroot-2022.05/flash.img') 124f7bc7da0SCédric Le Goater image_hash = ('549db6e9d8cdaf4367af21c36385a68bb465779c18b5e37094fc7343decccd3f') 125f7bc7da0SCédric Le Goater image_path = self.fetch_asset(image_url, asset_hash=image_hash, 126f7bc7da0SCédric Le Goater algorithm='sha256') 127f7bc7da0SCédric Le Goater 1287a7308eaSCédric Le Goater self.vm.add_args('-device', 1297a7308eaSCédric Le Goater 'tmp105,bus=aspeed.i2c.bus.3,address=0x4d,id=tmp-test'); 130f7bc7da0SCédric Le Goater self.do_test_arm_aspeed_buidroot_start(image_path, '0x0') 1317a7308eaSCédric Le Goater 1327a7308eaSCédric Le Goater exec_command_and_wait_for_pattern(self, 1337a7308eaSCédric Le Goater 'echo lm75 0x4d > /sys/class/i2c-dev/i2c-3/device/new_device', 1347a7308eaSCédric Le Goater 'i2c i2c-3: new_device: Instantiated device lm75 at 0x4d'); 1357a7308eaSCédric Le Goater exec_command_and_wait_for_pattern(self, 1367a7308eaSCédric Le Goater 'cat /sys/class/hwmon/hwmon1/temp1_input', '0') 1377a7308eaSCédric Le Goater self.vm.command('qom-set', path='/machine/peripheral/tmp-test', 1387a7308eaSCédric Le Goater property='temperature', value=18000); 1397a7308eaSCédric Le Goater exec_command_and_wait_for_pattern(self, 1407a7308eaSCédric Le Goater 'cat /sys/class/hwmon/hwmon1/temp1_input', '18000') 1417a7308eaSCédric Le Goater 142f7bc7da0SCédric Le Goater self.do_test_arm_aspeed_buidroot_poweroff() 143f7bc7da0SCédric Le Goater 144f7bc7da0SCédric Le Goater def test_arm_ast2600_evb_builroot(self): 145f7bc7da0SCédric Le Goater """ 146f7bc7da0SCédric Le Goater :avocado: tags=arch:arm 147f7bc7da0SCédric Le Goater :avocado: tags=machine:ast2600-evb 148f7bc7da0SCédric Le Goater """ 149f7bc7da0SCédric Le Goater 150f7bc7da0SCédric Le Goater image_url = ('https://github.com/legoater/qemu-aspeed-boot/raw/master/' 151f7bc7da0SCédric Le Goater 'images/ast2600-evb/buildroot-2022.05/flash.img') 152f7bc7da0SCédric Le Goater image_hash = ('6cc9e7d128fd4fa1fd01c883af67593cae8072c3239a0b8b6ace857f3538a92d') 153f7bc7da0SCédric Le Goater image_path = self.fetch_asset(image_url, asset_hash=image_hash, 154f7bc7da0SCédric Le Goater algorithm='sha256') 155f7bc7da0SCédric Le Goater 15661cf757dSCédric Le Goater self.vm.add_args('-device', 15761cf757dSCédric Le Goater 'tmp105,bus=aspeed.i2c.bus.3,address=0x4d,id=tmp-test'); 1583302184fSCédric Le Goater self.vm.add_args('-device', 1593302184fSCédric Le Goater 'ds1338,bus=aspeed.i2c.bus.3,address=0x32'); 160f7bc7da0SCédric Le Goater self.do_test_arm_aspeed_buidroot_start(image_path, '0xf00') 16161cf757dSCédric Le Goater 16261cf757dSCédric Le Goater exec_command_and_wait_for_pattern(self, 16361cf757dSCédric Le Goater 'echo lm75 0x4d > /sys/class/i2c-dev/i2c-3/device/new_device', 16461cf757dSCédric Le Goater 'i2c i2c-3: new_device: Instantiated device lm75 at 0x4d'); 16561cf757dSCédric Le Goater exec_command_and_wait_for_pattern(self, 16661cf757dSCédric Le Goater 'cat /sys/class/hwmon/hwmon0/temp1_input', '0') 16761cf757dSCédric Le Goater self.vm.command('qom-set', path='/machine/peripheral/tmp-test', 16861cf757dSCédric Le Goater property='temperature', value=18000); 16961cf757dSCédric Le Goater exec_command_and_wait_for_pattern(self, 17061cf757dSCédric Le Goater 'cat /sys/class/hwmon/hwmon0/temp1_input', '18000') 17161cf757dSCédric Le Goater 1723302184fSCédric Le Goater exec_command_and_wait_for_pattern(self, 1733302184fSCédric Le Goater 'echo ds1307 0x32 > /sys/class/i2c-dev/i2c-3/device/new_device', 1743302184fSCédric Le Goater 'i2c i2c-3: new_device: Instantiated device ds1307 at 0x32'); 1753302184fSCédric Le Goater year = time.strftime("%Y") 1763302184fSCédric Le Goater exec_command_and_wait_for_pattern(self, 'hwclock -f /dev/rtc1', year); 1773302184fSCédric Le Goater 178f7bc7da0SCédric Le Goater self.do_test_arm_aspeed_buidroot_poweroff() 179bceb4d99SCédric Le Goater 180bceb4d99SCédric Le Goater 181*92f8e8e2SAlex Bennéeclass AST2x00MachineSDK(QemuSystemTest): 182*92f8e8e2SAlex Bennée 183*92f8e8e2SAlex Bennée # FIXME: Although these tests boot a whole distro they are still 184*92f8e8e2SAlex Bennée # slower than comparable machine models. There may be some 185*92f8e8e2SAlex Bennée # optimisations which bring down the runtime. In the meantime they 186*92f8e8e2SAlex Bennée # have generous timeouts and are disable for CI which aims for all 187*92f8e8e2SAlex Bennée # tests to run in less than 60 seconds. 188*92f8e8e2SAlex Bennée timeout = 240 189*92f8e8e2SAlex Bennée 190*92f8e8e2SAlex Bennée def wait_for_console_pattern(self, success_message, vm=None): 191*92f8e8e2SAlex Bennée wait_for_console_pattern(self, success_message, 192*92f8e8e2SAlex Bennée failure_message='Kernel panic - not syncing', 193*92f8e8e2SAlex Bennée vm=vm) 194*92f8e8e2SAlex Bennée 195bceb4d99SCédric Le Goater def do_test_arm_aspeed_sdk_start(self, image, cpu_id): 196bceb4d99SCédric Le Goater self.vm.set_console() 197bceb4d99SCédric Le Goater self.vm.add_args('-drive', 'file=' + image + ',if=mtd,format=raw', 198bceb4d99SCédric Le Goater '-net', 'nic', '-net', 'user') 199bceb4d99SCédric Le Goater self.vm.launch() 200bceb4d99SCédric Le Goater 201bceb4d99SCédric Le Goater self.wait_for_console_pattern('U-Boot 2019.04') 202bceb4d99SCédric Le Goater self.wait_for_console_pattern('## Loading kernel from FIT Image') 203bceb4d99SCédric Le Goater self.wait_for_console_pattern('Starting kernel ...') 204bceb4d99SCédric Le Goater self.wait_for_console_pattern('Booting Linux on physical CPU ' + cpu_id) 205bceb4d99SCédric Le Goater 206*92f8e8e2SAlex Bennée @skipIf(os.getenv('GITLAB_CI'), 'Running on GitLab') 207bceb4d99SCédric Le Goater def test_arm_ast2500_evb_sdk(self): 208bceb4d99SCédric Le Goater """ 209bceb4d99SCédric Le Goater :avocado: tags=arch:arm 210bceb4d99SCédric Le Goater :avocado: tags=machine:ast2500-evb 211bceb4d99SCédric Le Goater """ 212bceb4d99SCédric Le Goater 213bceb4d99SCédric Le Goater image_url = ('https://github.com/AspeedTech-BMC/openbmc/releases/' 214bceb4d99SCédric Le Goater 'download/v08.01/ast2500-default-obmc.tar.gz') 215bceb4d99SCédric Le Goater image_hash = ('5375f82b4c43a79427909342a1e18b4e48bd663e38466862145d27bb358796fd') 216bceb4d99SCédric Le Goater image_path = self.fetch_asset(image_url, asset_hash=image_hash, 217bceb4d99SCédric Le Goater algorithm='sha256') 218bceb4d99SCédric Le Goater archive.extract(image_path, self.workdir) 219bceb4d99SCédric Le Goater 220bceb4d99SCédric Le Goater self.do_test_arm_aspeed_sdk_start( 221bceb4d99SCédric Le Goater self.workdir + '/ast2500-default/image-bmc', '0x0') 222bceb4d99SCédric Le Goater self.wait_for_console_pattern('ast2500-default login:') 223bceb4d99SCédric Le Goater 224*92f8e8e2SAlex Bennée @skipIf(os.getenv('GITLAB_CI'), 'Running on GitLab') 225bceb4d99SCédric Le Goater def test_arm_ast2600_evb_sdk(self): 226bceb4d99SCédric Le Goater """ 227bceb4d99SCédric Le Goater :avocado: tags=arch:arm 228bceb4d99SCédric Le Goater :avocado: tags=machine:ast2600-evb 229bceb4d99SCédric Le Goater """ 230bceb4d99SCédric Le Goater 231bceb4d99SCédric Le Goater image_url = ('https://github.com/AspeedTech-BMC/openbmc/releases/' 232bceb4d99SCédric Le Goater 'download/v08.01/ast2600-default-obmc.tar.gz') 233bceb4d99SCédric Le Goater image_hash = ('f12ef15e8c1f03a214df3b91c814515c5e2b2f56119021398c1dbdd626817d15') 234bceb4d99SCédric Le Goater image_path = self.fetch_asset(image_url, asset_hash=image_hash, 235bceb4d99SCédric Le Goater algorithm='sha256') 236bceb4d99SCédric Le Goater archive.extract(image_path, self.workdir) 237bceb4d99SCédric Le Goater 238bceb4d99SCédric Le Goater self.vm.add_args('-device', 239bceb4d99SCédric Le Goater 'tmp105,bus=aspeed.i2c.bus.5,address=0x4d,id=tmp-test'); 240bceb4d99SCédric Le Goater self.vm.add_args('-device', 241bceb4d99SCédric Le Goater 'ds1338,bus=aspeed.i2c.bus.5,address=0x32'); 242bceb4d99SCédric Le Goater self.do_test_arm_aspeed_sdk_start( 243bceb4d99SCédric Le Goater self.workdir + '/ast2600-default/image-bmc', '0xf00') 244bceb4d99SCédric Le Goater self.wait_for_console_pattern('ast2600-default login:') 245bceb4d99SCédric Le Goater exec_command_and_wait_for_pattern(self, 'root', 'Password:') 246bceb4d99SCédric Le Goater exec_command_and_wait_for_pattern(self, '0penBmc', 'root@ast2600-default:~#') 247bceb4d99SCédric Le Goater 248bceb4d99SCédric Le Goater exec_command_and_wait_for_pattern(self, 249bceb4d99SCédric Le Goater 'echo lm75 0x4d > /sys/class/i2c-dev/i2c-5/device/new_device', 250bceb4d99SCédric Le Goater 'i2c i2c-5: new_device: Instantiated device lm75 at 0x4d'); 251bceb4d99SCédric Le Goater exec_command_and_wait_for_pattern(self, 252bceb4d99SCédric Le Goater 'cat /sys/class/hwmon/hwmon19/temp1_input', '0') 253bceb4d99SCédric Le Goater self.vm.command('qom-set', path='/machine/peripheral/tmp-test', 254bceb4d99SCédric Le Goater property='temperature', value=18000); 255bceb4d99SCédric Le Goater exec_command_and_wait_for_pattern(self, 256bceb4d99SCédric Le Goater 'cat /sys/class/hwmon/hwmon19/temp1_input', '18000') 257bceb4d99SCédric Le Goater 258bceb4d99SCédric Le Goater exec_command_and_wait_for_pattern(self, 259bceb4d99SCédric Le Goater 'echo ds1307 0x32 > /sys/class/i2c-dev/i2c-5/device/new_device', 260bceb4d99SCédric Le Goater 'i2c i2c-5: new_device: Instantiated device ds1307 at 0x32'); 261bceb4d99SCédric Le Goater year = time.strftime("%Y") 262bceb4d99SCédric Le Goater exec_command_and_wait_for_pattern(self, 'hwclock -f /dev/rtc1', year); 263