1*4882a593Smuzhiyun# 2*4882a593Smuzhiyun# SPDX-License-Identifier: MIT 3*4882a593Smuzhiyun# 4*4882a593Smuzhiyun 5*4882a593Smuzhiyunfrom oeqa.runtime.case import OERuntimeTestCase 6*4882a593Smuzhiyunfrom oeqa.core.decorator.depends import OETestDepends 7*4882a593Smuzhiyunfrom oeqa.core.decorator.data import skipIfNotFeature 8*4882a593Smuzhiyunfrom oeqa.runtime.decorator.package import OEHasPackage 9*4882a593Smuzhiyunimport threading 10*4882a593Smuzhiyunimport time 11*4882a593Smuzhiyun 12*4882a593Smuzhiyunclass WestonTest(OERuntimeTestCase): 13*4882a593Smuzhiyun weston_log_file = '/tmp/weston-2.log' 14*4882a593Smuzhiyun 15*4882a593Smuzhiyun @classmethod 16*4882a593Smuzhiyun def tearDownClass(cls): 17*4882a593Smuzhiyun cls.tc.target.run('rm %s' % cls.weston_log_file) 18*4882a593Smuzhiyun 19*4882a593Smuzhiyun @OETestDepends(['ssh.SSHTest.test_ssh']) 20*4882a593Smuzhiyun @OEHasPackage(['weston']) 21*4882a593Smuzhiyun def test_weston_running(self): 22*4882a593Smuzhiyun cmd ='%s | grep [w]eston-desktop-shell' % self.tc.target_cmds['ps'] 23*4882a593Smuzhiyun status, output = self.target.run(cmd) 24*4882a593Smuzhiyun msg = ('Weston does not appear to be running %s' % 25*4882a593Smuzhiyun self.target.run(self.tc.target_cmds['ps'])[1]) 26*4882a593Smuzhiyun self.assertEqual(status, 0, msg=msg) 27*4882a593Smuzhiyun 28*4882a593Smuzhiyun def get_processes_of(self, target, error_msg): 29*4882a593Smuzhiyun status, output = self.target.run('pidof %s' % target) 30*4882a593Smuzhiyun self.assertEqual(status, 0, msg='Retrieve %s (%s) processes error: %s' % (target, error_msg, output)) 31*4882a593Smuzhiyun return output.split(" ") 32*4882a593Smuzhiyun 33*4882a593Smuzhiyun def get_weston_command(self, cmd): 34*4882a593Smuzhiyun return 'export XDG_RUNTIME_DIR=/run/user/`id -u weston`; export WAYLAND_DISPLAY=wayland-1; %s' % cmd 35*4882a593Smuzhiyun 36*4882a593Smuzhiyun def run_weston_init(self): 37*4882a593Smuzhiyun if 'systemd' in self.tc.td['VIRTUAL-RUNTIME_init_manager']: 38*4882a593Smuzhiyun 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) 39*4882a593Smuzhiyun else: 40*4882a593Smuzhiyun self.target.run(self.get_weston_command('openvt -- weston --socket=wayland-2 --log=%s' % self.weston_log_file)) 41*4882a593Smuzhiyun 42*4882a593Smuzhiyun def get_new_wayland_processes(self, existing_wl_processes): 43*4882a593Smuzhiyun try_cnt = 0 44*4882a593Smuzhiyun while try_cnt < 5: 45*4882a593Smuzhiyun time.sleep(5 + 5*try_cnt) 46*4882a593Smuzhiyun try_cnt += 1 47*4882a593Smuzhiyun wl_processes = self.get_processes_of('weston-desktop-shell', 'existing and new') 48*4882a593Smuzhiyun new_wl_processes = [x for x in wl_processes if x not in existing_wl_processes] 49*4882a593Smuzhiyun if new_wl_processes: 50*4882a593Smuzhiyun return new_wl_processes, try_cnt 51*4882a593Smuzhiyun 52*4882a593Smuzhiyun return new_wl_processes, try_cnt 53*4882a593Smuzhiyun 54*4882a593Smuzhiyun @OEHasPackage(['wayland-utils']) 55*4882a593Smuzhiyun def test_wayland_info(self): 56*4882a593Smuzhiyun if 'systemd' in self.tc.td['VIRTUAL-RUNTIME_init_manager']: 57*4882a593Smuzhiyun command = 'XDG_RUNTIME_DIR=/run wayland-info' 58*4882a593Smuzhiyun else: 59*4882a593Smuzhiyun command = self.get_weston_command('wayland-info') 60*4882a593Smuzhiyun status, output = self.target.run(command) 61*4882a593Smuzhiyun self.assertEqual(status, 0, msg='wayland-info error: %s' % output) 62*4882a593Smuzhiyun 63*4882a593Smuzhiyun @OEHasPackage(['weston']) 64*4882a593Smuzhiyun def test_weston_can_initialize_new_wayland_compositor(self): 65*4882a593Smuzhiyun existing_wl_processes = self.get_processes_of('weston-desktop-shell', 'existing') 66*4882a593Smuzhiyun existing_weston_processes = self.get_processes_of('weston', 'existing') 67*4882a593Smuzhiyun 68*4882a593Smuzhiyun weston_thread = threading.Thread(target=self.run_weston_init) 69*4882a593Smuzhiyun weston_thread.start() 70*4882a593Smuzhiyun new_wl_processes, try_cnt = self.get_new_wayland_processes(existing_wl_processes) 71*4882a593Smuzhiyun existing_and_new_weston_processes = self.get_processes_of('weston', 'existing and new') 72*4882a593Smuzhiyun new_weston_processes = [x for x in existing_and_new_weston_processes if x not in existing_weston_processes] 73*4882a593Smuzhiyun if 'systemd' in self.tc.td['VIRTUAL-RUNTIME_init_manager']: 74*4882a593Smuzhiyun self.target.run('systemctl stop weston-ptest.service') 75*4882a593Smuzhiyun else: 76*4882a593Smuzhiyun for w in new_weston_processes: 77*4882a593Smuzhiyun self.target.run('kill -9 %s' % w) 78*4882a593Smuzhiyun __, weston_log = self.target.run('cat %s' % self.weston_log_file) 79*4882a593Smuzhiyun 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)) 80