1import os 2 3import infra.basetest 4 5 6class TestWine(infra.basetest.BRTest): 7 # Wine depends on i386 architecture. The pre-build runtime test 8 # Kernel (for armv5) cannot be used. The config also uses a ext4 9 # rootfs due to the larger Wine footprint. We also enable NLS, 10 # which is required for cmd.exe shell to work. 11 config = \ 12 """ 13 BR2_i386=y 14 BR2_x86_pentium4=y 15 BR2_TOOLCHAIN_EXTERNAL=y 16 BR2_LINUX_KERNEL=y 17 BR2_LINUX_KERNEL_CUSTOM_VERSION=y 18 BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="6.6.27" 19 BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y 20 BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="board/qemu/x86/linux.config" 21 BR2_LINUX_KERNEL_NEEDS_HOST_OPENSSL=y 22 BR2_LINUX_KERNEL_NEEDS_HOST_LIBELF=y 23 BR2_PACKAGE_WINE=y 24 BR2_SYSTEM_ENABLE_NLS=y 25 BR2_TARGET_ROOTFS_EXT2=y 26 BR2_TARGET_ROOTFS_EXT2_4=y 27 BR2_TARGET_ROOTFS_EXT2_SIZE="256M" 28 # BR2_TARGET_ROOTFS_TAR is not set 29 """ 30 31 def test_run(self): 32 drive = os.path.join(self.builddir, "images", "rootfs.ext4") 33 kern = os.path.join(self.builddir, "images", "bzImage") 34 self.emulator.boot(arch="i386", 35 kernel=kern, 36 kernel_cmdline=["root=/dev/vda console=ttyS0"], 37 options=["-M", "pc", "-m", "256M", 38 "-drive", f"file={drive},if=virtio,format=raw"]) 39 self.emulator.login() 40 41 # Check the program can run. 42 self.assertRunOk("wine --version") 43 44 # Remove the Wine directory to make this test idempotent. This 45 # is because we use a persistent storage. This is useful only 46 # when the run-tests script is used with the "-k" option. 47 self.assertRunOk("rm -rf ~/.wine") 48 49 # Wine usually prints lots of debug messages. We disable all 50 # logs for this test. For debugging, this line can be 51 # commented, or extra log can also be added. "WINEDEBUG=+all" 52 # enable all logs and generates a lot of messages. 53 # See: https://wiki.winehq.org/Debug_Channels 54 self.assertRunOk("export WINEDEBUG=-all") 55 56 # We force the initialization of the WINEPREFIX 57 # directory. This operation can take some time. This will make 58 # subsequent wine invocation execution time more stable. 59 self.assertRunOk("wineboot --init", timeout=45) 60 61 # We check we can list files in the Windows OS directory. 62 cmd = "wine cmd.exe /C 'DIR C:\\WINDOWS\\'" 63 self.assertRunOk(cmd, timeout=10) 64 65 # We check we can read a Windows OS specific environment 66 # variable. We use "assertIn" rather than "assertEqual" 67 # because the cmd.exe shell write extra control characters. 68 cmd = "wine cmd.exe /C 'ECHO %OS%'" 69 out, ret = self.emulator.run(cmd, timeout=10) 70 self.assertEqual(ret, 0) 71 self.assertIn("Windows_NT", out[0]) 72 73 # We check we can print an arbitrary string with the 74 # cmd.exe shell. 75 string = "Hello Buildroot !" 76 cmd = f"wine cmd.exe /C 'ECHO {string}'" 77 out, ret = self.emulator.run(cmd, timeout=10) 78 self.assertEqual(ret, 0) 79 self.assertIn(string, out[0]) 80 81 # We check the VER command reports a Windows OS version. 82 cmd = "wine cmd.exe /C 'VER'" 83 out, ret = self.emulator.run(cmd, timeout=10) 84 self.assertEqual(ret, 0) 85 self.assertIn("Microsoft Windows", "\n".join(out)) 86 87 # We run the ping.exe command. 88 self.assertRunOk("wine ping.exe 127.0.0.1", timeout=10) 89