AUTHOR = "Peter Kukol pkukol@google.com"
NAME = "fsdev"
TIME = "LONG"
TEST_CATEGORY = "Functional"
TEST_CLASS = "Kernel"
TEST_TYPE = "client"

DOC = """
This test locates hard drives, formats them with given file systems/options
and then runs a given subset of tests against each file system.
"""

import fsdev_disks

# Initialize the FS_LIST variable below to the desired file system list; each
# entry should contain the following (single) string:
#        'type / mkfs_options     / mount_options  / unique_test_tag'
# The results will be tagged with 'unique_test_tag' for each FS entry.
FS_LIST=[
         'ext2 / -q               /                / ext2',
         'ext4 / -q -j -O extents / extents        / ext4_extents',
         'xfs  / -f -l size=128m  / logbufs=7      / xfs_log7'
        ]

# This file contains the scheduler tunable values we should use
_TUNEVAL_FILE="kernel_io_tunable_values"

# The following file describes the scheduler tunable parameter paths
_TUNEDSC_FILE="kernel_io_tunable_defs"

# Set this based on whether the test needs to use all the drives or just one
using_one_disk = True

# Create an instance of the 'fsdev disks' utility class
fd = fsdev_disks.fsdev_disks(job)

# Load the I/O scheduler / tunable descriptions
fd.config_sched_tunables(os.path.join(job.configdir, _TUNEDSC_FILE))

# Find all the data drives available on the box we're running on
disks = fsdev_disks.get_disk_list()
if len(disks) <= 0:
    raise JobError("No disks found to run test against")

# Load the I/O scheduler / tunable descriptions
fd.load_sched_tunable_values(os.path.join(job.configdir, _TUNEVAL_FILE))

# Set the scheduler and its tunables for all the disks we'll use
fd.set_sched_tunables(disks)

# Walk the list of file systems (and parameters) we are supposed to test
for fstline in FS_LIST:
    (dir,tag,xxx) = fsdev_disks.prepare_disks(job,
                                              fstline,
                                              disk1_only = using_one_disk,
                                              disk_list  = disks)

    # We're ready to invoke benchmarks for this file system
    job.run_test('iozone',
                 dir=disks[0]['mountpt'],
                 args='-l8 -u8 -M -s 8m -r16k +p80 -I -T -i0 -i8',
                 tag='small.'+tag)
    utils.drop_caches()

    job.run_test('iozone',
                 dir=disks[0]['mountpt'],
                 args='-l8 -u8 -M -s 8g -r16k +p80 -I -T -i0 -i8',
                 tag='large.'+tag)
    utils.drop_caches()

    # Clean up after the test
    if using_one_disk:
        fsdev_disks.wipe_disks(job, disk_list[0:1])
    else:
        fsdev_disks.wipe_disks(job, disk_list)

