#!/bin/bash

# udelay() test script
#
# Test is executed by writing and reading to /sys/kernel/debug/udelay_test
# and exercises a variety of delays to ensure that udelay() is delaying
# at least as long as requested (as compared to ktime).
#
# Copyright (C) 2014 Google, Inc.
#
# This software is licensed under the terms of the GNU General Public
# License version 2, as published by the Free Software Foundation, and
# may be copied, distributed, and modified under those terms.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

MODULE_NAME=udelay_test
UDELAY_PATH=/sys/kernel/debug/udelay_test

setup()
{
	/sbin/modprobe -q $MODULE_NAME
	tmp_file=`mktemp`
}

test_one()
{
	delay=$1
	echo $delay > $UDELAY_PATH
	tee -a $tmp_file < $UDELAY_PATH
}

cleanup()
{
	if [ -f $tmp_file ]; then
		rm $tmp_file
	fi
	/sbin/modprobe -q -r $MODULE_NAME
}

trap cleanup EXIT
setup

# Delay for a variety of times.
# 1..200, 200..500 (by 10), 500..2000 (by 100)
for (( delay = 1; delay < 200; delay += 1 )); do
	test_one $delay
done
for (( delay = 200; delay < 500; delay += 10 )); do
	test_one $delay
done
for (( delay = 500; delay <= 2000; delay += 100 )); do
	test_one $delay
done

# Search for failures
count=`grep -c FAIL $tmp_file`
if [ $? -eq "0" ]; then
	echo "ERROR: $count delays failed to delay long enough"
	retcode=1
fi

exit $retcode
it/'>summary</a><a href='/cgit.cgi/linux/net-next.git/refs/?id=c67b42f3a3f03e68bf915f32c8f7be0b726fec1a'>refs</a><a class='active' href='/cgit.cgi/linux/net-next.git/log/tools/perf/arch/powerpc/Build'>log</a><a href='/cgit.cgi/linux/net-next.git/tree/tools/perf/arch/powerpc/Build?id=c67b42f3a3f03e68bf915f32c8f7be0b726fec1a'>tree</a><a href='/cgit.cgi/linux/net-next.git/commit/tools/perf/arch/powerpc/Build?id=c67b42f3a3f03e68bf915f32c8f7be0b726fec1a'>commit</a><a href='/cgit.cgi/linux/net-next.git/diff/tools/perf/arch/powerpc/Build?id=c67b42f3a3f03e68bf915f32c8f7be0b726fec1a'>diff</a></td><td class='form'><form class='right' method='get' action='/cgit.cgi/linux/net-next.git/log/tools/perf/arch/powerpc/Build'>
<input type='hidden' name='id' value='c67b42f3a3f03e68bf915f32c8f7be0b726fec1a'/><select name='qt'>
<option value='grep'>log msg</option>
<option value='author'>author</option>
<option value='committer'>committer</option>
<option value='range'>range</option>
</select>
<input class='txt' type='search' size='10' name='q' value=''/>
<input type='submit' value='search'/>
</form>
</td></tr></table>
<div class='path'>path: <a href='/cgit.cgi/linux/net-next.git/log/?id=c67b42f3a3f03e68bf915f32c8f7be0b726fec1a'>root</a>/<a href='/cgit.cgi/linux/net-next.git/log/tools?id=c67b42f3a3f03e68bf915f32c8f7be0b726fec1a'>tools</a>/<a href='/cgit.cgi/linux/net-next.git/log/tools/perf?id=c67b42f3a3f03e68bf915f32c8f7be0b726fec1a'>perf</a>/<a href='/cgit.cgi/linux/net-next.git/log/tools/perf/arch?id=c67b42f3a3f03e68bf915f32c8f7be0b726fec1a'>arch</a>/<a href='/cgit.cgi/linux/net-next.git/log/tools/perf/arch/powerpc?id=c67b42f3a3f03e68bf915f32c8f7be0b726fec1a'>powerpc</a>/<a href='/cgit.cgi/linux/net-next.git/log/tools/perf/arch/powerpc/Build?id=c67b42f3a3f03e68bf915f32c8f7be0b726fec1a'>Build</a></div><div class='content'><table class='list nowrap'><tr class='nohover'><th class='left'>Age</th><th class='left'>Commit message (<a href='/cgit.cgi/linux/net-next.git/log/tools/perf/arch/powerpc/Build?id=c67b42f3a3f03e68bf915f32c8f7be0b726fec1a&amp;showmsg=1'>Expand</a>)</th><th class='left'>Author</th><th class='left'>Files</th><th class='left'>Lines</th></tr>