Skip to content

Commit 8dae584

Browse files
tcarmelveilleuxrestyled-commits
authored andcommitted
Fix MSR flag issues in TC-SWTCH-* (project-chip#35327)
* Fix MSR flag issues in TC-SWTCH-* - MSR is optional, but was checked as if mandatory. - See CHIP-Specifications/chip-test-plans#4593 - Fix initial conditions in CI * Restyled by clang-format * Restyled by autopep8 --------- Co-authored-by: Restyled.io <commits@restyled.io>
1 parent 40dd479 commit 8dae584

File tree

2 files changed

+64
-23
lines changed

2 files changed

+64
-23
lines changed

examples/all-clusters-app/linux/AllClustersCommandDelegate.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,34 @@ void HandleSimulateLatchPosition(Json::Value & jsonValue)
248248
}
249249
}
250250

251+
/**
252+
* Named pipe handler for simulating switch is idle
253+
*
254+
* Usage example:
255+
* echo '{"Name": "SimulateSwitchIdle", "EndpointId": 3}' > /tmp/chip_all_clusters_fifo_1146610
256+
*
257+
* JSON Arguments:
258+
* - "Name": Must be "SimulateSwitchIdle"
259+
* - "EndpointId": ID of endpoint having a switch cluster
260+
*
261+
* @param jsonValue - JSON payload from named pipe
262+
*/
263+
264+
void HandleSimulateSwitchIdle(Json::Value & jsonValue)
265+
{
266+
bool hasEndpointId = HasNumericField(jsonValue, "EndpointId");
267+
268+
if (!hasEndpointId)
269+
{
270+
std::string inputJson = jsonValue.toStyledString();
271+
ChipLogError(NotSpecified, "Missing or invalid value for one of EndpointId in %s", inputJson.c_str());
272+
return;
273+
}
274+
275+
EndpointId endpointId = static_cast<EndpointId>(jsonValue["EndpointId"].asUInt());
276+
(void) Switch::Attributes::CurrentPosition::Set(endpointId, 0);
277+
}
278+
251279
void EmitOccupancyChangedEvent(EndpointId endpointId, uint8_t occupancyValue)
252280
{
253281
Clusters::OccupancySensing::Events::OccupancyChanged::Type event{};
@@ -427,6 +455,10 @@ void AllClustersAppCommandHandler::HandleCommand(intptr_t context)
427455
{
428456
HandleSimulateLatchPosition(self->mJsonValue);
429457
}
458+
else if (name == "SimulateSwitchIdle")
459+
{
460+
HandleSimulateSwitchIdle(self->mJsonValue);
461+
}
430462
else if (name == "SetOccupancy")
431463
{
432464
uint8_t occupancy = static_cast<uint8_t>(self->mJsonValue["Occupancy"].asUInt());

src/python_testing/TC_SWTCH.py

+32-23
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,15 @@ def _send_latching_switch_named_pipe_command(self, endpoint_id: int, new_positio
104104
command_dict = {"Name": "SimulateLatchPosition", "EndpointId": endpoint_id, "PositionId": new_position}
105105
self._send_named_pipe_command(command_dict)
106106

107-
def _ask_for_switch_idle(self):
107+
def _send_switch_idle_named_pipe_command(self, endpoint_id: int):
108+
command_dict = {"Name": "SimulateSwitchIdle", "EndpointId": endpoint_id}
109+
self._send_named_pipe_command(command_dict)
110+
111+
def _ask_for_switch_idle(self, endpoint_id: int, omit_for_simulator: bool = False):
108112
if not self._use_button_simulator():
109113
self.wait_for_user_input(prompt_msg="Ensure switch is idle")
114+
elif not omit_for_simulator:
115+
self._send_switch_idle_named_pipe_command(endpoint_id)
110116

111117
def _ask_for_switch_position(self, endpoint_id: int, new_position: int):
112118
if not self._use_button_simulator():
@@ -283,7 +289,6 @@ async def test_TC_SWTCH_2_2(self):
283289
# Step 3: Operator sets switch to first position on the DUT.
284290
self.step(3)
285291
self._ask_for_switch_position(endpoint_id, new_position=0)
286-
event_listener.flush_events()
287292

288293
# Step 4: TH reads the CurrentPosition attribute from the DUT.
289294
# Verify that the value is 0.
@@ -369,7 +374,7 @@ async def test_TC_SWTCH_2_3(self):
369374
await event_listener.start(self.default_controller, self.dut_node_id, endpoint=endpoint_id)
370375

371376
self.step(3)
372-
self._ask_for_switch_idle()
377+
self._ask_for_switch_idle(endpoint_id)
373378

374379
self.step(4)
375380
button_val = await self.read_single_attribute_check_success(cluster=cluster, attribute=cluster.Attributes.CurrentPosition)
@@ -461,7 +466,7 @@ async def test_TC_SWTCH_2_4(self):
461466

462467
# Step 3: Operator does not operate switch on the DUT
463468
self.step(3)
464-
self._ask_for_switch_idle()
469+
self._ask_for_switch_idle(endpoint_id)
465470

466471
# Step 4: TH reads the CurrentPosition attribute from the DUT
467472
self.step(4)
@@ -486,9 +491,9 @@ async def test_TC_SWTCH_2_4(self):
486491
self._await_sequence_of_events(event_queue=event_listener.event_queue, endpoint_id=endpoint_id,
487492
sequence=expected_events, timeout_sec=post_prompt_settle_delay_seconds)
488493

489-
# - if MSL or AS feature is supported, expect to see LongPress/LongRelease in that order.
490-
if not has_msl_feature and not has_as_feature:
491-
logging.info("Since MSL and AS features both unsupported, skipping check for LongPress/LongRelease")
494+
# - if MSL feature is supported, expect to see LongPress/LongRelease in that order.
495+
if not has_msl_feature:
496+
logging.info("Since MSL feature unsupported, skipping check for LongPress/LongRelease")
492497
else:
493498
# - TH expects report of LongPress, LongRelease in that order.
494499
logging.info(f"Starting to wait for {post_prompt_settle_delay_seconds:.1f} seconds for LongPress then LongRelease.")
@@ -538,13 +543,13 @@ def steps_TC_SWTCH_2_5(self):
538543
TestStep("6b", "Operator repeat step 4a 3 times quickly",
539544
"""
540545
* Verify that the TH receives InitialPress event with NewPosition set to 1 from the DUT
541-
* Verify that the TH receives ShortRelease event with PreviousPosition set to 1 from the DUT
546+
* If MSR supported, Verify that the TH receives ShortRelease event with PreviousPosition set to 1 from the DUT
542547
* Verify that the TH receives InitialPress event with NewPosition set to 1 from the DUT
543548
* Verify that the TH receives MultiPressOngoing event with NewPosition set to 1 and CurrentNumberOfPressesCounted set to 2 from the DUT
544-
* Verify that the TH receives ShortRelease event with PreviousPosition set to 1 from the DUT
549+
* If MSR supported, Verify that the TH receives ShortRelease event with PreviousPosition set to 1 from the DUT
545550
* Verify that the TH receives InitialPress event with NewPosition set to 1 from the DUT
546551
* Verify that the TH receives MultiPressOngoing event with NewPosition set to 1 and CurrentNumberOfPressesCounted set to 3 from the DUT
547-
* Verify that the TH receives ShortRelease event with PreviousPosition set to 1 from the DUT +
552+
* If MSR supported, Verify that the TH receives ShortRelease event with PreviousPosition set to 1 from the DUT +
548553
549554
The events sequence from the subscription SHALL follow the same sequence as expressed above, in the exact order of events specified.
550555
"""),
@@ -561,11 +566,11 @@ def steps_TC_SWTCH_2_5(self):
561566
"""
562567
563568
* Verify that the TH receives InitialPress event with NewPosition set to 1 from the DUT
564-
* Verify that the TH receives ShortRelease event with PreviousPosition set to 1 from the DUT
569+
* If MSR supported, Verify that the TH receives ShortRelease event with PreviousPosition set to 1 from the DUT
565570
* Verify that the TH receives InitialPress event with NewPosition set to 1 from the DUT
566571
567572
* Verify that the TH receives MultiPressOngoing event with NewPosition set to 1 and CurrentNumberOfPressesCounted set to 2 from the DUT
568-
* Verify that the TH receives ShortRelease event with PreviousPosition set to 1 from the DUT
573+
* If MSR supported, verify that the TH receives ShortRelease event with PreviousPosition set to 1 from the DUT
569574
* Verify that the TH does not receive LongPress event from the DUT
570575
* Verify that the TH does not receive LongRelease event from the DUT
571576
@@ -586,7 +591,7 @@ def steps_TC_SWTCH_2_5(self):
586591
* Verify that the TH receives (one, not more than one) LongPress event with NewPosition set to 1 from the DUT
587592
* Verify that the TH receives LongRelease event with PreviousPosition set to 1 from the DUT
588593
* Verify that the TH receives InitialPress event with NewPosition set to 1 from the DUT
589-
* Verify that the TH receives ShortRelease event with PreviousPosition set to 1 from the DUT
594+
* If MSR supported, verify that the TH receives ShortRelease event with PreviousPosition set to 1 from the DUT
590595
* Verify that the TH does not receive MultiPressOngoing event from the DUT
591596
592597
The events sequence from the subscription SHALL follow the same sequence as expressed above, in the exact order of events specified.
@@ -610,6 +615,7 @@ async def test_TC_SWTCH_2_5(self):
610615
cluster = Clusters.Switch
611616
feature_map = await self.read_single_attribute_check_success(cluster, attribute=cluster.Attributes.FeatureMap)
612617
has_msl_feature = (feature_map & cluster.Bitmaps.Feature.kMomentarySwitchLongPress)
618+
has_msr_feature = (feature_map & cluster.Bitmaps.Feature.kMomentarySwitchRelease)
613619
multi_press_max = await self.read_single_attribute_check_success(cluster, attribute=cluster.Attributes.MultiPressMax)
614620

615621
endpoint_id = self.matter_test_config.endpoint
@@ -620,7 +626,7 @@ async def test_TC_SWTCH_2_5(self):
620626
await event_listener.start(self.default_controller, self.dut_node_id, endpoint=endpoint_id)
621627

622628
self.step(3)
623-
self._ask_for_switch_idle()
629+
self._ask_for_switch_idle(endpoint_id)
624630

625631
def test_multi_press_sequence(starting_step: str, count: int, short_long: bool = False):
626632
step = starting_step
@@ -640,12 +646,13 @@ def test_multi_press_sequence(starting_step: str, count: int, short_long: bool =
640646
asserts.assert_equal(event.newPosition, pressed_position, "Unexpected NewPosition on MultiPressOngoing")
641647
asserts.assert_equal(event.currentNumberOfPressesCounted, pos_idx + 1,
642648
"Unexpected CurrentNumberOfPressesCounted on MultiPressOngoing")
643-
event = event_listener.wait_for_event_report(cluster.Events.ShortRelease)
644-
asserts.assert_equal(event.previousPosition, pressed_position, "Unexpected PreviousPosition on ShortRelease")
649+
if has_msr_feature:
650+
event = event_listener.wait_for_event_report(cluster.Events.ShortRelease)
651+
asserts.assert_equal(event.previousPosition, pressed_position, "Unexpected PreviousPosition on ShortRelease")
645652

646653
step = bump_substep(step)
647654
self.step(step)
648-
self._ask_for_switch_idle()
655+
self._ask_for_switch_idle(endpoint_id, omit_for_simulator=True)
649656
event = event_listener.wait_for_event_report(cluster.Events.MultiPressComplete)
650657
asserts.assert_equal(event.previousPosition, pressed_position, "Unexpected PreviousPosition on MultiPressComplete")
651658
asserts.assert_equal(event.totalNumberOfPressesCounted, count, "Unexpected count on MultiPressComplete")
@@ -687,13 +694,15 @@ def test_multi_press_sequence(starting_step: str, count: int, short_long: bool =
687694

688695
event = event_listener.wait_for_event_report(cluster.Events.InitialPress)
689696
asserts.assert_equal(event.newPosition, pressed_position, "Unexpected NewPosition on InitialEvent")
690-
event = event_listener.wait_for_event_report(cluster.Events.ShortRelease)
691-
asserts.assert_equal(event.previousPosition, pressed_position, "Unexpected PreviousPosition on ShortRelease")
697+
698+
if has_msr_feature:
699+
event = event_listener.wait_for_event_report(cluster.Events.ShortRelease)
700+
asserts.assert_equal(event.previousPosition, pressed_position, "Unexpected PreviousPosition on ShortRelease")
692701

693702
# Because this is a queue, we verify that no multipress ongoing is received by verifying that the next event is the multipress complete
694703

695704
self.step("9b")
696-
self._ask_for_switch_idle()
705+
self._ask_for_switch_idle(endpoint_id, omit_for_simulator=True)
697706
event = event_listener.wait_for_event_report(cluster.Events.MultiPressComplete)
698707
asserts.assert_equal(event.previousPosition, pressed_position, "Unexpected PreviousPosition on MultiPressComplete")
699708
asserts.assert_equal(event.totalNumberOfPressesCounted, 1, "Unexpected count on MultiPressComplete")
@@ -795,7 +804,7 @@ async def test_TC_SWTCH_2_6(self):
795804
await event_listener.start(self.default_controller, self.dut_node_id, endpoint=endpoint_id)
796805

797806
self.step(3)
798-
self._ask_for_switch_idle()
807+
self._ask_for_switch_idle(endpoint_id)
799808

800809
def test_multi_press_sequence(starting_step: str, count: int, short_long: bool = False):
801810
step = starting_step
@@ -813,7 +822,7 @@ def test_multi_press_sequence(starting_step: str, count: int, short_long: bool =
813822

814823
step = bump_substep(step)
815824
self.step(step)
816-
self._ask_for_switch_idle()
825+
self._ask_for_switch_idle(endpoint_id, omit_for_simulator=True)
817826
event = event_listener.wait_for_event_report(cluster.Events.MultiPressComplete)
818827
asserts.assert_equal(event.previousPosition, pressed_position, "Unexpected PreviousPosition on MultiPressComplete")
819828
expected_count = 0 if count > multi_press_max else count
@@ -853,7 +862,7 @@ def test_multi_press_sequence(starting_step: str, count: int, short_long: bool =
853862

854863
# Verify that we don't receive the multi-press ongoing or short release by verifying that the next event in the sequence is the multi-press complete
855864
self.step("9b")
856-
self._ask_for_switch_idle()
865+
self._ask_for_switch_idle(endpoint_id, omit_for_simulator=True)
857866
event = event_listener.wait_for_event_report(cluster.Events.MultiPressComplete)
858867
asserts.assert_equal(event.previousPosition, pressed_position, "Unexpected PreviousPosition on MultiPressComplete")
859868
asserts.assert_equal(event.totalNumberOfPressesCounted, 1, "Unexpected count on MultiPressComplete")

0 commit comments

Comments
 (0)