Skip to content
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

Merged
merged 8 commits into from
Jun 25, 2024

Conversation

vadorovsky
Copy link
Contributor

@vadorovsky vadorovsky commented Jun 17, 2024

  • Reorganize the code to make clear distinction between zero-copy and
    copy utilities.
  • Cover the whole module with tests.

@vadorovsky vadorovsky force-pushed the vadorovsky/test-offset-util branch 2 times, most recently from 9453939 to 33a850c Compare June 18, 2024 08:06
@vadorovsky vadorovsky marked this pull request as ready for review June 18, 2024 08:07
@vadorovsky vadorovsky requested a review from ananas-block as a code owner June 18, 2024 08:07
@vadorovsky vadorovsky force-pushed the vadorovsky/test-offset-util branch from dcc5224 to fe8c5da Compare June 18, 2024 14:42
Copy link

nx-cloud bot commented Jun 18, 2024

☁️ Nx Cloud Report

CI 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


🟥 Failed Commands
nx test @lightprotocol/stateless.js
✅ Successfully ran 1 target

Sent with 💌 from NxCloud.

let size = mem::size_of::<T>();
let ptr = bytes[*offset..*offset + size].as_ptr() as *const T;
*offset += size;
// (*ptr).clone()
Copy link
Contributor

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();
Copy link
Contributor

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.

Copy link
Contributor Author

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

(*s).a = -9223372036854771632;
(*s).b = 9223372036854771632;
(*s).c = -9223372036854771632;
(*s).d = 9223372036854771632;
Copy link
Contributor

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?

Copy link
Contributor Author

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],
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor

@ananas-block ananas-block left a 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.

@vadorovsky vadorovsky force-pushed the vadorovsky/test-offset-util branch 2 times, most recently from 658fa72 to 3d49075 Compare June 22, 2024 08:54
(*s).g = -32721;
(*s).h = 32721;
(*s).i = -127;
(*s).j = 127;
Copy link
Contributor

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.
@vadorovsky vadorovsky force-pushed the vadorovsky/test-offset-util branch from 8d5141c to 4719758 Compare June 25, 2024 10:07
@vadorovsky vadorovsky merged commit b9c20f3 into main Jun 25, 2024
13 checks passed
@vadorovsky vadorovsky deleted the vadorovsky/test-offset-util branch June 25, 2024 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants