Skip to content

Commit 0b7c1c5

Browse files
Python framework - write_to_app_pipe updates. (#37637)
* Proposal update for write_to_app_pipe for MatterBaseTest. Added parameter app-pid to function. Added log info, added fail when app-pid is not present. Updated doc string. Naming fix * Removed need to use self.matter_test_config.app_pid in the base class. Moved pid definition into derived class. * Updated TC_SEAR test cases with new write_to_app_pipe from Matternase test * Refactor for write_to_pipe-app on TC_OCC Test cases * Refactor for write_to_pipe-app on TC_TVCCLEANM Test cases * Refactor for write_to_pipe_app on TC_TVCOPSTATE * Refactor for write_to_pipe_app on TC_RVCRUNM * Missing test case to add. * Refactored to use by default the args --app-pipe and --app-pid from the command line to build the app file to send the out of band command. Implemetation the same for CI and SSH * Add ci-arg --app-pipe with pipe name. Removed self.pid and self.pipe_name to use the values from arguments while on CI * Restyled by isort * Opstate fixes. Uses the param implementation as I dont want to modify all this code. * Added pattern to verify fifo file is correct. * Revert "Added pattern to verify fifo file is correct." This reverts commit 9e59ffd. * Updated app_pipe to work as app_pipe_prefix. This is because the app_pipe will be the one that contains the full app pipe but in order to achieve this is required to define a well defined path for linux app to read. * Updated file write. Using instead of replace. Removed inline imports.Updated docstring. --------- Co-authored-by: Restyled.io <commits@restyled.io>
1 parent 2b525af commit 0b7c1c5

File tree

15 files changed

+57
-129
lines changed

15 files changed

+57
-129
lines changed

src/python_testing/TC_OCC_3_1.py

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
# --trace-to json:${TRACE_TEST_JSON}.json
2828
# --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto
2929
# --endpoint 1
30+
# --app-pipe_prefix /tmp/chip_all_clusters_fifo_
3031
# --bool-arg simulate_occupancy:true
3132
# factory-reset: true
3233
# quiet: true
@@ -91,25 +92,9 @@ def pics_TC_OCC_3_1(self) -> list[str]:
9192
]
9293
return pics
9394

94-
# Sends and out-of-band command to the all-clusters-app
95-
def write_to_app_pipe(self, command):
96-
# CI app pipe id creation
97-
self.app_pipe = "/tmp/chip_all_clusters_fifo_"
98-
if self.is_ci:
99-
app_pid = self.matter_test_config.app_pid
100-
if app_pid == 0:
101-
asserts.fail("The --app-pid flag must be set when using named pipe")
102-
self.app_pipe = self.app_pipe + str(app_pid)
103-
104-
with open(self.app_pipe, "w") as app_pipe:
105-
app_pipe.write(command + "\n")
106-
# Delay for pipe command to be processed (otherwise tests are flaky)
107-
time.sleep(0.001)
108-
10995
@async_test_body
11096
async def test_TC_OCC_3_1(self):
11197
hold_time = 10 if not self.is_ci else 1.0 # 10 seconds for occupancy state hold time
112-
11398
self.step(1) # Commissioning already done
11499

115100
self.step(2)
@@ -133,7 +118,7 @@ async def test_TC_OCC_3_1(self):
133118

134119
if self.is_ci:
135120
# CI call to trigger unoccupied.
136-
self.write_to_app_pipe('{"Name":"SetOccupancy", "EndpointId": 1, "Occupancy": 0}')
121+
self.write_to_app_pipe({"Name": "SetOccupancy", "EndpointId": 1, "Occupancy": 0})
137122
else:
138123
self.wait_for_user_input(
139124
prompt_msg="Type any letter and press ENTER after the sensor occupancy is unoccupied state (occupancy attribute = 0)")
@@ -157,7 +142,7 @@ async def test_TC_OCC_3_1(self):
157142
self.step("5a")
158143
# CI call to trigger on
159144
if self.is_ci:
160-
self.write_to_app_pipe('{"Name":"SetOccupancy", "EndpointId": 1, "Occupancy": 1}')
145+
self.write_to_app_pipe({"Name": "SetOccupancy", "EndpointId": 1, "Occupancy": 1})
161146
else:
162147
# Trigger occupancy sensor to change Occupancy attribute value to 1 => TESTER ACTION on DUT
163148
self.wait_for_user_input(prompt_msg="Type any letter and press ENTER after a sensor occupancy is triggered.")
@@ -183,7 +168,7 @@ async def test_TC_OCC_3_1(self):
183168
self.step(6)
184169
if self.is_ci:
185170
# CI call to trigger unoccupied.
186-
self.write_to_app_pipe('{"Name":"SetOccupancy", "EndpointId": 1, "Occupancy": 0}')
171+
self.write_to_app_pipe({"Name": "SetOccupancy", "EndpointId": 1, "Occupancy": 0})
187172

