factory: A better way to define system component sysfs path. |
||||
Issue description
Currently we have lots of pytests taking Arg to decide which (sysfs) path to work on. And there's no recommended format. For example, removable_storage uses a dict for type c or a / left or right / which port. Some sensors use glob pattern. Some others use a list of RE expressions for "best match". Also, many BFT-aware tests have a complicated bft_fixture dict arg.
One way to manage them is to always provide that in Device API. However, this implies we have to write lots of Python code and creating sub classes. Also, it seems more flexible if the pytest can work with arbitrary target path if needed.
As a result, one proposal is to create a config dedicated for storing "mapping from components to system path", for example 'components.json' that:
{
"light_sensor": "/sys/class/light_sensor/*",
"usb": {
"left": {
"0": "/sys/class/usb/usb-1/1.0",
}
"right": {
}
}
"usb_c": {
"left": {
"0": "/sys/class/usb/usb-1/1.0",
}
}
}
And in Device API, provide a new top level function
def GetComponentPath(name, *args):
cfg = config_utils.LoadConfig('component')
result = cfg.get(name, {})
for subkey in args:
result = result.get(subkey, {})
return result
So in pytest, we always define arg
Arg('component_name', str, 'The name of target component to test')
And in runTest:
target_path = self.dut.GetComponentPath(self.args.component_name)
print('sys node: %s' % target_path)
,
Sep 7
,
Sep 7
,
Sep 8
I consulted youcheng and he said we don't need this. Some paths are dynamic and if we can't define path first in this case(or maybe should also use regex). And also this will leads to more files comparing to define paths in respective tests.
,
Sep 8
Thanks. I think one motivation background is we're wondering if this can simplify and generalize test list, to make it easier for partners to share same test list file with individual component configs. If youcheng things this is not needed, I'm fine to archive this until we need it again. |
||||
►
Sign in to add a comment |
||||
Comment 1 by hungte@chromium.org
, Aug 15Owner: hsinyi@chromium.org
Status: Assigned (was: Untriaged)