Blob Blame History Raw
# This file was written by Yao Qi <qiyao@cn.ibm.com>.

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

verbose "compiling source file now....."
# Build the shared libraries this test case needs.
if  { [ ltrace_compile "${srcdir}/${subdir}/${testfile}.c" "${objdir}/${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 "-tt"

# Run PUT for ltrace.
set exec_output [ltrace_runtest $objdir/$subdir $objdir/$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 $objdir/$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_min start_sec sleep_sec] then {
		# Remove extra zero.
		regexp {0([1-9])} $start_min match start_min
		regexp {0([1-9])} $start_sec match start_sec

		verbose "start_sec = $start_sec, sleep_sec = $sleep_sec"
		# get a new line for the end time of sleep
		gets $fd line
		regexp {[0-9]+:([0-9]+):([0-9]+)} $line match end_min end_sec
		verbose "end_sec = $end_sec"

		# Remove extra zero.
		regexp {0([1-9])} $end_min match end_min
		regexp {0([1-9])} $end_sec match end_sec

		if { (($end_min - $start_min)*60 + $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 sleep and 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 $objdir/$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][0-9][0-9]).* nanosleep} $line match start_sec start_usec ] then {
		# Remove extra zeros.
		regexp {0([1-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_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][0-9][0-9])} $line match end_sec end_usec

		# Remove extra zeros.
		regexp {0([1-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