-
Notifications
You must be signed in to change notification settings - Fork 51
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
hanhsuan
wants to merge
6
commits into
canonical:main
Choose a base branch
from
hanhsuan:add_amd_pmf_install_validation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7b2a5eb
Add AMD specific automatic test plan and AMD PMF driver detector
hanhsuan 53b658d
change the prompt of manifest
hanhsuan 0c7e7af
add also after suspend test
hanhsuan 6b7f159
Update providers/base/units/power-management/jobs.pxu
hanhsuan 299a5e3
Update providers/base/units/power-management/manifest.pxu
hanhsuan 1600173
1. change the is_pmf_loaded to check_pmf_loaded
hanhsuan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | ||
""" | ||
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.