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