summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/selftest/cases/runqemu.py
blob: cfeb22476916653426937defa3748705bfeea096 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#
# Copyright (c) 2017 Wind River Systems, Inc.
#

import re

from oeqa.selftest.case import OESelftestTestCase
from oeqa.utils.commands import bitbake, runqemu, get_bb_var
from oeqa.core.decorator.oeid import OETestID

class RunqemuTests(OESelftestTestCase):
    """Runqemu test class"""

    image_is_ready = False
    deploy_dir_image = ''
    # We only want to print runqemu stdout/stderr if there is a test case failure
    buffer = True

    def setUpLocal(self):
        super(RunqemuTests, self).setUpLocal()
        self.recipe = 'core-image-minimal'
        self.machine =  'qemux86-64'
        self.fstypes = "ext4 iso hddimg wic.vmdk wic.qcow2 wic.vdi"
        self.cmd_common = "runqemu nographic"

        self.write_config(
"""
MACHINE = "%s"
IMAGE_FSTYPES = "%s"
# 10 means 1 second
SYSLINUX_TIMEOUT = "10"
"""
% (self.machine, self.fstypes)
        )

        if not RunqemuTests.image_is_ready:
            RunqemuTests.deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE')
            bitbake(self.recipe)
            RunqemuTests.image_is_ready = True

    @OETestID(2001)
    def test_boot_machine(self):
        """Test runqemu machine"""
        cmd = "%s %s" % (self.cmd_common, self.machine)
        with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
            self.assertTrue(qemu.runner.logged, "Failed: %s" % cmd)

    @OETestID(2002)
    def test_boot_machine_ext4(self):
        """Test runqemu machine ext4"""
        cmd = "%s %s ext4" % (self.cmd_common, self.machine)
        with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
            with open(qemu.qemurunnerlog) as f:
                self.assertTrue('rootfs.ext4' in f.read(), "Failed: %s" % cmd)

    @OETestID(2003)
    def test_boot_machine_iso(self):
        """Test runqemu machine iso"""
        cmd = "%s %s iso" % (self.cmd_common, self.machine)
        with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
            with open(qemu.qemurunnerlog) as f:
                self.assertTrue('media=cdrom' in f.read(), "Failed: %s" % cmd)

    @OETestID(2004)
    def test_boot_recipe_image(self):
        """Test runqemu recipe-image"""
        cmd = "%s %s" % (self.cmd_common, self.recipe)
        with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
            self.assertTrue(qemu.runner.logged, "Failed: %s" % cmd)

    @OETestID(2005)
    def test_boot_recipe_image_vmdk(self):
        """Test runqemu recipe-image vmdk"""
        cmd = "%s %s wic.vmdk" % (self.cmd_common, self.recipe)
        with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
            with open(qemu.qemurunnerlog) as f:
                self.assertTrue('format=vmdk' in f.read(), "Failed: %s" % cmd)

    @OETestID(2006)
    def test_boot_recipe_image_vdi(self):
        """Test runqemu recipe-image vdi"""
        cmd = "%s %s wic.vdi" % (self.cmd_common, self.recipe)
        with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
            with open(qemu.qemurunnerlog) as f:
                self.assertTrue('format=vdi' in f.read(), "Failed: %s" % cmd)

    @OETestID(2007)
    def test_boot_deploy(self):
        """Test runqemu deploy_dir_image"""
        cmd = "%s %s" % (self.cmd_common, self.deploy_dir_image)
        with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
            self.assertTrue(qemu.runner.logged, "Failed: %s" % cmd)

    @OETestID(2008)
    def test_boot_deploy_hddimg(self):
        """Test runqemu deploy_dir_image hddimg"""
        cmd = "%s %s hddimg" % (self.cmd_common, self.deploy_dir_image)
        with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
            with open(qemu.qemurunnerlog) as f:
                self.assertTrue(re.search('file=.*.hddimg', f.read()), "Failed: %s" % cmd)

    @OETestID(2009)
    def test_boot_machine_slirp(self):
        """Test runqemu machine slirp"""
        cmd = "%s slirp %s" % (self.cmd_common, self.machine)
        with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
            with open(qemu.qemurunnerlog) as f:
                self.assertTrue(' -netdev user' in f.read(), "Failed: %s" % cmd)

    @OETestID(2009)
    def test_boot_machine_slirp_qcow2(self):
        """Test runqemu machine slirp qcow2"""
        cmd = "%s slirp wic.qcow2 %s" % (self.cmd_common, self.machine)
        with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
            with open(qemu.qemurunnerlog) as f:
                self.assertTrue('format=qcow2' in f.read(), "Failed: %s" % cmd)

    @OETestID(2010)
    def test_boot_qemu_boot(self):
        """Test runqemu /path/to/image.qemuboot.json"""
        qb_json = "%s-%s.qemuboot.json" % (self.recipe, self.machine)
        qb_json = os.path.join(self.deploy_dir_image, qb_json)
        if not os.path.exists(qb_json):
            self.skipTest("%s not found" % qb_json)
        cmd = "%s %s" % (self.cmd_common, qb_json)
        with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
            self.assertTrue(qemu.runner.logged, "Failed: %s" % cmd)

    @OETestID(2011)
    def test_boot_rootfs(self):
        """Test runqemu /path/to/rootfs.ext4"""
        rootfs = "%s-%s.ext4" % (self.recipe, self.machine)
        rootfs = os.path.join(self.deploy_dir_image, rootfs)
        if not os.path.exists(rootfs):
            self.skipTest("%s not found" % rootfs)
        cmd = "%s %s" % (self.cmd_common, rootfs)
        with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
            self.assertTrue(qemu.runner.logged, "Failed: %s" % cmd)