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

Declarative PIXITs in python tests #395 #36817

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

asirko-soft
Copy link

project-chip/matter-test-scripts#395

Added a common mechanism for tests to declare their optional and required PIXIT values and override flags and ensure the required values are supplied. Add information about optional override flags with descriptions in the error outputs of tests.

Example:

def pixits_TC_ICDM_3_4(self) -> list[PIXITDefinition]:
        """Declare PIXITs required for this test"""
        return [
            PIXITDefinition(
                name="PIXIT.WAITTIME.REBOOT",
                pixit_type=PIXITType.INT,
                description="Time to wait for device reboot (in seconds)",
                required=True
            )
        ]

Copy link

semanticdiff-com bot commented Dec 12, 2024

Review changes with  SemanticDiff

Changed Files
File Status
  src/python_testing/TestMatterTestingSupport.py  3% smaller
  src/python_testing/matter_testing_infrastructure/chip/testing/matter_testing.py  2% smaller

@github-actions github-actions bot added tests matter-1.4-te2-script-change Script changes before end of Matter 1.4 TE2 labels Dec 12, 2024
def validate_bool(value: Any) -> bool:
if isinstance(value, str):
value_lower = value.lower()
if value_lower not in ('true', 'false', '1', '0', 'yes', 'no'):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only true false supported

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


