From 7b2a5eb094839c33c77a0a8cd9853a3f0f87db67 Mon Sep 17 00:00:00 2001 From: hanhsuan Date: Thu, 21 Nov 2024 10:39:56 +0800 Subject: [PATCH 1/6] Add AMD specific automatic test plan and AMD PMF driver detector --- providers/base/bin/amd_pmf.py | 45 +++++++++++++ providers/base/tests/test_amd_pmf.py | 63 +++++++++++++++++++ .../base/units/power-management/jobs.pxu | 16 +++++ .../base/units/power-management/manifest.pxu | 5 ++ .../base/units/power-management/test-plan.pxu | 7 +++ 5 files changed, 136 insertions(+) create mode 100755 providers/base/bin/amd_pmf.py create mode 100644 providers/base/tests/test_amd_pmf.py create mode 100644 providers/base/units/power-management/manifest.pxu diff --git a/providers/base/bin/amd_pmf.py b/providers/base/bin/amd_pmf.py new file mode 100755 index 0000000000..5179986d5e --- /dev/null +++ b/providers/base/bin/amd_pmf.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python3 +# This file is part of Checkbox. +# +# Copyright 2024 Canonical Ltd. +# Written by: +# Hanhsuan Lee +# +# Checkbox is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 3, +# as published by the Free Software Foundation. +# +# Checkbox is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Checkbox. If not, see . + +import subprocess + + +class AMDPMF: + """ + This is a simple class to use lsmod to verify + amd pmf driver is loaded or not + """ + + def is_pmf_loaded(self): + cmd = ["lsmod"] + try: + output = subprocess.check_output( + cmd, + universal_newlines=True, + ) + if "amd_pmf" in output.lower(): + print("AMD PMF is loaded") + else: + raise SystemExit("AMD PMF isn't loaded") + except (subprocess.CalledProcessError, FileNotFoundError) as e: + raise SystemExit("running cmd:[{}] fail:{}".format(cmd, repr(e))) + + +if __name__ == "__main__": + AMDPMF().is_pmf_loaded() diff --git a/providers/base/tests/test_amd_pmf.py b/providers/base/tests/test_amd_pmf.py new file mode 100644 index 0000000000..b775cb5db6 --- /dev/null +++ b/providers/base/tests/test_amd_pmf.py @@ -0,0 +1,63 @@ +#!/usr/bin/env python3 +# Copyright 2024 Canonical Ltd. +# Written by: +# Hanhsuan Lee +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 3, +# as published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +from amd_pmf import * +from unittest.mock import patch +import unittest + + +class IsPMFLoadedTests(unittest.TestCase): + """ + This function should validate the amd_pmf is shown in the output + of lsmod + """ + + with_pmf_output = """ +Module Size Used by +amd_pmf 155648 0 +rfcomm 102400 4 +ccm 20480 9 +vhost_vsock 24576 0 + """ + + without_pmf_output = """ +Module Size Used by +tls 155648 0 +rfcomm 102400 4 +ccm 20480 9 +vhost_vsock 24576 0 + """ + + @patch("subprocess.check_output") + def test_succ(self, mock_output): + ap = AMDPMF() + mock_output.return_value = self.with_pmf_output + ap.is_pmf_loaded() + + @patch("subprocess.check_output") + def test_fail(self, mock_output): + ap = AMDPMF() + mock_output.return_value = self.without_pmf_output + with self.assertRaises(SystemExit): + ap.is_pmf_loaded() + + @patch("subprocess.check_output") + def test_command_fail(self, mock_output): + ap = AMDPMF() + mock_output.side_effect = FileNotFoundError + with self.assertRaises(SystemExit): + ap.is_pmf_loaded() diff --git a/providers/base/units/power-management/jobs.pxu b/providers/base/units/power-management/jobs.pxu index 06491543cd..fb6c5fb502 100644 --- a/providers/base/units/power-management/jobs.pxu +++ b/providers/base/units/power-management/jobs.pxu @@ -558,3 +558,19 @@ _verification: Did the Ambient Light Sensor values change when you _shook_ your hands over the sensor? Did the Screen backlight also change? _summary: Test the functionality of the Ambient Light Sensor by checking if sensor values and screen backlight change when covered. + +unit: job +plugin: shell +category_id: com.canonical.plainbox::power-management +id: power-management/amd_pmf_detect +flags: also-after-suspend +imports: from com.canonical.plainbox import manifest +requires: manifest.has_amd_pmf == 'True' +command: + amd_pmf.py +estimated_duration: 5s +summary: + Test this machine have the AMD PMF support or not +description: + The AMD PMF driver should be loaded while the BIOS enabling this function and could be validated by + the outcome of lsmod automatically. diff --git a/providers/base/units/power-management/manifest.pxu b/providers/base/units/power-management/manifest.pxu new file mode 100644 index 0000000000..ea69cc0bea --- /dev/null +++ b/providers/base/units/power-management/manifest.pxu @@ -0,0 +1,5 @@ +unit: manifest entry +id: has_amd_pmf +_name: AMD_PMF +_prompt: Does this machine have the AMD PMF support? +value-type: bool diff --git a/providers/base/units/power-management/test-plan.pxu b/providers/base/units/power-management/test-plan.pxu index 14aaab1a90..6d80aaef27 100644 --- a/providers/base/units/power-management/test-plan.pxu +++ b/providers/base/units/power-management/test-plan.pxu @@ -119,3 +119,10 @@ include: power-management/idle-screen-on-residency-check power-management/cpu-low-power-idle power-management/system-low-power-idle + +id: power-management-amd-specific-automated +unit: test plan +_name: AMD specific automated tests +_description: AMD specific automated tests for Ubuntu PC devices +include: + power-management/amd_pmf_detect From 53b658df768d333962ef9ee8877b377ded4de1d2 Mon Sep 17 00:00:00 2001 From: hanhsuan Date: Fri, 22 Nov 2024 10:28:52 +0800 Subject: [PATCH 2/6] change the prompt of manifest --- providers/base/units/power-management/manifest.pxu | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/providers/base/units/power-management/manifest.pxu b/providers/base/units/power-management/manifest.pxu index ea69cc0bea..eb36a91b5e 100644 --- a/providers/base/units/power-management/manifest.pxu +++ b/providers/base/units/power-management/manifest.pxu @@ -1,5 +1,5 @@ unit: manifest entry id: has_amd_pmf _name: AMD_PMF -_prompt: Does this machine have the AMD PMF support? +_prompt: Does this machine have the AMD PMF (Platform Management Framework) support? value-type: bool From 0c7e7afc352f349ac8e37e53a5b6428f31cac7e6 Mon Sep 17 00:00:00 2001 From: hanhsuan Date: Mon, 2 Dec 2024 08:21:03 +0800 Subject: [PATCH 3/6] add also after suspend test --- providers/base/units/power-management/test-plan.pxu | 1 + 1 file changed, 1 insertion(+) diff --git a/providers/base/units/power-management/test-plan.pxu b/providers/base/units/power-management/test-plan.pxu index 6d80aaef27..9200bb9eb7 100644 --- a/providers/base/units/power-management/test-plan.pxu +++ b/providers/base/units/power-management/test-plan.pxu @@ -126,3 +126,4 @@ _name: AMD specific automated tests _description: AMD specific automated tests for Ubuntu PC devices include: power-management/amd_pmf_detect + after-suspend-power-management/amd_pmf_detect From 6b7f159f7196f5b38de94c3aa4957cffd8b880eb Mon Sep 17 00:00:00 2001 From: hanhsuan <32028620+hanhsuan@users.noreply.github.com> Date: Fri, 20 Dec 2024 15:06:48 +0800 Subject: [PATCH 4/6] Update providers/base/units/power-management/jobs.pxu Co-authored-by: Pierre Equoy --- providers/base/units/power-management/jobs.pxu | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/providers/base/units/power-management/jobs.pxu b/providers/base/units/power-management/jobs.pxu index fb6c5fb502..0d839b931d 100644 --- a/providers/base/units/power-management/jobs.pxu +++ b/providers/base/units/power-management/jobs.pxu @@ -570,7 +570,7 @@ command: amd_pmf.py estimated_duration: 5s summary: - Test this machine have the AMD PMF support or not + Test this machine have the AMD Platform Management Framework support or not description: The AMD PMF driver should be loaded while the BIOS enabling this function and could be validated by the outcome of lsmod automatically. From 299a5e395e6c4507b85b15cb2e564d7aafe0e4d5 Mon Sep 17 00:00:00 2001 From: hanhsuan <32028620+hanhsuan@users.noreply.github.com> Date: Fri, 20 Dec 2024 15:07:15 +0800 Subject: [PATCH 5/6] Update providers/base/units/power-management/manifest.pxu Co-authored-by: Pierre Equoy --- providers/base/units/power-management/manifest.pxu | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/providers/base/units/power-management/manifest.pxu b/providers/base/units/power-management/manifest.pxu index eb36a91b5e..753a722510 100644 --- a/providers/base/units/power-management/manifest.pxu +++ b/providers/base/units/power-management/manifest.pxu @@ -1,5 +1,4 @@ unit: manifest entry id: has_amd_pmf -_name: AMD_PMF -_prompt: Does this machine have the AMD PMF (Platform Management Framework) support? +_name: AMD PMF (Platform Management Framework) support value-type: bool From 1600173154ef625358b596cc644b462efd8356db Mon Sep 17 00:00:00 2001 From: hanhsuan Date: Fri, 20 Dec 2024 15:08:08 +0800 Subject: [PATCH 6/6] 1. change the is_pmf_loaded to check_pmf_loaded 2. add and modify docstring 3. change the from amd_pmf to import amd_pmf --- providers/base/bin/amd_pmf.py | 17 +++++++++++------ providers/base/tests/test_amd_pmf.py | 19 ++++++++++--------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/providers/base/bin/amd_pmf.py b/providers/base/bin/amd_pmf.py index 5179986d5e..cc0241eebf 100755 --- a/providers/base/bin/amd_pmf.py +++ b/providers/base/bin/amd_pmf.py @@ -22,11 +22,14 @@ class AMDPMF: """ - This is a simple class to use lsmod to verify - amd pmf driver is loaded or not + This class is used to verify AMD Platform Management Framework """ - def is_pmf_loaded(self): + def check_pmf_loaded(self): + """ + This is a simple function to use lsmod to verify + AMD Platform Management Framework driver is loaded or not + """ cmd = ["lsmod"] try: output = subprocess.check_output( @@ -34,12 +37,14 @@ def is_pmf_loaded(self): universal_newlines=True, ) if "amd_pmf" in output.lower(): - print("AMD PMF is loaded") + print("AMD Platform Management Framework is loaded") else: - raise SystemExit("AMD PMF isn't loaded") + raise SystemExit( + "AMD Platform Management Framework isn't loaded" + ) except (subprocess.CalledProcessError, FileNotFoundError) as e: raise SystemExit("running cmd:[{}] fail:{}".format(cmd, repr(e))) if __name__ == "__main__": - AMDPMF().is_pmf_loaded() + AMDPMF().check_pmf_loaded() diff --git a/providers/base/tests/test_amd_pmf.py b/providers/base/tests/test_amd_pmf.py index b775cb5db6..eb74e43f0d 100644 --- a/providers/base/tests/test_amd_pmf.py +++ b/providers/base/tests/test_amd_pmf.py @@ -15,14 +15,14 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from amd_pmf import * from unittest.mock import patch import unittest +import amd_pmf -class IsPMFLoadedTests(unittest.TestCase): +class CheckPMFLoadedTests(unittest.TestCase): """ - This function should validate the amd_pmf is shown in the output + This function should validate that amd_pmf is shown in the output of lsmod """ @@ -44,20 +44,21 @@ class IsPMFLoadedTests(unittest.TestCase): @patch("subprocess.check_output") def test_succ(self, mock_output): - ap = AMDPMF() + ap = amd_pmf.AMDPMF() mock_output.return_value = self.with_pmf_output - ap.is_pmf_loaded() + ap.check_pmf_loaded() @patch("subprocess.check_output") def test_fail(self, mock_output): - ap = AMDPMF() + ap = amd_pmf.AMDPMF() mock_output.return_value = self.without_pmf_output with self.assertRaises(SystemExit): - ap.is_pmf_loaded() + ap.check_pmf_loaded() @patch("subprocess.check_output") def test_command_fail(self, mock_output): - ap = AMDPMF() + """Test outcome when `lsmod` command is not available""" + ap = amd_pmf.AMDPMF() mock_output.side_effect = FileNotFoundError with self.assertRaises(SystemExit): - ap.is_pmf_loaded() + ap.check_pmf_loaded()