xref: /qemu/tests/functional/test_arm_microbit.py (revision fb49b69bf9fd584546c7d946eaeec90941941d25)
1*cb5f6ca8SThomas Huth#!/usr/bin/env python3
2*cb5f6ca8SThomas Huth#
3*cb5f6ca8SThomas Huth# SPDX-License-Identifier: GPL-2.0-or-later
4*cb5f6ca8SThomas Huth#
5*cb5f6ca8SThomas Huth# Copyright 2025, The QEMU Project Developers.
6*cb5f6ca8SThomas Huth#
7*cb5f6ca8SThomas Huth# A functional test that runs MicroPython on the arm microbit machine.
8*cb5f6ca8SThomas Huth
9*cb5f6ca8SThomas Huthfrom qemu_test import QemuSystemTest, Asset, exec_command_and_wait_for_pattern
10*cb5f6ca8SThomas Huthfrom qemu_test import wait_for_console_pattern
11*cb5f6ca8SThomas Huth
12*cb5f6ca8SThomas Huth
13*cb5f6ca8SThomas Huthclass MicrobitMachine(QemuSystemTest):
14*cb5f6ca8SThomas Huth
15*cb5f6ca8SThomas Huth    ASSET_MICRO = Asset('https://ozlabs.org/~joel/microbit-micropython.hex',
16*cb5f6ca8SThomas Huth        '021641f93dfb11767d4978dbb3ca7f475d1b13c69e7f4aec3382f212636bffd6')
17*cb5f6ca8SThomas Huth
18*cb5f6ca8SThomas Huth    def test_arm_microbit(self):
19*cb5f6ca8SThomas Huth        self.set_machine('microbit')
20*cb5f6ca8SThomas Huth
21*cb5f6ca8SThomas Huth        micropython = self.ASSET_MICRO.fetch()
22*cb5f6ca8SThomas Huth        self.vm.set_console()
23*cb5f6ca8SThomas Huth        self.vm.add_args('-device', f'loader,file={micropython}')
24*cb5f6ca8SThomas Huth        self.vm.launch()
25*cb5f6ca8SThomas Huth        wait_for_console_pattern(self, 'Type "help()" for more information.')
26*cb5f6ca8SThomas Huth        exec_command_and_wait_for_pattern(self, 'import machine as mch', '>>>')
27*cb5f6ca8SThomas Huth        exec_command_and_wait_for_pattern(self, 'mch.reset()', 'MicroPython')
28*cb5f6ca8SThomas Huth        wait_for_console_pattern(self, '>>>')
29*cb5f6ca8SThomas Huth
30*cb5f6ca8SThomas Huthif __name__ == '__main__':
31*cb5f6ca8SThomas Huth    QemuSystemTest.main()
32