-
Notifications
You must be signed in to change notification settings - Fork 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
test: Add unit tests for light_utils::offset
#832
Conversation
9453939
to
33a850c
Compare
dcc5224
to
fe8c5da
Compare
☁️ Nx Cloud ReportCI is running/has finished running commands for commit 658fa72. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution
✅ Successfully ran 1 targetSent with 💌 from NxCloud. |
utils/src/offset/copy.rs
Outdated
let size = mem::size_of::<T>(); | ||
let ptr = bytes[*offset..*offset + size].as_ptr() as *const T; | ||
*offset += size; | ||
// (*ptr).clone() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
leftover comment?
where | ||
T: Clone, | ||
{ | ||
let size = mem::size_of::<T>() * metadata.capacity(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could add a safety comment that you cannot use this if T has properties that are vectors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, included it in the docstring
utils/src/offset/copy.rs
Outdated
(*s).a = -9223372036854771632; | ||
(*s).b = 9223372036854771632; | ||
(*s).c = -9223372036854771632; | ||
(*s).d = 9223372036854771632; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we use i64::MAX / u64::MAX?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
#[repr(C)] | ||
struct TestStruct { | ||
a: [i64; 32], | ||
b: [u64; 32], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably makes sense to do an explicit test with [u8;32] as well since that is what we use in prod in most cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Looks good in general a couple comments nothing fundamental.
658fa72
to
3d49075
Compare
utils/src/offset/zero_copy.rs
Outdated
(*s).g = -32721; | ||
(*s).h = 32721; | ||
(*s).i = -127; | ||
(*s).j = 127; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More magic numbers, other wise looks good feel free to merge after rebase and fix :)
* Reorganize the code to make clear distinction between zero-copy and copy utilities. * Cover the whole module with tests.
The former works fine with uninitialized regions. The latter does not.
* Use `MIN` and `MAX` values of primitive types. * Read vectors with `[u8; 32]` as a type.
8d5141c
to
4719758
Compare
copy utilities.