diff options
Diffstat (limited to 'integrationtests')
| -rw-r--r-- | integrationtests/cmd/ioworkload/scenarios.go | 32 | ||||
| -rw-r--r-- | integrationtests/truncate_test.go | 25 |
2 files changed, 54 insertions, 3 deletions
diff --git a/integrationtests/cmd/ioworkload/scenarios.go b/integrationtests/cmd/ioworkload/scenarios.go index e87d53e..c4583e9 100644 --- a/integrationtests/cmd/ioworkload/scenarios.go +++ b/integrationtests/cmd/ioworkload/scenarios.go @@ -52,7 +52,8 @@ var scenarios = map[string]func() error{ "sync-fdatasync": syncFdatasync, "sync-sync": syncSync, "sync-sync-file-range": syncSyncFileRange, - "truncate-basic": truncateBasic, + "truncate-basic": truncateBasic, + "truncate-ftruncate": truncateFtruncate, } func makeTempDir(prefix string) (string, func(), error) { @@ -1338,7 +1339,8 @@ func syncSyncFileRange() error { return syscall.SyncFileRange(fd, 0, int64(len(data)), 0) } -// truncateBasic opens a file, writes data, and truncates it. +// truncateBasic opens a file, writes data, then truncates it via +// syscall.Truncate which uses SYS_TRUNCATE directly on amd64 (path-based). func truncateBasic() error { dir, cleanup, err := makeTempDir("truncate-basic") if err != nil { @@ -1351,9 +1353,33 @@ func truncateBasic() error { if err != nil { return fmt.Errorf("open: %w", err) } - defer syscall.Close(fd) if _, err := syscall.Write(fd, []byte("truncate this content")); err != nil { + syscall.Close(fd) + return fmt.Errorf("write: %w", err) + } + syscall.Close(fd) + + return syscall.Truncate(path, 5) +} + +// truncateFtruncate opens a file, writes data, then truncates it via +// syscall.Ftruncate which uses SYS_FTRUNCATE directly on amd64 (fd-based). +func truncateFtruncate() error { + dir, cleanup, err := makeTempDir("truncate-ftruncate") + if err != nil { + return err + } + defer cleanup() + + path := filepath.Join(dir, "ftruncfile.txt") + fd, err := syscall.Open(path, syscall.O_RDWR|syscall.O_CREAT, 0o644) + if err != nil { + return fmt.Errorf("open: %w", err) + } + defer syscall.Close(fd) + + if _, err := syscall.Write(fd, []byte("ftruncate this content")); err != nil { return fmt.Errorf("write: %w", err) } return syscall.Ftruncate(fd, 5) diff --git a/integrationtests/truncate_test.go b/integrationtests/truncate_test.go new file mode 100644 index 0000000..9b94eed --- /dev/null +++ b/integrationtests/truncate_test.go @@ -0,0 +1,25 @@ +package integrationtests + +import "testing" + +func TestTruncateBasic(t *testing.T) { + runScenario(t, "truncate-basic", []ExpectedEvent{ + { + PathContains: "truncfile.txt", + Tracepoint: "enter_truncate", + Comm: "ioworkload", + MinCount: 1, + }, + }) +} + +func TestTruncateFtruncate(t *testing.T) { + runScenario(t, "truncate-ftruncate", []ExpectedEvent{ + { + PathContains: "ftruncfile.txt", + Tracepoint: "enter_ftruncate", + Comm: "ioworkload", + MinCount: 1, + }, + }) +} |
