-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
TC-TCCM Python Migration #36767
base: master
Are you sure you want to change the base?
TC-TCCM Python Migration #36767
Conversation
Changed Files
|
|
src/python_testing/tc_mode_base.py
Outdated
logger = logging.getLogger(__name__) | ||
|
||
|
||
class TC_MODE_BASE: |
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.
Needs some doc comments. I would avoid using filler works like base/support/helper/core/common because files and classes named like that end up being a dumping ground of unrelated things.
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.
class naming should be CamelCase
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.
Changed the names format and filename.
src/python_testing/tc_mode_base.py
Outdated
|
||
class TC_MODE_BASE: | ||
|
||
def initialize_tc_base(self, endpoint, attributes, requested_cluster, cluster_objects, *args): |
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.
also needs comments. Why is this a separate method and not __init__
?
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 was not sure of the "best" way to handle this additional class (also having problems with super().init when using TC_MODE_BASE along with MatterBaseTest in the test case). I've replaced this function with the init and reduced the parameters, still not sure if this is the "best" way tho.
src/python_testing/tc_mode_base.py
Outdated
class TC_MODE_BASE: | ||
|
||
def initialize_tc_base(self, endpoint, attributes, requested_cluster, cluster_objects, *args): | ||
self.commonTags = {0x0: 'Auto', |
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.
where do these magic constants come from? Do we have them from codegen or could we reference spec locations?
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.
They are defined in the spec for most of the "mode" clusters and seem to be common between them, this seems to be the spec (https://github.com/CHIP-Specifications/chip-test-plans/blob/master/src/cluster/modebase_common.adoc). However it seems that those values are part of the enum of each cluster so it is actually not needed to add them in a different structure.
src/python_testing/TC_TCCM_1_2.py
Outdated
from mobly import asserts | ||
|
||
|
||
class TC_TCCM_1_2(MatterBaseTest, TC_MODE_BASE): |
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.
maybe composition over inheritance would be better.
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.
This double-inheritance tends to happen in the tests because of the way the base framework finds the full test set. ie _find_test_class breaks when you inherit from MatterBaseTest and then re-inherit from another class. Definitely would be good to fix that, but it's a bit orthogonal
src/python_testing/TC_TCCM_1_2.py
Outdated
from mobly import asserts | ||
|
||
|
||
class TC_TCCM_1_2(MatterBaseTest, TC_MODE_BASE): |
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.
This double-inheritance tends to happen in the tests because of the way the base framework finds the full test set. ie _find_test_class breaks when you inherit from MatterBaseTest and then re-inherit from another class. Definitely would be good to fix that, but it's a bit orthogonal
src/python_testing/TC_TCCM_1_2.py
Outdated
|
||
self.step(2) | ||
await self.check_supported_modes_and_labels() | ||
additional_tags = [Clusters.RefrigeratorAndTemperatureControlledCabinetMode.Enums.ModeTag.kRapidCool, |
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.
minor question / possible nit - is this the entire enum there, or a subset? If it's the fully list, can you pull the full list by walking the enum? If it's a subset, can you add a comment noting that?
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.
From what I see in the different TCs, these tags are a subset of the whole enum and seem to be different for each cluster. Added a comment for this specific cluster.
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 wonder if we could somehow shorten things by giving a name to Clusters.RefrigeratorAndTemperatureControlledCabinetMode.Enums
as well as Clusters.RefrigeratorAndTemperatureControlledCabinetMode.Attributes
(probably like enums and attributes) as they make the code lines very long.
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.
we already named attributes
in the checks class.
src/python_testing/tc_mode_base.py
Outdated
else: | ||
labels.add(mode_options_struct.label) | ||
|
||
async def check_if_labels_in_lists(self, requiredtags=None): |
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.
does this need to be async? looked briefly for some await in impl and did not see anything obvious.
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.
My mistake, this is actually not needed.
src/python_testing/tc_mode_base.py
Outdated
at_least_one_common_or_derived = False | ||
for tag in mode_options_struct.modeTags: | ||
# Value should not larger than 16bits | ||
if tag.value > 0xFFFF or tag.value < 0: |
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.
could we use some constants for these magic values? especially for common tag logic I would imagine we already have some helpers somewhere.
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.
Wasn't able to find helpers for this so I moved them, however not sure if that is the correct way to define constants according to the project guidelines.
PR #36767: Size comparison from 43167a0 to ff5e2eb Full report (3 builds for cc32xx, stm32)
|
src/python_testing/tc_mode_base.py
Outdated
END_MFGTAGS_RANGE = 0xBFFF | ||
|
||
|
||
class ClusterModeCheck: |
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.
Based on the description:
- This class holds common checks between different test cases
- this is based on
ModeBase
common things
How about naming this ModeBaseClusterChecks
(and adjust the file name as well to not contain base
) ?
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.
Changed the name for the class and also the name of the file. I'm not sure if I can completely remove the word "base" since the name of the "parent" cluster is ModeBase, but hopefully it is less general now.
src/python_testing/tc_mode_base.py
Outdated
|
||
|
||
Attributes: | ||
requested_cluster: A reference to the cluster to be tested, it should be a derived from the Mode Base cluster. |
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.
nit: consider modebase_derived_cluster
(since the documentation says this should be a derived from the Mode Base cluster
)?
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.
That makes sense, changed the name of the parameter.
src/python_testing/tc_mode_base.py
Outdated
self.modeTags = [tag.value for tag in requested_cluster.Enums.ModeTag] | ||
self.requested_cluster = requested_cluster | ||
self.attributes = requested_cluster.Attributes | ||
self.supported_modes_dut = set() |
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.
having these as members seems to introduce a call dependency: you need to call check_supported_modes_and_labels and only then read_and_check_mode
Could we instead make things return values and not store internal state in the class? that would allow decoupling call order and make it more obvious to callers what data is used there (i.e. that the data from check is used in read_and_check)
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.
Yeah, that makes sense. I overlook this dependency.
Removed those members and used them as parameters in the other calls.
This change is the implementation of the test case TC-TCCM-1.2, part of the goal was to create a "base" implementation that can be reused by similar tests
Part of work for project-chip/matter-test-scripts#424