fidl_fuchsia_crashdriver_test/
fidl_fuchsia_crashdriver_test.rs1#![warn(clippy::all)]
4#![allow(unused_parens, unused_mut, unused_imports, nonstandard_style)]
5
6use bitflags::bitflags;
7use fidl::client::QueryResponseFut;
8use fidl::encoding::{MessageBufFor, ProxyChannelBox, ResourceDialect};
9use fidl::endpoints::{ControlHandle as _, Responder as _};
10pub use fidl_fuchsia_crashdriver_test_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct CrasherMarker;
16
17impl fidl::endpoints::ProtocolMarker for CrasherMarker {
18 type Proxy = CrasherProxy;
19 type RequestStream = CrasherRequestStream;
20 #[cfg(target_os = "fuchsia")]
21 type SynchronousProxy = CrasherSynchronousProxy;
22
23 const DEBUG_NAME: &'static str = "(anonymous) Crasher";
24}
25
26pub trait CrasherProxyInterface: Send + Sync {
27 type PingResponseFut: std::future::Future<Output = Result<u64, fidl::Error>> + Send;
28 fn r#ping(&self) -> Self::PingResponseFut;
29 fn r#crash(&self) -> Result<(), fidl::Error>;
30}
31#[derive(Debug)]
32#[cfg(target_os = "fuchsia")]
33pub struct CrasherSynchronousProxy {
34 client: fidl::client::sync::Client,
35}
36
37#[cfg(target_os = "fuchsia")]
38impl fidl::endpoints::SynchronousProxy for CrasherSynchronousProxy {
39 type Proxy = CrasherProxy;
40 type Protocol = CrasherMarker;
41
42 fn from_channel(inner: fidl::Channel) -> Self {
43 Self::new(inner)
44 }
45
46 fn into_channel(self) -> fidl::Channel {
47 self.client.into_channel()
48 }
49
50 fn as_channel(&self) -> &fidl::Channel {
51 self.client.as_channel()
52 }
53}
54
55#[cfg(target_os = "fuchsia")]
56impl CrasherSynchronousProxy {
57 pub fn new(channel: fidl::Channel) -> Self {
58 Self { client: fidl::client::sync::Client::new(channel) }
59 }
60
61 pub fn into_channel(self) -> fidl::Channel {
62 self.client.into_channel()
63 }
64
65 pub fn wait_for_event(
68 &self,
69 deadline: zx::MonotonicInstant,
70 ) -> Result<CrasherEvent, fidl::Error> {
71 CrasherEvent::decode(self.client.wait_for_event::<CrasherMarker>(deadline)?)
72 }
73
74 pub fn r#ping(&self, ___deadline: zx::MonotonicInstant) -> Result<u64, fidl::Error> {
76 let _response = self
77 .client
78 .send_query::<fidl::encoding::EmptyPayload, CrasherPingResponse, CrasherMarker>(
79 (),
80 0x63e0c4d973e4b1f9,
81 fidl::encoding::DynamicFlags::empty(),
82 ___deadline,
83 )?;
84 Ok(_response.pong)
85 }
86
87 pub fn r#crash(&self) -> Result<(), fidl::Error> {
89 self.client.send::<fidl::encoding::EmptyPayload>(
90 (),
91 0x15290e84d9b74bd2,
92 fidl::encoding::DynamicFlags::empty(),
93 )
94 }
95}
96
97#[cfg(target_os = "fuchsia")]
98impl From<CrasherSynchronousProxy> for zx::NullableHandle {
99 fn from(value: CrasherSynchronousProxy) -> Self {
100 value.into_channel().into()
101 }
102}
103
104#[cfg(target_os = "fuchsia")]
105impl From<fidl::Channel> for CrasherSynchronousProxy {
106 fn from(value: fidl::Channel) -> Self {
107 Self::new(value)
108 }
109}
110
111#[cfg(target_os = "fuchsia")]
112impl fidl::endpoints::FromClient for CrasherSynchronousProxy {
113 type Protocol = CrasherMarker;
114
115 fn from_client(value: fidl::endpoints::ClientEnd<CrasherMarker>) -> Self {
116 Self::new(value.into_channel())
117 }
118}
119
120#[derive(Debug, Clone)]
121pub struct CrasherProxy {
122 client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
123}
124
125impl fidl::endpoints::Proxy for CrasherProxy {
126 type Protocol = CrasherMarker;
127
128 fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
129 Self::new(inner)
130 }
131
132 fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
133 self.client.into_channel().map_err(|client| Self { client })
134 }
135
136 fn as_channel(&self) -> &::fidl::AsyncChannel {
137 self.client.as_channel()
138 }
139}
140
141impl CrasherProxy {
142 pub fn new(channel: ::fidl::AsyncChannel) -> Self {
144 let protocol_name = <CrasherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
145 Self { client: fidl::client::Client::new(channel, protocol_name) }
146 }
147
148 pub fn take_event_stream(&self) -> CrasherEventStream {
154 CrasherEventStream { event_receiver: self.client.take_event_receiver() }
155 }
156
157 pub fn r#ping(
159 &self,
160 ) -> fidl::client::QueryResponseFut<u64, fidl::encoding::DefaultFuchsiaResourceDialect> {
161 CrasherProxyInterface::r#ping(self)
162 }
163
164 pub fn r#crash(&self) -> Result<(), fidl::Error> {
166 CrasherProxyInterface::r#crash(self)
167 }
168}
169
170impl CrasherProxyInterface for CrasherProxy {
171 type PingResponseFut =
172 fidl::client::QueryResponseFut<u64, fidl::encoding::DefaultFuchsiaResourceDialect>;
173 fn r#ping(&self) -> Self::PingResponseFut {
174 fn _decode(
175 mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
176 ) -> Result<u64, fidl::Error> {
177 let _response = fidl::client::decode_transaction_body::<
178 CrasherPingResponse,
179 fidl::encoding::DefaultFuchsiaResourceDialect,
180 0x63e0c4d973e4b1f9,
181 >(_buf?)?;
182 Ok(_response.pong)
183 }
184 self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, u64>(
185 (),
186 0x63e0c4d973e4b1f9,
187 fidl::encoding::DynamicFlags::empty(),
188 _decode,
189 )
190 }
191
192 fn r#crash(&self) -> Result<(), fidl::Error> {
193 self.client.send::<fidl::encoding::EmptyPayload>(
194 (),
195 0x15290e84d9b74bd2,
196 fidl::encoding::DynamicFlags::empty(),
197 )
198 }
199}
200
201pub struct CrasherEventStream {
202 event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
203}
204
205impl std::marker::Unpin for CrasherEventStream {}
206
207impl futures::stream::FusedStream for CrasherEventStream {
208 fn is_terminated(&self) -> bool {
209 self.event_receiver.is_terminated()
210 }
211}
212
213impl futures::Stream for CrasherEventStream {
214 type Item = Result<CrasherEvent, fidl::Error>;
215
216 fn poll_next(
217 mut self: std::pin::Pin<&mut Self>,
218 cx: &mut std::task::Context<'_>,
219 ) -> std::task::Poll<Option<Self::Item>> {
220 match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
221 &mut self.event_receiver,
222 cx
223 )?) {
224 Some(buf) => std::task::Poll::Ready(Some(CrasherEvent::decode(buf))),
225 None => std::task::Poll::Ready(None),
226 }
227 }
228}
229
230#[derive(Debug)]
231pub enum CrasherEvent {}
232
233impl CrasherEvent {
234 fn decode(
236 mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
237 ) -> Result<CrasherEvent, fidl::Error> {
238 let (bytes, _handles) = buf.split_mut();
239 let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
240 debug_assert_eq!(tx_header.tx_id, 0);
241 match tx_header.ordinal {
242 _ => Err(fidl::Error::UnknownOrdinal {
243 ordinal: tx_header.ordinal,
244 protocol_name: <CrasherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
245 }),
246 }
247 }
248}
249
250pub struct CrasherRequestStream {
252 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
253 is_terminated: bool,
254}
255
256impl std::marker::Unpin for CrasherRequestStream {}
257
258impl futures::stream::FusedStream for CrasherRequestStream {
259 fn is_terminated(&self) -> bool {
260 self.is_terminated
261 }
262}
263
264impl fidl::endpoints::RequestStream for CrasherRequestStream {
265 type Protocol = CrasherMarker;
266 type ControlHandle = CrasherControlHandle;
267
268 fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
269 Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
270 }
271
272 fn control_handle(&self) -> Self::ControlHandle {
273 CrasherControlHandle { inner: self.inner.clone() }
274 }
275
276 fn into_inner(
277 self,
278 ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
279 {
280 (self.inner, self.is_terminated)
281 }
282
283 fn from_inner(
284 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
285 is_terminated: bool,
286 ) -> Self {
287 Self { inner, is_terminated }
288 }
289}
290
291impl futures::Stream for CrasherRequestStream {
292 type Item = Result<CrasherRequest, fidl::Error>;
293
294 fn poll_next(
295 mut self: std::pin::Pin<&mut Self>,
296 cx: &mut std::task::Context<'_>,
297 ) -> std::task::Poll<Option<Self::Item>> {
298 let this = &mut *self;
299 if this.inner.check_shutdown(cx) {
300 this.is_terminated = true;
301 return std::task::Poll::Ready(None);
302 }
303 if this.is_terminated {
304 panic!("polled CrasherRequestStream after completion");
305 }
306 fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
307 |bytes, handles| {
308 match this.inner.channel().read_etc(cx, bytes, handles) {
309 std::task::Poll::Ready(Ok(())) => {}
310 std::task::Poll::Pending => return std::task::Poll::Pending,
311 std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
312 this.is_terminated = true;
313 return std::task::Poll::Ready(None);
314 }
315 std::task::Poll::Ready(Err(e)) => {
316 return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
317 e.into(),
318 ))));
319 }
320 }
321
322 let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
324
325 std::task::Poll::Ready(Some(match header.ordinal {
326 0x63e0c4d973e4b1f9 => {
327 header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
328 let mut req = fidl::new_empty!(
329 fidl::encoding::EmptyPayload,
330 fidl::encoding::DefaultFuchsiaResourceDialect
331 );
332 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
333 let control_handle = CrasherControlHandle { inner: this.inner.clone() };
334 Ok(CrasherRequest::Ping {
335 responder: CrasherPingResponder {
336 control_handle: std::mem::ManuallyDrop::new(control_handle),
337 tx_id: header.tx_id,
338 },
339 })
340 }
341 0x15290e84d9b74bd2 => {
342 header.validate_request_tx_id(fidl::MethodType::OneWay)?;
343 let mut req = fidl::new_empty!(
344 fidl::encoding::EmptyPayload,
345 fidl::encoding::DefaultFuchsiaResourceDialect
346 );
347 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
348 let control_handle = CrasherControlHandle { inner: this.inner.clone() };
349 Ok(CrasherRequest::Crash { control_handle })
350 }
351 _ => Err(fidl::Error::UnknownOrdinal {
352 ordinal: header.ordinal,
353 protocol_name:
354 <CrasherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
355 }),
356 }))
357 },
358 )
359 }
360}
361
362#[derive(Debug)]
363pub enum CrasherRequest {
364 Ping { responder: CrasherPingResponder },
366 Crash { control_handle: CrasherControlHandle },
368}
369
370impl CrasherRequest {
371 #[allow(irrefutable_let_patterns)]
372 pub fn into_ping(self) -> Option<(CrasherPingResponder)> {
373 if let CrasherRequest::Ping { responder } = self { Some((responder)) } else { None }
374 }
375
376 #[allow(irrefutable_let_patterns)]
377 pub fn into_crash(self) -> Option<(CrasherControlHandle)> {
378 if let CrasherRequest::Crash { control_handle } = self {
379 Some((control_handle))
380 } else {
381 None
382 }
383 }
384
385 pub fn method_name(&self) -> &'static str {
387 match *self {
388 CrasherRequest::Ping { .. } => "ping",
389 CrasherRequest::Crash { .. } => "crash",
390 }
391 }
392}
393
394#[derive(Debug, Clone)]
395pub struct CrasherControlHandle {
396 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
397}
398
399impl CrasherControlHandle {
400 pub fn shutdown_with_epitaph(&self, status: impl Into<fidl::Epitaph>) {
401 self.inner.shutdown_with_epitaph(status.into())
402 }
403}
404
405impl fidl::endpoints::ControlHandle for CrasherControlHandle {
406 fn shutdown(&self) {
407 self.inner.shutdown()
408 }
409
410 fn shutdown_with_epitaph(&self, status: fidl::Epitaph) {
411 self.inner.shutdown_with_epitaph(status)
412 }
413
414 fn is_closed(&self) -> bool {
415 self.inner.channel().is_closed()
416 }
417 fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
418 self.inner.channel().on_closed()
419 }
420
421 #[cfg(target_os = "fuchsia")]
422 fn signal_peer(
423 &self,
424 clear_mask: zx::Signals,
425 set_mask: zx::Signals,
426 ) -> Result<(), zx_status::Status> {
427 use fidl::Peered;
428 self.inner.channel().signal_peer(clear_mask, set_mask)
429 }
430}
431
432impl CrasherControlHandle {}
433
434#[must_use = "FIDL methods require a response to be sent"]
435#[derive(Debug)]
436pub struct CrasherPingResponder {
437 control_handle: std::mem::ManuallyDrop<CrasherControlHandle>,
438 tx_id: u32,
439}
440
441impl std::ops::Drop for CrasherPingResponder {
445 fn drop(&mut self) {
446 self.control_handle.shutdown();
447 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
449 }
450}
451
452impl fidl::endpoints::Responder for CrasherPingResponder {
453 type ControlHandle = CrasherControlHandle;
454
455 fn control_handle(&self) -> &CrasherControlHandle {
456 &self.control_handle
457 }
458
459 fn drop_without_shutdown(mut self) {
460 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
462 std::mem::forget(self);
464 }
465}
466
467impl CrasherPingResponder {
468 pub fn send(self, mut pong: u64) -> Result<(), fidl::Error> {
472 let _result = self.send_raw(pong);
473 if _result.is_err() {
474 self.control_handle.shutdown();
475 }
476 self.drop_without_shutdown();
477 _result
478 }
479
480 pub fn send_no_shutdown_on_err(self, mut pong: u64) -> Result<(), fidl::Error> {
482 let _result = self.send_raw(pong);
483 self.drop_without_shutdown();
484 _result
485 }
486
487 fn send_raw(&self, mut pong: u64) -> Result<(), fidl::Error> {
488 self.control_handle.inner.send::<CrasherPingResponse>(
489 (pong,),
490 self.tx_id,
491 0x63e0c4d973e4b1f9,
492 fidl::encoding::DynamicFlags::empty(),
493 )
494 }
495}
496
497#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
498pub struct DeviceMarker;
499
500#[cfg(target_os = "fuchsia")]
501impl fidl::endpoints::ServiceMarker for DeviceMarker {
502 type Proxy = DeviceProxy;
503 type Request = DeviceRequest;
504 const SERVICE_NAME: &'static str = "fuchsia.crashdriver.test.Device";
505}
506
507#[cfg(target_os = "fuchsia")]
510pub enum DeviceRequest {
511 Crasher(CrasherRequestStream),
512}
513
514#[cfg(target_os = "fuchsia")]
515impl fidl::endpoints::ServiceRequest for DeviceRequest {
516 type Service = DeviceMarker;
517
518 fn dispatch(name: &str, _channel: fidl::AsyncChannel) -> Self {
519 match name {
520 "crasher" => Self::Crasher(
521 <CrasherRequestStream as fidl::endpoints::RequestStream>::from_channel(_channel),
522 ),
523 _ => panic!("no such member protocol name for service Device"),
524 }
525 }
526
527 fn member_names() -> &'static [&'static str] {
528 &["crasher"]
529 }
530}
531#[cfg(target_os = "fuchsia")]
532pub struct DeviceProxy(#[allow(dead_code)] Box<dyn fidl::endpoints::MemberOpener>);
533
534#[cfg(target_os = "fuchsia")]
535impl fidl::endpoints::ServiceProxy for DeviceProxy {
536 type Service = DeviceMarker;
537
538 fn from_member_opener(opener: Box<dyn fidl::endpoints::MemberOpener>) -> Self {
539 Self(opener)
540 }
541}
542
543#[cfg(target_os = "fuchsia")]
544impl DeviceProxy {
545 pub fn connect_to_crasher(&self) -> Result<CrasherProxy, fidl::Error> {
546 let (proxy, server_end) = fidl::endpoints::create_proxy::<CrasherMarker>();
547 self.connect_channel_to_crasher(server_end)?;
548 Ok(proxy)
549 }
550
551 pub fn connect_to_crasher_sync(&self) -> Result<CrasherSynchronousProxy, fidl::Error> {
554 let (proxy, server_end) = fidl::endpoints::create_sync_proxy::<CrasherMarker>();
555 self.connect_channel_to_crasher(server_end)?;
556 Ok(proxy)
557 }
558
559 pub fn connect_channel_to_crasher(
562 &self,
563 server_end: fidl::endpoints::ServerEnd<CrasherMarker>,
564 ) -> Result<(), fidl::Error> {
565 self.0.open_member("crasher", server_end.into_channel())
566 }
567
568 pub fn instance_name(&self) -> &str {
569 self.0.instance_name()
570 }
571}
572
573mod internal {
574 use super::*;
575}