|
| 1 | +# OEQA runtime tests for vscode + vscode-weston-launcher. |
| 2 | +# |
| 3 | +# These are picked up by the `testimage` bbclass when this layer is |
| 4 | +# enabled and TEST_SUITES contains "vscode_launcher". They run against |
| 5 | +# a booted qemu image via ssh. |
| 6 | + |
| 7 | +import time |
| 8 | + |
| 9 | +from oeqa.runtime.case import OERuntimeTestCase |
| 10 | +from oeqa.core.decorator.depends import OETestDepends |
| 11 | + |
| 12 | + |
| 13 | +class VSCodeLauncherInstallTest(OERuntimeTestCase): |
| 14 | + """Validate the vscode-weston-launcher postinst actually ran on the |
| 15 | + target and the VSCode binary itself is in place.""" |
| 16 | + |
| 17 | + def test_weston_ini_has_launcher(self): |
| 18 | + # The postinst writes a sentinel-delimited [launcher] block |
| 19 | + # into weston.ini. If it isn't there the installer ran on a |
| 20 | + # target that didn't have /etc/xdg/weston/weston.ini yet (e.g. |
| 21 | + # weston-init wasn't installed before vscode-weston-launcher), |
| 22 | + # or the postinst failed silently. |
| 23 | + status, out = self.target.run( |
| 24 | + "grep meta-vscode-launcher-begin /etc/xdg/weston/weston.ini") |
| 25 | + self.assertEqual( |
| 26 | + status, 0, |
| 27 | + "vscode-weston-launcher postinst didn't insert its block " |
| 28 | + "into /etc/xdg/weston/weston.ini.\nOutput: %s" % out) |
| 29 | + |
| 30 | + def test_vscode_binary_is_executable(self): |
| 31 | + status, out = self.target.run( |
| 32 | + "test -x /usr/share/vscode/bin/code " |
| 33 | + "&& test -f /usr/share/vscode/resources/app/resources/linux/code.png") |
| 34 | + self.assertEqual( |
| 35 | + status, 0, |
| 36 | + "/usr/share/vscode/bin/code or the launcher icon are not " |
| 37 | + "present on the target.\nOutput: %s" % out) |
| 38 | + |
| 39 | + @OETestDepends([ |
| 40 | + 'vscode_launcher.VSCodeLauncherInstallTest.test_vscode_binary_is_executable', |
| 41 | + ]) |
| 42 | + def test_vscode_cli_version(self): |
| 43 | + # CLI mode doesn't initialise Electron; it just dlopens enough |
| 44 | + # of node to print the version triplet: |
| 45 | + # |
| 46 | + # 1.120.0 |
| 47 | + # 0958016b2af9f09bb4257e0df4a95e2f90590f9f |
| 48 | + # x64 |
| 49 | + # |
| 50 | + # This proves the binary's glibc / libstdc++ / libnss links |
| 51 | + # are all resolved on the target. |
| 52 | + status, out = self.target.run("/usr/share/vscode/bin/code --version") |
| 53 | + self.assertEqual(status, 0, |
| 54 | + "code --version exit=%d: %s" % (status, out)) |
| 55 | + lines = out.strip().splitlines() |
| 56 | + self.assertGreaterEqual( |
| 57 | + len(lines), 2, |
| 58 | + "Expected at least 2 lines from --version, got: %r" % out) |
| 59 | + |
| 60 | + |
| 61 | +class WestonStartedTest(OERuntimeTestCase): |
| 62 | + """Validate weston-init started Weston on boot.""" |
| 63 | + |
| 64 | + def test_weston_process_running(self): |
| 65 | + # weston-init is socket-activated via systemd and brings weston |
| 66 | + # up shortly after boot. Give it 30s to settle. |
| 67 | + deadline = time.time() + 30 |
| 68 | + while time.time() < deadline: |
| 69 | + status, _ = self.target.run("pgrep -x weston") |
| 70 | + if status == 0: |
| 71 | + return |
| 72 | + time.sleep(1) |
| 73 | + self.fail("Weston did not start within 30s of boot") |
| 74 | + |
| 75 | + @OETestDepends([ |
| 76 | + 'vscode_launcher.WestonStartedTest.test_weston_process_running', |
| 77 | + ]) |
| 78 | + def test_wayland_socket_present(self): |
| 79 | + # XDG_RUNTIME_DIR varies (root vs the weston user); look in |
| 80 | + # both well-known locations. |
| 81 | + status, out = self.target.run( |
| 82 | + "for d in /run/user/0 /run/user/1000; do " |
| 83 | + " [ -S \"$d/wayland-0\" ] && echo \"$d\" && exit 0; " |
| 84 | + "done; exit 1") |
| 85 | + self.assertEqual(status, 0, |
| 86 | + "No wayland-0 socket found on the target") |
| 87 | + |
| 88 | + |
| 89 | +class VSCodeWaylandLaunchTest(OERuntimeTestCase): |
| 90 | + """Validate VSCode can talk to Weston: launch the Electron app |
| 91 | + against the live Wayland socket, give it a few seconds to settle, |
| 92 | + and verify the process is still alive and has the wayland socket |
| 93 | + open.""" |
| 94 | + |
| 95 | + @OETestDepends([ |
| 96 | + 'vscode_launcher.VSCodeLauncherInstallTest.test_vscode_cli_version', |
| 97 | + 'vscode_launcher.WestonStartedTest.test_wayland_socket_present', |
| 98 | + ]) |
| 99 | + def test_vscode_starts_on_wayland(self): |
| 100 | + # Find weston's XDG_RUNTIME_DIR. |
| 101 | + status, runtime_dir = self.target.run( |
| 102 | + "for d in /run/user/0 /run/user/1000; do " |
| 103 | + " [ -S \"$d/wayland-0\" ] && echo \"$d\" && exit 0; " |
| 104 | + "done") |
| 105 | + self.assertEqual(status, 0) |
| 106 | + runtime_dir = runtime_dir.strip() |
| 107 | + self.assertTrue(runtime_dir, "no wayland-0 socket found") |
| 108 | + |
| 109 | + # Launch VSCode pointed at the Wayland socket. --no-sandbox |
| 110 | + # because the chromium sandbox needs CAP_SYS_ADMIN which the |
| 111 | + # test rootfs doesn't grant. user-data-dir and extensions-dir |
| 112 | + # under /tmp so the launch doesn't try to write into |
| 113 | + # ~/.config / ~/.vscode and trip permission errors. |
| 114 | + launch_cmd = ( |
| 115 | + "rm -rf /tmp/vscode-test* && " |
| 116 | + "env WAYLAND_DISPLAY=wayland-0 " |
| 117 | + " XDG_RUNTIME_DIR=%s " |
| 118 | + "/usr/share/vscode/bin/code " |
| 119 | + " --no-sandbox " |
| 120 | + " --user-data-dir=/tmp/vscode-test " |
| 121 | + " --extensions-dir=/tmp/vscode-test-ext " |
| 122 | + " >/tmp/vscode.log 2>&1 &" % runtime_dir) |
| 123 | + self.target.run(launch_cmd) |
| 124 | + |
| 125 | + # Electron/VSCode takes 10-15s to fully spin up under qemu. |
| 126 | + time.sleep(20) |
| 127 | + |
| 128 | + # Process still running? |
| 129 | + status, _ = self.target.run("pgrep -f 'vscode-test'") |
| 130 | + self.assertEqual( |
| 131 | + status, 0, |
| 132 | + "VSCode died within 20s of launch. Last log lines:\n%s" |
| 133 | + % self.target.run("tail -40 /tmp/vscode.log")[1]) |
| 134 | + |
| 135 | + # Has the wayland-0 socket open in its fd table? |
| 136 | + status, fd_list = self.target.run( |
| 137 | + "for pid in $(pgrep -f vscode-test); do " |
| 138 | + " ls -l /proc/$pid/fd 2>/dev/null | grep -F wayland-0 && exit 0; " |
| 139 | + "done; exit 1") |
| 140 | + self.assertEqual( |
| 141 | + status, 0, |
| 142 | + "No VSCode process has wayland-0 open. fd dump:\n%s" |
| 143 | + % fd_list) |
| 144 | + |
| 145 | + # Tidy up so subsequent test runs don't trip over each other. |
| 146 | + self.target.run("pkill -9 -f vscode-test || true") |
0 commit comments