blob: 2aee9d3c90b130fbf64d05e1978c32ac5f23ac6e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# This file was written by Yao Qi <qiyao@cn.ibm.com>.
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
|