Skip to content

Commit 8666b8d

Browse files
authored
Merge branch 'master' into bugfix/DGSW_2_3_fails
2 parents 0d898d0 + 5570be9 commit 8666b8d

File tree

9 files changed

+425
-538
lines changed

9 files changed

+425
-538
lines changed

.pullapprove.yml

+8
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,14 @@ groups:
173173
teams: [reviewers-samsung]
174174
reviews:
175175
request: 10
176+
shared-reviewers-eve:
177+
type: optional
178+
conditions:
179+
- files.include('*')
180+
reviewers:
181+
teams: [reviewers-eve]
182+
reviews:
183+
request: 10
176184
# shared-reviewers-signify disabled for now, because the reviewers-signify
177185
# team is empty and pullapprove seems to mis-handle that badly and treats
178186
# _all_ reviewers as being in this group.

src/BUILD.gn

-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ if (chip_build_tests) {
9999
"${chip_root}/src/credentials/tests",
100100
"${chip_root}/src/lib/format/tests",
101101
"${chip_root}/src/lib/support/tests",
102-
"${chip_root}/src/lib/support/tests:tests_nltest",
103102
"${chip_root}/src/protocols/secure_channel/tests",
104103
"${chip_root}/src/protocols/secure_channel/tests:tests_nltest",
105104
"${chip_root}/src/system/tests",

src/controller/python/chip/ChipDeviceCtrl.py

+75-9
Original file line numberDiff line numberDiff line change
@@ -787,8 +787,16 @@ def GetClusterHandler(self):
787787

788788
return self._Cluster
789789

790-
def GetConnectedDeviceSync(self, nodeid, allowPASE=True, timeoutMs: int = None):
791-
''' Returns DeviceProxyWrapper upon success.'''
790+
def GetConnectedDeviceSync(self, nodeid, allowPASE: bool = True, timeoutMs: int = None):
791+
''' Gets an OperationalDeviceProxy or CommissioneeDeviceProxy for the specified Node.
792+
793+
nodeId: Target's Node ID
794+
allowPASE: Get a device proxy of a device being commissioned.
795+
timeoutMs: Timeout for a timed invoke request. Omit or set to 'None' to indicate a non-timed request.
796+
797+
Returns:
798+
- DeviceProxyWrapper on success
799+
'''
792800
self.CheckIsActive()
793801

794802
returnDevice = c_void_p(None)
@@ -824,7 +832,7 @@ def deviceAvailable(self, device, err):
824832
if returnDevice.value is None:
825833
with deviceAvailableCV:
826834
timeout = None
827-
if (timeoutMs):
835+
if timeoutMs is not None:
828836
timeout = float(timeoutMs) / 1000
829837

830838
ret = deviceAvailableCV.wait(timeout)
@@ -836,6 +844,64 @@ def deviceAvailable(self, device, err):
836844

837845
return DeviceProxyWrapper(returnDevice, self._dmLib)
838846

847+
async def GetConnectedDevice(self, nodeid, allowPASE: bool = True, timeoutMs: int = None):
848+
''' Gets an OperationalDeviceProxy or CommissioneeDeviceProxy for the specified Node.
849+
850+
nodeId: Target's Node ID
851+
allowPASE: Get a device proxy of a device being commissioned.
852+
timeoutMs: Timeout for a timed invoke request. Omit or set to 'None' to indicate a non-timed request.
853+
854+
Returns:
855+
- DeviceProxyWrapper on success
856+
'''
857+
self.CheckIsActive()
858+
859+
if allowPASE:
860+
returnDevice = c_void_p(None)
861+
res = self._ChipStack.Call(lambda: self._dmLib.pychip_GetDeviceBeingCommissioned(
862+
self.devCtrl, nodeid, byref(returnDevice)), timeoutMs)
863+
if res.is_success:
864+
logging.info('Using PASE connection')
865+
return DeviceProxyWrapper(returnDevice)
866+
867+
eventLoop = asyncio.get_running_loop()
868+
future = eventLoop.create_future()
869+
870+
class DeviceAvailableClosure():
871+
def __init__(self, loop, future: asyncio.Future):
872+
self._returnDevice = c_void_p(None)
873+
self._returnErr = None
874+
self._event_loop = loop
875+
self._future = future
876+
877+
def _deviceAvailable(self):
878+
if self._returnDevice.value is not None:
879+
self._future.set_result(self._returnDevice)
880+
else:
881+
self._future.set_exception(self._returnErr.to_exception())
882+
883+
def deviceAvailable(self, device, err):
884+
self._returnDevice = c_void_p(device)
885+
self._returnErr = err
886+
self._event_loop.call_soon_threadsafe(self._deviceAvailable)
887+
ctypes.pythonapi.Py_DecRef(ctypes.py_object(self))
888+
889+
closure = DeviceAvailableClosure(eventLoop, future)
890+
ctypes.pythonapi.Py_IncRef(ctypes.py_object(closure))
891+
self._ChipStack.Call(lambda: self._dmLib.pychip_GetConnectedDeviceByNodeId(
892+
self.devCtrl, nodeid, ctypes.py_object(closure), _DeviceAvailableCallback),
893+
timeoutMs).raise_on_error()
894+
895+
# The callback might have been received synchronously (during self._ChipStack.Call()).
896+
# In that case the Future has already been set it will return immediately
897+
if timeoutMs is not None:
898+
timeout = float(timeoutMs) / 1000
899+
await asyncio.wait_for(future, timeout=timeout)
900+
else:
901+
await future
902+
903+
return DeviceProxyWrapper(future.result(), self._dmLib)
904+
839905
def ComputeRoundTripTimeout(self, nodeid, upperLayerProcessingTimeoutMs: int = 0):
840906
''' Returns a computed timeout value based on the round-trip time it takes for the peer at the other end of the session to
841907
receive a message, process it and send it back. This is computed based on the session type, the type of transport,
@@ -900,7 +966,7 @@ async def TestOnlySendBatchCommands(self, nodeid: int, commands: typing.List[Clu
900966
eventLoop = asyncio.get_running_loop()
901967
future = eventLoop.create_future()
902968

903-
device = self.GetConnectedDeviceSync(nodeid, timeoutMs=interactionTimeoutMs)
969+
device = await self.GetConnectedDevice(nodeid, timeoutMs=interactionTimeoutMs)
904970

905971
ClusterCommand.TestOnlySendBatchCommands(
906972
future, eventLoop, device.deviceProxy, commands,
@@ -921,7 +987,7 @@ async def TestOnlySendCommandTimedRequestFlagWithNoTimedInvoke(self, nodeid: int
921987
eventLoop = asyncio.get_running_loop()
922988
future = eventLoop.create_future()
923989

924-
device = self.GetConnectedDeviceSync(nodeid, timeoutMs=None)
990+
device = await self.GetConnectedDevice(nodeid, timeoutMs=None)
925991
ClusterCommand.TestOnlySendCommandTimedRequestFlagWithNoTimedInvoke(
926992
future, eventLoop, responseType, device.deviceProxy, ClusterCommand.CommandPath(
927993
EndpointId=endpoint,
@@ -953,7 +1019,7 @@ async def SendCommand(self, nodeid: int, endpoint: int, payload: ClusterObjects.
9531019
eventLoop = asyncio.get_running_loop()
9541020
future = eventLoop.create_future()
9551021

956-
device = self.GetConnectedDeviceSync(nodeid, timeoutMs=interactionTimeoutMs)
1022+
device = await self.GetConnectedDevice(nodeid, timeoutMs=interactionTimeoutMs)
9571023
ClusterCommand.SendCommand(
9581024
future, eventLoop, responseType, device.deviceProxy, ClusterCommand.CommandPath(
9591025
EndpointId=endpoint,
@@ -994,7 +1060,7 @@ async def SendBatchCommands(self, nodeid: int, commands: typing.List[ClusterComm
9941060
eventLoop = asyncio.get_running_loop()
9951061
future = eventLoop.create_future()
9961062

997-
device = self.GetConnectedDeviceSync(nodeid, timeoutMs=interactionTimeoutMs)
1063+
device = await self.GetConnectedDevice(nodeid, timeoutMs=interactionTimeoutMs)
9981064

9991065
ClusterCommand.SendBatchCommands(
10001066
future, eventLoop, device.deviceProxy, commands,
@@ -1044,7 +1110,7 @@ async def WriteAttribute(self, nodeid: int,
10441110
eventLoop = asyncio.get_running_loop()
10451111
future = eventLoop.create_future()
10461112

1047-
device = self.GetConnectedDeviceSync(nodeid, timeoutMs=interactionTimeoutMs)
1113+
device = await self.GetConnectedDevice(nodeid, timeoutMs=interactionTimeoutMs)
10481114

10491115
attrs = []
10501116
for v in attributes:
@@ -1272,7 +1338,7 @@ async def Read(self, nodeid: int, attributes: typing.List[typing.Union[
12721338
eventLoop = asyncio.get_running_loop()
12731339
future = eventLoop.create_future()
12741340

1275-
device = self.GetConnectedDeviceSync(nodeid)
1341+
device = await self.GetConnectedDevice(nodeid)
12761342
attributePaths = [self._parseAttributePathTuple(
12771343
v) for v in attributes] if attributes else None
12781344
clusterDataVersionFilters = [self._parseDataVersionFilterTuple(

src/lib/support/tests/BUILD.gn

+5-34
Original file line numberDiff line numberDiff line change
@@ -40,60 +40,33 @@ chip_test_suite("tests") {
4040
"TestJsonToTlv.cpp",
4141
"TestJsonToTlvToJson.cpp",
4242
"TestPersistedCounter.cpp",
43+
"TestPool.cpp",
4344
"TestPrivateHeap.cpp",
4445
"TestSafeInt.cpp",
4546
"TestSafeString.cpp",
4647
"TestScoped.cpp",
4748
"TestScopedBuffer.cpp",
4849
"TestSorting.cpp",
4950
"TestSpan.cpp",
51+
"TestStateMachine.cpp",
5052
"TestStaticSupportSmartPtr.cpp",
5153
"TestStringBuilder.cpp",
5254
"TestStringSplitter.cpp",
5355
"TestTestPersistentStorageDelegate.cpp",
56+
"TestThreadOperationalDataset.cpp",
5457
"TestTimeUtils.cpp",
5558
"TestTlvJson.cpp",
5659
"TestTlvToJson.cpp",
5760
"TestUtf8.cpp",
5861
"TestVariant.cpp",
5962
"TestZclString.cpp",
6063
]
61-
sources = []
62-
63-
cflags = [
64-
"-Wconversion",
65-
66-
# TODO(#21255): work-around for SimpleStateMachine constructor issue.
67-
"-Wno-uninitialized",
68-
69-
# TestStringSplitter intentionally validates string overflows.
70-
"-Wno-stringop-truncation",
71-
]
72-
73-
public_deps = [
74-
"${chip_root}/src/credentials",
75-
"${chip_root}/src/lib/core",
76-
"${chip_root}/src/lib/support:static-support",
77-
"${chip_root}/src/lib/support:testing",
78-
"${chip_root}/src/lib/support/jsontlv",
79-
"${chip_root}/src/platform",
80-
]
81-
}
82-
83-
chip_test_suite_using_nltest("tests_nltest") {
84-
output_name = "libSupportTestsNL"
85-
86-
test_sources = [
87-
"TestPool.cpp",
88-
"TestStateMachine.cpp",
89-
"TestThreadOperationalDataset.cpp",
90-
]
91-
sources = []
92-
9364
if (current_os != "mbed") {
9465
test_sources += [ "TestCHIPArgParser.cpp" ]
9566
}
9667

68+
sources = []
69+
9770
cflags = [
9871
"-Wconversion",
9972

@@ -109,9 +82,7 @@ chip_test_suite_using_nltest("tests_nltest") {
10982
"${chip_root}/src/lib/core",
11083
"${chip_root}/src/lib/support:static-support",
11184
"${chip_root}/src/lib/support:testing",
112-
"${chip_root}/src/lib/support:testing_nlunit",
11385
"${chip_root}/src/lib/support/jsontlv",
11486
"${chip_root}/src/platform",
115-
"${nlunit_test_root}:nlunit-test",
11687
]
11788
}

0 commit comments

Comments
 (0)