oxigdal-bench 0.1.7

Comprehensive performance profiling and benchmarking suite for OxiGDAL
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
//! I/O performance benchmark scenarios.
//!
//! This module provides benchmark scenarios for I/O operations including:
//! - Sequential read/write performance
//! - Random access patterns
//! - Chunked I/O operations
//! - Different file formats
//! - Compression impact on I/O

use crate::error::{BenchError, Result};
use crate::scenarios::BenchmarkScenario;
use std::fs::File;
use std::io::{Read, Seek, SeekFrom, Write};
use std::path::PathBuf;

/// Sequential read benchmark scenario.
pub struct SequentialReadScenario {
    input_path: PathBuf,
    buffer_size: usize,
    total_bytes_read: usize,
}

impl SequentialReadScenario {
    /// Creates a new sequential read benchmark scenario.
    pub fn new<P: Into<PathBuf>>(input_path: P) -> Self {
        Self {
            input_path: input_path.into(),
            buffer_size: 8192,
            total_bytes_read: 0,
        }
    }

    /// Sets the buffer size for reading.
    pub fn with_buffer_size(mut self, size: usize) -> Self {
        self.buffer_size = size;
        self
    }
}

impl BenchmarkScenario for SequentialReadScenario {
    fn name(&self) -> &str {
        "sequential_read"
    }

    fn description(&self) -> &str {
        "Benchmark sequential file reading performance"
    }

    fn setup(&mut self) -> Result<()> {
        if !self.input_path.exists() {
            return Err(BenchError::scenario_failed(
                self.name(),
                format!("Input file does not exist: {}", self.input_path.display()),
            ));
        }

        Ok(())
    }

    fn execute(&mut self) -> Result<()> {
        let mut file = File::open(&self.input_path)?;
        let mut buffer = vec![0u8; self.buffer_size];
        self.total_bytes_read = 0;

        loop {
            let bytes_read = file.read(&mut buffer)?;
            if bytes_read == 0 {
                break;
            }
            self.total_bytes_read += bytes_read;
        }

        Ok(())
    }

    fn teardown(&mut self) -> Result<()> {
        Ok(())
    }
}

/// Sequential write benchmark scenario.
pub struct SequentialWriteScenario {
    output_path: PathBuf,
    file_size: usize,
    buffer_size: usize,
    created: bool,
}

impl SequentialWriteScenario {
    /// Creates a new sequential write benchmark scenario.
    pub fn new<P: Into<PathBuf>>(output_path: P, file_size: usize) -> Self {
        Self {
            output_path: output_path.into(),
            file_size,
            buffer_size: 8192,
            created: false,
        }
    }

    /// Sets the buffer size for writing.
    pub fn with_buffer_size(mut self, size: usize) -> Self {
        self.buffer_size = size;
        self
    }
}

impl BenchmarkScenario for SequentialWriteScenario {
    fn name(&self) -> &str {
        "sequential_write"
    }

    fn description(&self) -> &str {
        "Benchmark sequential file writing performance"
    }

    fn setup(&mut self) -> Result<()> {
        if let Some(parent) = self.output_path.parent() {
            std::fs::create_dir_all(parent)?;
        }

        Ok(())
    }

    fn execute(&mut self) -> Result<()> {
        let mut file = File::create(&self.output_path)?;
        let buffer = vec![0u8; self.buffer_size];

        let mut remaining = self.file_size;
        while remaining > 0 {
            let to_write = remaining.min(self.buffer_size);
            file.write_all(&buffer[..to_write])?;
            remaining -= to_write;
        }

        file.sync_all()?;
        self.created = true;

        Ok(())
    }

    fn teardown(&mut self) -> Result<()> {
        if self.created && self.output_path.exists() {
            std::fs::remove_file(&self.output_path)?;
        }
        Ok(())
    }
}

/// Random access read benchmark scenario.
pub struct RandomAccessScenario {
    input_path: PathBuf,
    access_count: usize,
    chunk_size: usize,
    file_size: u64,
}

impl RandomAccessScenario {
    /// Creates a new random access benchmark scenario.
    pub fn new<P: Into<PathBuf>>(input_path: P, access_count: usize) -> Self {
        Self {
            input_path: input_path.into(),
            access_count,
            chunk_size: 4096,
            file_size: 0,
        }
    }

    /// Sets the chunk size for each random access.
    pub fn with_chunk_size(mut self, size: usize) -> Self {
        self.chunk_size = size;
        self
    }
}

impl BenchmarkScenario for RandomAccessScenario {
    fn name(&self) -> &str {
        "random_access"
    }

    fn description(&self) -> &str {
        "Benchmark random access read performance"
    }

    fn setup(&mut self) -> Result<()> {
        if !self.input_path.exists() {
            return Err(BenchError::scenario_failed(
                self.name(),
                format!("Input file does not exist: {}", self.input_path.display()),
            ));
        }

        self.file_size = std::fs::metadata(&self.input_path)?.len();

        if self.file_size < self.chunk_size as u64 {
            return Err(BenchError::scenario_failed(
                self.name(),
                "File too small for random access benchmark".to_string(),
            ));
        }

        Ok(())
    }

    fn execute(&mut self) -> Result<()> {
        let mut file = File::open(&self.input_path)?;
        let mut buffer = vec![0u8; self.chunk_size];

        // Use a simple pseudo-random sequence for reproducibility
        let mut seed = 12345u64;
        for _ in 0..self.access_count {
            // Simple LCG for reproducible randomness
            seed = seed.wrapping_mul(1103515245).wrapping_add(12345);
            let max_offset = self.file_size.saturating_sub(self.chunk_size as u64);
            let offset = seed % max_offset.max(1);

            file.seek(SeekFrom::Start(offset))?;
            file.read_exact(&mut buffer)?;
        }

        Ok(())
    }

    fn teardown(&mut self) -> Result<()> {
        Ok(())
    }
}

/// Chunked I/O benchmark scenario.
pub struct ChunkedIoScenario {
    input_path: PathBuf,
    output_path: PathBuf,
    chunk_sizes: Vec<usize>,
    created: bool,
}

impl ChunkedIoScenario {
    /// Creates a new chunked I/O benchmark scenario.
    pub fn new<P1, P2>(input_path: P1, output_path: P2) -> Self
    where
        P1: Into<PathBuf>,
        P2: Into<PathBuf>,
    {
        Self {
            input_path: input_path.into(),
            output_path: output_path.into(),
            chunk_sizes: vec![512, 1024, 4096, 8192, 16384, 65536],
            created: false,
        }
    }

    /// Sets the chunk sizes to benchmark.
    pub fn with_chunk_sizes(mut self, sizes: Vec<usize>) -> Self {
        self.chunk_sizes = sizes;
        self
    }
}

impl BenchmarkScenario for ChunkedIoScenario {
    fn name(&self) -> &str {
        "chunked_io"
    }

    fn description(&self) -> &str {
        "Benchmark different chunk sizes for I/O operations"
    }

    fn setup(&mut self) -> Result<()> {
        if !self.input_path.exists() {
            return Err(BenchError::scenario_failed(
                self.name(),
                format!("Input file does not exist: {}", self.input_path.display()),
            ));
        }

        if let Some(parent) = self.output_path.parent() {
            std::fs::create_dir_all(parent)?;
        }

        Ok(())
    }

    fn execute(&mut self) -> Result<()> {
        for &chunk_size in &self.chunk_sizes {
            let mut input = File::open(&self.input_path)?;
            let mut output = File::create(&self.output_path)?;
            let mut buffer = vec![0u8; chunk_size];

            loop {
                let bytes_read = input.read(&mut buffer)?;
                if bytes_read == 0 {
                    break;
                }
                output.write_all(&buffer[..bytes_read])?;
            }

            output.sync_all()?;
        }

        self.created = true;
        Ok(())
    }

    fn teardown(&mut self) -> Result<()> {
        if self.created && self.output_path.exists() {
            std::fs::remove_file(&self.output_path)?;
        }
        Ok(())
    }
}

/// Buffered vs unbuffered I/O benchmark scenario.
pub struct BufferedIoScenario {
    input_path: PathBuf,
    use_buffering: bool,
    total_bytes: usize,
}

impl BufferedIoScenario {
    /// Creates a new buffered I/O benchmark scenario.
    pub fn new<P: Into<PathBuf>>(input_path: P, use_buffering: bool) -> Self {
        Self {
            input_path: input_path.into(),
            use_buffering,
            total_bytes: 0,
        }
    }
}

impl BenchmarkScenario for BufferedIoScenario {
    fn name(&self) -> &str {
        if self.use_buffering {
            "buffered_io"
        } else {
            "unbuffered_io"
        }
    }

    fn description(&self) -> &str {
        "Benchmark buffered vs unbuffered I/O performance"
    }

    fn setup(&mut self) -> Result<()> {
        if !self.input_path.exists() {
            return Err(BenchError::scenario_failed(
                self.name(),
                format!("Input file does not exist: {}", self.input_path.display()),
            ));
        }

        Ok(())
    }

