-
Notifications
You must be signed in to change notification settings - Fork 18
Add vcpu run loop hooks #245
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /* | ||
| * Native-host compile test for vcpu_run_loop hook API compatibility. | ||
| * | ||
| * Copyright 2026 elfuse contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #include <assert.h> | ||
| #include <stddef.h> | ||
| #include <stdio.h> | ||
|
|
||
| #include "syscall/proc.h" | ||
|
|
||
| typedef int vcpu_run_loop_sig(hv_vcpu_t vcpu, | ||
| hv_vcpu_exit_t *vexit, | ||
| guest_t *g, | ||
| bool verbose, | ||
| int timeout_sec, | ||
| int *wait_status_out); | ||
|
|
||
| typedef int vcpu_run_loop_with_hooks_sig(hv_vcpu_t vcpu, | ||
| hv_vcpu_exit_t *vexit, | ||
| guest_t *g, | ||
| bool verbose, | ||
| int timeout_sec, | ||
| int *wait_status_out, | ||
| const vcpu_run_hooks_t *hooks); | ||
|
|
||
| _Static_assert(__builtin_types_compatible_p(__typeof__(vcpu_run_loop), | ||
| vcpu_run_loop_sig), | ||
| "vcpu_run_loop compatibility signature changed"); | ||
| _Static_assert( | ||
| __builtin_types_compatible_p(__typeof__(vcpu_run_loop_with_hooks), | ||
| vcpu_run_loop_with_hooks_sig), | ||
| "vcpu_run_loop_with_hooks signature changed"); | ||
|
|
||
| static int tick(guest_t *g, void *opaque) | ||
| { | ||
| return g != NULL && opaque != NULL; | ||
| } | ||
|
|
||
| int main(void) | ||
| { | ||
| vcpu_run_hooks_t hooks = { | ||
| .tick = tick, | ||
| .opaque = (void *) 0x1, | ||
| }; | ||
|
|
||
| if (hooks.tick == NULL || hooks.opaque == NULL) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The runtime half of this test is tautological: given the initializer, hooks.tick/hooks.opaque are never NULL, so the if can't fire and main always reaches PASS; the tick function is defined but never called. The real value is the two _Static_assert's, which fire at compile time -- building the object is what matters, not running the binary, yet mk/tests.mk prints a "unit test" banner and executes it, implying runtime validation that does not exist. The new executable behavior (invoke tick, break on nonzero) has no coverage since no in-tree caller passes non-NULL hooks. Either make it a compile-only target, or have main actually call tick(g, opaque) and assert on both the non-NULL and NULL-opaque short-circuit results. |
||
| fprintf(stderr, "test-vcpu-run-hooks-host: API wiring failed\n"); | ||
| return 1; | ||
| } | ||
|
|
||
| /* Verify tick actually functions with non-NULL and NULL parameters */ | ||
| assert(hooks.tick((guest_t *) 0x1234, hooks.opaque) == 1); | ||
| assert(hooks.tick(NULL, hooks.opaque) == 0); | ||
| assert(hooks.tick((guest_t *) 0x1234, NULL) == 0); | ||
| assert(hooks.tick(NULL, NULL) == 0); | ||
|
|
||
| printf("test-vcpu-run-hooks-host: PASS\n"); | ||
| return 0; | ||
| } | ||
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.
The hook contract is underspecified in three ways: