target/arm: Update qemu-system-arm -cpu max to cortex-a57
[qemu.git] / tests / vm / freebsd
blob805db759d67041790864c4e0441e47fc4e662107
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.3/FreeBSD-12.3-RELEASE-amd64-disc1.iso.xz"
32     csum = "36dd0de50f1fe5f0a88e181e94657656de26fb64254412f74e80e128e8b938b4"
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",
66     ]
68     BUILD_SCRIPT = """
69         set -e;
70         rm -rf /home/qemu/qemu-test.*
71         cd $(mktemp -d /home/qemu/qemu-test.XXXXXX);
72         mkdir src build; cd src;
73         tar -xf /dev/vtbd1;
74         cd ../build
75         ../src/configure --python=python3.7 {configure_opts};
76         gmake --output-sync -j{jobs} {target} {verbose};
77     """
79     def console_boot_serial(self):
80         self.console_wait_send("Autoboot", "3")
81         self.console_wait_send("OK", "set console=comconsole\n")
82         self.console_wait_send("OK", "boot\n")
84     def build_image(self, img):
85         self.print_step("Downloading install iso")
86         cimg = self._download_with_cache(self.link, sha256sum=self.csum)
87         img_tmp = img + ".tmp"
88         iso = img + ".install.iso"
89         iso_xz = iso + ".xz"
91         self.print_step("Preparing iso and disk image")
92         subprocess.check_call(["cp", "-f", cimg, iso_xz])
93         subprocess.check_call(["xz", "-dvf", iso_xz])
94         self.exec_qemu_img("create", "-f", "qcow2", img_tmp, self.size)
96         self.print_step("Booting installer")
97         self.boot(img_tmp, extra_args = [
98             "-bios", "pc-bios/bios-256k.bin",
99             "-machine", "graphics=off",
100             "-device", "VGA",
101             "-cdrom", iso
102         ])
103         self.console_init()
104         self.console_boot_serial()
105         self.console_wait_send("Console type",          "xterm\n")
107         # pre-install configuration
108         self.console_wait_send("Welcome",               "\n")
109         self.console_wait_send("Keymap Selection",      "\n")
110         self.console_wait_send("Set Hostname",          "freebsd\n")
111         self.console_wait_send("Distribution Select",   "\n")
112         self.console_wait_send("Partitioning",          "\n")
113         self.console_wait_send("Partition",             "\n")
114         self.console_wait_send("Scheme",                "\n")
115         self.console_wait_send("Editor",                "f")
116         self.console_wait_send("Confirmation",          "c")
118         self.print_step("Installation started now, this will take a while")
120         # post-install configuration
121         self.console_wait("New Password:")
122         self.console_send("%s\n" % self._config["root_pass"])
123         self.console_wait("Retype New Password:")
124         self.console_send("%s\n" % self._config["root_pass"])
126         self.console_wait_send("Network Configuration", "\n")
127         self.console_wait_send("IPv4",                  "y")
128         self.console_wait_send("DHCP",                  "y")
129         self.console_wait_send("IPv6",                  "n")
130         self.console_wait_send("Resolver",              "\n")
132         self.console_wait_send("Time Zone Selector",    "0\n")
133         self.console_wait_send("Confirmation",          "y")
134         self.console_wait_send("Time & Date",           "\n")
135         self.console_wait_send("Time & Date",           "\n")
137         self.console_wait_send("System Configuration",  "\n")
138         self.console_wait_send("System Hardening",      "\n")
140         # qemu user
141         self.console_wait_send("Add User Accounts", "y")
142         self.console_wait("Username")
143         self.console_send("%s\n" % self._config["guest_user"])
144         self.console_wait("Full name")
145         self.console_send("%s\n" % self._config["guest_user"])
146         self.console_wait_send("Uid",                   "\n")
147         self.console_wait_send("Login group",           "\n")
148         self.console_wait_send("Login group",           "\n")
149         self.console_wait_send("Login class",           "\n")
150         self.console_wait_send("Shell",                 "\n")
151         self.console_wait_send("Home directory",        "\n")
152         self.console_wait_send("Home directory perm",   "\n")
153         self.console_wait_send("Use password",          "\n")
154         self.console_wait_send("Use an empty password", "\n")
155         self.console_wait_send("Use a random password", "\n")
156         self.console_wait("Enter password:")
157         self.console_send("%s\n" % self._config["guest_pass"])
158         self.console_wait("Enter password again:")
159         self.console_send("%s\n" % self._config["guest_pass"])
160         self.console_wait_send("Lock out",              "\n")
161         self.console_wait_send("OK",                    "yes\n")
162         self.console_wait_send("Add another user",      "no\n")
164         self.console_wait_send("Final Configuration",   "\n")
165         self.console_wait_send("Manual Configuration",  "\n")
166         self.console_wait_send("Complete",              "\n")
168         self.print_step("Installation finished, rebooting")
169         self.console_boot_serial()
171         # setup qemu user
172         prompt = "$"
173         self.console_ssh_init(prompt, self._config["guest_user"], self._config["guest_pass"])
174         self.console_wait_send(prompt, "exit\n")
176         # setup root user
177         prompt = "root@freebsd:~ #"
178         self.console_ssh_init(prompt, "root", self._config["root_pass"])
179         self.console_sshd_config(prompt)
181         # setup serial console
182         self.console_wait(prompt)
183         self.console_send("echo 'console=comconsole' >> /boot/loader.conf\n")
185         # setup boot delay
186         self.console_wait(prompt)
187         self.console_send("echo 'autoboot_delay=1' >> /boot/loader.conf\n")
189         # setup virtio-blk #1 (tarfile)
190         self.console_wait(prompt)
191         self.console_send("echo 'chmod 666 /dev/vtbd1' >> /etc/rc.local\n")
193         self.print_step("Configuration finished, rebooting")
194         self.console_wait_send(prompt, "reboot\n")
195         self.console_wait("login:")
196         self.wait_ssh()
198         self.print_step("Installing packages")
199         self.ssh_root_check("pkg install -y %s\n" % " ".join(self.pkgs))
201         # shutdown
202         self.ssh_root(self.poweroff)
203         self.console_wait("Uptime:")
204         self.wait()
206         if os.path.exists(img):
207             os.remove(img)
208         os.rename(img_tmp, img)
209         os.remove(iso)
210         self.print_step("All done")
212 if __name__ == "__main__":
213     sys.exit(basevm.main(FreeBSDVM, config=FREEBSD_CONFIG))