blob: 78595fe415d0c0ec21bad78bd1c0c427d2057707 [file] [log] [blame]
// Copyright 2022 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
use {
fidl_fuchsia_driver_test as fdt, fuchsia_async as fasync,
fuchsia_driver_test::{DriverTestRealmBuilder, DriverTestRealmInstance},
fuchsia_zircon as zx,
async fn test_sample_driver() {
// Start the driver test realm.
let builder = RealmBuilder::new().await.unwrap();
let _: &RealmBuilder = builder.driver_test_realm_setup().await.unwrap();
let instance =;
let () = instance.driver_test_realm_start(fdt::RealmArgs::default()).await.unwrap();
// Connect to our driver.
let dev = instance.driver_test_realm_connect_to_dev().unwrap();
let parent = device_watcher::recursive_wait_and_open::<
>(&dev, "sys/test/parent_device")
// Call a FIDL method to add a device. This should succeed.
let () = parent.add_device().await.unwrap().unwrap();
// Make sure the child device exists.
let child =
device_watcher::recursive_wait_and_open_directory(&dev, "sys/test/parent_device/duplicate")
let () = child.close().await.unwrap().unwrap();
// Call it again to add a second device with the same name, which should fail.
let response = parent.add_device().await.unwrap();
assert_eq!(response.map_err(zx::Status::from_raw), Err(zx::Status::BAD_STATE));