Skip to content

Add a system call return test that tries all syscall types - #583

Open
bradjc wants to merge 10 commits into
masterfrom
dev/syscall-return-test
Open

Add a system call return test that tries all syscall types#583
bradjc wants to merge 10 commits into
masterfrom
dev/syscall-return-test

Conversation

@bradjc

@bradjc bradjc commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Matches tock/tock#5083

To accomplish this, this PR also:

  • Adds the helper functions for all of the remaining command return types.
  • Implements the converters for rv64 support.
  • Fixes the riscv command implementation which was using only u32 types.
  • Adds a test which calls each command/subscribe/allow and checks the return values.

@brghena brghena left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One question for you right now

Comment thread libtock/tock.h
Comment on lines +197 to +216
// Convert a `syscall_return_t` failure with one u32 to a `returncode_t`.
//
// This expects a failure with one u32 value (i.e. `TOCK_SYSCALL_FAILURE_U32`).
// Fills `val` with the failure u32 on failure. Do not use with other expected
// SyscallReturn variants.
returncode_t tock_command_return_failure_u32_to_returncode(syscall_return_t, uint32_t*);

// Convert a `syscall_return_t` failure with two u32 values to a `returncode_t`.
//
// This expects a failure with two u32 values (i.e. `TOCK_SYSCALL_FAILURE_U32_U32`).
// Fills `val1` and `val2` with the failure u32s on failure. Do not use with
// other expected SyscallReturn variants.
returncode_t tock_command_return_failure_u32_u32_to_returncode(syscall_return_t, uint32_t*, uint32_t*);

// Convert a `syscall_return_t` failure with a u64 value to a `returncode_t`.
//
// This expects a failure with one u64 value (i.e. `TOCK_SYSCALL_FAILURE_U64`).
// Fills `val` with the failure u64 on failure. Do not use with other expected
// SyscallReturn variants.
returncode_t tock_command_return_failure_u64_to_returncode(syscall_return_t, uint64_t*);

@brghena brghena Aug 25, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm trying to decide if these failure variants are generally useful or only applicable to your test application.

Let's say I was building a capsule which either returns success with U32 and U64 or failure with U64. Is this how you'd propose it be implemented? Any problems with this?

syscall_return_t cval = command(...);

returncode_t ret = tock_command_return_u32_u64_to_returncode(cval, u32_ptr, u64_ptr);
if (ret != RETURNCODE_SUCCESS) {
  return tock_command_return_failure_u64_to_returncode(cval, u64_ptr);
}

For IPC, I made a tock_command_return_u32_u64_or_u64_to_returncode() function, but I'll admit that it did feel quite unwieldy. I could replace it with the above snippet.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh, interesting, you know I hadn't actually given this any thought. It seems wrong that we wrote the original converters assuming a default failure-no-value alternative without including that in the function name.

I kind of think what you did for IPC is what this all should look like. It's a little unwieldy, I guess, but it is what we want to express from syscalls: they have a single return success/failure variant.

But, I'm not sure how important it is to resolve this right now.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Well, the reason I asked was because I was trying to figure out what the purpose of the Failure variants are at all. I think they're useful for testing, for what I described above, and for nothing else.

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