Skip to content

Commit

Permalink
New test for checking systemd in WSL
Browse files Browse the repository at this point in the history
WSL now supports systemd, so there's need to check that we can enable and test it
  • Loading branch information
Pablo Herranz Ramírez committed Nov 22, 2023
1 parent 409ac33 commit 6086146
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
9 changes: 8 additions & 1 deletion schedule/wsl/wsl_main.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
---
name: wsl_main.yaml
name: wsl_main.yaml
description: >
WSL smoke test on Windows 10 image
conditional_schedule:
enable_systemd:
WSL_SYSTEMD:
'1':
- wsl/enable_systemd

schedule:
- wsl/boot_windows
- wsl/prepare_wsl
- wsl/install_wsl
- wsl/firstrun
- '{{enable_systemd}}'
- wsl/wsl_cmd_check
44 changes: 44 additions & 0 deletions tests/wsl/enable_systemd.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# SUSE's openQA tests
#
# Copyright 2012-2023 SUSE LLC
# SPDX-License-Identifier: FSFAP

# Summary: Configure WSL users
# Maintainer: qa-c <[email protected]>

use Mojo::Base qw(windowsbasetest);
use testapi;
use utils qw(enter_cmd_slow);
use version_utils qw(is_opensuse);
use wsl qw(is_fake_scc_url_needed);

sub run {
my $self = shift;

assert_screen(['windows_desktop', 'powershell-as-admin-window']);
$self->open_powershell_as_admin if match_has_tag('windows_desktop');
# In openSUSE the WSL shell is not root, so there's need to run become_root
# in order to write in the /etc/wsl.conf file
$self->run_in_powershell(
cmd => q(wsl),
code => sub {
become_root if (is_opensuse);
enter_cmd("ps 1 | grep '/init'");
enter_cmd("stat /init | grep 'init'");
enter_cmd("echo -e '[boot]\nsystemd=true' > /etc/wsl.conf");
wait_still_screen stilltime => 3, timeout => 10;
save_screenshot;
enter_cmd("exit");
# In openSUSE there's need to exit twice, one from the root and another
# one from the WSL
enter_cmd("exit") if (is_opensuse);
}
);
$self->run_in_powershell(cmd => q(wsl --shutdown));
$self->run_in_powershell(cmd => q(wsl /bin/bash -c "ps 1 | grep '/sbin/init'"));
$self->run_in_powershell(cmd => q(wsl /bin/bash -c "stat /sbin/init | grep 'systemd'"));
$self->run_in_powershell(cmd => q(wsl /bin/bash -c "systemctl list-unit-files --type=service | head -n 20"));
$self->run_in_powershell(cmd => q(wsl /bin/bash -c "exit"));
}

1;
5 changes: 5 additions & 0 deletions tests/wsl/prepare_wsl.pm
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ sub run {

$self->open_powershell_as_admin;

# These two commands disable notifications that Windows shows randomly and
# make our windows lose focus
$self->run_in_powershell(q(Set-ItemProperty -Path "HKCU:\Software\Policies\Microsoft\Windows\Explorer" -Name "DisableNotificationCenter" -Type DWord -Value 1));
$self->run_in_powershell(q(Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\PushNotifications" -Name "ToastEnabled" -Type DWord -Value 0));

$self->power_configuration if (is_aarch64);

if (get_var('WSL2')) {
Expand Down

0 comments on commit 6086146

Please sign in to comment.