1# This file was written by Yao Qi <qiyao@cn.ibm.com>. 2 3set testfile "time-record" 4set srcfile ${testfile}.c 5set binfile ${testfile}-tt 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 "-tt" 15 16# Run PUT for ltrace. 17set exec_output [ltrace_runtest $objdir/$subdir $objdir/$subdir/$binfile] 18 19# Check the output of this program. 20verbose "ltrace runtest output: $exec_output\n" 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# Verify the time for calling sleep. 30set fd [ open $objdir/$subdir/$binfile.ltrace r] 31set FOUND 0 32while { [gets $fd line] >= 0 } { 33 # match the line with sleep and extract the strat time and sleep argument. 34 if [ regexp {[0-9]+:([0-9]+):([0-9]+)\.[0-9]+ sleep\(([0-9]+)} $line match start_min start_sec sleep_sec] then { 35 # Remove extra zero. 36 regexp {0([1-9])} $start_min match start_min 37 regexp {0([1-9])} $start_sec match start_sec 38 39 verbose "start_sec = $start_sec, sleep_sec = $sleep_sec" 40 # get a new line for the end time of sleep 41 gets $fd line 42 regexp {[0-9]+:([0-9]+):([0-9]+)} $line match end_min end_sec 43 verbose "end_sec = $end_sec" 44 45 # Remove extra zero. 46 regexp {0([1-9])} $end_min match end_min 47 regexp {0([1-9])} $end_sec match end_sec 48 49 if { (($end_min - $start_min)*60 + $end_sec - $start_sec)== $sleep_sec } then { 50 pass "Correct Timestamp." 51 } else { 52 fail "Start at $start_sec, End at $end_sec, but PUT call sleep($sleep_sec)!" 53 } 54 set FOUND 1 55 break 56 } 57} 58close $fd 59 60if {$FOUND != 1} then { 61 fail "Fail to find call sleep!" 62} 63 64# Get the time of sleep and nanosleep in C source file. 65set fd [ open $srcdir/$subdir/$srcfile r] 66while { [gets $fd line] >= 0 } { 67 if [ regexp {define NANOSLEEP_COUNT ([0-9]+)} $line match nanosleep_usec] then { 68 break 69 } 70} 71close $fd 72 73# Verify the time for calling nanosleep. 74set FOUND 0 75set fd [ open $objdir/$subdir/$binfile.ltrace r] 76while { [gets $fd line] >= 0 } { 77 # match the line with sleep and extract the strat time and sleep argument. 78 if [ regexp {[0-9]+:[0-9]+:([0-9]+)\.([0-9][0-9][0-9]).* nanosleep} $line match start_sec start_usec ] then { 79 # Remove extra zeros. 80 regexp {0([1-9])} $start_sec match start_sec 81 regexp {0*([1-9][0-9]*)} $start_usec match start_usec 82 83 verbose "start_sec = $start_sec, start_usec = $start_usec, sleep_usec = $nanosleep_usec" 84 # get a new line for the end time of sleep 85 gets $fd line 86 regexp {[0-9]+:[0-9]+:([0-9]+)\.([0-9][0-9][0-9])} $line match end_sec end_usec 87 88 # Remove extra zeros. 89 regexp {0([1-9])} $end_sec match end_sec 90 regexp {0*([1-9][0-9]*)} $end_usec match end_usec 91 92 verbose "end_sec = $end_sec, end_usec = $end_usec" 93 if { (($end_sec - $start_sec)*1000 + $end_usec - $start_usec) >= $nanosleep_usec} then { 94 pass "Correct Timestamp." 95 } else { 96 fail "Start at $start_usec, End at $end_usec, but PUT call nanosleep($nanosleep_usec)!" 97 } 98 set FOUND 1 99 break 100 } 101} 102 103if { $FOUND != 1} then { 104 fail "Fail to find nanosleep" 105} 106close $fd 107 108