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