Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BDX transfer support for Python tests #34821

Open
wants to merge 42 commits into
base: master
Choose a base branch
from

Conversation

harimau-qirex
Copy link
Contributor

Add support for BDX transfers to the Python tests.

This allows Python tests to wait for BDX transfers, inspect the init message's details, accept or reject the transfer, and send or receive data. This assists with writing tests for the OTA requestor and diagnostic logs clusters that involve BDX transfers. The code takes some inspiration from the existing BDX transfer server code in src/protocols/bdx, and I think it's worth following up at some point to expand the capabilities of that code to reduce the amount of code specific to the Python controller code introduced in this change.

Included is a test that uses the diagnostic logs cluster on the all clusters app to initiate and complete a BDX transfer.

Also add the transfer obtained context to the C++ methods relating to expecting transfers.
…a BDX transfer.

Also run the python BDX initialisation.
Also ignore the BDX transfer server implementation that only handles diagnostic logs.
…ata.

* Call Responder::PrepareForTransfer from BdxTransfer.
* Correctly schedule satisfying the future on the event loop.
* Use the real property to determine if a PyChipError was a success.
Also don't ignore all messages after the init.
Copy link
Contributor

@cecille cecille left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to Cecille: made it down to bdx.cpp, but haven't reviewed that yet.

src/controller/python/chip/bdx/bdx-transfer-manager.cpp Outdated Show resolved Hide resolved
src/controller/python/chip/bdx/bdx-transfer-manager.h Outdated Show resolved Hide resolved
src/controller/python/chip/bdx/bdx-transfer-manager.cpp Outdated Show resolved Hide resolved
src/controller/python/chip/bdx/bdx-transfer-pool.h Outdated Show resolved Hide resolved
src/controller/python/chip/bdx/bdx-transfer-server.cpp Outdated Show resolved Hide resolved
src/controller/python/chip/bdx/bdx-transfer.cpp Outdated Show resolved Hide resolved
src/controller/python/chip/bdx/bdx-transfer.cpp Outdated Show resolved Hide resolved
src/controller/python/chip/ChipDeviceCtrl.py Outdated Show resolved Hide resolved
src/controller/python/chip/ChipStack.py Show resolved Hide resolved
src/controller/python/chip/bdx/bdx-transfer-manager.cpp Outdated Show resolved Hide resolved
src/controller/python/chip/bdx/bdx-transfer-manager.h Outdated Show resolved Hide resolved
src/controller/python/chip/bdx/bdx-transfer-pool.h Outdated Show resolved Hide resolved
src/controller/python/chip/bdx/bdx-transfer.cpp Outdated Show resolved Hide resolved
src/python_testing/TestBdxTransfer.py Outdated Show resolved Hide resolved
* remove a check that was inadvertently kept.
* print a log message when something that shouldn't happen inevitably does.
* use user_params to get the end user support log test parameter.


class BdxTransfer:
def __init__(self, bdx_transfer: c_void_p, init_message: InitMessage, data=None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a type annotation for data? Is it expecting bytes? or string? or something else entirely

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

if self._data != None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if self._data != None:
if self._data is not None:

I think Or not self._data if data can't be a thing that evaluates to false. Not sure on the data type or whether an empty data is viable.

OnTransferCompletedCallback gOnTransferCompletedCallback = nullptr;

// The information for a single transfer.
struct TransferData
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name of this struct is a bit odd because it's not the data for transfer, its the information about the transfer. Can this be TranferInfo or some other such thing

if (gOnTransferObtainedCallback && transferData)
{
gOnTransferObtainedCallback(transferData->OnTransferObtainedContext, ToPyChipError(result), nullptr,
static_cast<bdx::TransferControlFlags>(0), 0, 0, 0, nullptr, 0, nullptr, 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what are the args here?

// The information for a single transfer.
struct TransferData
{
bdx::BdxTransfer * Transfer = nullptr;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I've tracked down all the pieces, and it seems correct, but would you mind adding some documentation here about what owns which pieces of this transfer and what the expected lifefimes are? The callbacks are python, it looks like the TransferData is owned by the TransferMap (owned by ...? But referenced by the delegate?) Transfers are owned by the transfer server? Does the transfer server also own the data or is that owned externally? Does that change for receive/send?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants