# This file was written by Yao Qi . set testfile "time-record" set srcfile ${testfile}.c set binfile ${testfile}-ttt verbose "compiling source file now....." # Build the shared libraries this test case needs. if { [ ltrace_compile "${srcdir}/${subdir}/${testfile}.c" "${srcdir}/${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 "-ttt" # Run PUT for ltrace. set exec_output [ltrace_runtest $srcdir/$subdir $srcdir/$subdir/$binfile] # Check the output of this program. verbose "ltrace runtest output: $exec_output\n" 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 } # Verify the time for calling sleep. set fd [ open $srcdir/$subdir/$binfile.ltrace r] set FOUND 0 while { [gets $fd line] >= 0 } { # match the line with sleep and extract the strat time and sleep argument. if [ regexp {([0-9]+)\.([0-9][0-9][0-9]).* sleep\(([0-9]+)} $line match start_sec start_usec sleep_sec] then { # Remove extra zeros. regexp {0*([1-9][0-9]*)} $start_sec match start_sec regexp {0*([1-9][0-9]*)} $start_usec match start_usec verbose "start_sec = $start_sec, start_usec = $start_usec,sleep_sec = $sleep_sec" # get a new line for the end time of sleep gets $fd line regexp {([0-9]+)\.([0-9][0-9][0-9])} $line match end_sec end_usec verbose "end_sec = $end_sec, end_usec=$end_usec" # Remove extra zeros. regexp {0*([1-9][0-9]*)} $end_sec match end_sec regexp {0*([1-9][0-9]*)} $end_usec match end_usec if { $end_sec - $start_sec >= $sleep_sec } then { pass "Correct Timestamp." } else { fail "Start at $start_sec, End at $end_sec, but PUT call sleep($sleep_sec)!" } set FOUND 1 break } } close $fd if {$FOUND != 1} then { fail "Fail to find call sleep!" } # 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 nanosleep. set FOUND 0 set fd [ open $srcdir/$subdir/$binfile.ltrace r] while { [gets $fd line] >= 0 } { # match the line with sleep and extract the strat time and sleep argument. if [ regexp {([0-9]+)\.([0-9][0-9][0-9]).* nanosleep} $line match start_sec start_usec ] then { # Remove extra zeros. regexp {0*([1-9][0-9]*)} $start_sec match start_sec regexp {0*([1-9][0-9]*)} $start_usec match start_usec verbose "start_sec = $start_sec, start_usec = $start_usec, nanosleep_usec = $nanosleep_usec" # get a new line for the end time of sleep gets $fd line regexp {([0-9]+)\.([0-9][0-9][0-9])} $line match end_sec end_usec # Remove extra zeros. regexp {0*([1-9][0-9]*)} $end_sec match end_sec regexp {0*([1-9][0-9]*)} $end_usec match end_usec verbose "end_sec = $end_sec, end_usec = $end_usec" if { ($end_sec - $start_sec)*1000 + $end_usec - $start_usec >= $nanosleep_usec} then { pass "Correct Timestamp." } else { fail "Start at $start_usec, End at $end_usec, but PUT call nanosleep($nanosleep_usec)!" } set FOUND 1 break } } if { $FOUND != 1} then { fail "Fail to find nanosleep" } close $fd