summaryrefslogtreecommitdiff
path: root/integrationtests/cmd/ioworkload
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-02-21 19:39:11 +0200
committerPaul Buetow <paul@buetow.org>2026-02-21 19:39:11 +0200
commit4253a94b9bcb03c3c59e37a05ac006e79dfdc8bf (patch)
tree107344ad489fb9b39ebaf7941e7264916667699b /integrationtests/cmd/ioworkload
parentfa4de83302f992a94941ef904f05ce2752f6ec29 (diff)
Implement truncate_test.go + workload scenarios for truncate, ftruncate
- truncate-basic: tests SYS_TRUNCATE (path-based) via syscall.Truncate - truncate-ftruncate: tests SYS_FTRUNCATE (fd-based) via syscall.Ftruncate - Both syscall wrappers use direct SYS_* calls on amd64 (no *at wrapping) Task #343 Amp-Thread-ID: https://ampcode.com/threads/T-019c8145-7437-7218-95ff-4cb451e18655 Co-authored-by: Amp <amp@ampcode.com>
Diffstat (limited to 'integrationtests/cmd/ioworkload')
-rw-r--r--integrationtests/cmd/ioworkload/scenarios.go32
1 files changed, 29 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)