    fn execute(&mut self) -> Result<()> {
        use std::io::BufReader;

        let file = File::open(&self.input_path)?;
        self.total_bytes = 0;

        if self.use_buffering {
            let mut reader = BufReader::new(file);
            let mut buffer = vec![0u8; 8192];
            loop {
                let bytes_read = reader.read(&mut buffer)?;
                if bytes_read == 0 {
                    break;
                }
                self.total_bytes += bytes_read;
            }
        } else {
            let mut reader = file;
            let mut buffer = vec![0u8; 8192];
            loop {
                let bytes_read = reader.read(&mut buffer)?;
                if bytes_read == 0 {
                    break;
                }
                self.total_bytes += bytes_read;
            }
        }

        Ok(())
    }

    fn teardown(&mut self) -> Result<()> {
        Ok(())
    }
}

/// Memory-mapped I/O benchmark scenario.
pub struct MemoryMappedIoScenario {
    input_path: PathBuf,
    read_pattern: ReadPattern,
}

/// Read patterns for memory-mapped I/O.
#[derive(Debug, Clone, Copy)]
pub enum ReadPattern {
    /// Sequential read pattern.
    Sequential,
    /// Random read pattern.
    Random,
    /// Strided read pattern (every Nth byte).
    Strided(usize),
}

impl MemoryMappedIoScenario {
    /// Creates a new memory-mapped I/O benchmark scenario.
    pub fn new<P: Into<PathBuf>>(input_path: P) -> Self {
        Self {
            input_path: input_path.into(),
            read_pattern: ReadPattern::Sequential,
        }
    }

    /// Sets the read pattern.
    pub fn with_pattern(mut self, pattern: ReadPattern) -> Self {
        self.read_pattern = pattern;
        self
    }
}

impl BenchmarkScenario for MemoryMappedIoScenario {
    fn name(&self) -> &str {
        "memory_mapped_io"
    }

    fn description(&self) -> &str {
        "Benchmark memory-mapped file I/O performance"
    }

    fn setup(&mut self) -> Result<()> {
        if !self.input_path.exists() {
            return Err(BenchError::scenario_failed(
                self.name(),
                format!("Input file does not exist: {}", self.input_path.display()),
            ));
        }

        Ok(())
    }

    fn execute(&mut self) -> Result<()> {
        use oxigdal_core::io::MmapDataSource;

        // Memory-map the file so reads below go through the OS page cache
        // without an explicit buffered copy, unlike the other scenarios in
        // this module.
        let mmap = MmapDataSource::open(&self.input_path).map_err(|e| {
            BenchError::scenario_failed(self.name(), format!("Failed to mmap file: {e}"))
        })?;
        let buffer = mmap.as_bytes();

        // Simulate different read patterns
        let _sum: u64 = match self.read_pattern {
            ReadPattern::Sequential => buffer.iter().map(|&b| b as u64).sum(),
            ReadPattern::Random => {
                let mut seed = 12345u64;
                let mut sum = 0u64;
                for _ in 0..buffer.len().min(10000) {
                    seed = seed.wrapping_mul(1103515245).wrapping_add(12345);
                    let idx = (seed as usize) % buffer.len();
                    sum = sum.wrapping_add(buffer[idx] as u64);
                }
                sum
            }
            ReadPattern::Strided(stride) => buffer.iter().step_by(stride).map(|&b| b as u64).sum(),
        };

        Ok(())
    }

    fn teardown(&mut self) -> Result<()> {
        Ok(())
    }
}

/// Direct I/O benchmark scenario.
pub struct DirectIoScenario {
    input_path: PathBuf,
    alignment: usize,
}

impl DirectIoScenario {
    /// Creates a new direct I/O benchmark scenario.
    pub fn new<P: Into<PathBuf>>(input_path: P) -> Self {
        Self {
            input_path: input_path.into(),
            alignment: 4096,
        }
    }

    /// Sets the alignment requirement for direct I/O.
    pub fn with_alignment(mut self, alignment: usize) -> Self {
        self.alignment = alignment;
        self
    }
}

impl DirectIoScenario {
    /// Opens `input_path` requesting the OS's uncached / page-cache-bypassing
    /// read path where one is available:
    ///
    /// - Linux: `O_DIRECT` on `open()`.
    /// - macOS: `fcntl(fd, F_NOCACHE, 1)` after `open()` (Linux's `O_DIRECT`
    ///   has no macOS equivalent as an open flag; `F_NOCACHE` is the
    ///   documented substitute used by e.g. SQLite).
    /// - Everything else: a plain buffered open (no bypass available here).
    #[cfg(target_os = "linux")]
    fn open_direct(&self) -> Result<File> {
        use std::os::unix::fs::OpenOptionsExt;
        Ok(File::options()
            .read(true)
            .custom_flags(libc::O_DIRECT)
            .open(&self.input_path)?)
    }

