devicemapper-rs icon indicating copy to clipboard operation
devicemapper-rs copied to clipboard

Check for correctness of feature argument number when parsing feature arguments

Open waltdisgrace opened this issue 5 years ago • 13 comments

Preliminary PR for #485

waltdisgrace avatar Jun 22 '20 19:06 waltdisgrace

@waltdisgrace Ping me here once you've figured out the testing issues, happy to help if you get stuck.

jbaublitz avatar Jun 22 '20 20:06 jbaublitz

Rebased.

waltdisgrace avatar Jul 08 '20 14:07 waltdisgrace

@waltdisgrace Please post the error that you obtain from your newly added test with the unmodified code, i.e., the code w/out your additional changes in the source.

mulkieran avatar Jul 08 '20 17:07 mulkieran

@mulkieran:

Here is the relevant snippet of the make test output:

failures:

---- lineardev::tests::test_flakey_incorrect_feature_args_input stdout ----
thread 'lineardev::tests::test_flakey_incorrect_feature_args_input' panicked at 'index 9 out of range for slice of length 8', src/lineardev.rs:303:18
stack backtrace:
   0: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
   1: core::fmt::write
   2: std::io::Write::write_fmt
   3: std::io::impls::<impl std::io::Write for alloc::boxed::Box<W>>::write_fmt
   4: std::panicking::default_hook::{{closure}}
   5: std::panicking::default_hook
   6: std::panicking::rust_panic_with_hook
   7: rust_begin_unwind
   8: core::panicking::panic_fmt
   9: core::slice::slice_index_len_fail
  10: <core::ops::range::Range<usize> as core::slice::SliceIndex<[T]>>::index
             at /builddir/build/BUILD/rustc-1.44.0-src/src/libcore/slice/mod.rs:2919
  11: core::slice::<impl core::ops::index::Index<I> for [T]>::index
             at /builddir/build/BUILD/rustc-1.44.0-src/src/libcore/slice/mod.rs:2732
  12: <alloc::vec::Vec<T> as core::ops::index::Index<I>>::index
             at /builddir/build/BUILD/rustc-1.44.0-src/src/liballoc/vec.rs:1945
  13: <devicemapper::lineardev::FlakeyTargetParams as core::str::FromStr>::from_str
             at src/lineardev.rs:303
  14: core::str::<impl str>::parse
             at /builddir/build/BUILD/rustc-1.44.0-src/src/libcore/str/mod.rs:4280
  15: devicemapper::lineardev::tests::test_flakey_incorrect_feature_args_input
             at src/lineardev.rs:923
  16: devicemapper::lineardev::tests::test_flakey_incorrect_feature_args_input::{{closure}}
             at src/lineardev.rs:922
  17: core::ops::function::FnOnce::call_once
             at /builddir/build/BUILD/rustc-1.44.0-src/src/libcore/ops/function.rs:232
  18: test::run_test::run_test_inner::{{closure}}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

waltdisgrace avatar Jul 09 '20 17:07 waltdisgrace

@waltdisgrace: Ok! That failure looks right to me.

mulkieran avatar Jul 09 '20 17:07 mulkieran

Rebased

waltdisgrace avatar Jul 24 '20 16:07 waltdisgrace

@mulkieran Should the fixes for the other targets be done in separate PRs or the same PR as Flakey?

waltdisgrace avatar Jul 28 '20 13:07 waltdisgrace

@mulkieran Should the fixes for the other targets be done in separate PRs or the same PR as Flakey?

@waltdisgrace You should make up a separate commit in this PR for ThinPoolDev and for each of the other target types that require the change.

mulkieran avatar Jul 28 '20 14:07 mulkieran

Rebased

waltdisgrace avatar Aug 04 '20 17:08 waltdisgrace

I pushed a commit containing all of the changes you explicitly requested.

Regarding the test you provided: This test causes a panic at the assertion that the input results in an error, not at the source code. The name you chose for the test, "... too_few", implies that the input, "cache 42:42 42:43 42:44 16 2 writethrough passthrough default 0", has too few arguments. However, this is a valid input that has enough arguments. Am I missing something?

waltdisgrace avatar Aug 10 '20 12:08 waltdisgrace

I pushed a commit containing all of the changes you explicitly requested.

Regarding the test you provided: This test causes a panic at the assertion that the input results in an error, not at the source code. The name you chose for the test, "... too_few", implies that the input, "cache 42:42 42:43 42:44 16 2 writethrough passthrough default 0", has too few arguments. However, this is a valid input that has enough arguments. Am I missing something?

Whoops! Yes, I had modified the test to try out some other things. Try this instead:

    #[test]
    fn test_cache_target_params_too_few() {
        let result = "cache 42:42 42:43 42:44 16 4 writethrough passthrough default 0"
            .parse::<CacheTargetParams>();
        assert_matches!(result, Err(DmError::Dm(ErrorEnum::Invalid, _)));
    }

mulkieran avatar Aug 10 '20 12:08 mulkieran

@mulkieran. That test looks reasonable to me and it passes when run against the source code changes of my most recently pushed commit. Adding your test to the PR now.

waltdisgrace avatar Aug 10 '20 13:08 waltdisgrace

Unlikely to manage to get to this before next release.

mulkieran avatar Jan 29 '21 16:01 mulkieran