18c2ecf20Sopenharmony_ci#!/bin/bash
28c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0-only
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci# udelay() test script
58c2ecf20Sopenharmony_ci#
68c2ecf20Sopenharmony_ci# Test is executed by writing and reading to /sys/kernel/debug/udelay_test
78c2ecf20Sopenharmony_ci# and exercises a variety of delays to ensure that udelay() is delaying
88c2ecf20Sopenharmony_ci# at least as long as requested (as compared to ktime).
98c2ecf20Sopenharmony_ci#
108c2ecf20Sopenharmony_ci# Copyright (C) 2014 Google, Inc.
118c2ecf20Sopenharmony_ci#
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ciMODULE_NAME=udelay_test
148c2ecf20Sopenharmony_ciUDELAY_PATH=/sys/kernel/debug/udelay_test
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_cisetup()
178c2ecf20Sopenharmony_ci{
188c2ecf20Sopenharmony_ci	/sbin/modprobe -q $MODULE_NAME
198c2ecf20Sopenharmony_ci	tmp_file=`mktemp`
208c2ecf20Sopenharmony_ci}
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_citest_one()
238c2ecf20Sopenharmony_ci{
248c2ecf20Sopenharmony_ci	delay=$1
258c2ecf20Sopenharmony_ci	echo $delay > $UDELAY_PATH
268c2ecf20Sopenharmony_ci	tee -a $tmp_file < $UDELAY_PATH
278c2ecf20Sopenharmony_ci}
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_cicleanup()
308c2ecf20Sopenharmony_ci{
318c2ecf20Sopenharmony_ci	if [ -f $tmp_file ]; then
328c2ecf20Sopenharmony_ci		rm $tmp_file
338c2ecf20Sopenharmony_ci	fi
348c2ecf20Sopenharmony_ci	/sbin/modprobe -q -r $MODULE_NAME
358c2ecf20Sopenharmony_ci}
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_citrap cleanup EXIT
388c2ecf20Sopenharmony_cisetup
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci# Delay for a variety of times.
418c2ecf20Sopenharmony_ci# 1..200, 200..500 (by 10), 500..2000 (by 100)
428c2ecf20Sopenharmony_cifor (( delay = 1; delay < 200; delay += 1 )); do
438c2ecf20Sopenharmony_ci	test_one $delay
448c2ecf20Sopenharmony_cidone
458c2ecf20Sopenharmony_cifor (( delay = 200; delay < 500; delay += 10 )); do
468c2ecf20Sopenharmony_ci	test_one $delay
478c2ecf20Sopenharmony_cidone
488c2ecf20Sopenharmony_cifor (( delay = 500; delay <= 2000; delay += 100 )); do
498c2ecf20Sopenharmony_ci	test_one $delay
508c2ecf20Sopenharmony_cidone
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci# Search for failures
538c2ecf20Sopenharmony_cicount=`grep -c FAIL $tmp_file`
548c2ecf20Sopenharmony_ciif [ $? -eq "0" ]; then
558c2ecf20Sopenharmony_ci	echo "ERROR: $count delays failed to delay long enough"
568c2ecf20Sopenharmony_ci	retcode=1
578c2ecf20Sopenharmony_cifi
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ciexit $retcode
60