| // Copyright 2021 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 { |
| anyhow::Result, |
| fidl_fuchsia_driver_test as fdt, fuchsia_async as fasync, |
| fuchsia_component_test::RealmBuilder, |
| fuchsia_driver_test::{DriverTestRealmBuilder, DriverTestRealmInstance}, |
| }; |
| |
| #[fasync::run_singlethreaded(test)] |
| async fn test_sample_driver() -> Result<()> { |
| // Create the RealmBuilder. |
| let builder = RealmBuilder::new().await?; |
| builder.driver_test_realm_setup().await?; |
| // Build the Realm. |
| let instance = builder.build().await?; |
| // Start DriverTestRealm |
| let args = fdt::RealmArgs { |
| root_driver: Some("fuchsia-boot:///dtr#meta/test-parent-sys.cm".to_string()), |
| ..Default::default() |
| }; |
| instance.driver_test_realm_start(args).await?; |
| |
| // Connect to our driver. |
| let dev = instance.driver_test_realm_connect_to_dev()?; |
| let driver = |
| device_watcher::recursive_wait_and_open::<fidl_fuchsia_hardware_compat::LeafMarker>( |
| &dev, |
| "sys/test/root/leaf", |
| ) |
| .await?; |
| let response = driver.get_string().await.unwrap(); |
| assert_eq!(response, "hello world!"); |
| Ok(()) |
| } |