-
Notifications
You must be signed in to change notification settings - Fork 77
add regulator test (New) #2016
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
Merged
Merged
add regulator test (New) #2016
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0f42de9
add regulator test
stanley31huang 693e494
fixed pep8 error
stanley31huang 2e4bd77
revised regulator tests
stanley31huang bc52e4a
revised the regulator test scripts
stanley31huang cc61c9f
revised regulator test scripts
stanley31huang f5a4ddc
add regulator test plan into ce-oem test plan
stanley31huang 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
240 changes: 240 additions & 0 deletions
240
contrib/checkbox-ce-oem/checkbox-provider-ce-oem/bin/regulator_test.py
This file contains hidden or 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,240 @@ | ||
| #!/usr/bin/env python3 | ||
| import sys | ||
| import logging | ||
| import argparse | ||
| import copy | ||
|
|
||
| from collections import Counter | ||
| from enum import Enum | ||
| from pathlib import Path | ||
|
|
||
|
|
||
| def init_logger(): | ||
| """ | ||
| Set the logger to log DEBUG and INFO to stdout, and | ||
| WARNING, ERROR, CRITICAL to stderr. | ||
| """ | ||
| root_logger = logging.getLogger() | ||
| root_logger.setLevel(logging.INFO) | ||
| logger_format = "%(message)s" | ||
|
|
||
| # Log DEBUG and INFO to stdout, others to stderr | ||
| stdout_handler = logging.StreamHandler(sys.stdout) | ||
| stdout_handler.setFormatter(logging.Formatter(logger_format)) | ||
|
|
||
| stderr_handler = logging.StreamHandler(sys.stderr) | ||
| stderr_handler.setFormatter(logging.Formatter(logger_format)) | ||
|
|
||
| stdout_handler.setLevel(logging.DEBUG) | ||
| stderr_handler.setLevel(logging.WARNING) | ||
|
|
||
| # Add a filter to the stdout handler to limit log records to | ||
| # INFO level and below | ||
| stdout_handler.addFilter(lambda record: record.levelno <= logging.INFO) | ||
|
|
||
| root_logger.addHandler(stderr_handler) | ||
| root_logger.addHandler(stdout_handler) | ||
|
|
||
| return root_logger | ||
|
|
||
|
|
||
| SYS_REGULATOR_PATH = "/sys/class/regulator" | ||
|
|
||
|
|
||
| class RegulatorTypeEnum(Enum): | ||
| VOLTAGE = "voltage" | ||
| CURRENT = "current" | ||
|
|
||
| def __str__(self): | ||
| return self.value | ||
|
|
||
|
|
||
| class RegulatorAttribute: | ||
|
|
||
| def __init__(self): | ||
| self.name = "name" | ||
| self.type = "type" | ||
|
|
||
|
|
||
| def read_node_text(node): | ||
| try: | ||
| value = node.read_text().strip() | ||
| except FileNotFoundError: | ||
| logging.error("'%s' does not exists", str(node)) | ||
| return None | ||
| except OSError as err: | ||
| logging.error( | ||
| "Unexpected error while accessing %s. %s", str(node), err | ||
| ) | ||
| return None | ||
|
|
||
| return value | ||
|
|
||
|
|
||
| class RegulatorBase: | ||
|
|
||
| def __init__(self, regulator_type): | ||
| self.regulator_type = regulator_type | ||
| self.raw_regulators = {} | ||
| self.regulators = {} | ||
| self.duplicated_regulators = [] | ||
|
|
||
| def collect_data(self, node): | ||
| regulator_attr = RegulatorAttribute() | ||
| rg_type_text = read_node_text(node.joinpath(regulator_attr.type)) | ||
| if not rg_type_text: | ||
| return None | ||
|
|
||
| try: | ||
| RegulatorTypeEnum(rg_type_text) | ||
| data = {} | ||
| for key in regulator_attr.__dict__: | ||
| value = read_node_text(node.joinpath(key)) | ||
| if value is not None: | ||
| data[key] = value | ||
| logging.info("%s: %s", key, value) | ||
|
|
||
| return data | ||
| except ValueError: | ||
| logging.error( | ||
| "Unexpected type for '%s' regulator: %s", | ||
| node.name, | ||
| rg_type_text, | ||
| ) | ||
|
|
||
| def dump_sysfs_regulator(self): | ||
| for rg_dev in sorted(Path(SYS_REGULATOR_PATH).glob("regulator*")): | ||
| logging.info("- %s", rg_dev.name) | ||
| data = self.collect_data(rg_dev) | ||
| if data: | ||
| self.raw_regulators[rg_dev.name] = data | ||
|
|
||
| def filter_regulators_by_type(self): | ||
| logging.info("\n# filtering %s regulator ..", self.regulator_type) | ||
| for dev in self.raw_regulators.values(): | ||
| if RegulatorTypeEnum(dev["type"]) != self.regulator_type: | ||
| logging.info("skip '%s' regulator", dev["name"]) | ||
| continue | ||
|
|
||
| rg = copy.deepcopy(dev) | ||
| key = rg.pop("name") | ||
| self.regulators[key] = rg | ||
|
|
||
| def has_duplicated_regulators(self): | ||
| logging.info("\n# checking duplicated regulators ..") | ||
| name_counts = Counter( | ||
| [attrs["name"] for attrs in self.raw_regulators.values()] | ||
| ) | ||
| result = { | ||
| node: attrs["name"] | ||
| for node, attrs in self.raw_regulators.items() | ||
| if name_counts[attrs["name"]] > 1 | ||
| } | ||
|
|
||
| if result: | ||
| logging.error("# Some regulators has the same name") | ||
| for node, name in result.items(): | ||
| logging.error("- node: %s, name: %s", node, name) | ||
| return True | ||
|
|
||
| return False | ||
|
|
||
| def is_regulator_available(self, name): | ||
| if name in self.regulators.keys(): | ||
| return True | ||
| logging.error("%s regulator not found", name) | ||
| return False | ||
|
|
||
| def is_regulator_attr_available(self, regulator, attr): | ||
| if attr in self.regulators[regulator].keys(): | ||
| return True | ||
| logging.error("%s attribute not exists", attr) | ||
| return False | ||
|
|
||
| def get_regulator_attr(self, regulator, attr): | ||
| return self.regulators[regulator][attr] | ||
|
|
||
|
|
||
| def summarize_test_results(details_logs): | ||
| logging.info("\n# Details Test Results") | ||
| for regulator, msgs in details_logs.items(): | ||
| log = "## '{}' regulator: ".format(regulator) | ||
| log += "Failed" if msgs else "Passed" | ||
| log += msgs | ||
| logging.info(log) | ||
|
|
||
|
|
||
| def check_difference(exp_regulators, sysfs_regulators): | ||
| logging.info("\n# comparing regulators ..") | ||
| test_results = {"result": False, "logs": {}} | ||
|
|
||
| for regulator in exp_regulators: | ||
| details = "" | ||
| if not sysfs_regulators.is_regulator_available(regulator): | ||
| details += "\n- regulator device not exists" | ||
| test_results["result"] = True | ||
| test_results["logs"][regulator] = details | ||
|
|
||
| return test_results | ||
|
|
||
|
|
||
| def compare_regulators(args): | ||
| type = args.type | ||
|
|
||
| exp_regulator_devs = args.devices.split("|") | ||
| if not exp_regulator_devs: | ||
| raise SystemExit("Invalid input argument for devices") | ||
|
|
||
| regulator = RegulatorBase(type) | ||
| regulator.dump_sysfs_regulator() | ||
| regulator.filter_regulators_by_type() | ||
| duplicated = regulator.has_duplicated_regulators() | ||
|
|
||
| results = check_difference(exp_regulator_devs, regulator) | ||
| summarize_test_results(results["logs"]) | ||
| if results["result"]: | ||
| logging.error( | ||
| "\nFailed: the expected %s regulators does not match", type | ||
| ) | ||
| else: | ||
| logging.info( | ||
| "\nPassed: the expected %s regulators are all available", type | ||
| ) | ||
|
|
||
| if duplicated or results["result"]: | ||
| raise SystemExit(1) | ||
|
|
||
|
|
||
| def register_arguments(): | ||
| parser = argparse.ArgumentParser( | ||
| description="Voltage Regulator detection Tests", | ||
| ) | ||
| parser.add_argument( | ||
| "devices", | ||
| type=str, | ||
| help=( | ||
| "provides expected regulator information with following format.\n" | ||
| "format: name|...\n" | ||
| " e.g. LO1|LO2" | ||
| ), | ||
| ) | ||
| parser.add_argument( | ||
| "-t", | ||
stanley31huang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "--type", | ||
| type=RegulatorTypeEnum, | ||
| choices=list(RegulatorTypeEnum), | ||
| help="the regulator type", | ||
| ) | ||
|
|
||
| args = parser.parse_args() | ||
| return args | ||
|
|
||
|
|
||
| def main(): | ||
| init_logger() | ||
| args = register_arguments() | ||
| compare_regulators(args) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
3 changes: 3 additions & 0 deletions
3
contrib/checkbox-ce-oem/checkbox-provider-ce-oem/units/regulator/category.pxu
This file contains hidden or 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,3 @@ | ||
| unit: category | ||
| id: regulator | ||
| _name: Regulator Device Test |
15 changes: 15 additions & 0 deletions
15
contrib/checkbox-ce-oem/checkbox-provider-ce-oem/units/regulator/jobs.pxu
This file contains hidden or 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,15 @@ | ||
| id: ce-oem-regulator/check-voltage-regulators | ||
| category_id: regulator | ||
| _summary: Verify the voltage regulators match regulators defined in VOLTAGE_REGULATORS VAR | ||
| _description: | ||
| Check the regulator name and voltage for the platform, relies on the user specifying the information of regualtor. | ||
| Usage of parameter: {name|name|...} | ||
| VOLTAGE_REGULATORS="LDO5|BUCK4" | ||
| plugin: shell | ||
| flags: also-after-suspend | ||
| estimated_duration: 5 | ||
| requires: manifest.has_voltage_regulator == 'True' | ||
| environ: VOLTAGE_REGULATORS | ||
| imports: from com.canonical.plainbox import manifest | ||
| command: | ||
| regulator_test.py --type voltage "$VOLTAGE_REGULATORS" |
4 changes: 4 additions & 0 deletions
4
contrib/checkbox-ce-oem/checkbox-provider-ce-oem/units/regulator/manifest.pxu
This file contains hidden or 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_voltage_regulator | ||
| _name: Does platfrom supported Voltage Regulator Device? | ||
| value-type: bool |
40 changes: 40 additions & 0 deletions
40
contrib/checkbox-ce-oem/checkbox-provider-ce-oem/units/regulator/test-plan.pxu
This file contains hidden or 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,40 @@ | ||
| id: ce-oem-regulaotr-full | ||
| unit: test plan | ||
| _name: Regulator tests | ||
| _description: Full Regulator tests for devices | ||
| include: | ||
| nested_part: | ||
| ce-oem-regulator-manual | ||
| ce-oem-regulator-automated | ||
| after-suspend-ce-oem-regulator-manual | ||
| after-suspend-ce-oem-regulator-automated | ||
|
|
||
|
|
||
| id: ce-oem-regulator-manual | ||
| unit: test plan | ||
| _name: Regulator manual tests | ||
| _description: Manual regulator tests for devices | ||
| include: | ||
|
|
||
|
|
||
| id: ce-oem-regulator-automated | ||
| unit: test plan | ||
| _name: Regulator auto tests | ||
| _description: Automated led tests for devices | ||
| include: | ||
| ce-oem-regulator/check-voltage-regulators | ||
|
|
||
|
|
||
| id: after-suspend-ce-oem-regulator-manual | ||
| unit: test plan | ||
| _name: Post suspend Regulator manual tests | ||
| _description: Manual Regulator tests for devices | ||
| include: | ||
|
|
||
|
|
||
| id: after-suspend-ce-oem-regulator-automated | ||
| unit: test plan | ||
| _name: Post suspend regulator auto tests | ||
| _description: Automated Regulator tests for devices | ||
| include: | ||
| after-suspend-ce-oem-regulator/check-voltage-regulators |
This file contains hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.