1 # This file was written by Yao Qi <qiyao (at) cn.ibm.com>. 2 3 set testfile "time-record" 4 set srcfile ${testfile}.c 5 set binfile ${testfile}-T 6 7 verbose "compiling source file now....." 8 # Build the shared libraries this test case needs. 9 if { [ 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. 14 ltrace_options "-T" 15 16 # Run PUT for ltrace. 17 set exec_output [ltrace_runtest $objdir/$subdir $objdir/$subdir/$binfile] 18 verbose "ltrace runtest output: $exec_output\n" 19 20 # Check the output of this program. 21 if [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. 30 set fd [ open $srcdir/$subdir/$srcfile r] 31 while { [gets $fd line] >= 0 } { 32 if [ regexp {define NANOSLEEP_COUNT ([0-9]+)} $line match nanosleep_usec] then { 33 break 34 } 35 } 36 close $fd 37 38 39 # Verify the time for calling sleep. 40 set fd [ open $objdir/$subdir/$binfile.ltrace r] 41 set FOUND 0 42 while { [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 } 56 close $fd 57 58 if {$FOUND != 1} then { 59 fail "Fail to find call sleep!" 60 } 61 62 # Verify the time for calling nanosleep. 63 set FOUND 0 64 set fd [ open $objdir/$subdir/$binfile.ltrace r] 65 while { [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 80 if { $FOUND != 1} then { 81 fail "Fail to find nanosleep" 82 } 83 close $fd 84 85