1# This file was written by Yao Qi <qiyao@cn.ibm.com>. 2 3set testfile "time-record" 4set srcfile ${testfile}.c 5set binfile ${testfile}-T 6 7verbose "compiling source file now....." 8# Build the shared libraries this test case needs. 9if { [ ltrace_compile "${srcdir}/${subdir}/${testfile}.c" "${objdir}/${subdir}/${binfile}" executable {debug} ] != "" } { 10 send_user "Testcase compile failed, so all tests in this file will automatically fail.\n" 11} 12 13# set options for ltrace. 14ltrace_options "-T" 15 16# Run PUT for ltrace. 17set exec_output [ltrace_runtest $objdir/$subdir $objdir/$subdir/$binfile] 18verbose "ltrace runtest output: $exec_output\n" 19 20# Check the output of this program. 21if [regexp {ELF from incompatible architecture} $exec_output] { 22 fail "32-bit ltrace can not perform on 64-bit PUTs and rebuild ltrace in 64 bit mode!" 23 return 24} elseif [ regexp {Couldn't get .hash data} $exec_output ] { 25 fail "Couldn't get .hash data!" 26 return 27} 28 29# Get the time of nanosleep in C source file. 30set fd [ open $srcdir/$subdir/$srcfile r] 31while { [gets $fd line] >= 0 } { 32 if [ regexp {define NANOSLEEP_COUNT ([0-9]+)} $line match nanosleep_usec] then { 33 break 34 } 35} 36close $fd 37 38 39# Verify the time for calling sleep. 40set fd [ open $objdir/$subdir/$binfile.ltrace r] 41set FOUND 0 42while { [gets $fd line] >= 0 } { 43 # match the line with sleep and extract the spent time in sleep and sleep argument. 44 if [ regexp {sleep\(([0-9]+).*<([0-9]+\.[0-9]+)>} $line match sleep_sec sec ] then { 45 verbose "sleep_sec = $sleep_sec, sec = $sec" 46 47 if { $sec >= $sleep_sec } then { 48 pass "Correct Time spent inside call." 49 } else { 50 fail "Spent $sec inside call, but PUT call sleep($sleep_sec)!" 51 } 52 set FOUND 1 53 break 54 } 55} 56close $fd 57 58if {$FOUND != 1} then { 59 fail "Fail to find call sleep!" 60} 61 62# Verify the time for calling nanosleep. 63set FOUND 0 64set fd [ open $objdir/$subdir/$binfile.ltrace r] 65while { [gets $fd line] >= 0 } { 66 # match the line with nanosleep and extract spent time and nanosleep argument. 67 if [ regexp {nanosleep.*<([0-9]+\.[0-9]+)>} $line match usec] then { 68 verbose "nanosleep_usec = $nanosleep_usec, usec = $usec" 69 70 if { $usec * 1000 >= $nanosleep_usec} then { 71 pass "Correct Time spent inside call." 72 } else { 73 fail "Spent $usec inside call, but PUT call nanosleep($nanosleep_usec)!" 74 } 75 set FOUND 1 76 break 77 } 78} 79 80if { $FOUND != 1} then { 81 fail "Fail to find nanosleep" 82} 83close $fd 84 85