    #[cfg(target_os = "macos")]
    fn open_direct(&self) -> Result<File> {
        use std::os::unix::io::AsRawFd;
        let file = File::open(&self.input_path)?;
        // SAFETY: `fcntl` is called with a valid, currently-open file
        // descriptor owned by `file` and a well-formed `F_NOCACHE` argument;
        // it only flips a flag on the underlying file description and
        // touches no memory through raw pointers.
        #[allow(unsafe_code)]
        let ret = unsafe { libc::fcntl(file.as_raw_fd(), libc::F_NOCACHE, 1) };
        if ret == -1 {
            return Err(BenchError::scenario_failed(
                self.name(),
                format!(
                    "fcntl(F_NOCACHE) failed: {}",
                    std::io::Error::last_os_error()
                ),
            ));
        }
        Ok(file)
    }

    #[cfg(not(any(target_os = "linux", target_os = "macos")))]
    fn open_direct(&self) -> Result<File> {
        Ok(File::open(&self.input_path)?)
    }
}

impl BenchmarkScenario for DirectIoScenario {
    fn name(&self) -> &str {
        "direct_io"
    }

    fn description(&self) -> &str {
        #[cfg(target_os = "linux")]
        {
            "Benchmark direct I/O performance: O_DIRECT bypasses the page cache on open()"
        }
        #[cfg(target_os = "macos")]
        {
            "Benchmark direct I/O performance: F_NOCACHE bypasses the unified buffer cache \
             (macOS has no O_DIRECT open flag; F_NOCACHE is the platform equivalent)"
        }
        #[cfg(not(any(target_os = "linux", target_os = "macos")))]
        {
            "Benchmark aligned buffered read performance (this platform has no \
             O_DIRECT/F_NOCACHE equivalent wired up here; the page cache is NOT bypassed)"
        }
    }

    fn setup(&mut self) -> Result<()> {
        if !self.input_path.exists() {
            return Err(BenchError::scenario_failed(
                self.name(),
                format!("Input file does not exist: {}", self.input_path.display()),
            ));
        }

        if self.alignment == 0 {
            return Err(BenchError::scenario_failed(
                self.name(),
                "alignment must be non-zero".to_string(),
            ));
        }

        Ok(())
    }

    fn execute(&mut self) -> Result<()> {
        // Direct/uncached I/O requires the destination buffer to start on an
        // `alignment`-byte boundary. `Vec<u8>`'s allocator alignment is not
        // guaranteed to match block-device alignment, so carve an aligned
        // sub-slice out of an over-sized allocation. This only inspects
        // pointer *addresses* (safe, no dereference), so no `unsafe` is
        // needed here.
        let mut raw = vec![0u8; self.alignment * 2];
        let addr = raw.as_ptr() as usize;
        let pad = (self.alignment - (addr % self.alignment)) % self.alignment;
        let buffer = raw.get_mut(pad..pad + self.alignment).ok_or_else(|| {
            BenchError::scenario_failed(self.name(), "failed to align scratch buffer".to_string())
        })?;

        let mut file = self.open_direct()?;

        loop {
            let bytes_read = match file.read(buffer) {
                Ok(n) => n,
                // On Linux, O_DIRECT requires every read to be block-aligned
                // in length; a shorter-than-`alignment` trailing block
                // commonly surfaces as EINVAL. That is an expected O_DIRECT
                // edge case (not a benchmark failure) -- treat it as EOF.
                #[cfg(target_os = "linux")]
                Err(e) if e.raw_os_error() == Some(libc::EINVAL) => break,
                Err(e) => return Err(e.into()),
            };
            if bytes_read == 0 {
                break;
            }
        }

        Ok(())
    }

    fn teardown(&mut self) -> Result<()> {
        Ok(())
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use std::io::Write;

    fn create_test_file(path: &PathBuf, size: usize) -> std::io::Result<()> {
        let mut file = File::create(path)?;
        let data = vec![0u8; size];
        file.write_all(&data)?;
        file.sync_all()?;
        Ok(())
    }

    #[test]
    fn test_sequential_read_scenario_creation() {
        let scenario = SequentialReadScenario::new(std::env::temp_dir().join("test.bin"))
            .with_buffer_size(16384);

        assert_eq!(scenario.name(), "sequential_read");
        assert_eq!(scenario.buffer_size, 16384);
    }

    #[test]
    fn test_sequential_write_scenario_creation() {
        let scenario =
            SequentialWriteScenario::new(std::env::temp_dir().join("output.bin"), 1024 * 1024)
                .with_buffer_size(32768);

        assert_eq!(scenario.name(), "sequential_write");
        assert_eq!(scenario.buffer_size, 32768);
    }

    #[test]
    fn test_random_access_scenario_creation() {
        let scenario = RandomAccessScenario::new(std::env::temp_dir().join("test.bin"), 100)
            .with_chunk_size(8192);

        assert_eq!(scenario.name(), "random_access");
        assert_eq!(scenario.chunk_size, 8192);
    }

    #[test]
    fn test_chunked_io_scenario() {
        let temp_dir = std::env::temp_dir();
        let input_path = temp_dir.join("test_chunked_input.bin");
        let output_path = temp_dir.join("test_chunked_output.bin");

        // Create test file
        create_test_file(&input_path, 10240).expect("Failed to create test file");

        let scenario = ChunkedIoScenario::new(&input_path, &output_path)
            .with_chunk_sizes(vec![512, 1024, 4096]);

        assert_eq!(scenario.name(), "chunked_io");
        assert_eq!(scenario.chunk_sizes.len(), 3);

        // Cleanup
        let _ = std::fs::remove_file(&input_path);
    }

    #[test]
    fn test_buffered_io_scenario_creation() {
        let scenario = BufferedIoScenario::new(std::env::temp_dir().join("test.bin"), true);
        assert_eq!(scenario.name(), "buffered_io");

        let scenario = BufferedIoScenario::new(std::env::temp_dir().join("test.bin"), false);
        assert_eq!(scenario.name(), "unbuffered_io");
    }

    #[test]
    fn test_direct_io_scenario_creation() {
        let scenario = DirectIoScenario::new(std::env::temp_dir().join("test_direct_io.bin"))
            .with_alignment(8192);

        assert_eq!(scenario.name(), "direct_io");
        assert_eq!(scenario.alignment, 8192);
    }

    #[test]
    fn test_direct_io_scenario_description_matches_platform_behavior() {
        let scenario = DirectIoScenario::new(std::env::temp_dir().join("test_direct_io.bin"));
        let description = scenario.description();

        // The description must never claim an uncached bypass this build
        // does not actually provide (see `open_direct` cfg branches above).
        #[cfg(target_os = "linux")]
        assert!(description.contains("O_DIRECT"));
        #[cfg(target_os = "macos")]
        assert!(description.contains("F_NOCACHE"));
        #[cfg(not(any(target_os = "linux", target_os = "macos")))]
        assert!(description.contains("NOT bypassed"));
    }

    #[test]
    fn test_direct_io_scenario_rejects_zero_alignment() {
        let input_path = std::env::temp_dir().join("test_direct_io_zero_alignment.bin");
        create_test_file(&input_path, 4096).expect("Failed to create test file");

        let mut scenario = DirectIoScenario::new(&input_path).with_alignment(0);
        let result = scenario.setup();

        assert!(
            result.is_err(),
            "zero alignment must be rejected in setup()"
        );

        let _ = std::fs::remove_file(&input_path);
    }

    #[test]
    fn test_direct_io_scenario_setup_rejects_missing_file() {
        let mut scenario =
            DirectIoScenario::new(std::env::temp_dir().join("test_direct_io_does_not_exist.bin"));
        assert!(scenario.setup().is_err());
    }

    #[test]
    fn test_direct_io_scenario_execute_reads_full_file() {
        // Regression test: DirectIoScenario::execute() must actually read the
        // whole file through the platform's uncached/direct path (or the
        // honest buffered fallback), not silently no-op. `alignment` is kept
        // small and a multiple of the OS page size is not required here
        // since this file's fallback/`F_NOCACHE` paths (used on this test
        // runner's platform) have no O_DIRECT-style block-alignment
        // requirement; on Linux CI this exercises the real O_DIRECT open.
        let input_path = std::env::temp_dir().join("test_direct_io_execute.bin");
        // 3 alignment-sized blocks so the read loop iterates more than once.
        create_test_file(&input_path, 4096 * 3).expect("Failed to create test file");

        let mut scenario = DirectIoScenario::new(&input_path).with_alignment(4096);

        scenario.setup().expect("setup should succeed");
        let result = scenario.execute();
        scenario.teardown().expect("teardown should succeed");

        let _ = std::fs::remove_file(&input_path);

        assert!(
            result.is_ok(),
            "DirectIoScenario::execute() failed: {result:?}"
        );
    }
}