When migrating a DFv1 driver to DFv2, a major part of work is to update the driver interfaces to DFv2. However, if your target driver needs to talk to other DFv1 drivers that haven't yet migrated to DFv2, you need to use the compatibility shim to enable your now-DFv2 driver to talk to other DFv1 drivers in the system.
List of migration tasks
DFv1-to-DFv2 migration tasks are:
- Update dependencies from DDK to DFv2
- (Optional) Update dependencies for the compatibility shim
- Update the driver interfaces from DFv1 to DFv2
- Use the DFv2 service discovery
- Update component manifests of other drivers
- Expose a devfs node from the DFv2 driver
- Use dispatchers
- Use the DFv2 inspect
- Use the DFv2 logger
- (Optional) Implement your own load_firmware method
- (Optional) Use the node properties generated from FIDL service offers
- Update unit tests to DFv2
For more information and examples, see Additional resources.
Before you start (Frequently asked questions)
Before you start jumping into the DFv1-to-DFv2 migration tasks, the frequently asked questions below can help you identify special conditions or edge cases that may apply to your driver.
What is the compatibility shim and when is it necessary?
DFv1 and DFv2 drivers exist under a single branch of the node topology tree (that is, until all the drivers are migrated to DFv2) and they need to be able to talk to each other. To help with the migration process, Fuchsia's driver framework team created a compatibility shim to enable DFv1 drivers to live in DFv2.
If your target driver talks to other DFv1 drivers that still use Banjo and those drivers won't be migrated to DFv2 all at once, you need to use this compatibility shim (by manually creating
compat::DeviceServer
) for enabling the drivers in different framework versions to talk to each other.Can DFv2 drivers talk to Banjo protocols using the compatibility shim?
While it's strongly recommended that your DFv1 driver is migrated from Banjo to FIDL, if it is necessary for a DFv2 driver to talk to some existing Banjo protocols, the compatibility shim provides the following features:
compat::BanjoServer
makes it easier to serve Banjo (seebanjo_server.h
).compat::ConnectBanjo
makes it easier to connect to Banjo (seebanjo_client.h
).
What has changed in the new DFv2 driver interfaces?
One major change in DFv2 is that drivers take control of the life cycle of the child nodes (or devices) created by the drivers. This is different from DFv1 where the driver framework manages the life cycles of devices, such as tearing down devices, through the device tree.
In DFv1, devices are controlled by
zx_protocol_device
while drivers are controlled byzx_driver_ops
. Ifddktl
is used, the interfaces inzx_protocol_device
need to be wrapped byDdk*()
functions in the mixin template class. In DFv2, those interfaces have changed significantly.How does service discovery work in DFv2?
In DFv2, using a FIDL service is required to establish a protocol connection. The parent driver adds a FIDL service to the
driver::OutgoingDirectory
object and serves it to the child node, which then enables the parent driver to offer the service to the child node.DFv1 and DFv2 drivers do this differently in the following ways:
In DFv1, the driver sets and passes the offer from the
DeviceAddArgs::set_runtime_service_offers()
call. Then the driver creates andriver::OutgoingDirectory
object and passes the client end handle through theDeviceAddArgs::set_outgoing_dir()
call.In DFv2, the driver sets and passes the offer from the
NodeAddArgs::offers
object. The driver adds the service to the outgoing directory wrapped by theDriverBase
class (originally provided by theStart()
function). When the child driver binds to the child node, the driver host passes the incoming namespace containing the service to the child driver'sStart()
function.
On the child driver side, DFv1 and DFv2 drivers also connect to the protocol providing the service in different ways:
- A DFv1 driver calls the
DdkConnectRuntimeProtocol<ProtocolName>()
method. - A DFv2 driver calls the
driver::Connect<ProtocolName>()
method (orcontext().incoming()->Connect<ProtocolName>()
if theDriverBase
class is used).
For more information, see Use the DFv2 service discovery.
How does my driver's node (or device) get exposed in the system in DFv2?
Fuchsia has a global tree of devices exposed as a filesystem known as
devfs
, which is routed to most components as/dev
. When a driver adds a device node, it has the option of adding a "file" intodevfs
. Then this file indevfs
allows other components in the system to talk to the driver. For instance, an audio driver may add a speaker device node and the audio driver wants to make sure that other components can use this node to output audio to the speaker. To accomplish this, the audio driver adds (or exposes) adevfs
node for the speaker so that it appears as/dev/class/audio/<random_number>
in the system.What is not implemented in DFv2 that was available in DFv1?
If your DFv1 driver calls the
load_firmware()
function in the DDK library, you need to implement your own since an equivalent function is not available in DFv2. However, this is expected to be simple to implement.What has changed in the bind rules in DFv2?
DFv2 nodes contain additional node properties generated from their FIDL service offers.
What has changed in logging in DFv2?
DFv2 drivers cannot use the
zxlogf()
function or any debug library that wraps or uses this function.zxlogf()
is defined in//src/lib/ddk/include/lib/ddk/debug.h
and is removed from the dependencies in DFv2. Drivers migrating to DFv2 need to stop using this library and other libraries that depend on it.However, a new compatibility library, which is only available in the Fuchsia source tree (
fuchsia.git
) environment, is now added to allow DFv2 drivers to use DFv1-style logging.What has changed in inspect in DFv2?
DFv1 drivers use driver-specific inspect functions to create and update driver-maintained metrics. For instance, in DFv1 the
DeviceAddArgs::set_inspect_vmo()
function is called to indicate the VMO that the driver uses for inspect. In DFv2, however, we can just create aninspect::ComponentInspector
object.What do dispatchers do in DFv2?
A FIDL file generates templates and data types for a client-and-server pair. Between these client and server ends is a channel, and the dispatchers at each end fetch data from the channel. For more information on dispatchers, see Driver dispatcher and threads.
What are some issues with the new threading model when migrating a DFv1 driver to DFv2?
FIDL calls in DFv2 are not on a single thread basis and are asynchronous by design (although you can make them synchronous by adding
.sync()
to FIDL calls or usingfdf::WireSyncClient
). Drivers are generally discouraged from making synchronous calls because they can block other tasks from running. (However, if necessary, a driver can create a dispatcher with theFDF_DISPATCHER_OPTION_ALLOW_SYNC_CALLS
option, which is only supported for synchronized dispatchers.)Given the differences in the threading models between Banjo (DFv1) and FIDL (DFv2), you'll need to decide which kind of FIDL call (that is, synchronous or asynchronous) you want to use while migrating. If your original code is designed around the synchronous nature of Banjo and is hard to unwind to make it all asynchronous, then you may want to consider using the synchronous version of FIDL at first (which, however, may result in performance degradation for the time being). Later, you can revisit these calls and optimize them into using synchronous calls.
What has changed in testing drivers in DFv2?
The
mock_ddk
library, which is used in driver unit tests, is specific to DFv1. New testing libraries are now available for DFv2 drivers.Should I fork my driver into a DFv2 version while working on migration?
Forking an existing driver for migration depends on the complexity of the driver. In general, it is recommended to avoid forking a driver because it could end up creating more work. However, for larger drivers, it may make sense to fork the driver into a DFv2 version so that you can gradually land migration changes in smaller patches.
You can fork a driver by adding a new driver component in the GN args and use a flag to decide between the DFv1 or DFv2 version. This example CL demonstrates how a DFv2 fork of the
msd-arm-mali
driver was added.What are some recommended readings?
The DFv2 concept docs on fuchsia.dev and this Gerrit change from the previous DFv1 Intel WiFi driver migration (the
pcie-iwlwifi-driver.cc
file contains most of the new APIs).
Update dependencies from DDK to DFv2
DFv1 drivers use the DDK library (//src/lib/ddk
). For DFv2 drivers,
you can safely remove all package dependencies under this DDK library
directory and replace them with the following new library, which
includes most of the essential utilities for DFv2 drivers:
//sdk/lib/driver/component/cpp:cpp
In header files, include the following library for the new DFv2 driver interfaces:
#include <lib/driver/component/cpp/driver_base.h>
(Optional) Update dependencies for the compatibility shim
For DFv1 drivers that need to talk to DFv2 drivers, you need the following packages for the compatibility shim:
//sdk/lib/driver/compat/cpp:cpp
//sdk/lib/driver/compat/cpp:symbols
In header files, you need the following libraries for the compatibility shim:
#include <lib/driver/compat/cpp/compat.h>
#include <lib/driver/compat/cpp/symbols.h>
#include <lib/driver/compat/cpp/connect.h>
Update the driver interfaces from DFv1 to DFv2
DFv2 provides a virtual class called DriverBase
that
wraps regular routines for a driver. For DFv2 drivers, inheriting
DriverBase
in your new driver class is recommended, which makes the
interfaces much simpler.
For example, let's say you have the following class in your DFv1 driver:
class MyExampleDriver;
using MyExampleDeviceType = ddk::Device<MyExampleDriver, ddk::Initializable,
ddk::Unbindable>;
class MyExampleDriver : public MyExampleDeviceType {
public:
void DdkInit(ddk::InitTxn txn);
void DdkUnbind(ddk::UnbindTxn txn);
void DdkRelease();
}
If you update the interface to inherit from DriverBase
, the new class
may look like below:
class MyExampleDriver : public fdf::DriverBase {
public:
Driver(fdf::DriverStartArgs start_args,
fdf::UnownedSynchronizedDispatcher driver_dispatcher);
zx::result<> Start() override;
void Stop() override;
}
In addition to starting and stopping the driver (as shown in the example
above), the DriverBase
class provides the objects that enable the driver
to communicate with other components (and drivers). For instance,
instead of declaring and creating your own outgoing directory in DFv1
(as in the Migrate from Banjo to FIDL phase),
your driver can now call the outgoing()
method of the DriverBase
class
to retrieve an outgoing directory, for example:
class DriverBase {
...
// Used to access the outgoing directory that the driver is serving. Can be used to add both
// zircon and driver transport outgoing services.
std::shared_ptr<OutgoingDirectory>& outgoing() { return outgoing_; }
...
}
(Source: driver_base.h
)
Another useful class available in DFv2 is the Node
class. The example
below shows a DFv2 driver's code that connects to the Node
server and
uses the AddChild()
function to add a child node:
zx::result<> MyExampleDriver::Start() {
fidl::WireSyncClient<fuchsia_driver_framework::Node> node(std::move(node()));
auto args = fuchsia_driver_framework::wire::NodeAddArgs::Builder(arena)
.name(arena, “example_node”)
.Build();
zx::result controller_endpoints =
fidl::CreateEndpoints<fuchsia_driver_framework::NodeController>();
ZX_ASSERT(controller_endpoints.is_ok());
auto result = node_->AddChild(args, std::move(controller_endpoints->server), {});
if (!result.ok()) {
FDF_LOG(ERROR, "Failed to add child: %s", result.status_string());
return zx::error(result.status());
}
return zx::ok();
}
The NodeController
endpoint (controller_endpoints
in the example above) passed to the AddChild()
function can be used to
control the child node. For instance, this endpoint can be used to remove
the child node from the node topology, request the driver framework to bind
the node to a specific driver, or receive a callback when the child node is
bound. The example below shows a DFv2 driver's code that removes the child
node during shutdown:
void MyExampleDriver::Stop() {
// controller_endpoints defined in the previous example.
fidl::WireSyncClient<fuchsia_driver_framework::NodeController>
node_controller(controller_endpoints->client);
auto status = node_controller->Remove();
if (!status.ok()) {
FDF_LOG(ERROR, "Could not remove child: %s", status.status_string());
}
}
Moreover, in DFv2, the OnBind()
event is defined in the NodeController
protocol, which is invoked by the child node from the server side. The
DriverBase::PrepareStop()
function provides a chance to perform
de-initializations before DriverBase::Stop()
is called.
The table below shows the mapping of the common driver and device interfaces between DFv1 and DFv2:
DFv1 | DFv2 |
---|---|
zx_driver_ops::bind() |
DriverBase::Start() |
zx_driver_ops::init() |
DriverBase::Start() |
zx_driver_ops::release() |
DriverBase::Stop() |
device_add() DdkAdd() |
Node::AddChild() |
device_add_composite() DdkAddComposite() |
None. Add composite nodes using specifications. See Composite Node. |
device_add_composite_node_spec() DdkAddCompositeNodeSpec() |
CompositeNodeManager::AddSpec() |
zx_protocol_device::init() DdkInit() |
None. In DFv2, a driver is in charge of the life cycle of the nodes (devices) it adds. |
zx_protocol_device::unbind() DdkUnbind() |
None. In DFv2, a driver is in charge of the life cycle of the nodes (devices) it adds. |
zx_protocol_device::release() DdkRelease() |
NodeController::Remove() |
zx_protocol_device::get_protocol() device_get_protocol() |
None. These methods are based on Banjo protocols In DFv2, all communications are in FIDL. |
zx_protocol_device::service_connect() device_service_connect() DdkServiceConnect() |
None. This is an old-fashioned approach for drivers to establish FIDL connections with each other. For more information, see Use the DFv2 service discovery. |
Device_connect_runtime_protocol() DdkConnectRuntimeProtocol() |
None. These are newly added methods for service and protocol discovery in DFv1. For more information, see Use the DFv2 service discovery. |
Also, aside from updating the interfaces, you need to change the macro that populates your driver interface functions:
From:
ZIRCON_DRIVER()
To:
FUCHSIA_DRIVER_EXPORT()
Use the DFv2 service discovery
When working on driver migration, you will likely encounter one or more
of the following three scenarios in which two drivers establish a FIDL
connection (in child driver -> parent driver
format):
- Scenario 1: DFv2 driver -> DFv2 driver
- Scenario 2: DFv1 driver -> DFv2 driver
- Scenario 3: DFv2 driver -> DFv1 driver
Scenario 1 is the standard case for DFv2 drivers (this example shows the new DFv2 syntax). To update your driver under this scenario, see the DFv2 driver to DFv2 driver section below.
Scenario 2 and 3 are more complicated because the DFv1 driver is wrapped in the compatibility shim in the DFv2 world. However, the differences are:
In scenario 2, this Gerrit change shows a method that exposes a service from the DFv2 parent to the DFv1 child.
In scenario 3, the driver is connected to the
fuchsia_driver_compat::Service::Device
protocol provided by the compatibility shim of the parent driver, and the driver calls theConnectFidl()
method through this protocol to connect to the real protocol (for an example, see this Gerrit change).
To update your driver under scenario 2 or 3, see the DFv1 driver to DFv2 driver (with compatibility shim) section below.
DFv2 driver to DFv2 driver
To enable other DFv2 drivers to discover your driver's service, do the following:
Update your driver's
.fidl
file.The protocol discovery in DFv2 requires adding
service
fields for the driver's protocols, for example:library fuchsia.example; @discoverable @transport("Driver") protocol MyProtocol { MyMethod() -> (struct { ... }); }; service Service { my_protocol client_end:MyProtocol; };
Update the child driver.
DFv2 drivers can connect to protocols in the same way as FIDL services, for example:
driver::Connect<fuchsia_example::Service::MyProtocol>
You also need to update the component manifest (
.cml
) file to use your driver runtime service, for example:use: [ { service: "fuchsia.example.Service" }, ]
Update the parent driver.
Your parent driver needs to create a
driver::OutgoingDirectory
object. You can use thedriver::OutgoingDirectory::Create()
method or thedriver::DriverBase
class. With thedriver::OutgoingDirectory
object, you must use services rather than protocols.Then you need to add the runtime service to your outgoing directory. The example below is a driver that inherits from the
driver::DriverBase
class:zx::status<> Start() override { auto protocol = [this]( fdf::ServerEnd<fuchsia_example::MyProtocol> server_end) mutable { fdf::BindServer(dispatcher()->get(), std::move(server_end), this); }; fuchsia_example::Service::InstanceHandler handler( {.my_protocol = std::move(protocol)}); auto status = context().outgoing().AddService<fuchsia_wlan_phyimpl::Service>( std::move(handler)); if (status.is_error()) { return status.take_error(); } auto result = outgoing_dir_.Serve(std::move(server_end)); if (result.is_error()) { return result.take_error(); } return zx::ok(); }
Update the child node's
NodeAddArgs
to include an offer for your runtime service, for example:auto offers = std::vector{fdf::MakeOffer<fuchsia_example::Service>(arena, name)}; fidl::WireSyncClient<fuchsia_driver_framework::Node> node(std::move(node())); auto args = fuchsia_driver_framework::wire::NodeAddArgs::Builder(arena) .name(arena, “example_node”) .offers(offers) .Build(); zx::result controller_endpoints = fidl::CreateEndpoints<fuchsia_driver_framework::NodeController>(); ZX_ASSERT(controller_endpoints.is_ok()); auto result = node_->AddChild( args, std::move(controller_endpoints->server), {});
Similarly, update the parent driver's component manifest (
.cml
) file to offer your runtime service, for example:capabilities: [ { service: "fuchsia.example.Service" }, ], expose: [ { service: "fuchsia.example.Service", from: "self", }, ],
DFv1 driver to DFv2 driver (with compatibility shim)
To enable other DFv1 drivers to discover your DFv2 driver's service, do the following:
Update the DFv1 drivers.
You need to update the component manifest (
.cml
) files of the DFv1 drivers in the same way as mentioned in the DFv2 driver to DFv2 driver section above, for example:Child driver:
{ include: [ "//sdk/lib/driver_compat/compat.shard.cml", "inspect/client.shard.cml", "syslog/client.shard.cml", ], program: { runner: "driver", compat: "driver/child-driver-name.so", bind: "meta/bind/child-driver-name.bindbc", colocate: "true", }, use: [ { service: "fuchsia.example.Service" }, ], }
Parent driver:
{ include: [ "//sdk/lib/driver_compat/compat.shard.cml", "inspect/client.shard.cml", "syslog/client.shard.cml", ], program: { runner: "driver", compat: "driver/parent-driver-name.so", bind: "meta/bind/parent-driver-name.bindbc", }, capabilities: [ { service: "fuchsia.example.Service" }, ], expose: [ { service: "fuchsia.example.Service", from: "self", }, ], }
Update the DFv2 driver.
The example below shows a method that exposes a service from the DFv2 parent to the DFv1 child:
fit::result<fdf::NodeError> AddChild() { fidl::Arena arena; auto offer = fdf::MakeOffer<ft::Service>(kChildName); // Set the properties of the node that a driver will bind to. auto property = fdf::MakeProperty(1 /*BIND_PROTOCOL */, bind_fuchsia_test::BIND_PROTOCOL_COMPAT_CHILD); auto args = fdf::NodeAddArgs{ { .name = std::string(kChildName), .offers = std::vector{std::move(offer)}, .properties = std::vector{std::move(property)}, } }; // Create endpoints of the `NodeController` for the node. auto endpoints = fidl::CreateEndpoints<fdf::NodeController>(); if (endpoints.is_error()) { return fit::error(fdf::NodeError::kInternal); } auto add_result = node_.sync()->AddChild(fidl::ToWire(arena, std::move(args)), std::move(endpoints->server), {});
(Source:
root-driver.cc
)
Update component manifests of other drivers
To complete the migration of a DFv1 driver to DFv2, you not only need
to update the component manifest (.cml
) file of your target driver,
but you may also need to update the component manifest files of some
other drivers that interact with your now-DFv2 driver.
Do the following:
Update the component manifests of leaf drivers (that is, without child drivers) with the changes below:
- Remove
//sdk/lib/driver/compat/compat.shard.cml
from theinclude
field. - Replace the
program.compat
field withprogram.binary
.
- Remove
Update the component manifests of other drivers that perform the following tasks:
- Access kernel
args
. - Create composite devices.
- Detect reboot, shutdown, or rebind calls.
- Talk to other drivers using the Banjo protocol.
- Access metadata from a parent driver or forward it.
- Talk to a DFv1 driver that binds to a node added by your driver.
For these drivers, update their component manifest with the changes below:
Copy some of the
use
capabilities fromcompat.shard.cml
to the component manifest, for example:use: [ { protocol: [ "fuchsia.boot.Arguments", "fuchsia.boot.Items", "fuchsia.device.composite.DeprecatedCompositeCreator", "fuchsia.device.manager.SystemStateTransition", "fuchsia.driver.framework.CompositeNodeManager", ], }, { service: "fuchsia.driver.compat.Service" }, ],
Set the
program.runner
field todriver
, for example:program: { runner: "driver", binary: "driver/compat.so", },
- Access kernel
Expose a devfs node from the DFv2 driver
To expose a devfs
node from a DFv2 driver, you need to add
the device_args
member to the NodeAddArgs
.
In particular, it requires specifying the class name as well as
implementing the connector, which can be simplified by making use of
the Connector
library, for example:
zx::result connector = devfs_connector_.Bind(dispatcher());
if (connector.is_error()) {
return connector.take_error();
}
auto devfs =
fuchsia_driver_framework::wire::DevfsAddArgs::Builder(arena).connector(
std::move(connector.value()));
auto args = fuchsia_driver_framework::wire::NodeAddArgs::Builder(arena)
.name(arena, name)
.devfs_args(devfs.Build())
.Build();
(Source: parent-driver.cc
)
For more information, see
Expose the driver capabilities in the
DFv2 driver codelab. Also, see this implementation
of the ExportToDevfs
method mentioned in the codelab.
Use dispatchers
Dispatchers fetch data from a channel between a FIDL client-and-server pair. By default, FIDL calls in this channel are asynchronous.
For introducing asynchronization to drivers in DFv2, see the following suggestions:
The
fdf::Dispatcher::GetCurrent()
method gives you the default dispatcher that the driver is running on (see thisaml-ethernet
driver example). If possible, it is recommended to use this default dispatcher alone.Consider using multiple dispatchers for the following reasons (but not limited to):
The driver requires parallelism for performance.
The driver wants to perform blocking operations (because it is either a legacy driver or a non-Fuchsia driver being ported to Fuchsia) and it needs to handle more work while blocked.
If multiple dispatchers are needed, the
fdf::Dispatcher::Create()
method can create new dispatchers for your driver. However, you must call this method on the default dispatcher (for example, call it inside theStart()
hook) so that the driver host is aware of the additional dispatchers that belong to your driver.In DFv2, you don't need to shut down the dispatchers manually. They will be shut down between the
PrepareStop()
andStop()
calls.
For more details on migrating a driver to use multiple dispatchers, see the Update the DFv1 driver to use non-default dispatchers section (in the Migrate from Banjo to FIDL phrase).
Use the DFv2 inspect
To set up driver-maintained inspect metrics in DFv2,
you need to create an inspect::ComponentInspector
object, for example:
component_inspector_ =
std::make_unique<inspect::ComponentInspector>(out, dispatcher, *inspector_);
(Source: driver-inspector.cc
)
Creating an inspect::ComponentInspector
object needs the following
three input items:
The
component::OutgoingDirectory
object from theContext().outgoing()->component()
callA dispatcher
The original
inspect::Inspector
object
However, the DFv2 inspect does not require passing the VMO of
inspect::Inspector
to the driver framework.
Use the DFv2 logger
Instead of using zxlogf()
(which is deprecated in DFv2), the new
logging mechanism in DFv2 depends on the driver::Logger
object,
which is passed from the driver host through DriverStartArgs
when starting the driver.
The driver::DriverBase
class wraps driver::Logger
and the driver
can get its reference by calling the logger()
method (see this
wlantap-driver
driver example). With this reference,
you can print out logs using the logger.logf()
function or using these
macros, for example:
FDF_LOGL(INFO, *logger(), "Example log message here");
(Optional) Implement your own load_firmware method
If your DFv1 driver calls the load_firmware()
function in the DDK library, you need to implement your own version
of this function because an equivalent function is not available in DFv2.
This function is expected to be simple to implement. You need to get the backing VMO from the path manually. For an example, see this Gerrit change.
(Optional) Use the node properties generated from FIDL service offers
DFv2 nodes contain the node properties generated from the FIDL service offers from their parents.
For instance, in the Parent Driver (The Server)
example, the parent driver adds a node called "parent"
with a service
offer for fidl.examples.EchoService
. In DFv2, a driver that binds to this
node can have a bind rule for that FIDL service node property, for example:
using fidl.examples.echo;
fidl.examples.echo.Echo == fidl.examples.echo.Echo.ZirconTransport;
For more information, see the Generated bind libraries section of the FIDL tutorial page.
Update unit tests to DFv2
The mock_ddk
library (which is used in unit tests for testing
driver and device life cycle) is specific to DFv1. The new DFv2 test
framework (see this Gerrit change) makes
mocked FIDL servers available to DFv2 drivers through the TestEnvironment
class.
The following libraries are available for unit testing DFv2 drivers:
-
TestNode
– This class implements thefuchsia_driver_framework::Node
protocol, which can be provided to a driver to create child nodes. This class is also used by tests to access the child nodes that the driver has created.TestEnvironment
– A wrapper over anOutgoingDirectory
object that serves as the backing VFS (virtual file system) for the incoming namespace of the driver under test.DriverUnderTest
– This class is a RAII (Resource Acquisition Is Initialization) wrapper for the driver under test.DriverRuntime
– This class is a RAII wrapper over the managed driver runtime thread pool.
//sdk/lib/driver/testing/cpp/driver_runtime.h
TestSynchronizedDispatcher
– This class is a RAII wrapper over the driver dispatcher.
The following library may be helpful for writing driver unit tests:
//src/devices/bus/testing/fake-pdev/fake-pdev.h
– This helper library implements a fake version of thepdev
FIDL protocol.
Lastly, the following example unit tests cover different configurations and test cases:
//sdk/lib/driver/component/cpp/tests/driver_base_test.cc
- This file contains examples of the different threading models that driver tests can have.//sdk/lib/driver/component/cpp/tests/driver_fidl_test.cc
- This file demonstrates how to work with incoming and outgoing FIDL services fo both driver transport and Zircon transport as well asdevfs
.
Additional resources
Some DFv2 drivers examples:
All the Gerrit changes mentioned in this section:
- [iwlwifi] Dfv2 migration for iwlwifi driver
- [compat-runtime-test] Migrate off usage of DeviceServer
- [msd-arm-mali] Add DFv2 version
- [sdk][driver][testing] Add testing library
All the source code files mentioned in this section:
//examples/drivers/transport/zircon/v2/parent-driver.cc
//sdk/fidl/fuchsia.driver.framework/topology.fidl
//sdk/lib/driver/component/cpp/driver_base.h
//sdk/lib/driver/component/cpp/tests/driver_base_test.cc
//sdk/lib/driver/component/cpp/tests/driver_fidl_test.cc
//sdk/lib/driver/compat/cpp/banjo_server.h
//sdk/lib/driver/compat/cpp/banjo_client.h
//sdk/lib/driver/compat/cpp/device_server.h
//sdk/lib/driver/testing/cpp/driver_runtime.h
//src/connectivity/wlan/testing/wlantap-driver/wlantap-driver.cc
//src/devices/bus/testing/fake-pdev/fake-pdev.h
//src/devices/tests/v2/compat-runtime/root-driver.cc
//src/lib/ddk/include/lib/ddk/device.h
//src/lib/ddk/include/lib/ddk/driver.h
//third_party/iwlwifi/platform/driver-inspector.cc
All the documentation pages mentioned in this section:
- Banjo
- Drivers and nodes
- Driver communication
- Drivers and nodes
- Driver dispatcher and threads
- Drivers
- Composite nodes
- Expose the driver capabilities
- Fuchsia component inspection overview
- Mock DDK Migration
- An Example of the Tear-Down Sequence (from Device driver lifecycle)
- Parent Driver (The Server) (from FIDL tutorial)
- Generated bind libraries (from FIDL tutorial)