188173
if has_hold_time:
189174
time.sleep(hold_time + 2.0) # add some extra 2 seconds to ensure hold time has passed.

src/python_testing/TC_OCC_3_2.py

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
# --passcode 20202021
3030
# --trace-to json:${TRACE_TEST_JSON}.json
3131
# --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto
32+
# --app-pipe_prefix /tmp/chip_all_clusters_fifo_
3233
# --endpoint 1
3334
# --bool-arg simulate_occupancy:true
3435
# factory-reset: true
@@ -41,7 +42,6 @@
4142
# [TC-OCC-3.2] test precedure step 3a, 3c
4243

4344
import logging
44-
import time
4545

4646
import chip.clusters as Clusters
4747
from chip.testing.matter_testing import (ClusterAttributeChangeAccumulator, MatterBaseTest, TestStep, async_test_body,
@@ -83,21 +83,6 @@ def pics_TC_OCC_3_2(self) -> list[str]:
8383
]
8484
return pics
8585

86-
# Sends and out-of-band command to the all-clusters-app
87-
def write_to_app_pipe(self, command):
88-
# CI app pipe id creation
89-
self.app_pipe = "/tmp/chip_all_clusters_fifo_"
90-
if self.is_ci:
91-
app_pid = self.matter_test_config.app_pid
92-
if app_pid == 0:
93-
asserts.fail("The --app-pid flag must be set when using named pipe")
94-
self.app_pipe = self.app_pipe + str(app_pid)
95-
96-
with open(self.app_pipe, "w") as app_pipe:
97-
app_pipe.write(command + "\n")
98-
# Delay for pipe command to be processed (otherwise tests are flaky)
99-
time.sleep(0.001)
100-
10186
@async_test_body
10287
async def test_TC_OCC_3_2(self):
10388
endpoint_id = self.get_endpoint()
@@ -136,7 +121,7 @@ async def test_TC_OCC_3_2(self):
136121
self.step("3a")
137122
# CI call to trigger off
138123
if self.is_ci:
139-
self.write_to_app_pipe('{"Name":"SetOccupancy", "EndpointId": 1, "Occupancy": 0}')
124+
self.write_to_app_pipe({"Name": "SetOccupancy", "EndpointId": 1, "Occupancy": 0})
140125
else:
141126
self.wait_for_user_input(prompt_msg="Type any letter and press ENTER after DUT goes back to unoccupied state.")
142127

@@ -150,7 +135,7 @@ async def test_TC_OCC_3_2(self):
150135

151136
# CI call to trigger on
152137
if self.is_ci:
153-
self.write_to_app_pipe('{"Name":"SetOccupancy", "EndpointId": 1, "Occupancy": 1}')
138+
self.write_to_app_pipe({"Name": "SetOccupancy", "EndpointId": 1, "Occupancy": 1})
154139
else:
155140
self.wait_for_user_input(
156141
prompt_msg="Type any letter and press ENTER after the sensor occupancy is triggered and its occupancy state changed.")

src/python_testing/TC_OpstateCommon.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ def init_test(self):
109109
app_pid = get_pid("chip-all-clusters-app")
110110
if app_pid is None:
111111
asserts.fail("The --app-pid flag must be set when PICS_SDK_CI_ONLY is set")
112-
self.app_pipe = self.app_pipe + str(app_pid)
112+
self.app_pid = app_pid
113113

