xref: /openbmc/qemu/tests/vm/freebsd (revision ec6fb1c8cd8d55c3d2a34cacfea6df0fe6c76057)
1c88ee46cSPhilippe Mathieu-Daudé#!/usr/bin/env python3
2111e30c0SFam Zheng#
3111e30c0SFam Zheng# FreeBSD VM image
4111e30c0SFam Zheng#
5918fb8faSGerd Hoffmann# Copyright 2017-2019 Red Hat Inc.
6111e30c0SFam Zheng#
7111e30c0SFam Zheng# Authors:
8111e30c0SFam Zheng#  Fam Zheng <famz@redhat.com>
9918fb8faSGerd Hoffmann#  Gerd Hoffmann <kraxel@redhat.com>
10111e30c0SFam Zheng#
11111e30c0SFam Zheng# This code is licensed under the GPL version 2 or later.  See
12111e30c0SFam Zheng# the COPYING file in the top-level directory.
13111e30c0SFam Zheng#
14111e30c0SFam Zheng
15111e30c0SFam Zhengimport os
16918fb8faSGerd Hoffmannimport re
17111e30c0SFam Zhengimport sys
18918fb8faSGerd Hoffmannimport time
19918fb8faSGerd Hoffmannimport socket
20111e30c0SFam Zhengimport subprocess
21111e30c0SFam Zhengimport basevm
22111e30c0SFam Zheng
23262fd273SWarner LoshFREEBSD_CONFIG = {
24262fd273SWarner Losh    'cpu'	: "max,sse4.2=off",
25262fd273SWarner Losh}
26262fd273SWarner Losh
27111e30c0SFam Zhengclass FreeBSDVM(basevm.BaseVM):
28111e30c0SFam Zheng    name = "freebsd"
2931719c37SPhilippe Mathieu-Daudé    arch = "x86_64"
30918fb8faSGerd Hoffmann
31*ec6fb1c8SThomas Huth    link = "https://download.freebsd.org/releases/CI-IMAGES/13.2-RELEASE/amd64/Latest/FreeBSD-13.2-RELEASE-amd64-BASIC-CI.raw.xz"
32*ec6fb1c8SThomas Huth    csum = "a4fb3b6c7b75dd4d58fb0d75e4caf72844bffe0ca00e66459c028b198ffb3c0e"
33918fb8faSGerd Hoffmann    size = "20G"
34918fb8faSGerd Hoffmann    pkgs = [
35918fb8faSGerd Hoffmann        # build tools
36918fb8faSGerd Hoffmann        "git",
37918fb8faSGerd Hoffmann        "pkgconf",
38918fb8faSGerd Hoffmann        "bzip2",
39*ec6fb1c8SThomas Huth        "python39",
40345d7053SPaolo Bonzini        "ninja",
41918fb8faSGerd Hoffmann
42918fb8faSGerd Hoffmann        # gnu tools
43918fb8faSGerd Hoffmann        "bash",
44918fb8faSGerd Hoffmann        "gmake",
45918fb8faSGerd Hoffmann        "gsed",
46e8f3bd71SMarc-André Lureau        "gettext",
47918fb8faSGerd Hoffmann
48918fb8faSGerd Hoffmann        # libs: crypto
49918fb8faSGerd Hoffmann        "gnutls",
50918fb8faSGerd Hoffmann
51918fb8faSGerd Hoffmann        # libs: images
52918fb8faSGerd Hoffmann        "jpeg-turbo",
53918fb8faSGerd Hoffmann        "png",
54918fb8faSGerd Hoffmann
55918fb8faSGerd Hoffmann        # libs: ui
56918fb8faSGerd Hoffmann        "sdl2",
57918fb8faSGerd Hoffmann        "gtk3",
58918fb8faSGerd Hoffmann        "libxkbcommon",
59918fb8faSGerd Hoffmann
60918fb8faSGerd Hoffmann        # libs: opengl
61918fb8faSGerd Hoffmann        "libepoxy",
62918fb8faSGerd Hoffmann        "mesa-libs",
633a678481SJuan Quintela
643a678481SJuan Quintela        # libs: migration
653a678481SJuan Quintela        "zstd",
660026be1dSThomas Huth
670026be1dSThomas Huth        # libs: networking
680026be1dSThomas Huth        "libslirp",
698f4bcbcfSBrad Smith
708f4bcbcfSBrad Smith        # libs: sndio
718f4bcbcfSBrad Smith        "sndio",
72918fb8faSGerd Hoffmann    ]
73918fb8faSGerd Hoffmann
74111e30c0SFam Zheng    BUILD_SCRIPT = """
75111e30c0SFam Zheng        set -e;
76918fb8faSGerd Hoffmann        rm -rf /home/qemu/qemu-test.*
77918fb8faSGerd Hoffmann        cd $(mktemp -d /home/qemu/qemu-test.XXXXXX);
78918fb8faSGerd Hoffmann        mkdir src build; cd src;
79111e30c0SFam Zheng        tar -xf /dev/vtbd1;
80918fb8faSGerd Hoffmann        cd ../build
81*ec6fb1c8SThomas Huth        ../src/configure --python=python3.9 {configure_opts};
825c2ec9b6SAlex Bennée        gmake --output-sync -j{jobs} {target} {verbose};
83111e30c0SFam Zheng    """
84111e30c0SFam Zheng
85111e30c0SFam Zheng    def build_image(self, img):
86*ec6fb1c8SThomas Huth        self.print_step("Downloading disk image")
87918fb8faSGerd Hoffmann        cimg = self._download_with_cache(self.link, sha256sum=self.csum)
88*ec6fb1c8SThomas Huth        tmp_raw = img + ".tmp.raw"
89*ec6fb1c8SThomas Huth        tmp_raw_xz = tmp_raw + ".xz"
90*ec6fb1c8SThomas Huth        img_tmp = img + ".tmp.qcow2"
91918fb8faSGerd Hoffmann
92*ec6fb1c8SThomas Huth        self.print_step("Preparing disk image")
93*ec6fb1c8SThomas Huth        subprocess.check_call(["cp", "-f", cimg, tmp_raw_xz])
94*ec6fb1c8SThomas Huth        subprocess.check_call(["xz", "-dvf", tmp_raw_xz])
95*ec6fb1c8SThomas Huth        self.exec_qemu_img("convert", "-O", "qcow2", tmp_raw, img_tmp)
96*ec6fb1c8SThomas Huth        self.exec_qemu_img("resize", img_tmp, self.size)
97*ec6fb1c8SThomas Huth        os.remove(tmp_raw)
98918fb8faSGerd Hoffmann
99*ec6fb1c8SThomas Huth        self.print_step("Preparing disk image")
100918fb8faSGerd Hoffmann        self.boot(img_tmp, extra_args = [
101918fb8faSGerd Hoffmann            "-machine", "graphics=off",
102*ec6fb1c8SThomas Huth            "-vga", "none"
103918fb8faSGerd Hoffmann        ])
104918fb8faSGerd Hoffmann        self.console_init()
105*ec6fb1c8SThomas Huth        self.console_wait_send("login:", "root\n")
106*ec6fb1c8SThomas Huth        self.console_wait_send("~ #", "service growfs onestart\n")
107918fb8faSGerd Hoffmann
108*ec6fb1c8SThomas Huth        # root user
109*ec6fb1c8SThomas Huth        self.console_wait_send("~ #", "passwd\n")
110918fb8faSGerd Hoffmann        self.console_wait("New Password:")
111df001680SRobert Foley        self.console_send("%s\n" % self._config["root_pass"])
112918fb8faSGerd Hoffmann        self.console_wait("Retype New Password:")
113df001680SRobert Foley        self.console_send("%s\n" % self._config["root_pass"])
114918fb8faSGerd Hoffmann
115918fb8faSGerd Hoffmann        # qemu user
116*ec6fb1c8SThomas Huth        self.console_wait_send("~ #", "adduser\n")
117918fb8faSGerd Hoffmann        self.console_wait("Username")
118df001680SRobert Foley        self.console_send("%s\n" % self._config["guest_user"])
119918fb8faSGerd Hoffmann        self.console_wait("Full name")
120df001680SRobert Foley        self.console_send("%s\n" % self._config["guest_user"])
121918fb8faSGerd Hoffmann        self.console_wait_send("Uid",                   "\n")
122918fb8faSGerd Hoffmann        self.console_wait_send("Login group",           "\n")
123918fb8faSGerd Hoffmann        self.console_wait_send("Login group",           "\n")
124918fb8faSGerd Hoffmann        self.console_wait_send("Login class",           "\n")
125918fb8faSGerd Hoffmann        self.console_wait_send("Shell",                 "\n")
126918fb8faSGerd Hoffmann        self.console_wait_send("Home directory",        "\n")
127918fb8faSGerd Hoffmann        self.console_wait_send("Home directory perm",   "\n")
128918fb8faSGerd Hoffmann        self.console_wait_send("Use password",          "\n")
129918fb8faSGerd Hoffmann        self.console_wait_send("Use an empty password", "\n")
130918fb8faSGerd Hoffmann        self.console_wait_send("Use a random password", "\n")
131918fb8faSGerd Hoffmann        self.console_wait("Enter password:")
132df001680SRobert Foley        self.console_send("%s\n" % self._config["guest_pass"])
133918fb8faSGerd Hoffmann        self.console_wait("Enter password again:")
134df001680SRobert Foley        self.console_send("%s\n" % self._config["guest_pass"])
135918fb8faSGerd Hoffmann        self.console_wait_send("Lock out",              "\n")
136918fb8faSGerd Hoffmann        self.console_wait_send("OK",                    "yes\n")
137918fb8faSGerd Hoffmann        self.console_wait_send("Add another user",      "no\n")
138*ec6fb1c8SThomas Huth        self.console_wait_send("~ #", "exit\n")
139918fb8faSGerd Hoffmann
140918fb8faSGerd Hoffmann        # setup qemu user
141918fb8faSGerd Hoffmann        prompt = "$"
142df001680SRobert Foley        self.console_ssh_init(prompt, self._config["guest_user"], self._config["guest_pass"])
143918fb8faSGerd Hoffmann        self.console_wait_send(prompt, "exit\n")
144918fb8faSGerd Hoffmann
145918fb8faSGerd Hoffmann        # setup root user
146918fb8faSGerd Hoffmann        prompt = "root@freebsd:~ #"
147df001680SRobert Foley        self.console_ssh_init(prompt, "root", self._config["root_pass"])
148918fb8faSGerd Hoffmann        self.console_sshd_config(prompt)
149918fb8faSGerd Hoffmann
150918fb8faSGerd Hoffmann        # setup virtio-blk #1 (tarfile)
151918fb8faSGerd Hoffmann        self.console_wait(prompt)
152918fb8faSGerd Hoffmann        self.console_send("echo 'chmod 666 /dev/vtbd1' >> /etc/rc.local\n")
153918fb8faSGerd Hoffmann
154918fb8faSGerd Hoffmann        self.print_step("Installing packages")
155918fb8faSGerd Hoffmann        self.ssh_root_check("pkg install -y %s\n" % " ".join(self.pkgs))
156918fb8faSGerd Hoffmann
157918fb8faSGerd Hoffmann        # shutdown
158918fb8faSGerd Hoffmann        self.ssh_root(self.poweroff)
159918fb8faSGerd Hoffmann        self.wait()
160918fb8faSGerd Hoffmann
161918fb8faSGerd Hoffmann        if os.path.exists(img):
162918fb8faSGerd Hoffmann            os.remove(img)
163111e30c0SFam Zheng        os.rename(img_tmp, img)
164918fb8faSGerd Hoffmann        self.print_step("All done")
165111e30c0SFam Zheng
166111e30c0SFam Zhengif __name__ == "__main__":
167262fd273SWarner Losh    sys.exit(basevm.main(FreeBSDVM, config=FREEBSD_CONFIG))
168