#!/bin/sh _root="$(dirname "${0}")"; . "${_root}/lib/sh/env.sh" want log suexec [ "$(hostname -s)" = "nabihinew" ] || wtf "Run this on nabihinew only!" suexec "${0}" "${@}" want stopwatch # Environment and needed stuff tests="${_root}/tests" # Log maintenance logs="${_root}/log" [ -d "${logs}" ] || mkdir -p "${logs}" run_log="${logs}/bench-$(date +%Y-%m-%d_%H:%M:%S).log" # Zpool handling zpool_name="test" zpool_create() { echo zpool create -O mountpoint="${scratch}" "${zpool_name}" "${@}" zpool create -O mountpoint="${scratch}" "${zpool_name}" "${@}" || wtf "Couldn't create zpool!" zpool status zpool list } zpool_destroy() { zpool list -Ho name | grep -q "^${zpool_name}$" && zpool destroy "${zpool_name}" } # Scratch directory maintenance scratch="/bonnie" clean_scratch() { [ -d "${scratch}" ] || mkdir -p "${scratch}" zpool_destroy mount | grep -q ' on '"${scratch}"' ' && umount "${scratch}" || true find "${scratch}" ${bonnie_uid:+-uid "${bonnie_uid}"} -xdev -delete } clean_scratch # Bonnie setup bonnie_uid="4444" bonnie_opts="-q -d /bonnie -u ${bonnie_uid} -s 12288 -n 16:16384:0 -f 0" bonnie_log="${logs}/bonnie-%s-$(date +%Y-%m-%d_%H:%M:%S).csv" run_bonnie() { chown "${bonnie_uid}" "${scratch}" /usr/local/sbin/bonnie++ ${bonnie_opts} -m "${test}" >> "$(printf "${bonnie_log}" "${test}")" } # Default methods setup() { clean_scratch } run() { run_bonnie } teardown() { clean_scratch } # Main event if [ "${#}" -eq 0 ] then log "Considering tests: $(cd "${tests}"; echo *)" | tee -a "${run_log}" script -a "${run_log}" sh -c "( cd '${tests}'; ls -1 ) | xargs -L1 '${0}'" else test="${1}"; shift testfile="${tests}/${test}" [ -f "${testfile}" ] || wtf "Test '${test}' does not exist" ( log "Preparing test: ${test}" . "${testfile}" setup sync trap "teardown" EXIT HUP INT TERM KILL log "$(stopwatch run start)" run; result=$? log "$(stopwatch run stop) Test result ${result}" trap - EXIT HUP INT TERM KILL teardown ) fi