#!/bin/bash
test_begin() {
ctr=0
[ -z "$RTLA" ] && RTLA="./rtla"
[ -n "$TEST_COUNT" ] && echo "1..$TEST_COUNT"
}
reset_osnoise() {
pushd /sys/kernel/tracing >/dev/null || return 1
echo 0 > tracing_thresh
cd instances
for i in osnoise_top osnoise_hist timerlat_top timerlat_hist
do
[ ! -d "$i" ] && continue
rmdir "$i"
done
cd ../osnoise
echo all > cpus
echo DEFAULTS > options
echo 1000000 > period_us
echo 0 > print_stack
echo 1000000 > runtime_us
echo 0 > stop_tracing_total_us
echo 0 > stop_tracing_us
echo 1000 > timerlat_period_us
popd >/dev/null
}
check() {
test_name=$0
tested_command=$1
expected_exitcode=${3:-0}
expected_output=$4
ctr=$(($ctr + 1))
if [ -n "$TEST_COUNT" ]
then
[ "$NO_RESET_OSNOISE" == 1 ] || reset_osnoise
result=$(eval stdbuf -oL $TIMEOUT "$RTLA" $2 2>&1); exitcode=$?
if [ -n "$expected_output" ]
then
grep -E "$expected_output" <<< "$result" > /dev/null; grep_result=$?
else
grep_result=0
fi
if [ $exitcode -eq $expected_exitcode ] && [ $grep_result -eq 0 ]
then
echo "ok $ctr - $1"
else
echo "not ok $ctr - $1"
echo "$result" | col -b | while read line; do echo "# $line"; done
printf "#\n# exit code %s\n" $exitcode
[ -n "$expected_output" ] && [ $grep_result -ne 0 ] && \
printf "# Output match failed: \"%s\"\n" "$expected_output"
fi
fi
}
check_with_osnoise_options() {
arg1=$1
arg2=$2
arg3=$3
if [ -n "$TEST_COUNT" ]
then
[ "$NO_RESET_OSNOISE" == 1 ] || reset_osnoise
shift
shift
while shift
do
[ "$1" == "" ] && continue
option=$(echo $1 | cut -d '=' -f 1)
value=$(echo $1 | cut -d '=' -f 2)
echo "option: $option, value: $value"
echo "$value" > "/sys/kernel/tracing/osnoise/$option" || return 1
done
fi
NO_RESET_OSNOISE=1 check "$arg1" "$arg2" "$arg3"
}
set_timeout() {
TIMEOUT="timeout -v -k 15s $1"
}
unset_timeout() {
unset TIMEOUT
}
set_no_reset_osnoise() {
NO_RESET_OSNOISE=1
}
unset_no_reset_osnoise() {
unset NO_RESET_OSNOISE
}
test_end() {
[ -z "$TEST_COUNT" ] && TEST_COUNT=$ctr exec bash $0 || true
}
export LC_ALL=C
unset_timeout