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