1988b0c54SDavid Riley#!/bin/bash 2988b0c54SDavid Riley 3988b0c54SDavid Riley# udelay() test script 4988b0c54SDavid Riley# 5988b0c54SDavid Riley# Test is executed by writing and reading to /sys/kernel/debug/udelay_test 6988b0c54SDavid Riley# and exercises a variety of delays to ensure that udelay() is delaying 7988b0c54SDavid Riley# at least as long as requested (as compared to ktime). 8988b0c54SDavid Riley# 9988b0c54SDavid Riley# Copyright (C) 2014 Google, Inc. 10988b0c54SDavid Riley# 11988b0c54SDavid Riley# This software is licensed under the terms of the GNU General Public 12988b0c54SDavid Riley# License version 2, as published by the Free Software Foundation, and 13988b0c54SDavid Riley# may be copied, distributed, and modified under those terms. 14988b0c54SDavid Riley# 15988b0c54SDavid Riley# This program is distributed in the hope that it will be useful, 16988b0c54SDavid Riley# but WITHOUT ANY WARRANTY; without even the implied warranty of 17988b0c54SDavid Riley# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18988b0c54SDavid Riley# GNU General Public License for more details. 19988b0c54SDavid Riley 20988b0c54SDavid RileyMODULE_NAME=udelay_test 21988b0c54SDavid RileyUDELAY_PATH=/sys/kernel/debug/udelay_test 22988b0c54SDavid Riley 23988b0c54SDavid Rileysetup() 24988b0c54SDavid Riley{ 25988b0c54SDavid Riley /sbin/modprobe -q $MODULE_NAME 26988b0c54SDavid Riley tmp_file=`mktemp` 27988b0c54SDavid Riley} 28988b0c54SDavid Riley 29988b0c54SDavid Rileytest_one() 30988b0c54SDavid Riley{ 31988b0c54SDavid Riley delay=$1 32988b0c54SDavid Riley echo $delay > $UDELAY_PATH 33988b0c54SDavid Riley tee -a $tmp_file < $UDELAY_PATH 34988b0c54SDavid Riley} 35988b0c54SDavid Riley 36988b0c54SDavid Rileycleanup() 37988b0c54SDavid Riley{ 38988b0c54SDavid Riley if [ -f $tmp_file ]; then 39988b0c54SDavid Riley rm $tmp_file 40988b0c54SDavid Riley fi 41988b0c54SDavid Riley /sbin/modprobe -q -r $MODULE_NAME 42988b0c54SDavid Riley} 43988b0c54SDavid Riley 44988b0c54SDavid Rileytrap cleanup EXIT 45988b0c54SDavid Rileysetup 46988b0c54SDavid Riley 47988b0c54SDavid Riley# Delay for a variety of times. 48988b0c54SDavid Riley# 1..200, 200..500 (by 10), 500..2000 (by 100) 49988b0c54SDavid Rileyfor (( delay = 1; delay < 200; delay += 1 )); do 50988b0c54SDavid Riley test_one $delay 51988b0c54SDavid Rileydone 52988b0c54SDavid Rileyfor (( delay = 200; delay < 500; delay += 10 )); do 53988b0c54SDavid Riley test_one $delay 54988b0c54SDavid Rileydone 55988b0c54SDavid Rileyfor (( delay = 500; delay <= 2000; delay += 100 )); do 56988b0c54SDavid Riley test_one $delay 57988b0c54SDavid Rileydone 58988b0c54SDavid Riley 59988b0c54SDavid Riley# Search for failures 60988b0c54SDavid Rileycount=`grep -c FAIL $tmp_file` 61988b0c54SDavid Rileyif [ $? -eq "0" ]; then 62988b0c54SDavid Riley echo "ERROR: $count delays failed to delay long enough" 63988b0c54SDavid Riley retcode=1 64988b0c54SDavid Rileyfi 65988b0c54SDavid Riley 66988b0c54SDavid Rileyexit $retcode 67