Skip to content

Commit

Permalink
TC-ACE-1.2 (#27157)
Browse files Browse the repository at this point in the history
* TC-ACE-1.2

* Add TC-ACE-1.2 to CI

* Whoops, added test twice

* Fixes to TC-ACE-1.2

* Set an option to not auto-resubscribe

If we error on initial subscription becuase we're NEVER going to
have access, the python scripts will never return - they will
continue to resubscribe forever and the future never completes.

This flag prevents any resubscription attempts. It's used in this
test becuase I know we're going to get a failure and I'd like to
have it returned.

* Fix python linter

* Restyled by isort

* linter.

* Apply suggestions from code review

Co-authored-by: Marc Lepage <67919234+mlepage-google@users.noreply.github.com>

* Fix weird typo.

---------

Co-authored-by: Restyled.io <commits@restyled.io>
Co-authored-by: Marc Lepage <67919234+mlepage-google@users.noreply.github.com>
  • Loading branch information
3 people authored and pull[bot] committed Feb 13, 2024
1 parent f9bf825 commit 8988187
Show file tree
Hide file tree
Showing 5 changed files with 303 additions and 11 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ jobs:
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --app out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app --factoryreset --app-args "--discriminator 1234 --KVS kvs1 --trace_decode 1" --script "src/python_testing/TC_SC_3_6.py" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021"'
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --app out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app --factoryreset --app-args "--discriminator 1234 --KVS kvs1 --trace_decode 1" --script "src/python_testing/TC_DA_1_7.py" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --bool-arg allow_sdk_dac:true"'
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --app out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app --factoryreset --app-args "--discriminator 1234 --KVS kvs1 --trace_decode 1 --enable-key 000102030405060708090a0b0c0d0e0f" --script "src/python_testing/TC_TestEventTrigger.py" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --bool-arg allow_sdk_dac:true"'
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --app out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app --factoryreset --app-args "--discriminator 1234 --KVS kvs1 --trace_decode 1" --script "src/python_testing/TC_ACE_1_2.py" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021"'
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --app out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app --factoryreset --app-args "--discriminator 1234 --KVS kvs1 --trace_decode 1" --script "src/python_testing/TC_ACE_1_4.py" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --int-arg PIXIT.ACE.APPENDPOINT:1 PIXIT.ACE.APPDEVTYPEID:0x0100 --string-arg PIXIT.ACE.APPCLUSTER:OnOff PIXIT.ACE.APPATTRIBUTE:OnOff"'
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --app out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app --factoryreset --app-args "--discriminator 1234 --KVS kvs1 --trace_decode 1" --script "src/python_testing/TC_ACE_1_3.py" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021"'
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --app out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app --factoryreset --app-args "--discriminator 1234 --KVS kvs1 --trace_decode 1" --script "src/python_testing/TC_CGEN_2_4.py" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021"'
Expand Down
15 changes: 9 additions & 6 deletions src/controller/python/chip/ChipDeviceCtrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@ async def Read(self, nodeid: int, attributes: typing.List[typing.Union[
]] = None,
eventNumberFilter: typing.Optional[int] = None,
returnClusterObject: bool = False, reportInterval: typing.Tuple[int, int] = None,
fabricFiltered: bool = True, keepSubscriptions: bool = False):
fabricFiltered: bool = True, keepSubscriptions: bool = False, autoResubscribe: bool = True):
'''
Read a list of attributes and/or events from a target node
Expand Down Expand Up @@ -1076,7 +1076,7 @@ async def Read(self, nodeid: int, attributes: typing.List[typing.Union[
subscriptionParameters=ClusterAttribute.SubscriptionParameters(
reportInterval[0], reportInterval[1]) if reportInterval else None,
fabricFiltered=fabricFiltered,
keepSubscriptions=keepSubscriptions).raise_on_error()
keepSubscriptions=keepSubscriptions, autoResubscribe=autoResubscribe).raise_on_error()
return await future

async def ReadAttribute(self, nodeid: int, attributes: typing.List[typing.Union[
Expand All @@ -1093,7 +1093,7 @@ async def ReadAttribute(self, nodeid: int, attributes: typing.List[typing.Union[
]], dataVersionFilters: typing.List[typing.Tuple[int, typing.Type[ClusterObjects.Cluster], int]] = None,
returnClusterObject: bool = False,
reportInterval: typing.Tuple[int, int] = None,
fabricFiltered: bool = True, keepSubscriptions: bool = False):
fabricFiltered: bool = True, keepSubscriptions: bool = False, autoResubscribe: bool = True):
'''
Read a list of attributes from a target node, this is a wrapper of DeviceController.Read()
Expand Down Expand Up @@ -1125,7 +1125,8 @@ async def ReadAttribute(self, nodeid: int, attributes: typing.List[typing.Union[
returnClusterObject=returnClusterObject,
reportInterval=reportInterval,
fabricFiltered=fabricFiltered,
keepSubscriptions=keepSubscriptions)
keepSubscriptions=keepSubscriptions,
autoResubscribe=autoResubscribe)
if isinstance(res, ClusterAttribute.SubscriptionTransaction):
return res
else:
Expand All @@ -1146,7 +1147,8 @@ async def ReadEvent(self, nodeid: int, events: typing.List[typing.Union[
]], eventNumberFilter: typing.Optional[int] = None,
fabricFiltered: bool = True,
reportInterval: typing.Tuple[int, int] = None,
keepSubscriptions: bool = False):
keepSubscriptions: bool = False,
autoResubscribe: bool = True):
'''
Read a list of events from a target node, this is a wrapper of DeviceController.Read()
Expand Down Expand Up @@ -1174,7 +1176,8 @@ async def ReadEvent(self, nodeid: int, events: typing.List[typing.Union[
When not provided, a read request will be sent.
'''
res = await self.Read(nodeid=nodeid, events=events, eventNumberFilter=eventNumberFilter,
fabricFiltered=fabricFiltered, reportInterval=reportInterval, keepSubscriptions=keepSubscriptions)
fabricFiltered=fabricFiltered, reportInterval=reportInterval, keepSubscriptions=keepSubscriptions,
autoResubscribe=autoResubscribe)
if isinstance(res, ClusterAttribute.SubscriptionTransaction):
return res
else:
Expand Down
10 changes: 7 additions & 3 deletions src/controller/python/chip/clusters/Attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,8 +615,8 @@ def __repr__(self):
return f'<Subscription (Id={self._subscriptionId})>'


