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}-ttt 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 "-ttt" 15 16 # Run PUT for ltrace. 17 set exec_output [ltrace_runtest $objdir/$subdir $objdir/$subdir/$binfile] 18 19 20 # Check the output of this program. 21 verbose "ltrace runtest output: $exec_output\n" 22 if [regexp {ELF from incompatible architecture} $exec_output] { 23 fail "32-bit ltrace can not perform on 64-bit PUTs and rebuild ltrace in 64 bit mode!" 24 return 25 } elseif [ regexp {Couldn't get .hash data} $exec_output ] { 26 fail "Couldn't get .hash data!" 27 return 28 } 29 30 # Verify the time for calling sleep. 31 set fd [ open $objdir/$subdir/$binfile.ltrace r] 32 set FOUND 0 33 while { [gets $fd line] >= 0 } { 34 # match the line with sleep and extract the strat time and sleep argument. 35 if [ regexp {([0-9]+)\.([0-9][0-9][0-9]).* sleep\(([0-9]+)} $line match start_sec start_usec sleep_sec] then { 36 37 # Remove extra zeros. 38 regexp {0*([1-9][0-9]*)} $start_sec match start_sec 39 regexp {0*([1-9][0-9]*)} $start_usec match start_usec 40 41 verbose "start_sec = $start_sec, start_usec = $start_usec,sleep_sec = $sleep_sec" 42 # get a new line for the end time of sleep 43 gets $fd line 44 regexp {([0-9]+)\.([0-9][0-9][0-9])} $line match end_sec end_usec 45 verbose "end_sec = $end_sec, end_usec=$end_usec" 46 47 # Remove extra zeros. 48 regexp {0*([1-9][0-9]*)} $end_sec match end_sec 49 regexp {0*([1-9][0-9]*)} $end_usec match end_usec 50 51 if { $end_sec - $start_sec >= $sleep_sec } then { 52 pass "Correct Timestamp." 53 } else { 54 fail "Start at $start_sec, End at $end_sec, but PUT call sleep($sleep_sec)!" 55 } 56 set FOUND 1 57 break 58 } 59 } 60 61 close $fd 62 63 if {$FOUND != 1} then { 64 fail "Fail to find call sleep!" 65 } 66 67 68 # Get the time of nanosleep in C source file. 69 set fd [ open $srcdir/$subdir/$srcfile r] 70 while { [gets $fd line] >= 0 } { 71 if [ regexp {define NANOSLEEP_COUNT ([0-9]+)} $line match nanosleep_usec] then { 72 break 73 } 74 } 75 close $fd 76 77 # Verify the time for calling nanosleep. 78 set FOUND 0 79 set fd [ open $objdir/$subdir/$binfile.ltrace r] 80 while { [gets $fd line] >= 0 } { 81 # match the line with sleep and extract the strat time and sleep argument. 82 if [ regexp {([0-9]+)\.([0-9][0-9][0-9]).* nanosleep} $line match start_sec start_usec ] then { 83 84 # Remove extra zeros. 85 regexp {0*([1-9][0-9]*)} $start_sec match start_sec 86 regexp {0*([1-9][0-9]*)} $start_usec match start_usec 87 88 verbose "start_sec = $start_sec, start_usec = $start_usec, nanosleep_usec = $nanosleep_usec" 89 # get a new line for the end time of sleep 90 gets $fd line 91 regexp {([0-9]+)\.([0-9][0-9][0-9])} $line match end_sec end_usec 92 93 # Remove extra zeros. 94 regexp {0*([1-9][0-9]*)} $end_sec match end_sec 95 regexp {0*([1-9][0-9]*)} $end_usec match end_usec 96 97 verbose "end_sec = $end_sec, end_usec = $end_usec" 98 if { ($end_sec - $start_sec)*1000 + $end_usec - $start_usec >= $nanosleep_usec} then { 99 pass "Correct Timestamp." 100 } else { 101 fail "Start at $start_usec, End at $end_usec, but PUT call nanosleep($nanosleep_usec)!" 102 } 103 set FOUND 1 104 break 105 } 106 } 107 108 if { $FOUND != 1} then { 109 fail "Fail to find nanosleep" 110 } 111 close $fd 112 113