@staticmethod
def validate_float(value: Any) -> bool:
float(value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • value is str for all validators
  • validate_xxx --> is_xxx_pixit_value_valid

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


@staticmethod
def validate_string(value: Any) -> bool:
str(value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For all these you need to wrap the possibly-failing conversion in a try: except ValueError before true/false returned.

Also, when returning False, you are losing the reason for why it failed validation, which would have come out fo the exception.

Recommend moving all of these validators to raise exceptions rather than be bool return. In that case, it could remain validate_xxx

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed and converted bool returns to exceptions

return True

@classmethod
def validate_value(cls, value: Any, pixit_def: PIXITDefinition) -> tuple[bool, Optional[str]]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid raw tuple returns. Raise an exception with message on failure

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this, I was afraid that with using tuple there readability degrades a bit. Removed tuple return

if missing or invalid:
error = ""
if missing:
error += "\nMissing required PIXITs:\n" + "\n".join(missing)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid multi-line emssages

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

default: Any = None

@staticmethod
def is_pixit(arg_name: str) -> bool:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, we probably want to validate all the flags. There are some flags that should be exposed that aren't called PIXIT.whatever

Copy link
Author

@asirko-soft asirko-soft Dec 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you suggest to rename all methods to use some more generic words?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. Naming is one of the hardest things, but I'm tempted to go with Parameter? I know you hate the generic names so @andy31415 - thoughts?


# Validate PIXITs before proceeding
validator = PIXITValidator()
valid, error = validator.validate_pixits(test_info[0].pixits, matter_test_config.global_test_params)
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 validate only for the first test in the list?

might be better in the setup_test function for each test.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, thank you for noticing this issue, I've moved validation to setup_test

@@ -612,6 +612,142 @@ def test_skipped(self, filename: str, name: str):
logging.info(f"Skipping test from {filename}: {name}")


class PIXITType(Enum):
INT = "int"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approach in general is OK, but I do want to consider this in the larger context of verifying that the test invocations are correct in a broader way. We can land this in stages, but it is important to consider how the other checks are going to be integrated here.

In particular, test authors need an easy way to declare certain other test requirements that also need verification. Ex. Endpoint project-chip/matter-test-scripts#450, which we should consider mandating with no default for tests that are run against a single endpoint, no --endpoint flag for tests that run against the entire node at once. Need a way to declare that a test requires a commissioned device, whether or not that commissioning happens as a part of the test invocation. Some tests require passcodes, discriminators etc, even for tests where the commissioning happens external to the test. Tests that DO use PICS (hopefully fewer and fewer) should have a PICS file specified (and this get extra difficult in the context of the test harness)

Anyway, worth thinking through how these extended checks would fit in with this design. I don't see anything in particular blocking these options right now.

It's also worth thinking through how to expose this properly to test authors. ie, is there a way that we can alert test authors that are using test flags that they should be providing these functions?

@@ -612,6 +612,142 @@ def test_skipped(self, filename: str, name: str):
logging.info(f"Skipping test from {filename}: {name}")


class PIXITType(Enum):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know I used PIXIT in the issue, but I think this applies generally to test flags. But I can't think of a great name for just "Flags" that doesn't sound too generic. Ideas welcome.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I also don't have many ideas. TestFlag? TestFlagType? TestParamType?

Copy link
Contributor

@cecille cecille left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind adding some tests here that the verifiers are correctly catching errors? We have some examples of how to test these frameworking bits in TestMatterTestingSupport.py et. al.

Copy link

PR #36817: Size comparison from 75ab4c9 to d3976d0

Full report (1 build for stm32)
platform target config section 75ab4c9 d3976d0 change % change
stm32 light STM32WB5MM-DK FLASH 484720 484728 8 0.0
RAM 144880 144880 0 0.0

Copy link

github-actions bot commented Dec 18, 2024

PR #36817: Size comparison from b0d0614 to d097888

Full report (69 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, cyw30739, efr32, esp32, linux, nrfconnect, nxp, psoc6, qpg, stm32, telink, tizen)
platform target config section b0d0614 d097888 change % change
bl602 lighting-app bl602+mfd+littlefs+rpc FLASH 1353786 1353786 0 0.0
RAM 104136 104136 0 0.0
bl702 lighting-app bl702+eth FLASH 651960 651960 0 0.0
RAM 25353 25353 0 0.0
bl702+wifi FLASH 829548 829548 0 0.0
RAM 14093 14093 0 0.0
bl706+mfd+rpc+littlefs FLASH 1058020 1058020 0 0.0
RAM 23933 23933 0 0.0
bl702l lighting-app bl702l+mfd+littlefs FLASH 979394 979394 0 0.0
RAM 16596 16596 0 0.0
cc13x4_26x4 lighting-app LP_EM_CC1354P10_6 FLASH 839984 839984 0 0.0
RAM 123672 123672 0 0.0
lock-ftd LP_EM_CC1354P10_6 FLASH 825508 825508 0 0.0
RAM 125560 125560 0 0.0
pump-app LP_EM_CC1354P10_6 FLASH 772372 772372 0 0.0
RAM 114036 114036 0 0.0
pump-controller-app LP_EM_CC1354P10_6 FLASH 756560 756560 0 0.0
RAM 114236 114236 0 0.0
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 539853 539853 0 0.0
RAM 205776 205776 0 0.0
lock CC3235SF_LAUNCHXL FLASH 574165 574165 0 0.0
RAM 205920 205920 0 0.0
cyw30739 light CYW30739B2-P5-EVK-01 unknown 2040 2040 0 0.0
FLASH 681745 681745 0 0.0
RAM 78732 78732 0 0.0
CYW30739B2-P5-EVK-02 unknown 2040 2040 0 0.0
FLASH 701597 701597 0 0.0
RAM 81372 81372 0 0.0
CYW30739B2-P5-EVK-03 unknown 2040 2040 0 0.0
FLASH 701597 701597 0 0.0
RAM 81372 81372 0 0.0
CYW930739M2EVB-02 unknown 2040 2040 0 0.0
FLASH 658525 658525 0 0.0
RAM 73800 73800 0 0.0
light-switch CYW30739B2-P5-EVK-01 unknown 2040 2040 0 0.0
FLASH 618361 618361 0 0.0
RAM 71724 71724 0 0.0
CYW30739B2-P5-EVK-02 unknown 2040 2040 0 0.0
FLASH 637989 637989 0 0.0
RAM 74268 74268 0 0.0
CYW30739B2-P5-EVK-03 unknown 2040 2040 0 0.0
FLASH 637989 637989 0 0.0
RAM 74268 74268 0 0.0
lock CYW30739B2-P5-EVK-01 unknown 2040 2040 0 0.0
FLASH 637761 637761 0 0.0
RAM 74732 74732 0 0.0
CYW30739B2-P5-EVK-02 unknown 2040 2040 0 0.0
FLASH 657469 657469 0 0.0
RAM 77276 77276 0 0.0
CYW30739B2-P5-EVK-03 unknown 2040 2040 0 0.0
FLASH 657469 657469 0 0.0
RAM 77276 77276 0 0.0
thermostat CYW30739B2-P5-EVK-01 unknown 2040 2040 0 0.0
FLASH 614213 614213 0 0.0
RAM 68820 68820 0 0.0
CYW30739B2-P5-EVK-02 unknown 2040 2040 0 0.0
FLASH 634073 634073 0 0.0
RAM 71452 71452 0 0.0
CYW30739B2-P5-EVK-03 unknown 2040 2040 0 0.0
FLASH 634073 634073 0 0.0
RAM 71452 71452 0 0.0
efr32 lock-app BRD4187C FLASH 932620 932620 0 0.0
RAM 160204 160204 0 0.0
BRD4338a FLASH 746584 746584 0 0.0
RAM 233332 233332 0 0.0
window-app BRD4187C FLASH 1025264 1025256 -8 -0.0
RAM 128308 128308 0 0.0
esp32 all-clusters-app c3devkit DRAM 95376 95376 0 0.0
FLASH 1543600 1543600 0 0.0
IRAM 82542 82542 0 0.0
m5stack DRAM 116320 116320 0 0.0
FLASH 1550198 1550198 0 0.0
IRAM 117039 117039 0 0.0
linux air-purifier-app debug unknown 4720 4720 0 0.0
FLASH 2716225 2716225 0 0.0
RAM 129928 129928 0 0.0
all-clusters-app debug unknown 5560 5560 0 0.0
FLASH 6009676 6009676 0 0.0
RAM 523640 523640 0 0.0
all-clusters-minimal-app debug unknown 5456 5456 0 0.0
FLASH 5346184 5346184 0 0.0
RAM 242728 242728 0 0.0
bridge-app debug unknown 5440 5440 0 0.0
FLASH 4685720 4685720 0 0.0
RAM 218528 218528 0 0.0
chip-tool debug unknown 5992 5992 0 0.0
FLASH 12849428 12849428 0 0.0
RAM 582506 582506 0 0.0
chip-tool-ipv6only arm64 unknown 21352 21352 0 0.0
FLASH 10984032 10984032 0 0.0
RAM 633432 633432 0 0.0
fabric-admin debug unknown 5816 5816 0 0.0
FLASH 11255977 11255977 0 0.0
RAM 582850 582850 0 0.0
fabric-bridge-app debug unknown 4696 4696 0 0.0
FLASH 4511112 4511112 0 0.0
RAM 205696 205696 0 0.0
fabric-sync debug unknown 4936 4936 0 0.0
FLASH 5611173 5611173 0 0.0
RAM 472696 472696 0 0.0
lighting-app debug+rpc+ui unknown 6104 6104 0 0.0
FLASH 5622449 5622449 0 0.0
RAM 228888 228888 0 0.0
lock-app debug unknown 5376 5376 0 0.0
FLASH 4734992 4734992 0 0.0
RAM 204872 204872 0 0.0
ota-provider-app debug unknown 4752 4752 0 0.0
FLASH 4360698 4360698 0 0.0
RAM 198560 198560 0 0.0
ota-requestor-app debug unknown 4688 4688 0 0.0
FLASH 4499722 4499722 0 0.0
RAM 203144 203144 0 0.0
shell debug unknown 4248 4248 0 0.0
FLASH 3033613 3033613 0 0.0
RAM 160552 160552 0 0.0
thermostat-no-ble arm64 unknown 9552 9552 0 0.0
FLASH 4104928 4104928 0 0.0
RAM 243168 243168 0 0.0
tv-app debug unknown 5704 5704 0 0.0
FLASH 5960293 5960293 0 0.0
RAM 596128 596128 0 0.0
tv-casting-app debug unknown 5288 5288 0 0.0
FLASH 11055821 11055821 0 0.0
RAM 692328 692328 0 0.0
nrfconnect all-clusters-app nrf52840dk_nrf52840 FLASH 918120 918120 0 0.0
RAM 143308 143308 0 0.0
nrf7002dk_nrf5340_cpuapp FLASH 890264 890264 0 0.0
RAM 141495 141495 0 0.0
all-clusters-minimal-app nrf52840dk_nrf52840 FLASH 852004 852004 0 0.0
RAM 142220 142220 0 0.0
nxp contact k32w0+release FLASH 585624 585624 0 0.0
RAM 71088 71088 0 0.0
mcxw71+release FLASH 600320 600320 0 0.0
RAM 63184 63184 0 0.0
light k32w0+release FLASH 612548 612548 0 0.0
RAM 70480 70480 0 0.0
k32w1+release FLASH 686808 686808 0 0.0
RAM 48816 48816 0 0.0
lock mcxw71+release FLASH 763216 763216 0 0.0
RAM 70852 70852 0 0.0
psoc6 all-clusters cy8ckit_062s2_43012 FLASH 1647148 1647148 0 0.0
RAM 212104 212104 0 0.0
all-clusters-minimal cy8ckit_062s2_43012 FLASH 1554580 1554580 0 0.0
RAM 208920 208920 0 0.0
light cy8ckit_062s2_43012 FLASH 1469884 1469884 0 0.0
RAM 200888 200888 0 0.0
lock cy8ckit_062s2_43012 FLASH 1467620 1467620 0 0.0
RAM 225248 225248 0 0.0
qpg lighting-app qpg6105+debug FLASH 664304 664304 0 0.0
RAM 105432 105432 0 0.0
lock-app qpg6105+debug FLASH 622108 622108 0 0.0
RAM 99884 99884 0 0.0
stm32 light STM32WB5MM-DK FLASH 485012 485012 0 0.0
RAM 144888 144888 0 0.0
telink bridge-app tlsr9258a FLASH 683216 683216 0 0.0
RAM 91224 91224 0 0.0
contact-sensor-app tlsr9528a_retention FLASH 623630 623630 0 0.0
RAM 31456 31456 0 0.0
light-app-ota-compress-lzma-shell-factory-data tl3218x FLASH 772448 772448 0 0.0
RAM 49316 49316 0 0.0
light-switch-app-ota-compress-lzma-shell-factory-data tlsr9528a FLASH 711070 711070 0 0.0
RAM 73520 73520 0 0.0
lighting-app-ota-factory-data tlsr9118bdk40d FLASH 628086 628086 0 0.0
RAM 142156 142156 0 0.0
lighting-app-ota-rpc-factory-data-4mb tlsr9518adk80d FLASH 814104 814104 0 0.0
RAM 99700 99700 0 0.0
tizen all-clusters-app arm unknown 4996 4996 0 0.0
FLASH 1735008 1735008 0 0.0
RAM 90788 90788 0 0.0
chip-tool-ubsan arm unknown 10804 10804 0 0.0
FLASH 17973686 17973686 0 0.0
RAM 7842724 7842724 0 0.0

PIXITValidator.validate_hex_pixit_value("0x1234") # Should pass
PIXITValidator.validate_hex_pixit_value("1234") # Should pass
PIXITValidator.validate_hex_pixit_value("ABCD") # Should pass
PIXITValidator.validate_hex_pixit_value("abcd") # Should pass
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one of the other formats we sometimes get is hex:12ab. I don't know if that is handled correctly in the argument parser though.

default: Any = None

@staticmethod
def is_pixit(arg_name: str) -> bool:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. Naming is one of the hardest things, but I'm tempted to go with Parameter? I know you hate the generic names so @andy31415 - thoughts?

)

PIXITValidator.validate_value(None, optional_pixit) # Should pass as it's optional

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also please add a test for the validate_pixits function to ensure they get mapped properly?

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.

3 participants