fuchsia_fuzzctl_test

Struct Test

Source
pub struct Test { /* private fields */ }
Expand description

General purpose test context for the ffx fuzz plugin unit tests.

This object groups several commonly used routines used to capture data produced as a part of unit tests, such as:

  • It can create temporary files and directories, and ensure they persist for duration of the test.
  • It maintains a list of expected outputs.
  • It shares a list of actual outputs with a BufferSink and can verify that they match its expectations.
  • It can produce Writers backed by its associated BufferSink.

Implementations§

Source§

impl Test

Source

pub fn try_new() -> Result<Self>

Creates a new Test.

When running tests, users may optionally set the FFX_FUZZ_ECHO_TEST_OUTPUT environment variable, which will cause this object to use an existing directory rather than create a temporary one.

Source

pub fn root_dir(&self) -> &Path

Returns the writable temporary directory for this test.

Source

pub fn create_dir<P: AsRef<Path>>(&self, path: P) -> Result<PathBuf>

Creates a directory under this object’s root_dir.

The given path may be relative or absolute, but if it is the latter it must be prefixed with this object’s root_dir.

Returns a PathBuf on success and an error if the path is outside the root_dir or the filesystem returns an error.

Source

pub fn artifact_dir(&self) -> PathBuf

Returns the path where the fuzzer will store artifacts.

Source

pub fn corpus_dir(&self, corpus_type: Corpus) -> PathBuf

Returns the path where the fuzzer will store its corpus of the given type.

Source

pub fn write_fx_build_dir<P: AsRef<Path>>(&self, build_dir: P) -> Result<()>

Creates a fake “.fx-build-dir” file for testing.

The “.fx-build-dir” file will be created under this object’s root_dir, and will contain the relative_path to the build directory. Except for some util::tests, unit tests should prefer create_tests_json.

Returns an error if any filesystem operations fail.

Source

pub fn write_tests_json<P: AsRef<Path>, S: AsRef<str>>( &self, build_dir: P, contents: S, ) -> Result<PathBuf>

Creates a fake “tests.json” file for testing.

The “tests.json” will be created under the relative_path from this object’s root_dir and will contain the given contents. Except for some util::tests, unit tests should prefer create_tests_json.

Returns an error if any filesystem operations fail.

Source

pub fn create_tests_json<D: Display>( &self, urls: impl Iterator<Item = D>, ) -> Result<PathBuf>

Creates a fake “tests.json” file for testing.

The “tests.json” will include an array of valid JSON objects for the given urls.

Returns an error if any filesystem operations fail.

Source

pub fn create_test_files<P: AsRef<Path>, D: Display>( &self, test_dir: P, files: impl Iterator<Item = D>, ) -> Result<()>

Creates several temporary files from the given iterator for testing.

Each file’s contents will simpl be its name, which is taken from the given files.

Returns an error if writing to the filesystem fails.

Source

pub fn url(&self) -> Rc<RefCell<Option<String>>>

Clones the RefCell holding the URL provided to the fake manager.

Source

pub fn controller(&self) -> FakeController

Clones the fake fuzzer controller “connected” by the fake manager.

Source

pub fn record<S: AsRef<str>>(&mut self, request: S)

Records a FIDL request made to a test fake.

Source

pub fn requests(&mut self) -> Vec<String>

Returns the recorded FIDL requests.

As a side-effect, this resets the recorded requests.

Source

pub fn output_matches<T: AsRef<str> + Display>(&mut self, msg: T)

Adds an expectation that an output written to the BufferSink will exactly match msg.

Source

pub fn output_includes<T: AsRef<str> + Display>(&mut self, msg: T)

Adds an expectation that an output written to the BufferSink will contain msg.

Source

pub fn verify_output(&mut self) -> Result<()>

Iterates over the expected and actual output and verifies expectations are met.

Source

pub fn writer(&self) -> &Writer<BufferSink>

Returns a Writer using the BufferSink associated with this object.

Trait Implementations§

Source§

impl Clone for Test

Source§

fn clone(&self) -> Test

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Test

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Test

§

impl !RefUnwindSafe for Test

§

impl !Send for Test

§

impl !Sync for Test

§

impl Unpin for Test

§

impl !UnwindSafe for Test

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T, D> Encode<Ambiguous1, D> for T
where D: ResourceDialect,

Source§

unsafe fn encode( self, _encoder: &mut Encoder<'_, D>, _offset: usize, _depth: Depth, ) -> Result<(), Error>

Encodes the object into the encoder’s buffers. Any handles stored in the object are swapped for Handle::INVALID. Read more
Source§

impl<T, D> Encode<Ambiguous2, D> for T
where D: ResourceDialect,

Source§

unsafe fn encode( self, _encoder: &mut Encoder<'_, D>, _offset: usize, _depth: Depth, ) -> Result<(), Error>

Encodes the object into the encoder’s buffers. Any handles stored in the object are swapped for Handle::INVALID. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more