Merge tag 'qemu-macppc-20230206' of https://github.com/mcayland/qemu into staging
[qemu/rayw.git] / tests / vm / freebsd
blobba2ba23d24d0178be42ae79c3457c62db2bf4af3
1 #!/usr/bin/env python3
3 # FreeBSD VM image
5 # Copyright 2017-2019 Red Hat Inc.
7 # Authors:
8 #  Fam Zheng <famz@redhat.com>
9 #  Gerd Hoffmann <kraxel@redhat.com>
11 # This code is licensed under the GPL version 2 or later.  See
12 # the COPYING file in the top-level directory.
15 import os
16 import re
17 import sys
18 import time
19 import socket
20 import subprocess
21 import basevm
23 FREEBSD_CONFIG = {
24     'cpu'       : "max,sse4.2=off",
27 class FreeBSDVM(basevm.BaseVM):
28     name = "freebsd"
29     arch = "x86_64"
31     link = "https://download.freebsd.org/ftp/releases/ISO-IMAGES/12.4/FreeBSD-12.4-RELEASE-amd64-disc1.iso.xz"
32     csum = "1dcf6446e31bf3f81b582e9aba3319a258c29a937a2af6138ee4b181ed719a87"
33     size = "20G"
34     pkgs = [
35         # build tools
36         "git",
37         "pkgconf",
38         "bzip2",
39         "python37",
40         "ninja",
42         # gnu tools
43         "bash",
44         "gmake",
45         "gsed",
46         "gettext",
48         # libs: crypto
49         "gnutls",
51         # libs: images
52         "jpeg-turbo",
53         "png",
55         # libs: ui
56         "sdl2",
57         "gtk3",
58         "libxkbcommon",
60         # libs: opengl
61         "libepoxy",
62         "mesa-libs",
64         # libs: migration
65         "zstd",
67         # libs: networking
68         "libslirp",
70         # libs: sndio
71         "sndio",
72     ]
74     BUILD_SCRIPT = """
75         set -e;
76         rm -rf /home/qemu/qemu-test.*
77         cd $(mktemp -d /home/qemu/qemu-test.XXXXXX);
78         mkdir src build; cd src;
79         tar -xf /dev/vtbd1;
80         cd ../build
81         ../src/configure --python=python3.7 {configure_opts};
82         gmake --output-sync -j{jobs} {target} {verbose};
83     """
85     def console_boot_serial(self):
86         self.console_wait_send("Autoboot", "3")
87         self.console_wait_send("OK", "set console=comconsole\n")
88         self.console_wait_send("OK", "boot\n")
90     def build_image(self, img):
91         self.print_step("Downloading install iso")
92         cimg = self._download_with_cache(self.link, sha256sum=self.csum)
93         img_tmp = img + ".tmp"
94         iso = img + ".install.iso"
95         iso_xz = iso + ".xz"
97         self.print_step("Preparing iso and disk image")
98         subprocess.check_call(["cp", "-f", cimg, iso_xz])
99         subprocess.check_call(["xz", "-dvf", iso_xz])
100         self.exec_qemu_img("create", "-f", "qcow2", img_tmp, self.size)
102         self.print_step("Booting installer")
103         self.boot(img_tmp, extra_args = [
104             "-machine", "graphics=off",
105             "-device", "VGA",
106             "-cdrom", iso
107         ])
108         self.console_init()
109         self.console_boot_serial()
110         self.console_wait_send("Console type",          "xterm\n")
112         # pre-install configuration
113         self.console_wait_send("Welcome",               "\n")
114         self.console_wait_send("Keymap Selection",      "\n")
115         self.console_wait_send("Set Hostname",          "freebsd\n")
116         self.console_wait_send("Distribution Select",   "\n")
117         self.console_wait_send("Partitioning",          "\n")
118         self.console_wait_send("Partition",             "\n")
119         self.console_wait_send("Scheme",                "\n")
120         self.console_wait_send("Editor",                "f")
121         self.console_wait_send("Confirmation",          "c")
123         self.print_step("Installation started now, this will take a while")
125         # post-install configuration
126         self.console_wait("New Password:")
127         self.console_send("%s\n" % self._config["root_pass"])
128         self.console_wait("Retype New Password:")
129         self.console_send("%s\n" % self._config["root_pass"])
131         self.console_wait_send("Network Configuration", "\n")
132         self.console_wait_send("IPv4",                  "y")
133         self.console_wait_send("DHCP",                  "y")
134         self.console_wait_send("IPv6",                  "n")
135         self.console_wait_send("Resolver",              "\n")
137         self.console_wait_send("Time Zone Selector",    "0\n")
138         self.console_wait_send("Confirmation",          "y")
139         self.console_wait_send("Time & Date",           "\n")
140         self.console_wait_send("Time & Date",           "\n")
142         self.console_wait_send("System Configuration",  "\n")
143         self.console_wait_send("System Hardening",      "\n")
145         # qemu user
146         self.console_wait_send("Add User Accounts", "y")
147         self.console_wait("Username")
148         self.console_send("%s\n" % self._config["guest_user"])
149         self.console_wait("Full name")
150         self.console_send("%s\n" % self._config["guest_user"])
151         self.console_wait_send("Uid",                   "\n")
152         self.console_wait_send("Login group",           "\n")
153         self.console_wait_send("Login group",           "\n")
154         self.console_wait_send("Login class",           "\n")
155         self.console_wait_send("Shell",                 "\n")
156         self.console_wait_send("Home directory",        "\n")
157         self.console_wait_send("Home directory perm",   "\n")
158         self.console_wait_send("Use password",          "\n")
159         self.console_wait_send("Use an empty password", "\n")
160         self.console_wait_send("Use a random password", "\n")
161         self.console_wait("Enter password:")
162         self.console_send("%s\n" % self._config["guest_pass"])
163         self.console_wait("Enter password again:")
164         self.console_send("%s\n" % self._config["guest_pass"])
165         self.console_wait_send("Lock out",              "\n")
166         self.console_wait_send("OK",                    "yes\n")
167         self.console_wait_send("Add another user",      "no\n")
169         self.console_wait_send("Final Configuration",   "\n")
170         self.console_wait_send("Manual Configuration",  "\n")
171         self.console_wait_send("Complete",              "\n")
173         self.print_step("Installation finished, rebooting")
174         self.console_boot_serial()
176         # setup qemu user
177         prompt = "$"
178         self.console_ssh_init(prompt, self._config["guest_user"], self._config["guest_pass"])
179         self.console_wait_send(prompt, "exit\n")
181         # setup root user
182         prompt = "root@freebsd:~ #"
183         self.console_ssh_init(prompt, "root", self._config["root_pass"])
184         self.console_sshd_config(prompt)
186         # setup serial console
187         self.console_wait(prompt)
188         self.console_send("echo 'console=comconsole' >> /boot/loader.conf\n")
190         # setup boot delay
191         self.console_wait(prompt)
192         self.console_send("echo 'autoboot_delay=1' >> /boot/loader.conf\n")
194         # setup virtio-blk #1 (tarfile)
195         self.console_wait(prompt)
196         self.console_send("echo 'chmod 666 /dev/vtbd1' >> /etc/rc.local\n")
198         self.print_step("Configuration finished, rebooting")
199         self.console_wait_send(prompt, "reboot\n")
200         self.console_wait("login:")
201         self.wait_ssh()
203         self.print_step("Installing packages")
204         self.ssh_root_check("pkg install -y %s\n" % " ".join(self.pkgs))
206         # shutdown
207         self.ssh_root(self.poweroff)
208         self.console_wait("Uptime:")
209         self.wait()
211         if os.path.exists(img):
212             os.remove(img)
213         os.rename(img_tmp, img)
214         os.remove(iso)
215         self.print_step("All done")
217 if __name__ == "__main__":
218     sys.exit(basevm.main(FreeBSDVM, config=FREEBSD_CONFIG))