114114
def send_raw_manual_or_pipe_command(self, command: dict, msg: str):
115115
if self.is_ci:
116-
self.write_to_app_pipe(command)
116+
self.write_to_app_pipe(command, app_pipe_prefix=self.app_pipe, app_pid=self.app_pid)
117117
time.sleep(0.1)
118118
else:
119119
prompt = msg if msg is not None else "Press Enter when ready."

src/python_testing/TC_RVCCLEANM_2_1.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
# --int-arg PIXIT.RVCCLEANM.MODE_CHANGE_FAIL:1
3333
# --int-arg PIXIT.RVCCLEANM.MODE_CHANGE_OK:2
3434
# --endpoint 1
35+
# --app-pipe_prefix /tmp/chip_rvc_fifo_
3536
# --trace-to json:${TRACE_TEST_JSON}.json
3637
# --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto
3738
# factory-reset: true
@@ -57,7 +58,6 @@ def __init__(self, *args):
5758
self.mode_ok = 0
5859
self.mode_fail = 0
5960
self.is_ci = False
60-
self.app_pipe = "/tmp/chip_rvc_fifo_"
6161

6262
async def read_mod_attribute_expect_success(self, endpoint, attribute):
6363
cluster = Clusters.Objects.RvcCleanMode
@@ -92,11 +92,6 @@ async def test_TC_RVCCLEANM_2_1(self):
9292
self.mode_ok = self.matter_test_config.global_test_params['PIXIT.RVCCLEANM.MODE_CHANGE_OK']
9393
self.mode_fail = self.matter_test_config.global_test_params['PIXIT.RVCCLEANM.MODE_CHANGE_FAIL']
9494
self.is_ci = self.check_pics("PICS_SDK_CI_ONLY")
95-
if self.is_ci:
96-
app_pid = self.matter_test_config.app_pid
97-
if app_pid == 0:
98-
asserts.fail("The --app-pid flag must be set when PICS_SDK_CI_ONLY is set")
99-
self.app_pipe = self.app_pipe + str(app_pid)
10095

10196
asserts.assert_true(self.check_pics("RVCCLEANM.S.A0000"), "RVCCLEANM.S.A0000 must be supported")
10297
asserts.assert_true(self.check_pics("RVCCLEANM.S.A0001"), "RVCCLEANM.S.A0001 must be supported")

src/python_testing/TC_RVCCLEANM_2_2.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
# --discriminator 1234
3030
# --passcode 20202021
3131
# --PICS examples/rvc-app/rvc-common/pics/rvc-app-pics-values
32+
# --app-pipe_prefix /tmp/chip_rvc_fifo_
3233
# --endpoint 1
3334
# --trace-to json:${TRACE_TEST_JSON}.json
3435
# --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto
@@ -63,7 +64,6 @@ def __init__(self, *args):
6364
self.old_clean_mode_dut = 0
6465
self.new_clean_mode_th = 0
6566
self.is_ci = False
66-
self.app_pipe = "/tmp/chip_rvc_fifo_"
6767

