aboutsummaryrefslogtreecommitdiff
path: root/testsuite/ltrace.minor/time-record-T.exp
blob: b411adda9f3250531b9a616ed60f62e943ed2091 (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
# This file was written by Yao Qi <qiyao@cn.ibm.com>.

set testfile "time-record"
set srcfile ${testfile}.c
set binfile ${testfile}-T

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 "-T"

# Run PUT for ltrace.
set exec_output [ltrace_runtest $srcdir/$subdir $srcdir/$subdir/$binfile]
verbose "ltrace runtest output: $exec_output\n"

# Check the output of this program.
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
}

# 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 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 spent time in sleep and sleep argument.
	if [ regexp {sleep\(([0-9]+).*<([0-9]+\.[0-9]+)>} $line match  sleep_sec sec ] then {
		verbose "sleep_sec = $sleep_sec, sec = $sec"

		if { $sec >= $sleep_sec } then {
			pass "Correct Time spent inside call."
		} else {
			fail "Spent $sec inside call, but PUT call sleep($sleep_sec)!"
		}
	set FOUND 1
	break
        }
}
close $fd

if {$FOUND != 1} then {
	fail "Fail to find call sleep!"
}

#  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 nanosleep and extract spent time and nanosleep argument.
        if [ regexp {nanosleep.*<([0-9]+\.[0-9]+)>} $line match usec] then {
                verbose "nanosleep_usec = $nanosleep_usec, usec = $usec"

                if { $usec * 1000 >= $nanosleep_usec} then {
                        pass "Correct Time spent inside call."
                } else {
                        fail "Spent $usec inside call, but PUT call nanosleep($nanosleep_usec)!"
                }
        set FOUND 1
        break
        }
}

if { $FOUND != 1} then {
	fail "Fail to find nanosleep"
}
close $fd