-
Notifications
You must be signed in to change notification settings - Fork 1
Soundness Fix for the Trigger struct as well as added unsafe call for the QuickTune struct since the type is not yet fully represented with rusts type system, and the fact the C struct is a union that we do not enforce. #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,3 +34,49 @@ impl From<Backend> for bladerf_backend { | |
| value as i32 as bladerf_backend | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod test { | ||
| use libbladerf_sys::bladerf_backend; | ||
|
|
||
| use crate::Backend; | ||
|
|
||
| #[test] | ||
| /// Precautionary test since the From<Backend> impl has 2 casts as I believe the [bladerf_backend] type is not consistent across platforms. | ||
| fn backend_enum_conversion_test() { | ||
|
Comment on lines
+45
to
+46
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you elaborate on this? What kind of failure mode are you trying to guard against? The variants in the header file have ordinals 0..=100 so we shouldnt have any issues with representing that in our
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I put this in primarily as a sanity check if there are future code changes. I don't think it should be needed, but because of the double as cast, I was thinking about going through and adding some sort of brute force tests to anything that is repr(C). I did not really put a lot of though into this specific item, it was more of an addition so I would not have to think |
||
| let bk = Backend::Any; | ||
| let bk_int: i64 = (bk as i32).into(); | ||
| assert_eq!( | ||
| bk_int, | ||
| <bladerf_backend as std::convert::Into<i64>>::into(bk.into()) | ||
| ); | ||
|
|
||
| let bk = Backend::LibUsb; | ||
| let bk_int: i64 = (bk as i32).into(); | ||
| assert_eq!( | ||
| bk_int, | ||
| <bladerf_backend as std::convert::Into<i64>>::into(bk.into()) | ||
| ); | ||
|
|
||
| let bk = Backend::Linux; | ||
| let bk_int: i64 = (bk as i32).into(); | ||
| assert_eq!( | ||
| bk_int, | ||
| <bladerf_backend as std::convert::Into<i64>>::into(bk.into()) | ||
| ); | ||
|
|
||
| let bk = Backend::Cypress; | ||
| let bk_int: i64 = (bk as i32).into(); | ||
| assert_eq!( | ||
| bk_int, | ||
| <bladerf_backend as std::convert::Into<i64>>::into(bk.into()) | ||
| ); | ||
|
|
||
| let bk = Backend::Dummy; | ||
| let bk_int: i64 = (bk as i32).into(); | ||
| assert_eq!( | ||
| bk_int, | ||
| <bladerf_backend as std::convert::Into<i64>>::into(bk.into()) | ||
| ); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.