6868
async def read_mod_attribute_expect_success(self, cluster, attribute):
6969
return await self.read_single_attribute_check_success(
@@ -107,11 +107,6 @@ async def test_TC_RVCCLEANM_2_2(self):
107107
self.directmodech_bit_mask = Clusters.RvcCleanMode.Bitmaps.Feature.kDirectModeChange
108108
self.endpoint = self.get_endpoint()
109109
self.is_ci = self.check_pics("PICS_SDK_CI_ONLY")
110-
if self.is_ci:
111-
app_pid = self.matter_test_config.app_pid
112-
if app_pid == 0:
113-
asserts.fail("The --app-pid flag must be set when PICS_SDK_CI_ONLY is set.c")
114-
self.app_pipe = self.app_pipe + str(app_pid)
115110

116111
asserts.assert_true(self.check_pics("RVCCLEANM.S"), "RVCCLEANM.S must be supported")
117112
asserts.assert_true(self.check_pics("RVCRUNM.S.A0000"), "RVCRUNM.S.A0000 must be supported")

src/python_testing/TC_RVCOPSTATE_2_1.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
# --passcode 20202021
3131
# --PICS examples/rvc-app/rvc-common/pics/rvc-app-pics-values
3232
# --endpoint 1
33+
# --app-pipe_prefix /tmp/chip_rvc_fifo_
3334
# --trace-to json:${TRACE_TEST_JSON}.json
3435
# --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto
3536
# factory-reset: true
@@ -49,7 +50,6 @@ def __init__(self, *args):
4950
super().__init__(*args)
5051
self.endpoint = None
5152
self.is_ci = False
52-
self.app_pipe = "/tmp/chip_rvc_fifo_"
5353

5454
async def read_mod_attribute_expect_success(self, endpoint, attribute):
5555
cluster = Clusters.Objects.RvcOperationalState
@@ -90,11 +90,6 @@ async def test_TC_RVCOPSTATE_2_1(self):
9090
self.endpoint = self.get_endpoint()
9191
asserts.assert_false(self.endpoint is None, "--endpoint <endpoint> must be included on the command line in.")
9292
self.is_ci = self.check_pics("PICS_SDK_CI_ONLY")
93-
if self.is_ci:
94-
app_pid = self.matter_test_config.app_pid
95-
if app_pid == 0:
96-
asserts.fail("The --app-pid flag must be set when PICS_SDK_CI_ONLY is set")
97-
self.app_pipe = self.app_pipe + str(app_pid)
9893

9994
cluster = Clusters.RvcOperationalState
10095
attributes = cluster.Attributes

src/python_testing/TC_RVCOPSTATE_2_3.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
# --passcode 20202021
3131
# --PICS examples/rvc-app/rvc-common/pics/rvc-app-pics-values
3232
# --endpoint 1
33+
# --app-pipe_prefix /tmp/chip_rvc_fifo_
3334
# --trace-to json:${TRACE_TEST_JSON}.json
3435
# --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto
3536
# factory-reset: true
@@ -99,7 +100,6 @@ def __init__(self, *args):
99100
super().__init__(*args)
100101
self.endpoint = None
101102
self.is_ci = False
102-
self.app_pipe = "/tmp/chip_rvc_fifo_"
103103

104104
async def read_mod_attribute_expect_success(self, endpoint, attribute):
105105
cluster = Clusters.Objects.RvcOperationalState
@@ -161,11 +161,6 @@ async def test_TC_RVCOPSTATE_2_3(self):
161161
self.endpoint = self.get_endpoint()
162162
asserts.assert_false(self.endpoint is None, "--endpoint <endpoint> must be included on the command line in.")
163163
self.is_ci = self.check_pics("PICS_SDK_CI_ONLY")
164-
if self.is_ci:
165-
app_pid = self.matter_test_config.app_pid
166-
if app_pid == 0:
167-
asserts.fail("The --app-pid flag must be set when PICS_SDK_CI_ONLY is set.c")
168-
self.app_pipe = self.app_pipe + str(app_pid)
169164

170165
asserts.assert_true(self.check_pics("RVCOPSTATE.S.A0003"), "RVCOPSTATE.S.A0003 must be supported")
171166
asserts.assert_true(self.check_pics("RVCOPSTATE.S.A0004"), "RVCOPSTATE.S.A0004 must be supported")

src/python_testing/TC_RVCOPSTATE_2_4.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
# --passcode 20202021
3131
# --PICS examples/rvc-app/rvc-common/pics/rvc-app-pics-values
3232
# --endpoint 1
33+
# --app-pipe_prefix /tmp/chip_rvc_fifo_
3334
# --trace-to json:${TRACE_TEST_JSON}.json
3435
# --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto
3536
# factory-reset: true
@@ -64,7 +65,6 @@ def __init__(self, *args):
6465
super().__init__(*args)
6566
self.endpoint = None
6667
self.is_ci = False
67-
self.app_pipe = "/tmp/chip_rvc_fifo_"
6868

6969
async def read_mod_attribute_expect_success(self, endpoint, attribute):
7070
cluster = Clusters.Objects.RvcOperationalState
@@ -106,11 +106,6 @@ async def test_TC_RVCOPSTATE_2_4(self):
106106
self.endpoint = self.get_endpoint()
107107
asserts.assert_false(self.endpoint is None, "--endpoint <endpoint> must be included on the command line in.")
108108
self.is_ci = self.check_pics("PICS_SDK_CI_ONLY")
109-
if self.is_ci:
110-
app_pid = self.matter_test_config.app_pid
111-
if app_pid == 0:
112-
asserts.fail("The --app-pid flag must be set when PICS_SDK_CI_ONLY is set.c")
113-
self.app_pipe = self.app_pipe + str(app_pid)
114109

115110
asserts.assert_true(self.check_pics("RVCOPSTATE.S.A0004"), "RVCOPSTATE.S.A0004 must be supported")
116111
asserts.assert_true(self.check_pics("RVCOPSTATE.S.C04.Tx"), "RVCOPSTATE.S.C04.Tx must be supported")

src/python_testing/TC_RVCRUNM_2_1.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
# --endpoint 1
3333
# --int-arg PIXIT.RVCRUNM.MODE_CHANGE_OK:0
3434
# --int-arg PIXIT.RVCRUNM.MODE_CHANGE_FAIL:2
35+
# --app-pipe_prefix /tmp/chip_rvc_fifo_
3536
# --trace-to json:${TRACE_TEST_JSON}.json
3637
# --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto
3738
# factory-reset: true
@@ -58,7 +59,6 @@ def __init__(self, *args):
5859
self.mode_ok = 0
5960
self.mode_fail = 0
6061
self.is_ci = False
61-
self.app_pipe = "/tmp/chip_rvc_fifo_"
6262

6363
async def read_mod_attribute_expect_success(self, endpoint, attribute):
6464
cluster = Clusters.Objects.RvcRunMode
@@ -87,11 +87,6 @@ async def test_TC_RVCRUNM_2_1(self):
8787
self.mode_ok = self.matter_test_config.global_test_params['PIXIT.RVCRUNM.MODE_CHANGE_OK']
8888
self.mode_fail = self.matter_test_config.global_test_params['PIXIT.RVCRUNM.MODE_CHANGE_FAIL']
8989
self.is_ci = self.check_pics("PICS_SDK_CI_ONLY")
90-
if self.is_ci:
91-
app_pid = self.matter_test_config.app_pid
92-
if app_pid == 0:
93-
asserts.fail("The --app-pid flag must be set when PICS_SDK_CI_ONLY is set.c")
94-
self.app_pipe = self.app_pipe + str(app_pid)
9590

9691
asserts.assert_true(self.check_pics("RVCRUNM.S.A0000"), "RVCRUNM.S.A0000 must be supported")
9792
asserts.assert_true(self.check_pics("RVCRUNM.S.A0001"), "RVCRUNM.S.A0001 must be supported")

src/python_testing/TC_RVCRUNM_2_2.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
# --discriminator 1234
3131
# --passcode 20202021
3232
# --endpoint 1
33+
# --app-pipe_prefix /tmp/chip_rvc_fifo_
3334
# --int-arg PIXIT.RVCRUNM.MODE_A:1
3435
# --int-arg PIXIT.RVCRUNM.MODE_B:2
3536
# --trace-to json:${TRACE_TEST_JSON}.json
@@ -84,7 +85,6 @@ def __init__(self, *args):
8485
self.supported_run_modes_dut = []
8586
self.idle_mode_dut = 0
8687
self.is_ci = False
87-
self.app_pipe = "/tmp/chip_rvc_fifo_"
8888

8989
async def read_mod_attribute_expect_success(self, cluster, attribute):
9090
return await self.read_single_attribute_check_success(
@@ -138,11 +138,6 @@ async def test_TC_RVCRUNM_2_2(self):
138138
self.is_ci = self.check_pics("PICS_SDK_CI_ONLY")
139139
self.mode_a = self.matter_test_config.global_test_params['PIXIT.RVCRUNM.MODE_A']
140140
self.mode_b = self.matter_test_config.global_test_params['PIXIT.RVCRUNM.MODE_B']
141-
if self.is_ci:
142-
app_pid = self.matter_test_config.app_pid
143-
if app_pid == 0:
144-
asserts.fail("The --app-pid flag must be set when PICS_SDK_CI_ONLY is set.c")
145-
self.app_pipe = self.app_pipe + str(app_pid)
146141

147142
asserts.assert_true(self.check_pics("RVCRUNM.S"), "RVCRUNM.S must be supported")
148143
# I think that the following PICS should be listed in the preconditions section in the test plan as if either

0 commit comments

Comments
 (0)