summaryrefslogtreecommitdiff
path: root/automated/linux/cyclictest/cyclictest.sh
blob: 7586a84aa558a3b70386a0ff92a5f495b6a5abe6 (plain)
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
#!/bin/sh -e
# cyclictest measures event latency in Linux kernel by measuring the amount of
# time that passes between when a timer expires and when the thread which set
# the timer actually runs.

# shellcheck disable=SC1091
. ../../lib/sh-test-lib

OUTPUT="$(pwd)/output"
LOGFILE="${OUTPUT}/cyclictest.txt"
RESULT_FILE="${OUTPUT}/result.txt"

PRIORITY="99"
INTERVAL="10000"
THREADS="1"
LOOPS="10000"

usage() {
    echo "Usage: $0 [-p priority] [-i interval] [-t threads] [-l loops]" 1>&2
    exit 1
}

while getopts ":p:i:t:l:" opt; do
    case "${opt}" in
        p) PRIORITY="${OPTARG}" ;;
        i) INTERVAL="${OPTARG}" ;;
        t) THREADS="${OPTARG}" ;;
        l) LOOPS="${OPTARG}" ;;
        *) usage ;;
    esac
done

! check_root && error_msg "Please run this script as root."
[ -d "${OUTPUT}" ] && mv "${OUTPUT}" "${OUTPUT}_$(date +%Y%m%d%H%M%S)"
mkdir -p "${OUTPUT}"

# Run cyclictest.
detect_abi
# shellcheck disable=SC2154
./bin/"${abi}"/cyclictest -p "${PRIORITY}" -i "${INTERVAL}" -t "${THREADS}" \
    -l "${LOOPS}" | tee "${LOGFILE}"

# Parse test log.
tail -n "${THREADS}" "${LOGFILE}" \
    | sed 's/T:/T: /' \
    | awk '{printf("t%s-min-latency pass %s us\n", $2, $(NF-6))};
           {printf("t%s-avg-latency pass %s us\n", $2, $(NF-2))};
           {printf("t%s-max-latency pass %s us\n", $2, $NF)};'  \
    | tee -a "${RESULT_FILE}"