1import os
2
3import infra.basetest
4
5GLXINFO_TIMEOUT = 120
6
7
8class TestGlxinfo(infra.basetest.BRTest):
9    config = \
10        """
11        BR2_x86_core2=y
12        BR2_TOOLCHAIN_EXTERNAL=y
13        BR2_TOOLCHAIN_EXTERNAL_BOOTLIN=y
14        BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_X86_CORE2_GLIBC_STABLE=y
15        BR2_LINUX_KERNEL=y
16        BR2_LINUX_KERNEL_CUSTOM_VERSION=y
17        BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="6.1.26"
18        BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y
19        BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="board/qemu/x86/linux.config"
20        BR2_PACKAGE_MESA3D_DEMOS=y
21        BR2_PACKAGE_MESA3D=y
22        BR2_PACKAGE_MESA3D_GALLIUM_DRIVER_SWRAST=y
23        BR2_PACKAGE_MESA3D_OPENGL_GLX=y
24        BR2_PACKAGE_XORG7=y
25        BR2_PACKAGE_XSERVER_XORG_SERVER=y
26        BR2_TARGET_GENERIC_GETTY_PORT="ttyS0"
27        BR2_TARGET_ROOTFS_EXT2=y
28        # BR2_TARGET_ROOTFS_TAR is not set
29        BR2_ROOTFS_OVERLAY="{}"
30        """.format(
31          infra.filepath("tests/package/test_glxinfo/rootfs-overlay"))
32
33    def wait_for_xserver(self):
34        # xserver takes some time to start up
35        # The test case fail here if for some reason xserver is not properly installed
36        _, _ = self.emulator.run('while [ ! -e /var/run/xorg.pid ]; do sleep 1; done', 120)
37
38    def login(self):
39        img = os.path.join(self.builddir, "images", "rootfs.ext2")
40        kern = os.path.join(self.builddir, "images", "bzImage")
41        # glxinfo overallocate memory and the minimum that seemed to work was 512MB
42        self.emulator.boot(arch="i386",
43                           kernel=kern,
44                           kernel_cmdline=["root=/dev/vda console=ttyS0"],
45                           options=["-M", "pc", "-cpu", "core2duo", "-m", "512",
46                                    "-drive", "file={},if=virtio,format=raw".format(img)])
47        self.emulator.login()
48
49    def test_run(self):
50        self.login()
51        self.wait_for_xserver()
52
53        # The test case verifies that the xserver with GLX is working
54        cmd = "glxinfo -B -display :0"
55        output, exit_code = self.emulator.run(cmd, GLXINFO_TIMEOUT)
56        self.assertEqual(exit_code, 0)
57        for line in output:
58            self.assertNotIn("Error", line)
59        # Error case: "Error: couldn't find RGB GLX visual or fbconfig"
60