1#!/usr/bin/env python3
2#
3# Functional test that boots known good tuxboot images the same way
4# that tuxrun (www.tuxrun.org) does. This tool is used by things like
5# the LKFT project to run regression tests on kernels.
6#
7# Copyright (c) 2023 Linaro Ltd.
8#
9# Author:
10#  Alex Bennée <alex.bennee@linaro.org>
11#
12# SPDX-License-Identifier: GPL-2.0-or-later
13
14import tempfile
15
16from qemu_test import run_cmd, Asset
17from qemu_test.tuxruntest import TuxRunBaselineTest
18
19class TuxRunPPC64Test(TuxRunBaselineTest):
20
21    def ppc64_common_tuxrun(self, kernel_asset, rootfs_asset, prefix):
22        self.set_machine('pseries')
23        self.cpu='POWER10'
24        self.console='hvc0'
25        self.root='sda'
26        self.extradev='spapr-vscsi'
27        # add device args to command line.
28        self.require_netdev('user')
29        self.vm.add_args('-netdev', 'user,id=vnet,hostfwd=:127.0.0.1:0-:22',
30                         '-device', 'virtio-net,netdev=vnet')
31        self.vm.add_args('-netdev', '{"type":"user","id":"hostnet0"}',
32                         '-device', '{"driver":"virtio-net-pci","netdev":'
33                         '"hostnet0","id":"net0","mac":"52:54:00:4c:e3:86",'
34                         '"bus":"pci.0","addr":"0x9"}')
35        self.vm.add_args('-device', '{"driver":"qemu-xhci","p2":15,"p3":15,'
36                         '"id":"usb","bus":"pci.0","addr":"0x2"}')
37        self.vm.add_args('-device', '{"driver":"virtio-scsi-pci","id":"scsi0"'
38                         ',"bus":"pci.0","addr":"0x3"}')
39        self.vm.add_args('-device', '{"driver":"virtio-serial-pci","id":'
40                         '"virtio-serial0","bus":"pci.0","addr":"0x4"}')
41        self.vm.add_args('-device', '{"driver":"scsi-cd","bus":"scsi0.0"'
42                         ',"channel":0,"scsi-id":0,"lun":0,"device_id":'
43                         '"drive-scsi0-0-0-0","id":"scsi0-0-0-0"}')
44        self.vm.add_args('-device', '{"driver":"virtio-balloon-pci",'
45                         '"id":"balloon0","bus":"pci.0","addr":"0x6"}')
46        self.vm.add_args('-audiodev', '{"id":"audio1","driver":"none"}')
47        self.vm.add_args('-device', '{"driver":"usb-tablet","id":"input0"'
48                         ',"bus":"usb.0","port":"1"}')
49        self.vm.add_args('-device', '{"driver":"usb-kbd","id":"input1"'
50                         ',"bus":"usb.0","port":"2"}')
51        self.vm.add_args('-device', '{"driver":"VGA","id":"video0",'
52                         '"vgamem_mb":16,"bus":"pci.0","addr":"0x7"}')
53        self.vm.add_args('-object', '{"qom-type":"rng-random","id":"objrng0"'
54                         ',"filename":"/dev/urandom"}',
55                         '-device', '{"driver":"virtio-rng-pci","rng":"objrng0"'
56                         ',"id":"rng0","bus":"pci.0","addr":"0x8"}')
57        self.vm.add_args('-object', '{"qom-type":"cryptodev-backend-builtin",'
58                         '"id":"objcrypto0","queues":1}',
59                         '-device', '{"driver":"virtio-crypto-pci",'
60                         '"cryptodev":"objcrypto0","id":"crypto0","bus"'
61                         ':"pci.0","addr":"0xa"}')
62        self.vm.add_args('-device', '{"driver":"spapr-pci-host-bridge"'
63                         ',"index":1,"id":"pci.1"}')
64        self.vm.add_args('-device', '{"driver":"spapr-vscsi","id":"scsi1"'
65                         ',"reg":12288}')
66        self.vm.add_args('-m', '2G,slots=32,maxmem=4G',
67                         '-object', 'memory-backend-ram,id=ram1,size=1G',
68                         '-device', 'pc-dimm,id=dimm1,memdev=ram1')
69
70        # Create a temporary qcow2 and launch the test-case
71        with tempfile.NamedTemporaryFile(prefix=prefix,
72                                         suffix='.qcow2') as qcow2:
73            run_cmd([self.qemu_img, 'create', '-f', 'qcow2', qcow2.name, ' 1G'])
74
75            self.vm.add_args('-drive', 'file=' + qcow2.name +
76                         ',format=qcow2,if=none,id='
77                         'drive-virtio-disk1',
78                         '-device', 'virtio-blk-pci,bus=pci.0,'
79                         'addr=0xb,drive=drive-virtio-disk1,id=virtio-disk1'
80                         ',bootindex=2')
81            self.common_tuxrun(kernel_asset, rootfs_asset=rootfs_asset,
82                               drive="scsi-hd")
83
84    ASSET_PPC64_KERNEL = Asset(
85        'https://storage.tuxboot.com/20230331/ppc64/vmlinux',
86        '1d953e81a4379e537fc8e41e05a0a59d9b453eef97aa03d47866c6c45b00bdff')
87    ASSET_PPC64_ROOTFS = Asset(
88        'https://storage.tuxboot.com/20230331/ppc64/rootfs.ext4.zst',
89        'f22a9b9e924174a4c199f4c7e5d91a2339fcfe51c6eafd0907dc3e09b64ab728')
90
91    def test_ppc64(self):
92        self.ppc64_common_tuxrun(kernel_asset=self.ASSET_PPC64_KERNEL,
93                                 rootfs_asset=self.ASSET_PPC64_ROOTFS,
94                                 prefix='tuxrun_ppc64_')
95
96    ASSET_PPC64LE_KERNEL = Asset(
97        'https://storage.tuxboot.com/20230331/ppc64le/vmlinux',
98        '979eb61b445a010fb13e2b927126991f8ceef9c590fa2be0996c00e293e80cf2')
99    ASSET_PPC64LE_ROOTFS = Asset(
100        'https://storage.tuxboot.com/20230331/ppc64le/rootfs.ext4.zst',
101        'b442678c93fb8abe1f7d3bfa20556488de6b475c22c8fed363f42cf81a0a3906')
102
103    def test_ppc64le(self):
104        self.ppc64_common_tuxrun(kernel_asset=self.ASSET_PPC64LE_KERNEL,
105                                 rootfs_asset=self.ASSET_PPC64LE_ROOTFS,
106                                 prefix='tuxrun_ppc64le_')
107
108
109if __name__ == '__main__':
110    TuxRunBaselineTest.main()
111