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}-tt
7 verbose "compiling source file now....."
8 # Build the shared libraries this test case needs.
9 if { [ ltrace_compile "${srcdir}/${subdir}/${testfile}.c" "${srcdir}/${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 $srcdir/$subdir $srcdir/$subdir/$binfile]
19 # Check the output of this program.
20 verbose "ltrace runtest output: $exec_output\n"
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!"
24 } elseif [ regexp {Couldn't get .hash data} $exec_output ] {
25 fail "Couldn't get .hash data!"
29 # Verify the time for calling sleep.
30 set fd [ open $srcdir/$subdir/$binfile.ltrace r]
32 while { [gets $fd line] >= 0 } {
33 # match the line with sleep and extract the strat time and sleep argument.
34 if [ regexp {[0-9]+:([0-9]+):([0-9]+)\.[0-9]+ sleep\(([0-9]+)} $line match start_min start_sec sleep_sec] then {
36 regexp {0([1-9])} $start_min match start_min
37 regexp {0([1-9])} $start_sec match start_sec
39 verbose "start_sec = $start_sec, sleep_sec = $sleep_sec"
40 # get a new line for the end time of sleep
42 regexp {[0-9]+:([0-9]+):([0-9]+)} $line match end_min end_sec
43 verbose "end_sec = $end_sec"
46 regexp {0([1-9])} $end_min match end_min
47 regexp {0([1-9])} $end_sec match end_sec
49 if { (($end_min - $start_min)*60 + $end_sec - $start_sec)== $sleep_sec } then {
50 pass "Correct Timestamp."
52 fail "Start at $start_sec, End at $end_sec, but PUT call sleep($sleep_sec)!"
60 if {$FOUND != 1} then {
61 fail "Fail to find call sleep!"
64 # Get the time of sleep and nanosleep in C source file.
65 set fd [ open $srcdir/$subdir/$srcfile r]
66 while { [gets $fd line] >= 0 } {
67 if [ regexp {define NANOSLEEP_COUNT ([0-9]+)} $line match nanosleep_usec] then {
73 # Verify the time for calling nanosleep.
75 set fd [ open $srcdir/$subdir/$binfile.ltrace r]
76 while { [gets $fd line] >= 0 } {
77 # match the line with sleep and extract the strat time and sleep argument.
78 if [ regexp {[0-9]+:[0-9]+:([0-9]+)\.([0-9][0-9][0-9]).* nanosleep} $line match start_sec start_usec ] then {
80 regexp {0([1-9])} $start_sec match start_sec
81 regexp {0*([1-9][0-9]*)} $start_usec match start_usec
83 verbose "start_sec = $start_sec, start_usec = $start_usec, sleep_usec = $nanosleep_usec"
84 # get a new line for the end time of sleep
86 regexp {[0-9]+:[0-9]+:([0-9]+)\.([0-9][0-9][0-9])} $line match end_sec end_usec
89 regexp {0([1-9])} $end_sec match end_sec
90 regexp {0*([1-9][0-9]*)} $end_usec match end_usec
92 verbose "end_sec = $end_sec, end_usec = $end_usec"
93 if { (($end_sec - $start_sec)*1000 + $end_usec - $start_usec) >= $nanosleep_usec} then {
94 pass "Correct Timestamp."
96 fail "Start at $start_usec, End at $end_usec, but PUT call nanosleep($nanosleep_usec)!"
103 if { $FOUND != 1} then {
104 fail "Fail to find nanosleep"