drivers_only_common/
lib.rs1use fidl::HandleBased;
6use fidl::endpoints::{Proxy, create_endpoints, create_proxy};
7use fuchsia_component::client::connect_to_protocol;
8use realm_client::{InstalledNamespace, extend_namespace};
9use test_realm_helpers::constants::TESTCONTROLLER_DRIVER_TOPOLOGICAL_PATH;
10use test_realm_helpers::tracing::Tracing;
11use {fidl_test_wlan_realm as fidl_realm, fidl_test_wlan_testcontroller as fidl_testcontroller};
12
13pub mod sme_helpers;
14
15pub struct DriversOnlyTestRealm {
16 testcontroller_proxy: Option<fidl_testcontroller::TestControllerProxy>,
17 _tracing: Tracing,
18 _test_ns: InstalledNamespace,
19}
20
21impl DriversOnlyTestRealm {
22 pub async fn new() -> Self {
23 let realm_factory = connect_to_protocol::<fidl_realm::RealmFactoryMarker>()
24 .expect("Could not connect to realm factory protocol");
25
26 let (dict_client, dict_server) = create_endpoints();
27 let (dev_topological, dev_topological_server) = create_proxy();
28 let (_dev_class, dev_class_server) = create_proxy();
29
30 let (pkg_client, pkg_server) = create_endpoints();
31 fuchsia_fs::directory::open_channel_in_namespace(
32 "/pkg",
33 fidl_fuchsia_io::PERM_READABLE | fidl_fuchsia_io::PERM_EXECUTABLE,
34 pkg_server,
35 )
36 .expect("Could not open /pkg");
37
38 let options = fidl_realm::RealmOptions {
39 topology: Some(fidl_realm::Topology::DriversOnly(fidl_realm::DriversOnly {
40 driver_config: Some(fidl_realm::DriverConfig {
41 dev_topological: Some(dev_topological_server),
42 dev_class: Some(dev_class_server),
43 driver_test_realm_start_args: Some(fidl_fuchsia_driver_test::RealmArgs {
44 pkg: Some(pkg_client),
45 ..Default::default()
46 }),
47 ..Default::default()
48 }),
49 ..Default::default()
50 })),
51 ..Default::default()
52 };
53
54 realm_factory
55 .create_realm2(options, dict_server)
56 .await
57 .expect("FIDL error on create_realm")
58 .expect("create_realm returned an error");
59
60 let testcontroller_proxy = device_watcher::recursive_wait_and_open::<
61 fidl_testcontroller::TestControllerMarker,
62 >(
63 &dev_topological, TESTCONTROLLER_DRIVER_TOPOLOGICAL_PATH
64 )
65 .await
66 .expect("Could not open testcontroller_proxy");
67
68 let test_ns =
69 extend_namespace(realm_factory, dict_client).await.expect("Failed to extend ns");
70 let tracing = Tracing::start_at(test_ns.prefix()).await.unwrap();
71
72 Self {
73 testcontroller_proxy: Some(testcontroller_proxy),
74 _tracing: tracing,
75 _test_ns: test_ns,
76 }
77 }
78
79 pub fn testcontroller_proxy(&self) -> &fidl_testcontroller::TestControllerProxy {
80 self.testcontroller_proxy.as_ref().unwrap()
81 }
82
83 pub fn take_sync_testcontroller_proxy(
84 &mut self,
85 ) -> fidl_testcontroller::TestControllerSynchronousProxy {
86 fidl_testcontroller::TestControllerSynchronousProxy::new(fidl::Channel::from_handle(
87 self.testcontroller_proxy
88 .take()
89 .unwrap()
90 .into_channel()
91 .expect("Failed to get fidl::AsyncChannel from proxy")
92 .into_zx_channel()
93 .into_handle(),
94 ))
95 }
96}