#!/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. global MODULE_NAME := 'udelay_test' global UDELAY_PATH := '/sys/kernel/debug/udelay_test' proc setup { /sbin/modprobe -q $MODULE_NAME global tmp_file := $[mktemp] } proc test_one { global delay := $1 echo $delay > $UDELAY_PATH tee -a $tmp_file < $UDELAY_PATH } proc cleanup { if test -f $tmp_file { rm $tmp_file } /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 global count := $[grep -c FAIL $tmp_file] if test $Status -eq "0" { echo "ERROR: $count delays failed to delay long enough" global retcode := '1' } exit $retcode (CommandList children: [ (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:MODULE_NAME) op:Equal rhs:{(udelay_test)} spids:[53])] spids: [53] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:UDELAY_PATH) op: Equal rhs: {(/sys/kernel/debug/udelay_test)} spids: [56] ) ] spids: [56] ) (FuncDef name: setup body: (BraceGroup children: [ (C {(/sbin/modprobe)} {(-q)} {($ VSub_Name "$MODULE_NAME")}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:tmp_file) op: Equal rhs: { (CommandSubPart command_list: (CommandList children:[(C {(mktemp)})]) left_token: spids: [75 77] ) } spids: [74] ) ] spids: [74] ) ] spids: [64] ) spids: [60 63] ) (FuncDef name: test_one body: (BraceGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:delay) op: Equal rhs: {($ VSub_Number "$1")} spids: [89] ) ] spids: [89] ) (SimpleCommand words: [{(echo)} {($ VSub_Name "$delay")}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {($ VSub_Name "$UDELAY_PATH")} spids: [97] ) ] ) (SimpleCommand words: [{(tee)} {(-a)} {($ VSub_Name "$tmp_file")}] redirects: [ (Redir op_id: Redir_Less fd: -1 arg_word: {($ VSub_Name "$UDELAY_PATH")} spids: [108] ) ] ) ] spids: [86] ) spids: [82 85] ) (FuncDef name: cleanup body: (BraceGroup children: [ (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(-f)} {($ VSub_Name "$tmp_file")} {(Lit_Other "]")}) terminator: ) ] action: [(C {(rm)} {($ VSub_Name "$tmp_file")})] spids: [-1 133] ) ] spids: [-1 141] ) (C {(/sbin/modprobe)} {(-q)} {(-r)} {($ VSub_Name "$MODULE_NAME")}) ] spids: [119] ) spids: [115 118] ) (C {(trap)} {(cleanup)} {(EXIT)}) (C {(setup)}) (ForExpr init: (BinaryAssign op_id: Arith_Equal left: (LhsName name:delay) right: (ArithWord w:{(Lit_Digits 1)}) ) cond: (ArithBinary op_id: Arith_Less left: (ArithVarRef name:delay) right: (ArithWord w:{(Lit_Digits 200)}) ) update: (BinaryAssign op_id: Arith_PlusEqual left: (LhsName name:delay) right: (ArithWord w:{(Lit_Digits 1)}) ) body: (DoGroup children:[(C {(test_one)} {($ VSub_Name "$delay")})] spids:[198205]) ) (ForExpr init: (BinaryAssign op_id: Arith_Equal left: (LhsName name:delay) right: (ArithWord w:{(Lit_Digits 200)}) ) cond: (ArithBinary op_id: Arith_Less left: (ArithVarRef name:delay) right: (ArithWord w:{(Lit_Digits 500)}) ) update: (BinaryAssign op_id: Arith_PlusEqual left: (LhsName name:delay) right: (ArithWord w:{(Lit_Digits 10)}) ) body: (DoGroup children:[(C {(test_one)} {($ VSub_Name "$delay")})] spids:[235242]) ) (ForExpr init: (BinaryAssign op_id: Arith_Equal left: (LhsName name:delay) right: (ArithWord w:{(Lit_Digits 500)}) ) cond: (ArithBinary op_id: Arith_LessEqual left: (ArithVarRef name:delay) right: (ArithWord w:{(Lit_Digits 2000)}) ) update: (BinaryAssign op_id: Arith_PlusEqual left: (LhsName name:delay) right: (ArithWord w:{(Lit_Digits 100)}) ) body: (DoGroup children:[(C {(test_one)} {($ VSub_Name "$delay")})] spids:[272279]) ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:count) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [(C {(grep)} {(-c)} {(FAIL)} {($ VSub_Name "$tmp_file")})] ) left_token: spids: [286 294] ) } spids: [285] ) ] spids: [285] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {($ VSub_QMark "$?")} {(-eq)} {(DQ (0))} {(Lit_Other "]")}) terminator: ) ] action: [ (C {(echo)} {(DQ ("ERROR: ") ($ VSub_Name "$count") (" delays failed to delay long enough"))} ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:retcode) op:Equal rhs:{(1)} spids:[323])] spids: [323] ) ] spids: [-1 311] ) ] spids: [-1 326] ) (C {(exit)} {($ VSub_Name "$retcode")}) ] )