Skip to content

Commit

Permalink
Add pics_ handler, address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
cecille committed Dec 5, 2023
1 parent 7926d27 commit 92085b3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/python_testing/TC_ACE_1_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async def read_descriptor_expect_unsupported_access(self, th):
dev_ctrl=th, endpoint=0, cluster=cluster, attribute=attribute, error=Status.UnsupportedAccess)

def desc_TC_ACE_1_3(self) -> str:
return ""
return "[TC-ACE-1.3] Subjects"

def steps_TC_ACE_1_3(self) -> list[TestStep]:
steps = [
Expand Down
14 changes: 11 additions & 3 deletions src/python_testing/hello_external_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class TestRunnerHooks:

MATTER_DEVELOPMENT_PAA_ROOT_CERTS = "credentials/development/paa-root-certs"


class TestTestRunnerHooks(TestRunnerHooks):
def reset(self):
self.start_called = False
Expand All @@ -48,6 +49,7 @@ def reset(self):
self.step_success_count = 0
self.step_failure_count = 0
self.step_unknown_count = 0

def __init__(self):
self.reset()

Expand Down Expand Up @@ -89,7 +91,8 @@ def summary(self):
print(f'step_failure_count = {self.step_failure_count}')
print(f'step_unknown_count = {self.step_unknown_count}')

def run_in_process(test_name:str, config: MatterTestConfig) -> None:

def run_in_process(test_name: str, config: MatterTestConfig) -> None:
BaseManager.register('TestTestRunnerHooks', TestTestRunnerHooks)
manager = BaseManager()
manager.start()
Expand All @@ -100,11 +103,14 @@ def run_in_process(test_name:str, config: MatterTestConfig) -> None:
print(f'Results from test {test_name}:')
print(my_hooks.summary())


def commission() -> None:
paa_path = os.path.join(DEFAULT_CHIP_ROOT, MATTER_DEVELOPMENT_PAA_ROOT_CERTS)
config = MatterTestConfig(commissioning_method="on-network", commission_only=True, discriminators=[3840], setup_passcodes=[20202021], dut_node_ids=[0x12344321], paa_trust_store_path=paa_path, storage_path='admin_storage.json')
config = MatterTestConfig(commissioning_method="on-network", commission_only=True, discriminators=[3840], setup_passcodes=[
20202021], dut_node_ids=[0x12344321], paa_trust_store_path=paa_path, storage_path='admin_storage.json')
run_in_process("commission", config)


def one_test(test_name):
# Run a test NOT using the default main. Pass in our own runner and make sure it
# gets called back.
Expand All @@ -119,13 +125,14 @@ def one_test(test_name):

run_in_process(test_name, config)


def main():

# Fire up an example app to test against
# TODO: make factory reset and app path configurable, maybe the storage location too.
subprocess.call("rm -rf /tmp/chip_* /tmp/repl* admin_storage.json", shell=True)
app_path = os.path.abspath(os.path.join(DEFAULT_CHIP_ROOT, 'out',
'linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test', 'chip-all-clusters-app'))
'linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test', 'chip-all-clusters-app'))
app_cmd = str(app_path)
app_process = subprocess.Popen([app_cmd], stdout=sys.stdout, stderr=sys.stderr, bufsize=0)

Expand All @@ -138,5 +145,6 @@ def main():
app_process.wait()
print("app stopped")


if __name__ == "__main__":
main()
29 changes: 25 additions & 4 deletions src/python_testing/matter_testing_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,8 @@ class TestStep:
class TestInfo:
function: str
desc: str
steps: typing.List[TestStep]
steps: list[TestStep]
pics: list[str]


class MatterBaseTest(base_test.BaseTestClass):
Expand All @@ -569,7 +570,7 @@ def __init__(self, *args):
self.problems = []
self.is_commissioning = False

def get_test_steps(self, test:str) -> list[TestStep]:
def get_test_steps(self, test: str) -> list[TestStep]:
''' Retrieves the test step list for the given test
Test steps are defined in the function called steps_<functionname>.
Expand All @@ -583,7 +584,6 @@ def get_test_steps(self, test:str) -> list[TestStep]:
steps = self._get_defined_test_steps(test)
return [TestStep(1, "Run entire test")] if steps is None else steps


def _get_defined_test_steps(self, test: str) -> list[TestStep]:
steps_name = 'steps_' + test[5:]
try:
Expand All @@ -592,6 +592,26 @@ def _get_defined_test_steps(self, test: str) -> list[TestStep]:
except AttributeError:
return None

def get_test_pics(self, test: str) -> list[str]:
''' Retrieves a list of top-level PICS that should be checked before running this test
An empty list means the test will always be run.
PICS are defined in a function called pics_<functionname>.
ex. for test test_TC_TEST_1_1, the pics are in a function called
pics_TC_TEST_1_1.
'''
pics = self._get_defined_pics(test)
return [] if pics is None else pics

def _get_defined_pics(self, test: str) -> list[TestStep]:
steps_name = 'pics_' + test[5:]
try:
fn = getattr(self, steps_name)
return fn()
except AttributeError:
return None

def get_test_desc(self, test: str) -> str:
''' Returns a description of this test
Expand Down Expand Up @@ -1292,6 +1312,7 @@ def async_runner(self: MatterBaseTest, *args, **kwargs):

class CommissionDeviceTest(MatterBaseTest):
"""Test class auto-injected at the start of test list to commission a device when requested"""

def __init__(self, *args):
super().__init__(*args)
self.is_commissioning = True
Expand Down Expand Up @@ -1398,7 +1419,7 @@ def get_test_info(test_class: MatterBaseTest, matter_test_config: MatterTestConf

info = []
for t in tests:
info.append(TestInfo(t, steps=base.get_test_steps(t), desc=base.get_test_desc(t)))
info.append(TestInfo(t, steps=base.get_test_steps(t), desc=base.get_test_desc(t), pics=base.get_test_pics(t)))

return info

Expand Down

0 comments on commit 92085b3

Please sign in to comment.