xref: /qemu/tests/functional/test_arm_emcraft_sf2.py (revision ba182a693fe15a4f6f2a04e8ecb865c2630e5a16) !
1bade2d51SThomas Huth#!/usr/bin/env python3
2bade2d51SThomas Huth#
3bade2d51SThomas Huth# Functional test that boots a Linux kernel and checks the console
4bade2d51SThomas Huth#
5bade2d51SThomas Huth# SPDX-License-Identifier: GPL-2.0-or-later
6bade2d51SThomas Huth
7bade2d51SThomas Huthimport os
8bade2d51SThomas Huthimport shutil
9bade2d51SThomas Huth
10bade2d51SThomas Huthfrom qemu_test import LinuxKernelTest, Asset, exec_command_and_wait_for_pattern
11bade2d51SThomas Huthfrom qemu_test.utils import file_truncate
12bade2d51SThomas Huth
13bade2d51SThomas Huthclass EmcraftSf2Machine(LinuxKernelTest):
14bade2d51SThomas Huth
15bade2d51SThomas Huth    ASSET_UBOOT = Asset(
16bade2d51SThomas Huth        ('https://raw.githubusercontent.com/Subbaraya-Sundeep/qemu-test-binaries/'
17bade2d51SThomas Huth         'fe371d32e50ca682391e1e70ab98c2942aeffb01/u-boot'),
18bade2d51SThomas Huth        '5c6a15103375db11b21f2236473679a9dbbed6d89652bfcdd501c263d68ab725')
19bade2d51SThomas Huth
20bade2d51SThomas Huth    ASSET_SPI = Asset(
21bade2d51SThomas Huth        ('https://raw.githubusercontent.com/Subbaraya-Sundeep/qemu-test-binaries/'
22bade2d51SThomas Huth         'fe371d32e50ca682391e1e70ab98c2942aeffb01/spi.bin'),
23bade2d51SThomas Huth        'cd9bdd2c4cb55a59c3adb6bcf74881667c4500dde0570a43aa3be2b17eecfdb6')
24bade2d51SThomas Huth
25bade2d51SThomas Huth    def test_arm_emcraft_sf2(self):
26bade2d51SThomas Huth        self.set_machine('emcraft-sf2')
27bade2d51SThomas Huth        self.require_netdev('user')
28bade2d51SThomas Huth
29bade2d51SThomas Huth        uboot_path = self.ASSET_UBOOT.fetch()
30bade2d51SThomas Huth        spi_path = self.ASSET_SPI.fetch()
31*beaf88c8SDaniel P. Berrangé        spi_path_rw = self.scratch_file('spi.bin')
32bade2d51SThomas Huth        shutil.copy(spi_path, spi_path_rw)
33bade2d51SThomas Huth        os.chmod(spi_path_rw, 0o600)
34bade2d51SThomas Huth
35bade2d51SThomas Huth        file_truncate(spi_path_rw, 16 << 20) # Spansion S25FL128SDPBHICO is 16 MiB
36bade2d51SThomas Huth
37bade2d51SThomas Huth        self.vm.set_console()
38bade2d51SThomas Huth        kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE
39bade2d51SThomas Huth        self.vm.add_args('-kernel', uboot_path,
40bade2d51SThomas Huth                         '-append', kernel_command_line,
41bade2d51SThomas Huth                         '-drive', 'file=' + spi_path_rw + ',if=mtd,format=raw',
42bade2d51SThomas Huth                         '-no-reboot')
43bade2d51SThomas Huth        self.vm.launch()
44bade2d51SThomas Huth        self.wait_for_console_pattern('Enter \'help\' for a list')
45bade2d51SThomas Huth
46bade2d51SThomas Huth        exec_command_and_wait_for_pattern(self, 'ifconfig eth0 10.0.2.15',
47bade2d51SThomas Huth                                                 'eth0: link becomes ready')
48bade2d51SThomas Huth        exec_command_and_wait_for_pattern(self, 'ping -c 3 10.0.2.2',
49bade2d51SThomas Huth            '3 packets transmitted, 3 packets received, 0% packet loss')
50bade2d51SThomas Huth
51bade2d51SThomas Huthif __name__ == '__main__':
52bade2d51SThomas Huth    LinuxKernelTest.main()
53