Add basic tests for grates.#590
Add basic tests for grates.#590stupendoussuperpowers wants to merge 3 commits intoLind-Project:mainfrom
Conversation
- Add grate tests - Fix diff for test script
|
For reviewers: The changes to the test script were to ensure that the grate specific compile script is used. Since these tests can only run on lind, they are treated like non-deterministic tests where we use asserts to mark a passing/failing test. I am not sure if grate-tests belong on the top level like they currently do, or within |
tests/grate-tests/register-basic.c
Outdated
| int ret = register_handler(grateid, 107, 1, grateid, fn_ptr_addr); | ||
|
|
||
| ASSERT(ret, 0); | ||
| ASSERT(geteuid(), 2 * geteuid_orig); |
There was a problem hiding this comment.
Maybe add one instead? If the geteuid is 0, this grate doesn't change the value.
| ASSERT(ret, 0); | ||
|
|
||
| // Conflicting register should fail | ||
| ret = register_handler(grateid, 107, 1, grateid + 1, fn_ptr_addr); |
There was a problem hiding this comment.
@Yaxuan-w @stupendoussuperpowers Why should this fail? Why doesn't it overwrite?
I'm not saying you are wrong. I just want to understand the logic
There was a problem hiding this comment.
lind-wasm/src/threei/src/threei.rs
Lines 324 to 327 in 148d55f
Based on the comments on the function, I believe this is to discourage accidental overwrites. Probably the behavior we're pushing for is to deregister, and then reregister in case we want the mapping to be updated.
JustinCappos
left a comment
There was a problem hiding this comment.
I'd change the *2 to be something else like +1 which will always change the value. Overall, these seem reasonable (but another reviewer needs to run them before merging).
|
Isn't it usually the case you're overwriting an existing handler? Is this
always the case unless you have a system call that isn't currently mapped
to any function?
Also, from the link you posted I noticed:
/// If a handler is already registered for this (syscall number, in grate
function address) pair with the same
/// destination cage, the call is treated as a no-op.
Does this mean if the same handler was already registered or if any handler
is? It sounds like the latter, which is odd and will lead to accidental
errors.
…On Fri, Jan 2, 2026 at 11:38 AM Sanchit Sahay ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In tests/grate-tests/register-duplicate.c
<#590 (comment)>
:
> + geteuid_orig = geteuid();
+
+ ASSERT(geteuid(), geteuid_orig);
+
+ uint64_t fn_ptr_addr = (uint64_t)(uintptr_t)&geteuid_grate;
+ int ret = register_handler(grateid, 107, 1, grateid, fn_ptr_addr);
+
+ ASSERT(ret, 0);
+ ASSERT(geteuid(), 2 * geteuid_orig);
+
+ // Duplicate registration is a no-op
+ ret = register_handler(grateid, 107, 1, grateid, fn_ptr_addr);
+ ASSERT(ret, 0);
+
+ // Conflicting register should fail
+ ret = register_handler(grateid, 107, 1, grateid + 1, fn_ptr_addr);
https://github.com/Lind-Project/lind-wasm/blob/148d55f7eddf0ec07db65b014913e8b856e5194c/src/threei/src/threei.rs#L324-L327
Based on the comments on the function, I believe this is to discourage
accidental overwrites. Probably the behavior we're pushing for is to
deregister, and then reregister in case we want the mapping to be updated.
—
Reply to this email directly, view it on GitHub
<#590 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAGROD5GDBN6ZLGVBGZRHXD4E2NIXAVCNFSM6AAAAACQQVQMPCVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZTMMRTGQ4TOMZTGM>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
|
It's only a no-op if the handler is also the same. |
|
So you have one function which can only "unset" it and the other can only
"set" it. Would it make sense for register_handler to instead take a flag
to indicate whether it expects it to be empty or not?
I'm not sure whether this matters or not. I'm just trying to think through
what is clearer for a reader.
Perhaps have this in mind as you write a few grates and we can tweak the
API as is needed.
…On Fri, Jan 2, 2026 at 10:37 PM Sanchit Sahay ***@***.***> wrote:
*stupendoussuperpowers* left a comment (Lind-Project/lind-wasm#590)
<#590 (comment)>
It's only a no-op if the handler is also the same.
—
Reply to this email directly, view it on GitHub
<#590 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAGROD27WIXJXFUH3ZLVM2D4E42QLAVCNFSM6AAAAACQQVQMPCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTOMBWGY2TSMJQGA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
|
Will keep this in mind. Currently it's 0 -> deregister, non-0 -> register. We could multiplex on this parameter to add that feature if needed. Unrelated to this, I think the Similarly, the |
Yaxuan-w
left a comment
There was a problem hiding this comment.
I'm bit confused on these tests flows... It seems only grate files for each...?
|
Using same test file for only register_handler related tests makes sense to me. However, I'm a bit worried about other 3i syscall routine related tests. It's a bit different from how grates are suppose to be used in general cases. Also would be helpful to have comments about each tests |
|
I'd suggest that to keep geteuid related tests and we can have a separate PR for test script. |
This PR adds some basic regression tests for common grate patterns/endpoints.
register-basic.c: Check theregister_handlerfunction for registration.register-deregister.c: Test for de-registration and re-registration for a syscall num.register-duplicate.c: Test duplicate registrations for a syscall num.register-multi-syscall.c: Test registering 2 different syscall nums.copy-data-basic.c: Test copy-in and copy-out forcopy_data_between_cagesThe
scripts/wasmtestreport.pyhas also been modified to include thetests/grate-testsfolder in the test runs.