tree: 47635a9bb78ec811415a024975a53b1dcb932c34 [path history] [tgz]
  1. meta/
  2. BUILD.bazel
  3. BUILD.gn
  4. power_driver.cc
  5. power_driver.h
  6. README.md
  7. realm_test.rs
examples/drivers/power/cpp/README.md

Power C++ Driver

Reviewed on: 2025-06-25

Power C++ Driver is an example that showcase how to write a C++ driver that implements power functionality.

Building

To include the driver to your build, append --with //examples/drivers:drivers to your fx set command. For example:

$ fx set core.x64 --with //examples/drivers:drivers
$ fx build

Running

Register the driver by running this command

$ ffx driver register fuchsia-pkg://fuchsia.com/power_driver#meta/power_driver.cm

Verify that fuchsia-pkg://fuchsia.com/power_driver#meta/power_driver.cm shows up in the list after running this command

ffx driver list

Add a test node that binds to the driver:

$ ffx driver test-node add my_node gizmo.example.TEST_NODE_ID=power_driver

Run the following command to verify that the driver is bound to the node:

$ ffx driver list-devices -v my_node

You should see something like this:

Name     : my_node
Moniker  : dev.my_node
Driver   : fuchsia-pkg://fuchsia.com/power_driver#meta/power_driver.cm
1 Properties
[ 1/  1] : Key "gizmo.example.TEST_NODE_ID"   Value "power_driver"
0 Offers

If you want to explore the driver lifecycle and test the driver's stop functions, stop the driver by removing the node:

$ ffx driver test-node remove my_node

View the driver logs with ffx log --filter power_driver to see the execution order of the driver functions.

Testing

Include the tests to your build by appending --with //examples/drivers:tests to your fx set command. For example:

$ fx set core.x64 --with //examples/drivers:drivers --with //examples:tests
$ fx build

Run unit tests with the command:

$ fx test power-driver

The tests run the power driver and then invoke the suspend and resume hooks.