1#!/usr/bin/env python3 2# 3# Test the bFLT loader format 4# 5# Copyright (C) 2019 Philippe Mathieu-Daudé <f4bug@amsat.org> 6# 7# SPDX-License-Identifier: GPL-2.0-or-later 8 9import os 10import bz2 11 12from qemu_test import QemuUserTest, Asset 13from qemu_test import has_cmd 14from qemu_test.utils import cpio_extract 15from unittest import skipUnless 16 17 18class LoadBFLT(QemuUserTest): 19 20 ASSET_ROOTFS = Asset( 21 ('https://elinux.org/images/5/51/Stm32_mini_rootfs.cpio.bz2'), 22 'eefb788e4980c9e8d6c9d60ce7d15d4da6bf4fbc6a80f487673824600d5ba9cc') 23 24 @skipUnless(*has_cmd('cpio')) 25 @skipUnless(os.getenv('QEMU_TEST_ALLOW_UNTRUSTED_CODE'), 'untrusted code') 26 def test_stm32(self): 27 # See https://elinux.org/STM32#User_Space 28 rootfs_path_bz2 = self.ASSET_ROOTFS.fetch() 29 busybox_path = os.path.join(self.workdir, "bin/busybox") 30 31 with bz2.open(rootfs_path_bz2, 'rb') as cpio_handle: 32 cpio_extract(cpio_handle, self.workdir) 33 34 res = self.run_cmd(busybox_path) 35 ver = 'BusyBox v1.24.0.git (2015-02-03 22:17:13 CET) multi-call binary.' 36 self.assertIn(ver, res.stdout) 37 38 res = self.run_cmd(busybox_path, ['uname', '-a']) 39 unm = 'armv7l GNU/Linux' 40 self.assertIn(unm, res.stdout) 41 42 43if __name__ == '__main__': 44 QemuUserTest.main() 45