1*8011837aSPhilippe Mathieu-Daudé# Test the bFLT loader format 2*8011837aSPhilippe Mathieu-Daudé# 3*8011837aSPhilippe Mathieu-Daudé# Copyright (C) 2019 Philippe Mathieu-Daudé <f4bug@amsat.org> 4*8011837aSPhilippe Mathieu-Daudé# 5*8011837aSPhilippe Mathieu-Daudé# SPDX-License-Identifier: GPL-2.0-or-later 6*8011837aSPhilippe Mathieu-Daudé 7*8011837aSPhilippe Mathieu-Daudéimport os 8*8011837aSPhilippe Mathieu-Daudéimport bz2 9*8011837aSPhilippe Mathieu-Daudéimport subprocess 10*8011837aSPhilippe Mathieu-Daudé 11*8011837aSPhilippe Mathieu-Daudéfrom avocado import skipUnless 12*8011837aSPhilippe Mathieu-Daudéfrom avocado_qemu import QemuUserTest 13*8011837aSPhilippe Mathieu-Daudéfrom avocado_qemu import has_cmd 14*8011837aSPhilippe Mathieu-Daudé 15*8011837aSPhilippe Mathieu-Daudé 16*8011837aSPhilippe Mathieu-Daudéclass LoadBFLT(QemuUserTest): 17*8011837aSPhilippe Mathieu-Daudé 18*8011837aSPhilippe Mathieu-Daudé def extract_cpio(self, cpio_path): 19*8011837aSPhilippe Mathieu-Daudé """ 20*8011837aSPhilippe Mathieu-Daudé Extracts a cpio archive into the test workdir 21*8011837aSPhilippe Mathieu-Daudé 22*8011837aSPhilippe Mathieu-Daudé :param cpio_path: path to the cpio archive 23*8011837aSPhilippe Mathieu-Daudé """ 24*8011837aSPhilippe Mathieu-Daudé cwd = os.getcwd() 25*8011837aSPhilippe Mathieu-Daudé os.chdir(self.workdir) 26*8011837aSPhilippe Mathieu-Daudé with bz2.open(cpio_path, 'rb') as archive_cpio: 27*8011837aSPhilippe Mathieu-Daudé subprocess.run(['cpio', '-i'], input=archive_cpio.read(), 28*8011837aSPhilippe Mathieu-Daudé stderr=subprocess.DEVNULL) 29*8011837aSPhilippe Mathieu-Daudé os.chdir(cwd) 30*8011837aSPhilippe Mathieu-Daudé 31*8011837aSPhilippe Mathieu-Daudé @skipUnless(*has_cmd('cpio')) 32*8011837aSPhilippe Mathieu-Daudé @skipUnless(os.getenv('AVOCADO_ALLOW_UNTRUSTED_CODE'), 'untrusted code') 33*8011837aSPhilippe Mathieu-Daudé def test_stm32(self): 34*8011837aSPhilippe Mathieu-Daudé """ 35*8011837aSPhilippe Mathieu-Daudé :avocado: tags=arch:arm 36*8011837aSPhilippe Mathieu-Daudé :avocado: tags=linux_user 37*8011837aSPhilippe Mathieu-Daudé :avocado: tags=quick 38*8011837aSPhilippe Mathieu-Daudé """ 39*8011837aSPhilippe Mathieu-Daudé # See https://elinux.org/STM32#User_Space 40*8011837aSPhilippe Mathieu-Daudé rootfs_url = ('https://elinux.org/images/5/51/' 41*8011837aSPhilippe Mathieu-Daudé 'Stm32_mini_rootfs.cpio.bz2') 42*8011837aSPhilippe Mathieu-Daudé rootfs_hash = '9f065e6ba40cce7411ba757f924f30fcc57951e6' 43*8011837aSPhilippe Mathieu-Daudé rootfs_path_bz2 = self.fetch_asset(rootfs_url, asset_hash=rootfs_hash) 44*8011837aSPhilippe Mathieu-Daudé busybox_path = os.path.join(self.workdir, "/bin/busybox") 45*8011837aSPhilippe Mathieu-Daudé 46*8011837aSPhilippe Mathieu-Daudé self.extract_cpio(rootfs_path_bz2) 47*8011837aSPhilippe Mathieu-Daudé 48*8011837aSPhilippe Mathieu-Daudé res = self.run(busybox_path) 49*8011837aSPhilippe Mathieu-Daudé ver = 'BusyBox v1.24.0.git (2015-02-03 22:17:13 CET) multi-call binary.' 50*8011837aSPhilippe Mathieu-Daudé self.assertIn(ver, res.stdout_text) 51*8011837aSPhilippe Mathieu-Daudé 52*8011837aSPhilippe Mathieu-Daudé res = self.run(busybox_path, ['uname', '-a']) 53*8011837aSPhilippe Mathieu-Daudé unm = 'armv7l GNU/Linux' 54*8011837aSPhilippe Mathieu-Daudé self.assertIn(unm, res.stdout_text) 55