Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 1 | # |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 2 | # Copyright OpenEmbedded Contributors |
| 3 | # |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 4 | # SPDX-License-Identifier: MIT |
| 5 | # |
| 6 | |
| 7 | from oeqa.runtime.case import OERuntimeTestCase |
| 8 | from oeqa.core.decorator.depends import OETestDepends |
| 9 | from oeqa.core.decorator.data import skipIfNotFeature |
| 10 | from oeqa.runtime.decorator.package import OEHasPackage |
| 11 | import threading |
| 12 | import time |
| 13 | |
| 14 | class WestonTest(OERuntimeTestCase): |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 15 | weston_log_file = '/tmp/weston-2.log' |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 16 | |
| 17 | @classmethod |
| 18 | def tearDownClass(cls): |
| 19 | cls.tc.target.run('rm %s' % cls.weston_log_file) |
| 20 | |
| 21 | @OETestDepends(['ssh.SSHTest.test_ssh']) |
| 22 | @OEHasPackage(['weston']) |
| 23 | def test_weston_running(self): |
| 24 | cmd ='%s | grep [w]eston-desktop-shell' % self.tc.target_cmds['ps'] |
| 25 | status, output = self.target.run(cmd) |
| 26 | msg = ('Weston does not appear to be running %s' % |
| 27 | self.target.run(self.tc.target_cmds['ps'])[1]) |
| 28 | self.assertEqual(status, 0, msg=msg) |
| 29 | |
| 30 | def get_processes_of(self, target, error_msg): |
| 31 | status, output = self.target.run('pidof %s' % target) |
| 32 | self.assertEqual(status, 0, msg='Retrieve %s (%s) processes error: %s' % (target, error_msg, output)) |
| 33 | return output.split(" ") |
| 34 | |
| 35 | def get_weston_command(self, cmd): |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 36 | return 'export XDG_RUNTIME_DIR=/run/user/`id -u weston`; export WAYLAND_DISPLAY=wayland-1; %s' % cmd |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 37 | |
| 38 | def run_weston_init(self): |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 39 | if 'systemd' in self.tc.td['VIRTUAL-RUNTIME_init_manager']: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 40 | self.target.run('systemd-run --collect --unit=weston-ptest.service --uid=0 -p PAMName=login -p TTYPath=/dev/tty6 -E XDG_RUNTIME_DIR=/tmp -E WAYLAND_DISPLAY=wayland-0 /usr/bin/weston --socket=wayland-1 --log=%s' % self.weston_log_file) |
| 41 | else: |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 42 | self.target.run(self.get_weston_command('openvt -- weston --socket=wayland-2 --log=%s' % self.weston_log_file)) |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 43 | |
| 44 | def get_new_wayland_processes(self, existing_wl_processes): |
| 45 | try_cnt = 0 |
| 46 | while try_cnt < 5: |
| 47 | time.sleep(5 + 5*try_cnt) |
| 48 | try_cnt += 1 |
| 49 | wl_processes = self.get_processes_of('weston-desktop-shell', 'existing and new') |
| 50 | new_wl_processes = [x for x in wl_processes if x not in existing_wl_processes] |
| 51 | if new_wl_processes: |
| 52 | return new_wl_processes, try_cnt |
| 53 | |
| 54 | return new_wl_processes, try_cnt |
| 55 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 56 | @OEHasPackage(['wayland-utils']) |
| 57 | def test_wayland_info(self): |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 58 | if 'systemd' in self.tc.td['VIRTUAL-RUNTIME_init_manager']: |
| 59 | command = 'XDG_RUNTIME_DIR=/run wayland-info' |
| 60 | else: |
| 61 | command = self.get_weston_command('wayland-info') |
| 62 | status, output = self.target.run(command) |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 63 | self.assertEqual(status, 0, msg='wayland-info error: %s' % output) |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 64 | |
| 65 | @OEHasPackage(['weston']) |
| 66 | def test_weston_can_initialize_new_wayland_compositor(self): |
| 67 | existing_wl_processes = self.get_processes_of('weston-desktop-shell', 'existing') |
| 68 | existing_weston_processes = self.get_processes_of('weston', 'existing') |
| 69 | |
| 70 | weston_thread = threading.Thread(target=self.run_weston_init) |
| 71 | weston_thread.start() |
| 72 | new_wl_processes, try_cnt = self.get_new_wayland_processes(existing_wl_processes) |
| 73 | existing_and_new_weston_processes = self.get_processes_of('weston', 'existing and new') |
| 74 | new_weston_processes = [x for x in existing_and_new_weston_processes if x not in existing_weston_processes] |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 75 | if 'systemd' in self.tc.td['VIRTUAL-RUNTIME_init_manager']: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 76 | self.target.run('systemctl stop weston-ptest.service') |
| 77 | else: |
| 78 | for w in new_weston_processes: |
| 79 | self.target.run('kill -9 %s' % w) |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 80 | __, weston_log = self.target.run('cat %s' % self.weston_log_file) |
| 81 | self.assertTrue(new_wl_processes, msg='Could not get new weston-desktop-shell processes (%s, try_cnt:%s) weston log: %s' % (new_wl_processes, try_cnt, weston_log)) |
Andrew Geissler | 615f2f1 | 2022-07-15 14:00:58 -0500 | [diff] [blame] | 82 | |
| 83 | @skipIfNotFeature('x11', 'Test requires x11 to be in DISTRO_FEATURES') |
| 84 | @OEHasPackage(['weston']) |
| 85 | def test_weston_supports_xwayland(self): |
| 86 | cmd ='cat %s | grep "xserver listening on display"' % self.weston_log_file |
| 87 | status, output = self.target.run(cmd) |
| 88 | msg = ('xwayland does not appear to be running') |
| 89 | self.assertEqual(status, 0, msg=msg) |