Skip to content

Add basic tests for grates.#590

Open
stupendoussuperpowers wants to merge 3 commits intoLind-Project:mainfrom
stupendoussuperpowers:add-grate-tests
Open

Add basic tests for grates.#590
stupendoussuperpowers wants to merge 3 commits intoLind-Project:mainfrom
stupendoussuperpowers:add-grate-tests

Conversation

@stupendoussuperpowers
Copy link
Contributor

This PR adds some basic regression tests for common grate patterns/endpoints.

  • register-basic.c: Check the register_handler function 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 for copy_data_between_cages

The scripts/wasmtestreport.py has also been modified to include the tests/grate-tests folder in the test runs.

- Add grate tests

- Fix diff for test script
@stupendoussuperpowers
Copy link
Contributor Author

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 unit-tests/grate_tests/..., I feel like the current structure makes more sense.

@stupendoussuperpowers stupendoussuperpowers marked this pull request as ready for review January 2, 2026 12:28
int ret = register_handler(grateid, 107, 1, grateid, fn_ptr_addr);

ASSERT(ret, 0);
ASSERT(geteuid(), 2 * geteuid_orig);
Copy link
Member

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

@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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

/// If a conflicting mapping exists, the function panics to prevent accidental overwrite.
///
/// 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.

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.

Copy link
Member

@JustinCappos JustinCappos left a comment

Choose a reason for hiding this comment

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

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).

@JustinCappos
Copy link
Member

JustinCappos commented Jan 2, 2026 via email

@stupendoussuperpowers
Copy link
Contributor Author

It's only a no-op if the handler is also the same.

@JustinCappos
Copy link
Member

JustinCappos commented Jan 3, 2026 via email

@stupendoussuperpowers
Copy link
Contributor Author

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 lind_syscall.h should also include the constants we use for threei. For example, in this test I had to manually define the ELINDAPIABORTED constant in the test case file.

Similarly, the lind_syscall_num.h is not a part of sysroot includes, but it should be. This is so that we use GETEUID_NUM instead of having to look up the number 107 when writing grates.

Copy link
Member

@Yaxuan-w Yaxuan-w left a comment

Choose a reason for hiding this comment

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

I'm bit confused on these tests flows... It seems only grate files for each...?

@Yaxuan-w
Copy link
Member

Yaxuan-w commented Jan 5, 2026

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

@Yaxuan-w
Copy link
Member

Yaxuan-w commented Jan 5, 2026

I'd suggest that to keep geteuid related tests and we can have a separate PR for test script.

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.

3 participants