#!/usr/bin/clitest
# Test services check
# Requirements:
# * installed: systemd, power-profile-daemon
# * RESTORE_DEVICE_STATE_ON_STARTUP, DEVICES_TO_DISABLE_ON_STARTUP, DEVICES_TO_ENABLE_ON_STARTUP not configured
# Copyright (c) 2023 Thomas Koch <linrunner at gmx.net>.
# SPDX-License-Identifier: GPL-2.0-or-later
#
$ # --- tlp.service
$ # prepare
$ sudo systemctl -q disable tlp.service
$ # test
$ sudo tlp start > /dev/null
Error: TLP's power saving will not apply on boot because tlp.service is not enabled --> Invoke 'systemctl enable tlp.service' to ensure the full functionality of TLP.

$ sudo tlp-stat -s > /dev/null
Error: TLP's power saving will not apply on boot because tlp.service is not enabled --> Invoke 'systemctl enable tlp.service' to ensure the full functionality of TLP.

$ # restore
$ sudo systemctl -q enable tlp.service
$ #
$ # --- systemd-rfkill.service/.socket
$ # prepare
$ sudo systemctl -q unmask systemd-rfkill.service
$ sudo systemctl -q unmask systemd-rfkill.socket
$ # test
$ sudo tlp start -- RESTORE_DEVICE_STATE_ON_STARTUP=1 > /dev/null
Warning: TLP's radio device switching on boot may not work as expected because RESTORE_DEVICE_STATE_ON_STARTUP=1 is configured and systemd-rfkill.service is not masked --> Invoke 'systemctl mask systemd-rfkill.service' to ensure the full functionality of TLP.

Warning: TLP's radio device switching on boot may not work as expected because RESTORE_DEVICE_STATE_ON_STARTUP=1 is configured and systemd-rfkill.socket is not masked --> Invoke 'systemctl mask systemd-rfkill.socket' to ensure the full functionality of TLP.

$ sudo tlp-stat -s -- RESTORE_DEVICE_STATE_ON_STARTUP=1 > /dev/null
Warning: TLP's radio device switching on boot may not work as expected because RESTORE_DEVICE_STATE_ON_STARTUP=1 is configured and systemd-rfkill.service is not masked --> Invoke 'systemctl mask systemd-rfkill.service' to ensure the full functionality of TLP.

Warning: TLP's radio device switching on boot may not work as expected because RESTORE_DEVICE_STATE_ON_STARTUP=1 is configured and systemd-rfkill.socket is not masked --> Invoke 'systemctl mask systemd-rfkill.socket' to ensure the full functionality of TLP.

$ sudo tlp-stat -s -- DEVICES_TO_ENABLE_ON_STARTUP="dummy" > /dev/null
Warning: TLP's radio device switching on boot may not work as expected because DEVICES_TO_DISABLE_ON_STARTUP or DEVICES_TO_ENABLE_ON_STARTUP is configured and systemd-rfkill.service is not masked --> Invoke 'systemctl mask systemd-rfkill.service' to ensure the full functionality of TLP.

Warning: TLP's radio device switching on boot may not work as expected because DEVICES_TO_DISABLE_ON_STARTUP or DEVICES_TO_ENABLE_ON_STARTUP is configured and systemd-rfkill.socket is not masked --> Invoke 'systemctl mask systemd-rfkill.socket' to ensure the full functionality of TLP.

$ sudo tlp-stat -s -- DEVICES_TO_DISABLE_ON_STARTUP="dummy" > /dev/null
Warning: TLP's radio device switching on boot may not work as expected because DEVICES_TO_DISABLE_ON_STARTUP or DEVICES_TO_ENABLE_ON_STARTUP is configured and systemd-rfkill.service is not masked --> Invoke 'systemctl mask systemd-rfkill.service' to ensure the full functionality of TLP.

Warning: TLP's radio device switching on boot may not work as expected because DEVICES_TO_DISABLE_ON_STARTUP or DEVICES_TO_ENABLE_ON_STARTUP is configured and systemd-rfkill.socket is not masked --> Invoke 'systemctl mask systemd-rfkill.socket' to ensure the full functionality of TLP.

$ # restore
$ sudo systemctl -q mask systemd-rfkill.service
$ sudo systemctl -q mask systemd-rfkill.socket
$ #
$ # --- power-profiles-daemon.service
$ # prepare
$ sudo systemctl -q unmask power-profiles-daemon.service
$ sudo systemctl -q start power-profiles-daemon.service
$ # test -- note: may fail partially depending on hardware
$ sudo tlp start > /dev/null
Warning: PLATFORM_PROFILE_ON_AC/BAT is not set because power-profiles-daemon is running.
Warning: CPU_ENERGY_PERF_POLICY_ON_AC/BAT is not set because power-profiles-daemon is running.
Warning: CPU_BOOST_ON_BAT/BAT is not set because power-profiles-daemon is running.
$ sudo tlp-stat -s > /dev/null
Warning: TLP's power saving will not apply on boot because the conflicting power-profiles-daemon.service is active --> Uninstall power-profiles-daemon or invoke 'systemctl mask power-profiles-daemon.service to ensure the full functionality of TLP.

$ # restore
$ sudo systemctl -q mask --now power-profiles-daemon.service
$ #
