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

TC-TCCM Python Migration #36767

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

tersal
Copy link

@tersal tersal commented Dec 9, 2024

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

Copy link

semanticdiff-com bot commented Dec 9, 2024

Review changes with  SemanticDiff

Changed Files
File Status
  src/python_testing/TC_TCCM_1_2.py  0% smaller
  src/python_testing/modebase_cluster_check.py  0% smaller

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@github-actions github-actions bot added tests matter-1.4-te2-script-change Script changes before end of Matter 1.4 TE2 labels Dec 9, 2024
logger = logging.getLogger(__name__)


class TC_MODE_BASE:
Copy link
Contributor

@andy31415 andy31415 Dec 9, 2024

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.

Copy link
Contributor

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

Copy link
Author

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.


class TC_MODE_BASE:

def initialize_tc_base(self, endpoint, attributes, requested_cluster, cluster_objects, *args):
Copy link
Contributor

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__ ?

Copy link
Author

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.

class TC_MODE_BASE:

def initialize_tc_base(self, endpoint, attributes, requested_cluster, cluster_objects, *args):
self.commonTags = {0x0: 'Auto',
Copy link
Contributor

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?

Copy link
Author

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.

from mobly import asserts


class TC_TCCM_1_2(MatterBaseTest, TC_MODE_BASE):
Copy link
Contributor

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.

Copy link
Contributor

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

from mobly import asserts


class TC_TCCM_1_2(MatterBaseTest, TC_MODE_BASE):
Copy link
Contributor

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


self.step(2)
await self.check_supported_modes_and_labels()
additional_tags = [Clusters.RefrigeratorAndTemperatureControlledCabinetMode.Enums.ModeTag.kRapidCool,
Copy link
Contributor

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?

Copy link
Author

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

else:
labels.add(mode_options_struct.label)

async def check_if_labels_in_lists(self, requiredtags=None):
Copy link
Contributor

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.

Copy link
Author

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.

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:
Copy link
Contributor

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.

Copy link
Author

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.

Copy link

PR #36767: Size comparison from 43167a0 to ff5e2eb

Full report (3 builds for cc32xx, stm32)
platform target config section 43167a0 ff5e2eb change % change
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 631050 631050 0 0.0
RAM 205824 205824 0 0.0
lock CC3235SF_LAUNCHXL FLASH 669646 669646 0 0.0
RAM 205968 205968 0 0.0
stm32 light STM32WB5MM-DK FLASH 484720 484720 0 0.0
RAM 144880 144880 0 0.0

END_MFGTAGS_RANGE = 0xBFFF


class ClusterModeCheck:
Copy link
Contributor

@andy31415 andy31415 Dec 11, 2024

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) ?

Copy link
Author

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.



Attributes:
requested_cluster: A reference to the cluster to be tested, it should be a derived from the Mode Base cluster.
Copy link
Contributor

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)?

Copy link
Author

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.

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()
Copy link
Contributor

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)

Copy link
Author

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.

@tersal tersal marked this pull request as ready for review December 20, 2024 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
matter-1.4-te2-script-change Script changes before end of Matter 1.4 TE2 tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants