#!/bin/bash

# --- Configuration ---
FIO_JOB_FILE=&#34;buffered_integrity_test.fio&#34;
# The full path to the test file that fio will create.
# This must match the &#39;directory&#39; and &#39;filename&#39; options in the .fio file.
FIO_TEST_FILE=&#34;/Volumes/YourSCSIVolume/fio-test/fio_test_file.dat&#34;
# Define the sequence of file sizes to test.
# This sequence intentionally crosses the 2GB and 4GB boundaries,
# which are common points for 32-bit overflow issues.
TEST_SIZES=(&#34;64M&#34; &#34;128M&#34; &#34;256M&#34; &#34;512M&#34; &#34;1G&#34; &#34;2G&#34; &#34;3G&#34; &#34;3900M&#34; &#34;4G&#34; &#34;5G&#34; &#34;8G&#34; &#34;16G&#34; &#34;20G&#34;)

# --- Script Start ---
# Check if the FIO job file exists.
if [ ! -f &#34;$FIO_JOB_FILE&#34; ]; then
    echo &#34;Error: FIO job file &#39;$FIO_JOB_FILE&#39; not found!&#34;
    exit 1
fi

echo &#34;Starting systematic I/O integrity test...&#34;
echo &#34;=================================&#34;

# Iterate through all defined sizes.
for size in &#34;${TEST_SIZES[@]}&#34;; do
    echo -e &#34;\n[*] Testing file size: $size&#34;

    # Pre-test cleanup: Ensure the test file does not exist from a previous failed run.
    rm -f &#34;$FIO_TEST_FILE&#34;

    # Run fio, using the --size parameter to override the size in the job file.
    fio --size=$size &#34;$FIO_JOB_FILE&#34;
    FIO_EXIT_CODE=$? # Store fio&#39;s exit code.

    # Post-test cleanup: Always remove the test file after the run.
    rm -f &#34;$FIO_TEST_FILE&#34;

    # Check the exit code of fio.
    # Any non-zero code indicates an error (I/O error or verification failure).
    if [ $FIO_EXIT_CODE -ne 0 ]; then
        echo &#34;--------------------------------------------------&#34;
        echo &#34;[!!!] TEST FAILED at file size: $size&#34;
        echo &#34;The issue is likely related to transfers of this size.&#34;
        echo &#34;Check the fio output for &#39;verify&#39; or &#39;IO&#39; related error messages.&#34;
        echo &#34;--------------------------------------------------&#34;
        # Stop the script after finding the first failure.
        exit 1
    else
        echo &#34;[OK] Test passed for file size $size.&#34;
    fi
done

echo &#34;=================================&#34;
echo &#34;All fio integrity tests completed successfully!&#34;
