Skip to content

Commit

Permalink
Merge branch 'master' into bugfix/DGSW_2_3_fails
Browse files Browse the repository at this point in the history
  • Loading branch information
Thirsrin authored May 2, 2024
2 parents 0d898d0 + 5570be9 commit 8666b8d
Show file tree
Hide file tree
Showing 9 changed files with 425 additions and 538 deletions.
8 changes: 8 additions & 0 deletions .pullapprove.yml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,14 @@ groups:
teams: [reviewers-samsung]
reviews:
request: 10
shared-reviewers-eve:
type: optional
conditions:
- files.include('*')
reviewers:
teams: [reviewers-eve]
reviews:
request: 10
# shared-reviewers-signify disabled for now, because the reviewers-signify
# team is empty and pullapprove seems to mis-handle that badly and treats
# _all_ reviewers as being in this group.
Expand Down
1 change: 0 additions & 1 deletion src/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ if (chip_build_tests) {
"${chip_root}/src/credentials/tests",
"${chip_root}/src/lib/format/tests",
"${chip_root}/src/lib/support/tests",
"${chip_root}/src/lib/support/tests:tests_nltest",
"${chip_root}/src/protocols/secure_channel/tests",
"${chip_root}/src/protocols/secure_channel/tests:tests_nltest",
"${chip_root}/src/system/tests",
Expand Down
84 changes: 75 additions & 9 deletions src/controller/python/chip/ChipDeviceCtrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -787,8 +787,16 @@ def GetClusterHandler(self):

return self._Cluster

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

returnDevice = c_void_p(None)
Expand Down Expand Up @@ -824,7 +832,7 @@ def deviceAvailable(self, device, err):
if returnDevice.value is None:
with deviceAvailableCV:
timeout = None
if (timeoutMs):
if timeoutMs is not None:
timeout = float(timeoutMs) / 1000

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

return DeviceProxyWrapper(returnDevice, self._dmLib)

async def GetConnectedDevice(self, nodeid, allowPASE: bool = True, timeoutMs: int = None):
''' Gets an OperationalDeviceProxy or CommissioneeDeviceProxy for the specified Node.
nodeId: Target's Node ID
allowPASE: Get a device proxy of a device being commissioned.
timeoutMs: Timeout for a timed invoke request. Omit or set to 'None' to indicate a non-timed request.
Returns:
- DeviceProxyWrapper on success
'''
self.CheckIsActive()

if allowPASE:
returnDevice = c_void_p(None)
res = self._ChipStack.Call(lambda: self._dmLib.pychip_GetDeviceBeingCommissioned(
self.devCtrl, nodeid, byref(returnDevice)), timeoutMs)
if res.is_success:
logging.info('Using PASE connection')
return DeviceProxyWrapper(returnDevice)

eventLoop = asyncio.get_running_loop()
future = eventLoop.create_future()

class DeviceAvailableClosure():
def __init__(self, loop, future: asyncio.Future):
self._returnDevice = c_void_p(None)
self._returnErr = None
self._event_loop = loop
self._future = future

def _deviceAvailable(self):
if self._returnDevice.value is not None:
self._future.set_result(self._returnDevice)
else:
self._future.set_exception(self._returnErr.to_exception())

def deviceAvailable(self, device, err):
self._returnDevice = c_void_p(device)
self._returnErr = err
self._event_loop.call_soon_threadsafe(self._deviceAvailable)
ctypes.pythonapi.Py_DecRef(ctypes.py_object(self))

closure = DeviceAvailableClosure(eventLoop, future)
ctypes.pythonapi.Py_IncRef(ctypes.py_object(closure))
self._ChipStack.Call(lambda: self._dmLib.pychip_GetConnectedDeviceByNodeId(
self.devCtrl, nodeid, ctypes.py_object(closure), _DeviceAvailableCallback),
timeoutMs).raise_on_error()

# The callback might have been received synchronously (during self._ChipStack.Call()).
# In that case the Future has already been set it will return immediately
if timeoutMs is not None:
timeout = float(timeoutMs) / 1000
await asyncio.wait_for(future, timeout=timeout)
else:
await future

return DeviceProxyWrapper(future.result(), self._dmLib)

def ComputeRoundTripTimeout(self, nodeid, upperLayerProcessingTimeoutMs: int = 0):
''' Returns a computed timeout value based on the round-trip time it takes for the peer at the other end of the session to
receive a message, process it and send it back. This is computed based on the session type, the type of transport,
Expand Down Expand Up @@ -900,7 +966,7 @@ async def TestOnlySendBatchCommands(self, nodeid: int, commands: typing.List[Clu
eventLoop = asyncio.get_running_loop()
future = eventLoop.create_future()

device = self.GetConnectedDeviceSync(nodeid, timeoutMs=interactionTimeoutMs)
device = await self.GetConnectedDevice(nodeid, timeoutMs=interactionTimeoutMs)

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

device = self.GetConnectedDeviceSync(nodeid, timeoutMs=None)
device = await self.GetConnectedDevice(nodeid, timeoutMs=None)
ClusterCommand.TestOnlySendCommandTimedRequestFlagWithNoTimedInvoke(
future, eventLoop, responseType, device.deviceProxy, ClusterCommand.CommandPath(
EndpointId=endpoint,
Expand Down Expand Up @@ -953,7 +1019,7 @@ async def SendCommand(self, nodeid: int, endpoint: int, payload: ClusterObjects.
eventLoop = asyncio.get_running_loop()
future = eventLoop.create_future()

device = self.GetConnectedDeviceSync(nodeid, timeoutMs=interactionTimeoutMs)
device = await self.GetConnectedDevice(nodeid, timeoutMs=interactionTimeoutMs)
ClusterCommand.SendCommand(
future, eventLoop, responseType, device.deviceProxy, ClusterCommand.CommandPath(
EndpointId=endpoint,
Expand Down Expand Up @@ -994,7 +1060,7 @@ async def SendBatchCommands(self, nodeid: int, commands: typing.List[ClusterComm
eventLoop = asyncio.get_running_loop()
future = eventLoop.create_future()

device = self.GetConnectedDeviceSync(nodeid, timeoutMs=interactionTimeoutMs)
device = await self.GetConnectedDevice(nodeid, timeoutMs=interactionTimeoutMs)

ClusterCommand.SendBatchCommands(
future, eventLoop, device.deviceProxy, commands,
Expand Down Expand Up @@ -1044,7 +1110,7 @@ async def WriteAttribute(self, nodeid: int,
eventLoop = asyncio.get_running_loop()
future = eventLoop.create_future()

device = self.GetConnectedDeviceSync(nodeid, timeoutMs=interactionTimeoutMs)
device = await self.GetConnectedDevice(nodeid, timeoutMs=interactionTimeoutMs)

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

device = self.GetConnectedDeviceSync(nodeid)
device = await self.GetConnectedDevice(nodeid)
attributePaths = [self._parseAttributePathTuple(
v) for v in attributes] if attributes else None
clusterDataVersionFilters = [self._parseDataVersionFilterTuple(
Expand Down
39 changes: 5 additions & 34 deletions src/lib/support/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -40,60 +40,33 @@ chip_test_suite("tests") {
"TestJsonToTlv.cpp",
"TestJsonToTlvToJson.cpp",
"TestPersistedCounter.cpp",
"TestPool.cpp",
"TestPrivateHeap.cpp",
"TestSafeInt.cpp",
"TestSafeString.cpp",
"TestScoped.cpp",
"TestScopedBuffer.cpp",
"TestSorting.cpp",
"TestSpan.cpp",
"TestStateMachine.cpp",
"TestStaticSupportSmartPtr.cpp",
"TestStringBuilder.cpp",
"TestStringSplitter.cpp",
"TestTestPersistentStorageDelegate.cpp",
"TestThreadOperationalDataset.cpp",
"TestTimeUtils.cpp",
"TestTlvJson.cpp",
"TestTlvToJson.cpp",
"TestUtf8.cpp",
"TestVariant.cpp",
"TestZclString.cpp",
]
sources = []

cflags = [
"-Wconversion",

# TODO(#21255): work-around for SimpleStateMachine constructor issue.
"-Wno-uninitialized",

# TestStringSplitter intentionally validates string overflows.
"-Wno-stringop-truncation",
]

public_deps = [
"${chip_root}/src/credentials",
"${chip_root}/src/lib/core",
"${chip_root}/src/lib/support:static-support",
"${chip_root}/src/lib/support:testing",
"${chip_root}/src/lib/support/jsontlv",
"${chip_root}/src/platform",
]
}

chip_test_suite_using_nltest("tests_nltest") {
output_name = "libSupportTestsNL"

test_sources = [
"TestPool.cpp",
"TestStateMachine.cpp",
"TestThreadOperationalDataset.cpp",
]
sources = []

if (current_os != "mbed") {
test_sources += [ "TestCHIPArgParser.cpp" ]
}

sources = []

cflags = [
"-Wconversion",

Expand All @@ -109,9 +82,7 @@ chip_test_suite_using_nltest("tests_nltest") {
"${chip_root}/src/lib/core",
"${chip_root}/src/lib/support:static-support",
"${chip_root}/src/lib/support:testing",
"${chip_root}/src/lib/support:testing_nlunit",
"${chip_root}/src/lib/support/jsontlv",
"${chip_root}/src/platform",
"${nlunit_test_root}:nlunit-test",
]
}
Loading

0 comments on commit 8666b8d

Please sign in to comment.