This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 1/7] New test case gdb.trace/signal.exp


On 04/11/2016 09:40 AM, Yao Qi wrote:



> +# Record the hit times of each tracepoint in this array.
> +array set tracepoint_hits { }
> +
> +set test "tfind 0"
> +gdb_test_multiple $test $test {

Why do we need this separate "tfind 0" step?  I'd think the
"tfind" loop below would be sufficient?

> +    -re "Found trace frame 0, tracepoint ($decimal).*\r\n$gdb_prompt $" {
> +
> +	set idx [expr $expect_out(1,string)]
> +
> +	if {[info exists tracepoint_hits($idx)]} {
> +	    incr tracepoint_hits($idx)
> +	} else {
> +	    set tracepoint_hits($idx) 1
> +	}
> +    }
> +}
> +
> +set loop 1
> +while { $loop } {
> +    set test "tfind"
> +    gdb_test_multiple $test $test {
> +	-re "Found trace frame $decimal, tracepoint ($decimal).*\r\n$gdb_prompt $" {
> +	    set idx [expr $expect_out(1,string)]
> +
> +	    if {[info exists tracepoint_hits($idx)]} {
> +		incr tracepoint_hits($idx)
> +	    } else {
> +		set tracepoint_hits($idx) 1
> +	    }
> +	}
> +	-re "Target failed to find requested trace frame\..*\r\n$gdb_prompt $" {
> +	    set loop 0
> +	}
> +    }

If this gdb_test_multiple FAILs or times out, the loop
will continue, over and over, forever.  So we need to reverse
the logic -- assume no looping, unless the "Found trace ..." regex matched.

I'd also suggest to preinitialize the array elements to 0, avoiding
the "info exists" calls in "Step 3", here:

> +# Step 3, check the number of collections on each tracepoint.
> +
> +for { set i $tpnum } { $i < [expr $tpnum + 2] } { incr i } {
> +    if {[info exists tracepoint_hits($i)]} {
> +	gdb_assert { $tracepoint_hits($i) == $iterations } \
> +	    "tracepoint $i hit $iterations times"
> +    } else {
> +	fail "can't find tracepoint $i hit"

Also, here I think it's nicer if PASS/FAIL messages are the same,
for test result diffing.

Thus, something like:

for { set i $tpnum } { $i < [expr $tpnum + 2] } { incr i } {
  set tracepoint_hits($idx) 0
}

while { 1 } {
   set test "tfind"
   set idx 0
   gdb_test_multiple $test $test {
	-re "Found trace frame $decimal, tracepoint ($decimal).*\r\n$gdb_prompt $" {
	    set idx [expr $expect_out(1,string)]
	    incr tracepoint_hits($idx)
	}
   }
   if {$idx == 0} {
	break
   }
}

# Step 3, check the number of collections on each tracepoint.
for { set i $tpnum } { $i < [expr $tpnum + 2] } { incr i } {
   gdb_assert { $tracepoint_hits($i) == $iterations } \
      "tracepoint $i hit $iterations times"
}


Otherwise looks good to me.

Thanks,
Pedro Alves


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]