async def DefaultResubscriptionAttemptedCallback(transaction: SubscriptionTransaction,
terminationError, nextResubscribeIntervalMsec):
def DefaultResubscriptionAttemptedCallback(transaction: SubscriptionTransaction,
terminationError, nextResubscribeIntervalMsec):
print(f"Previous subscription failed with Error: {terminationError} - re-subscribing in {nextResubscribeIntervalMsec}ms...")


Expand Down Expand Up @@ -773,6 +773,8 @@ def handleSubscriptionEstablished(self, subscriptionId):
self._handleSubscriptionEstablished, subscriptionId)

def handleResubscriptionAttempted(self, terminationCause: PyChipError, nextResubscribeIntervalMsec: int):
if not self._subscription_handler:
return
if (self._subscription_handler._onResubscriptionAttemptedCb_isAsync):
self._event_loop.create_task(self._subscription_handler._onResubscriptionAttemptedCb(
self._subscription_handler, terminationCause.code, nextResubscribeIntervalMsec))
Expand Down Expand Up @@ -1040,14 +1042,15 @@ def WriteGroupAttributes(groupId: int, devCtrl: c_void_p, attributes: List[Attri
"IsSubscription" / construct.Flag,
"IsFabricFiltered" / construct.Flag,
"KeepSubscriptions" / construct.Flag,
"AutoResubscribe" / construct.Flag,
)


def Read(future: Future, eventLoop, device, devCtrl,
attributes: List[AttributePath] = None, dataVersionFilters: List[DataVersionFilter] = None,
events: List[EventPath] = None, eventNumberFilter: Optional[int] = None, returnClusterObject: bool = True,
subscriptionParameters: SubscriptionParameters = None,
fabricFiltered: bool = True, keepSubscriptions: bool = False) -> PyChipError:
fabricFiltered: bool = True, keepSubscriptions: bool = False, autoResubscribe: bool = True) -> PyChipError:
if (not attributes) and dataVersionFilters:
raise ValueError(
"Must provide valid attribute list when data version filters is not null")
Expand Down Expand Up @@ -1119,6 +1122,7 @@ def Read(future: Future, eventLoop, device, devCtrl,
if subscriptionParameters is not None:
params.MinInterval = subscriptionParameters.MinReportIntervalFloorSeconds
params.MaxInterval = subscriptionParameters.MaxReportIntervalCeilingSeconds
params.AutoResubscribe = autoResubscribe
params.IsSubscription = True
params.KeepSubscriptions = keepSubscriptions
params.IsFabricFiltered = fabricFiltered
Expand Down
16 changes: 14 additions & 2 deletions src/controller/python/chip/clusters/attribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,17 @@ class ReadClientCallback : public ReadClient::Callback

CHIP_ERROR OnResubscriptionNeeded(ReadClient * apReadClient, CHIP_ERROR aTerminationCause) override
{
ReturnErrorOnFailure(ReadClient::Callback::OnResubscriptionNeeded(apReadClient, aTerminationCause));
if (mAutoResubscribe)
{
ReturnErrorOnFailure(ReadClient::Callback::OnResubscriptionNeeded(apReadClient, aTerminationCause));
}
gOnResubscriptionAttemptedCallback(mAppContext, ToPyChipError(aTerminationCause),
apReadClient->ComputeTimeTillNextSubscription());
return CHIP_NO_ERROR;
if (mAutoResubscribe)
{
return CHIP_NO_ERROR;
}
return aTerminationCause;
}

void OnEventData(const EventHeader & aEventHeader, TLV::TLVReader * apData, const StatusIB * apStatus) override
Expand Down Expand Up @@ -226,12 +233,15 @@ class ReadClientCallback : public ReadClient::Callback

void AdoptReadClient(std::unique_ptr<ReadClient> apReadClient) { mReadClient = std::move(apReadClient); }

void SetAutoResubscribe(bool autoResubscribe) { mAutoResubscribe = autoResubscribe; }

private:
BufferedReadCallback mBufferedReadCallback;

PyObject * mAppContext;

std::unique_ptr<ReadClient> mReadClient;
bool mAutoResubscribe = true;
};

extern "C" {
Expand All @@ -243,6 +253,7 @@ struct __attribute__((packed)) PyReadAttributeParams
bool isSubscription;
bool isFabricFiltered;
bool keepSubscriptions;
bool autoResubscribe;
};

// Encodes n attribute write requests, follows 3 * n arguments, in the (AttributeWritePath*=void *, uint8_t*, size_t) order.
Expand Down Expand Up @@ -564,6 +575,7 @@ PyChipError pychip_ReadClient_Read(void * appContext, ReadClient ** pReadClient,
params.mMinIntervalFloorSeconds = pyParams.minInterval;
params.mMaxIntervalCeilingSeconds = pyParams.maxInterval;
params.mKeepSubscriptions = pyParams.keepSubscriptions;
callback->SetAutoResubscribe(pyParams.autoResubscribe);

dataVersionFilters.release();
attributePaths.release();
Expand Down
Loading

0 comments on commit 8988187

Please sign in to comment.