fidl_fuchsia_io_test__common/
fidl_fuchsia_io_test__common.rs

1// WARNING: This file is machine generated by fidlgen.
2
3#![warn(clippy::all)]
4#![allow(unused_parens, unused_mut, unused_imports, nonstandard_style)]
5
6use bitflags::bitflags;
7use fidl::encoding::{MessageBufFor, ProxyChannelBox, ResourceDialect};
8use futures::future::{self, MaybeDone, TryFutureExt};
9use zx_status;
10
11/// Adds an executable file that supports opening as readable + executable. The file has a non-zero
12/// size, but the contents are otherwise unspecified.
13///
14/// Enabled via the `supports_executable_file` configuration option. `ExecutableFile` objects should
15/// support fuchsia.io/File.GetBackingMemory.
16#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
17pub struct ExecutableFile {
18    pub name: String,
19}
20
21impl fidl::Persistable for ExecutableFile {}
22
23/// File object which supports reading and writing. Use [`ExecutableFile`] if execute rights are
24/// required.
25#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
26pub struct File {
27    pub name: String,
28    pub contents: Vec<u8>,
29}
30
31impl fidl::Persistable for File {}
32
33/// Conformance test harnesses will implement this protocol to setup its
34/// associated filesystem servers with the described directory layout,
35/// allowing their implementation of `fuchsia.io` and `fuchsia.io2` protocols
36/// to be verified by a common test suite.
37///
38/// Different test cases will not interact with one another during the
39/// conformance test, and only one test case will be active at a time per
40/// tested filesystem. So it is possible to host all cases as different
41/// sub-directories under a common filesystem instance, to simplify the
42/// lifecycle and implementation.
43///
44/// If a test case has mutable bits, each method call should be implemented
45/// to obtain the directory in its original state. In other words, repeated
46/// test case set up should "as-if" yield new directories.
47///
48/// See `src/storage/conformance/README.md` for an overview of io conformance
49/// testing.
50///
51/// `HarnessConfig` lets the test harness modulate the set of expected outcomes and
52/// behaviors validated by the test suite, by declaring specific properties
53/// about the filesystem implementation. For example, setting [`ImmutableFile`]
54/// to true informs the test suites that files hosted by this harness do not
55/// support mutation.
56#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
57pub struct HarnessConfig {
58    /// ExecutableFile objects are supported.
59    pub supports_executable_file: bool,
60    /// Supports writing to files and updating file attributes.
61    pub supports_mutable_file: bool,
62    /// GetBackingMemory is supported.
63    pub supports_get_backing_memory: bool,
64    /// Remote directories are supported.
65    pub supports_remote_dir: bool,
66    /// GetToken is supported.
67    pub supports_get_token: bool,
68    /// Supports fuchsia.io's LinkInto method.
69    pub supports_link_into: bool,
70    /// Files can be opened in append mode.
71    pub supports_append: bool,
72    /// Files can be truncated (resized).
73    pub supports_truncate: bool,
74    /// The set of attributes the filesystem supports. If mutable attributes are reported, the
75    /// harness must support [`fuchsia.io/Node.SetAttr`] and [`fuchsia.io/Node.UpdateAttributes`].
76    pub supported_attributes: fidl_fuchsia_io__common::NodeAttributesQuery,
77    /// Directories support creating files, Rename, Link, and Unlink.
78    pub supports_modify_directory: bool,
79    /// Supports services.
80    pub supports_services: bool,
81    /// Supports unnamed temporary files.
82    pub supports_unnamed_temporary_file: bool,
83}
84
85impl fidl::Persistable for HarnessConfig {}
86
87#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
88pub struct TestHarnessGetConfigResponse {
89    pub config: HarnessConfig,
90}
91
92impl fidl::Persistable for TestHarnessGetConfigResponse {}
93
94pub mod test_harness_ordinals {
95    pub const GET_CONFIG: u64 = 0x758882a165dbaa23;
96    pub const CREATE_DIRECTORY: u64 = 0x626b0ce412a0cb4c;
97    pub const OPEN_SERVICE_DIRECTORY: u64 = 0x42904fe08b12ef88;
98}
99
100mod internal {
101    use super::*;
102
103    impl fidl::encoding::ValueTypeMarker for ExecutableFile {
104        type Borrowed<'a> = &'a Self;
105        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
106            value
107        }
108    }
109
110    unsafe impl fidl::encoding::TypeMarker for ExecutableFile {
111        type Owned = Self;
112
113        #[inline(always)]
114        fn inline_align(_context: fidl::encoding::Context) -> usize {
115            8
116        }
117
118        #[inline(always)]
119        fn inline_size(_context: fidl::encoding::Context) -> usize {
120            16
121        }
122    }
123
124    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<ExecutableFile, D>
125        for &ExecutableFile
126    {
127        #[inline]
128        unsafe fn encode(
129            self,
130            encoder: &mut fidl::encoding::Encoder<'_, D>,
131            offset: usize,
132            _depth: fidl::encoding::Depth,
133        ) -> fidl::Result<()> {
134            encoder.debug_check_bounds::<ExecutableFile>(offset);
135            // Delegate to tuple encoding.
136            fidl::encoding::Encode::<ExecutableFile, D>::encode(
137                (<fidl::encoding::BoundedString<255> as fidl::encoding::ValueTypeMarker>::borrow(
138                    &self.name,
139                ),),
140                encoder,
141                offset,
142                _depth,
143            )
144        }
145    }
146    unsafe impl<
147            D: fidl::encoding::ResourceDialect,
148            T0: fidl::encoding::Encode<fidl::encoding::BoundedString<255>, D>,
149        > fidl::encoding::Encode<ExecutableFile, D> for (T0,)
150    {
151        #[inline]
152        unsafe fn encode(
153            self,
154            encoder: &mut fidl::encoding::Encoder<'_, D>,
155            offset: usize,
156            depth: fidl::encoding::Depth,
157        ) -> fidl::Result<()> {
158            encoder.debug_check_bounds::<ExecutableFile>(offset);
159            // Zero out padding regions. There's no need to apply masks
160            // because the unmasked parts will be overwritten by fields.
161            // Write the fields.
162            self.0.encode(encoder, offset + 0, depth)?;
163            Ok(())
164        }
165    }
166
167    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for ExecutableFile {
168        #[inline(always)]
169        fn new_empty() -> Self {
170            Self { name: fidl::new_empty!(fidl::encoding::BoundedString<255>, D) }
171        }
172
173        #[inline]
174        unsafe fn decode(
175            &mut self,
176            decoder: &mut fidl::encoding::Decoder<'_, D>,
177            offset: usize,
178            _depth: fidl::encoding::Depth,
179        ) -> fidl::Result<()> {
180            decoder.debug_check_bounds::<Self>(offset);
181            // Verify that padding bytes are zero.
182            fidl::decode!(
183                fidl::encoding::BoundedString<255>,
184                D,
185                &mut self.name,
186                decoder,
187                offset + 0,
188                _depth
189            )?;
190            Ok(())
191        }
192    }
193
194    impl fidl::encoding::ValueTypeMarker for File {
195        type Borrowed<'a> = &'a Self;
196        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
197            value
198        }
199    }
200
201    unsafe impl fidl::encoding::TypeMarker for File {
202        type Owned = Self;
203
204        #[inline(always)]
205        fn inline_align(_context: fidl::encoding::Context) -> usize {
206            8
207        }
208
209        #[inline(always)]
210        fn inline_size(_context: fidl::encoding::Context) -> usize {
211            32
212        }
213    }
214
215    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<File, D> for &File {
216        #[inline]
217        unsafe fn encode(
218            self,
219            encoder: &mut fidl::encoding::Encoder<'_, D>,
220            offset: usize,
221            _depth: fidl::encoding::Depth,
222        ) -> fidl::Result<()> {
223            encoder.debug_check_bounds::<File>(offset);
224            // Delegate to tuple encoding.
225            fidl::encoding::Encode::<File, D>::encode(
226                (
227                    <fidl::encoding::BoundedString<255> as fidl::encoding::ValueTypeMarker>::borrow(&self.name),
228                    <fidl::encoding::UnboundedVector<u8> as fidl::encoding::ValueTypeMarker>::borrow(&self.contents),
229                ),
230                encoder, offset, _depth
231            )
232        }
233    }
234    unsafe impl<
235            D: fidl::encoding::ResourceDialect,
236            T0: fidl::encoding::Encode<fidl::encoding::BoundedString<255>, D>,
237            T1: fidl::encoding::Encode<fidl::encoding::UnboundedVector<u8>, D>,
238        > fidl::encoding::Encode<File, D> for (T0, T1)
239    {
240        #[inline]
241        unsafe fn encode(
242            self,
243            encoder: &mut fidl::encoding::Encoder<'_, D>,
244            offset: usize,
245            depth: fidl::encoding::Depth,
246        ) -> fidl::Result<()> {
247            encoder.debug_check_bounds::<File>(offset);
248            // Zero out padding regions. There's no need to apply masks
249            // because the unmasked parts will be overwritten by fields.
250            // Write the fields.
251            self.0.encode(encoder, offset + 0, depth)?;
252            self.1.encode(encoder, offset + 16, depth)?;
253            Ok(())
254        }
255    }
256
257    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for File {
258        #[inline(always)]
259        fn new_empty() -> Self {
260            Self {
261                name: fidl::new_empty!(fidl::encoding::BoundedString<255>, D),
262                contents: fidl::new_empty!(fidl::encoding::UnboundedVector<u8>, D),
263            }
264        }
265
266        #[inline]
267        unsafe fn decode(
268            &mut self,
269            decoder: &mut fidl::encoding::Decoder<'_, D>,
270            offset: usize,
271            _depth: fidl::encoding::Depth,
272        ) -> fidl::Result<()> {
273            decoder.debug_check_bounds::<Self>(offset);
274            // Verify that padding bytes are zero.
275            fidl::decode!(
276                fidl::encoding::BoundedString<255>,
277                D,
278                &mut self.name,
279                decoder,
280                offset + 0,
281                _depth
282            )?;
283            fidl::decode!(
284                fidl::encoding::UnboundedVector<u8>,
285                D,
286                &mut self.contents,
287                decoder,
288                offset + 16,
289                _depth
290            )?;
291            Ok(())
292        }
293    }
294
295    impl fidl::encoding::ValueTypeMarker for HarnessConfig {
296        type Borrowed<'a> = &'a Self;
297        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
298            value
299        }
300    }
301
302    unsafe impl fidl::encoding::TypeMarker for HarnessConfig {
303        type Owned = Self;
304
305        #[inline(always)]
306        fn inline_align(_context: fidl::encoding::Context) -> usize {
307            8
308        }
309
310        #[inline(always)]
311        fn inline_size(_context: fidl::encoding::Context) -> usize {
312            24
313        }
314    }
315
316    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<HarnessConfig, D>
317        for &HarnessConfig
318    {
319        #[inline]
320        unsafe fn encode(
321            self,
322            encoder: &mut fidl::encoding::Encoder<'_, D>,
323            offset: usize,
324            _depth: fidl::encoding::Depth,
325        ) -> fidl::Result<()> {
326            encoder.debug_check_bounds::<HarnessConfig>(offset);
327            // Delegate to tuple encoding.
328            fidl::encoding::Encode::<HarnessConfig, D>::encode(
329                (
330                    <bool as fidl::encoding::ValueTypeMarker>::borrow(&self.supports_executable_file),
331                    <bool as fidl::encoding::ValueTypeMarker>::borrow(&self.supports_mutable_file),
332                    <bool as fidl::encoding::ValueTypeMarker>::borrow(&self.supports_get_backing_memory),
333                    <bool as fidl::encoding::ValueTypeMarker>::borrow(&self.supports_remote_dir),
334                    <bool as fidl::encoding::ValueTypeMarker>::borrow(&self.supports_get_token),
335                    <bool as fidl::encoding::ValueTypeMarker>::borrow(&self.supports_link_into),
336                    <bool as fidl::encoding::ValueTypeMarker>::borrow(&self.supports_append),
337                    <bool as fidl::encoding::ValueTypeMarker>::borrow(&self.supports_truncate),
338                    <fidl_fuchsia_io__common::NodeAttributesQuery as fidl::encoding::ValueTypeMarker>::borrow(&self.supported_attributes),
339                    <bool as fidl::encoding::ValueTypeMarker>::borrow(&self.supports_modify_directory),
340                    <bool as fidl::encoding::ValueTypeMarker>::borrow(&self.supports_services),
341                    <bool as fidl::encoding::ValueTypeMarker>::borrow(&self.supports_unnamed_temporary_file),
342                ),
343                encoder, offset, _depth
344            )
345        }
346    }
347    unsafe impl<
348            D: fidl::encoding::ResourceDialect,
349            T0: fidl::encoding::Encode<bool, D>,
350            T1: fidl::encoding::Encode<bool, D>,
351            T2: fidl::encoding::Encode<bool, D>,
352            T3: fidl::encoding::Encode<bool, D>,
353            T4: fidl::encoding::Encode<bool, D>,
354            T5: fidl::encoding::Encode<bool, D>,
355            T6: fidl::encoding::Encode<bool, D>,
356            T7: fidl::encoding::Encode<bool, D>,
357            T8: fidl::encoding::Encode<fidl_fuchsia_io__common::NodeAttributesQuery, D>,
358            T9: fidl::encoding::Encode<bool, D>,
359            T10: fidl::encoding::Encode<bool, D>,
360            T11: fidl::encoding::Encode<bool, D>,
361        > fidl::encoding::Encode<HarnessConfig, D>
362        for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)
363    {
364        #[inline]
365        unsafe fn encode(
366            self,
367            encoder: &mut fidl::encoding::Encoder<'_, D>,
368            offset: usize,
369            depth: fidl::encoding::Depth,
370        ) -> fidl::Result<()> {
371            encoder.debug_check_bounds::<HarnessConfig>(offset);
372            // Zero out padding regions. There's no need to apply masks
373            // because the unmasked parts will be overwritten by fields.
374            unsafe {
375                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(16);
376                (ptr as *mut u64).write_unaligned(0);
377            }
378            // Write the fields.
379            self.0.encode(encoder, offset + 0, depth)?;
380            self.1.encode(encoder, offset + 1, depth)?;
381            self.2.encode(encoder, offset + 2, depth)?;
382            self.3.encode(encoder, offset + 3, depth)?;
383            self.4.encode(encoder, offset + 4, depth)?;
384            self.5.encode(encoder, offset + 5, depth)?;
385            self.6.encode(encoder, offset + 6, depth)?;
386            self.7.encode(encoder, offset + 7, depth)?;
387            self.8.encode(encoder, offset + 8, depth)?;
388            self.9.encode(encoder, offset + 16, depth)?;
389            self.10.encode(encoder, offset + 17, depth)?;
390            self.11.encode(encoder, offset + 18, depth)?;
391            Ok(())
392        }
393    }
394
395    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for HarnessConfig {
396        #[inline(always)]
397        fn new_empty() -> Self {
398            Self {
399                supports_executable_file: fidl::new_empty!(bool, D),
400                supports_mutable_file: fidl::new_empty!(bool, D),
401                supports_get_backing_memory: fidl::new_empty!(bool, D),
402                supports_remote_dir: fidl::new_empty!(bool, D),
403                supports_get_token: fidl::new_empty!(bool, D),
404                supports_link_into: fidl::new_empty!(bool, D),
405                supports_append: fidl::new_empty!(bool, D),
406                supports_truncate: fidl::new_empty!(bool, D),
407                supported_attributes: fidl::new_empty!(
408                    fidl_fuchsia_io__common::NodeAttributesQuery,
409                    D
410                ),
411                supports_modify_directory: fidl::new_empty!(bool, D),
412                supports_services: fidl::new_empty!(bool, D),
413                supports_unnamed_temporary_file: fidl::new_empty!(bool, D),
414            }
415        }
416
417        #[inline]
418        unsafe fn decode(
419            &mut self,
420            decoder: &mut fidl::encoding::Decoder<'_, D>,
421            offset: usize,
422            _depth: fidl::encoding::Depth,
423        ) -> fidl::Result<()> {
424            decoder.debug_check_bounds::<Self>(offset);
425            // Verify that padding bytes are zero.
426            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(16) };
427            let padval = unsafe { (ptr as *const u64).read_unaligned() };
428            let mask = 0xffffffffff000000u64;
429            let maskedval = padval & mask;
430            if maskedval != 0 {
431                return Err(fidl::Error::NonZeroPadding {
432                    padding_start: offset + 16 + ((mask as u64).trailing_zeros() / 8) as usize,
433                });
434            }
435            fidl::decode!(
436                bool,
437                D,
438                &mut self.supports_executable_file,
439                decoder,
440                offset + 0,
441                _depth
442            )?;
443            fidl::decode!(bool, D, &mut self.supports_mutable_file, decoder, offset + 1, _depth)?;
444            fidl::decode!(
445                bool,
446                D,
447                &mut self.supports_get_backing_memory,
448                decoder,
449                offset + 2,
450                _depth
451            )?;
452            fidl::decode!(bool, D, &mut self.supports_remote_dir, decoder, offset + 3, _depth)?;
453            fidl::decode!(bool, D, &mut self.supports_get_token, decoder, offset + 4, _depth)?;
454            fidl::decode!(bool, D, &mut self.supports_link_into, decoder, offset + 5, _depth)?;
455            fidl::decode!(bool, D, &mut self.supports_append, decoder, offset + 6, _depth)?;
456            fidl::decode!(bool, D, &mut self.supports_truncate, decoder, offset + 7, _depth)?;
457            fidl::decode!(
458                fidl_fuchsia_io__common::NodeAttributesQuery,
459                D,
460                &mut self.supported_attributes,
461                decoder,
462                offset + 8,
463                _depth
464            )?;
465            fidl::decode!(
466                bool,
467                D,
468                &mut self.supports_modify_directory,
469                decoder,
470                offset + 16,
471                _depth
472            )?;
473            fidl::decode!(bool, D, &mut self.supports_services, decoder, offset + 17, _depth)?;
474            fidl::decode!(
475                bool,
476                D,
477                &mut self.supports_unnamed_temporary_file,
478                decoder,
479                offset + 18,
480                _depth
481            )?;
482            Ok(())
483        }
484    }
485
486    impl fidl::encoding::ValueTypeMarker for TestHarnessGetConfigResponse {
487        type Borrowed<'a> = &'a Self;
488        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
489            value
490        }
491    }
492
493    unsafe impl fidl::encoding::TypeMarker for TestHarnessGetConfigResponse {
494        type Owned = Self;
495
496        #[inline(always)]
497        fn inline_align(_context: fidl::encoding::Context) -> usize {
498            8
499        }
500
501        #[inline(always)]
502        fn inline_size(_context: fidl::encoding::Context) -> usize {
503            24
504        }
505    }
506
507    unsafe impl<D: fidl::encoding::ResourceDialect>
508        fidl::encoding::Encode<TestHarnessGetConfigResponse, D> for &TestHarnessGetConfigResponse
509    {
510        #[inline]
511        unsafe fn encode(
512            self,
513            encoder: &mut fidl::encoding::Encoder<'_, D>,
514            offset: usize,
515            _depth: fidl::encoding::Depth,
516        ) -> fidl::Result<()> {
517            encoder.debug_check_bounds::<TestHarnessGetConfigResponse>(offset);
518            // Delegate to tuple encoding.
519            fidl::encoding::Encode::<TestHarnessGetConfigResponse, D>::encode(
520                (<HarnessConfig as fidl::encoding::ValueTypeMarker>::borrow(&self.config),),
521                encoder,
522                offset,
523                _depth,
524            )
525        }
526    }
527    unsafe impl<D: fidl::encoding::ResourceDialect, T0: fidl::encoding::Encode<HarnessConfig, D>>
528        fidl::encoding::Encode<TestHarnessGetConfigResponse, D> for (T0,)
529    {
530        #[inline]
531        unsafe fn encode(
532            self,
533            encoder: &mut fidl::encoding::Encoder<'_, D>,
534            offset: usize,
535            depth: fidl::encoding::Depth,
536        ) -> fidl::Result<()> {
537            encoder.debug_check_bounds::<TestHarnessGetConfigResponse>(offset);
538            // Zero out padding regions. There's no need to apply masks
539            // because the unmasked parts will be overwritten by fields.
540            // Write the fields.
541            self.0.encode(encoder, offset + 0, depth)?;
542            Ok(())
543        }
544    }
545
546    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
547        for TestHarnessGetConfigResponse
548    {
549        #[inline(always)]
550        fn new_empty() -> Self {
551            Self { config: fidl::new_empty!(HarnessConfig, D) }
552        }
553
554        #[inline]
555        unsafe fn decode(
556            &mut self,
557            decoder: &mut fidl::encoding::Decoder<'_, D>,
558            offset: usize,
559            _depth: fidl::encoding::Depth,
560        ) -> fidl::Result<()> {
561            decoder.debug_check_bounds::<Self>(offset);
562            // Verify that padding bytes are zero.
563            fidl::decode!(HarnessConfig, D, &mut self.config, decoder, offset + 0, _depth)?;
564            Ok(())
565        }
566    }
567}