master
py 95 lines 3.33 KB
Raw
1 #!/usr/bin/env python3
2 #
3 # Linux initrd integration test.
4 #
5 # Copyright (c) 2018 Red Hat, Inc.
6 #
7 # Author:
8 # Wainer dos Santos Moschetta <wainersm@redhat.com>
9 #
10 # This work is licensed under the terms of the GNU GPL, version 2 or
11 # later. See the COPYING file in the top-level directory.
12
13 import logging
14 import tempfile
15
16 from qemu_test import QemuSystemTest, Asset, skipFlakyTest
17
18
19 class LinuxInitrd(QemuSystemTest):
20 """
21 Checks QEMU evaluates correctly the initrd file passed as -initrd option.
22 """
23
24 timeout = 300
25
26 ASSET_F18_KERNEL = Asset(
27 ('https://archives.fedoraproject.org/pub/archive/fedora/linux/'
28 'releases/18/Fedora/x86_64/os/images/pxeboot/vmlinuz'),
29 '1a27cb42559ce29237ac186699d063556ad69c8349d732bb1bd8d614e5a8cc2e')
30
31 ASSET_F28_KERNEL = Asset(
32 ('https://archives.fedoraproject.org/pub/archive/fedora/linux/'
33 'releases/28/Everything/x86_64/os/images/pxeboot/vmlinuz'),
34 'd05909c9d4a742a6fcc84dcc0361009e4611769619cc187a07107579a035f24e')
35
36 def test_with_2gib_file_should_exit_error_msg_with_linux_v3_6(self):
37 """
38 Pretends to boot QEMU with an initrd file with size of 2GiB
39 and expect it exits with error message.
40 Fedora-18 shipped with linux-3.6 which have not supported xloadflags
41 cannot support more than 2GiB initrd.
42 """
43 self.set_machine('pc')
44 kernel_path = self.ASSET_F18_KERNEL.fetch()
45 max_size = 2 * (1024 ** 3) - 1
46
47 with tempfile.NamedTemporaryFile() as initrd:
48 initrd.seek(max_size)
49 initrd.write(b'\0')
50 initrd.flush()
51 self.vm.add_args('-kernel', kernel_path, '-initrd', initrd.name,
52 '-m', '4096')
53 self.vm.set_qmp_monitor(enabled=False)
54 self.vm.launch()
55 self.vm.wait()
56 self.assertEqual(self.vm.exitcode(), 1)
57 expected_msg = r'.*initrd is too large.*max: \d+, need %s.*' % (
58 max_size + 1)
59 self.assertRegex(self.vm.get_log(), expected_msg)
60
61 # XXX file tracking bug
62 @skipFlakyTest(bug_url=None)
63 def test_with_2gib_file_should_work_with_linux_v4_16(self):
64 """
65 QEMU has supported up to 4 GiB initrd for recent kernel
66 Expect guest can reach 'Unpacking initramfs...'
67 """
68 self.set_machine('pc')
69 kernel_path = self.ASSET_F28_KERNEL.fetch()
70 max_size = 2 * (1024 ** 3) + 1
71
72 with tempfile.NamedTemporaryFile() as initrd:
73 initrd.seek(max_size)
74 initrd.write(b'\0')
75 initrd.flush()
76
77 self.vm.set_console()
78 kernel_command_line = 'console=ttyS0'
79 self.vm.add_args('-kernel', kernel_path,
80 '-append', kernel_command_line,
81 '-initrd', initrd.name,
82 '-m', '5120')
83 self.vm.launch()
84 console = self.vm.console_socket.makefile()
85 console_logger = logging.getLogger('console')
86 while True:
87 msg = console.readline()
88 console_logger.debug(msg.strip())
89 if 'Unpacking initramfs...' in msg:
90 break
91 if 'Kernel panic - not syncing' in msg:
92 self.fail("Kernel panic reached")
93
94 if __name__ == '__main__':
95 QemuSystemTest.main()