diff options
| author | Paul Buetow <paul@buetow.org> | 2026-02-21 21:47:34 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-02-21 21:47:34 +0200 |
| commit | 36f216c757eea7db82cf04aeae592956199b9f76 (patch) | |
| tree | 57ad3f59c2a5f5f6a95643597f77a099c1bdb0df /integrationtests | |
| parent | 08cb9dfe46f843114feb42cc9ffa599717ebcc32 (diff) | |
Add negative integration tests for io_uring syscalls (EBADF)
Add two new scenarios and tests:
- iouring-enter-ebadf: io_uring_enter with invalid fd 99999
- iouring-register-ebadf: io_uring_register with invalid fd 99999
Both verify ior captures the tracepoint even when the syscall fails.
Task: 348
Amp-Thread-ID: https://ampcode.com/threads/T-019c81bb-a460-7298-a25a-fa33502272b9
Co-authored-by: Amp <amp@ampcode.com>
Diffstat (limited to 'integrationtests')
| -rw-r--r-- | integrationtests/cmd/ioworkload/scenarios.go | 43 | ||||
| -rw-r--r-- | integrationtests/iouring_test.go | 20 |
2 files changed, 60 insertions, 3 deletions
diff --git a/integrationtests/cmd/ioworkload/scenarios.go b/integrationtests/cmd/ioworkload/scenarios.go index f25b8a4..0344999 100644 --- a/integrationtests/cmd/ioworkload/scenarios.go +++ b/integrationtests/cmd/ioworkload/scenarios.go @@ -90,9 +90,11 @@ var scenarios = map[string]func() error{ "truncate-ftruncate": truncateFtruncate, "truncate-enoent": truncateEnoent, "truncate-ftruncate-ebadf": truncateFtruncateEbadf, - "iouring-setup": iouringSetup, - "iouring-enter": iouringEnter, - "iouring-register": iouringRegister, + "iouring-setup": iouringSetup, + "iouring-enter": iouringEnter, + "iouring-register": iouringRegister, + "iouring-enter-ebadf": iouringEnterEbadf, + "iouring-register-ebadf": iouringRegisterEbadf, } func makeTempDir(prefix string) (string, func(), error) { @@ -2434,6 +2436,41 @@ func iouringRegister() error { return nil } +// iouringEnterEbadf calls io_uring_enter on an invalid fd. +// The syscall fails with EBADF, but ior captures the enter_io_uring_enter tracepoint. +func iouringEnterEbadf() error { + _, _, errno := syscall.Syscall6( + sysIoUringEnter, + 99999, // invalid fd + 0, // to_submit + 0, // min_complete + 0, // flags + 0, // sig + 0, // sz + ) + if errno == 0 { + return fmt.Errorf("expected EBADF, but io_uring_enter succeeded") + } + return nil +} + +// iouringRegisterEbadf calls io_uring_register on an invalid fd. +// The syscall fails with EBADF, but ior captures the enter_io_uring_register tracepoint. +func iouringRegisterEbadf() error { + _, _, errno := syscall.Syscall6( + sysIoUringRegister, + 99999, // invalid fd + ioringRegisterProbe, + 0, // arg (NULL) + 0, // nr_args + 0, 0, + ) + if errno == 0 { + return fmt.Errorf("expected EBADF, but io_uring_register succeeded") + } + return nil +} + // ioUringSetupRing calls io_uring_setup(2) and returns the ring fd. func ioUringSetupRing(entries uint32) (int, error) { var params [ioUringParamsSize]byte diff --git a/integrationtests/iouring_test.go b/integrationtests/iouring_test.go index 20c156c..02d7a16 100644 --- a/integrationtests/iouring_test.go +++ b/integrationtests/iouring_test.go @@ -31,3 +31,23 @@ func TestIouringRegister(t *testing.T) { }, }) } + +func TestIouringEnterEbadf(t *testing.T) { + runScenario(t, "iouring-enter-ebadf", []ExpectedEvent{ + { + Tracepoint: "enter_io_uring_enter", + Comm: "ioworkload", + MinCount: 1, + }, + }) +} + +func TestIouringRegisterEbadf(t *testing.T) { + runScenario(t, "iouring-register-ebadf", []ExpectedEvent{ + { + Tracepoint: "enter_io_uring_register", + Comm: "ioworkload", + MinCount: 1, + }, + }) +} |
