| # This file was written by Yao Qi <qiyao@cn.ibm.com>. |
| |
| set testfile "time-record" |
| set srcfile ${testfile}.c |
| set binfile ${testfile}-T |
| |
| verbose "compiling source file now....." |
| # Build the shared libraries this test case needs. |
| if { [ ltrace_compile "${srcdir}/${subdir}/${testfile}.c" "${objdir}/${subdir}/${binfile}" executable {debug} ] != "" } { |
| send_user "Testcase compile failed, so all tests in this file will automatically fail.\n" |
| } |
| |
| # set options for ltrace. |
| ltrace_options "-T" |
| |
| # Run PUT for ltrace. |
| set exec_output [ltrace_runtest $objdir/$subdir $objdir/$subdir/$binfile] |
| verbose "ltrace runtest output: $exec_output\n" |
| |
| # Check the output of this program. |
| if [regexp {ELF from incompatible architecture} $exec_output] { |
| fail "32-bit ltrace can not perform on 64-bit PUTs and rebuild ltrace in 64 bit mode!" |
| return |
| } elseif [ regexp {Couldn't get .hash data} $exec_output ] { |
| fail "Couldn't get .hash data!" |
| return |
| } |
| |
| # Get the time of nanosleep in C source file. |
| set fd [ open $srcdir/$subdir/$srcfile r] |
| while { [gets $fd line] >= 0 } { |
| if [ regexp {define NANOSLEEP_COUNT ([0-9]+)} $line match nanosleep_usec] then { |
| break |
| } |
| } |
| close $fd |
| |
| |
| # Verify the time for calling sleep. |
| set fd [ open $objdir/$subdir/$binfile.ltrace r] |
| set FOUND 0 |
| while { [gets $fd line] >= 0 } { |
| # match the line with sleep and extract the spent time in sleep and sleep argument. |
| if [ regexp {sleep\(([0-9]+).*<([0-9]+\.[0-9]+)>} $line match sleep_sec sec ] then { |
| verbose "sleep_sec = $sleep_sec, sec = $sec" |
| |
| if { $sec >= $sleep_sec } then { |
| pass "Correct Time spent inside call." |
| } else { |
| fail "Spent $sec inside call, but PUT call sleep($sleep_sec)!" |
| } |
| set FOUND 1 |
| break |
| } |
| } |
| close $fd |
| |
| if {$FOUND != 1} then { |
| fail "Fail to find call sleep!" |
| } |
| |
| # Verify the time for calling nanosleep. |
| set FOUND 0 |
| set fd [ open $objdir/$subdir/$binfile.ltrace r] |
| while { [gets $fd line] >= 0 } { |
| # match the line with nanosleep and extract spent time and nanosleep argument. |
| if [ regexp {nanosleep.*<([0-9]+\.[0-9]+)>} $line match usec] then { |
| verbose "nanosleep_usec = $nanosleep_usec, usec = $usec" |
| |
| if { $usec * 1000 >= $nanosleep_usec} then { |
| pass "Correct Time spent inside call." |
| } else { |
| fail "Spent $usec inside call, but PUT call nanosleep($nanosleep_usec)!" |
| } |
| set FOUND 1 |
| break |
| } |
| } |
| |
| if { $FOUND != 1} then { |
| fail "Fail to find nanosleep" |
| } |
| close $fd |
| |