1 # This file was written by Yao Qi <qiyao@cn.ibm.com>.
3 set testfile "time-record"
4 set srcfile ${testfile}.c
5 set binfile ${testfile}-ttt
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"
13 # Set options for ltrace.
17 set exec_output [ltrace_runtest $objdir/$subdir $objdir/$subdir/$binfile]
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!"
25 } elseif [ regexp {Couldn't get .hash data} $exec_output ] {
26 fail "Couldn't get .hash data!"
30 # Verify the time for calling sleep.
31 set fd [ open $objdir/$subdir/$binfile.ltrace r]
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 {
38 regexp {0*([1-9][0-9]*)} $start_sec match start_sec
39 regexp {0*([1-9][0-9]*)} $start_usec match start_usec
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
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"
48 regexp {0*([1-9][0-9]*)} $end_sec match end_sec
49 regexp {0*([1-9][0-9]*)} $end_usec match end_usec
51 if { $end_sec - $start_sec >= $sleep_sec } then {
52 pass "Correct Timestamp."
54 fail "Start at $start_sec, End at $end_sec, but PUT call sleep($sleep_sec)!"
63 if {$FOUND != 1} then {
64 fail "Fail to find call sleep!"
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 {
77 # Verify the time for calling nanosleep.
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 {
85 regexp {0*([1-9][0-9]*)} $start_sec match start_sec
86 regexp {0*([1-9][0-9]*)} $start_usec match start_usec
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
91 regexp {([0-9]+)\.([0-9][0-9][0-9])} $line match end_sec end_usec
94 regexp {0*([1-9][0-9]*)} $end_sec match end_sec
95 regexp {0*([1-9][0-9]*)} $end_usec match end_usec
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."
101 fail "Start at $start_usec, End at $end_usec, but PUT call nanosleep($nanosleep_usec)!"
108 if { $FOUND != 1} then {
109 fail "Fail to find nanosleep"