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