class TestNode

Defined at line 40 of file ../../sdk/lib/driver/testing/cpp/test_node.h

This class serves as the FIDL servers for the fuchsia_driver_framework::Node and

fuchsia_driver_framework::NodeController to a driver under test.

In a regular driver environment, this is provided by the driver framework's driver manager.

The Node FIDL is how drivers communicate with the driver framework to add child nodes into the

driver topology.

The TestNode is part of the unit test's environment that is given to the driver under test using

it's start args. Therefore this class is where the test acquires the start args to give to the

driver, using CreateStartArgsAndServe. The result of this contains three values:

- The actual start args for the driver to be given to the driver's Start.

- A server end of the incoming directory the driver will use. This must be passed into the

|fdf_testing::TestEnvironment::Initialize| function.

- A client end to the outgoing directory of the driver. This can be used by the test to

talk to FIDLs provided by the driver under test.

# Thread safety

This class is thread-unsafe. Instances must be managed and used from a synchronized dispatcher.

See

https://fuchsia.dev/fuchsia-src/development/languages/c-cpp/thread-safe-async#synchronized-dispatcher

If the dispatcher used for it is the foreground dispatcher, the TestNode does not need to be

wrapped in a DispatcherBound.

If the dispatcher is a background dispatcher, the suggestion is to wrap this inside of an

|async_patterns::TestDispatcherBound|.

Public Methods

void TestNode (std::string name, async_dispatcher_t * dispatcher)

If no dispatcher is provided, this will try to use the current fdf_dispatcher. If there

is also no fdf_dispatcher, it will try to use the thread's default async_dispatcher.

Defined at line 25 of file ../../sdk/lib/driver/testing/cpp/test_node.cc

void ~TestNode ()

Defined at line 30 of file ../../sdk/lib/driver/testing/cpp/test_node.cc

zx::result<fidl::ClientEnd<fuchsia_driver_framework::Node>> CreateNodeChannel ()

Create a channel pair, serve the server end, and return the client end.

This method is thread-unsafe. Must be called from the same context as the dispatcher.

Defined at line 32 of file ../../sdk/lib/driver/testing/cpp/test_node.cc

zx::result<> Serve (fidl::ServerEnd<fuchsia_driver_framework::Node> server_end)

Serve the given server end.

This method is thread-unsafe. Must be called from the same context as the dispatcher.

Defined at line 42 of file ../../sdk/lib/driver/testing/cpp/test_node.cc

zx::result<CreateStartArgsResult> CreateStartArgsAndServe ()

Creates the start args for a driver, and serve the fdf::Node in it.

Defined at line 53 of file ../../sdk/lib/driver/testing/cpp/test_node.cc

ChildrenMap & children ()

Gets the children created by the driver on this node.

Defined at line 68 of file ../../sdk/lib/driver/testing/cpp/test_node.h

const std::string & name ()

Gets the name of the node.

Defined at line 71 of file ../../sdk/lib/driver/testing/cpp/test_node.h

zx::result<zx::channel> ConnectToDevice ()

Connects to the devfs device this node is serving.

Defined at line 83 of file ../../sdk/lib/driver/testing/cpp/test_node.cc

bool HasNode ()

Whether this node has started serving the fdf::Node, this happens when |Serve|

or |CreateNodeChannel| has been called.

Defined at line 89 of file ../../sdk/lib/driver/testing/cpp/test_node.h

std::vector<fuchsia_driver_framework::NodeProperty2> GetProperties ()

Get the node properties that this node was created with. Can be used to validate that a driver

is creating valid child nodes.

Defined at line 104 of file ../../sdk/lib/driver/testing/cpp/test_node.h

std::vector<BindData> GetBindData ()

Gets the bind data that were stored as part of NodeController::RequestBind calls.

Defined at line 111 of file ../../sdk/lib/driver/testing/cpp/test_node.h

async_dispatcher_t * dispatcher ()

Get the dispatcher this Node object lives and serves FIDLs on.

Defined at line 117 of file ../../sdk/lib/driver/testing/cpp/test_node.h

Records