Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AMD PMF driver loading validation (New) #1620

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions providers/base/bin/amd_pmf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env python3
# This file is part of Checkbox.
#
# Copyright 2024 Canonical Ltd.
# Written by:
# Hanhsuan Lee <hanhsuan.lee@canonical.com>
#
# 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 <http://www.gnu.org/licenses/>.

import subprocess


class AMDPMF:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is a class necessary here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that there will be more test cases for AMD PMF driver. Therefore, I would like to use class to make it could add more function.

"""
This class is used to verify AMD Platform Management Framework
"""

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(
cmd,
universal_newlines=True,
)
if "amd_pmf" in output.lower():
print("AMD Platform Management Framework is loaded")
else:
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().check_pmf_loaded()
64 changes: 64 additions & 0 deletions providers/base/tests/test_amd_pmf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env python3
# Copyright 2024 Canonical Ltd.
# Written by:
# Hanhsuan Lee <hanhsuan.lee@canonical.com>
#
# 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 <http://www.gnu.org/licenses/>.

from unittest.mock import patch
import unittest
import amd_pmf


class CheckPMFLoadedTests(unittest.TestCase):
"""
This function should validate that 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 = amd_pmf.AMDPMF()
mock_output.return_value = self.with_pmf_output
ap.check_pmf_loaded()

@patch("subprocess.check_output")
def test_fail(self, mock_output):
ap = amd_pmf.AMDPMF()
mock_output.return_value = self.without_pmf_output
with self.assertRaises(SystemExit):
ap.check_pmf_loaded()

@patch("subprocess.check_output")
def test_command_fail(self, mock_output):
hanhsuan marked this conversation as resolved.
Show resolved Hide resolved
"""Test outcome when `lsmod` command is not available"""
ap = amd_pmf.AMDPMF()
mock_output.side_effect = FileNotFoundError
with self.assertRaises(SystemExit):
ap.check_pmf_loaded()
16 changes: 16 additions & 0 deletions providers/base/units/power-management/jobs.pxu
Original file line number Diff line number Diff line change
Expand Up @@ -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 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.
4 changes: 4 additions & 0 deletions providers/base/units/power-management/manifest.pxu
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
unit: manifest entry
id: has_amd_pmf
_name: AMD PMF (Platform Management Framework) support
value-type: bool
8 changes: 8 additions & 0 deletions providers/base/units/power-management/test-plan.pxu
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,11 @@ 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
after-suspend-power-management/amd_pmf_detect
Loading