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]

[RFC]: New testcase for hw watchpoint, covering watch/rwatch/awatch


Hello all,

I see that the current watchpoint testcases don't differentiate too much 
on software watchpoints and hardware ones.  And rwatch and awatch is not 
covered in any testcase.  I ever proposed to have a specific testcase for 
h/w watchpoint.  OK.  Here it is.  I am look it as a strawman.  So if you 
are interested, you will have something to shot.  :-)

The testcase will first use "rwatch" command to detect if hardware 
watchpoint is supported.  If not, it skip and quit.  Otherwise, it will
test watch (set can-use-hardware-watchpoint 1), rwatch and awatch 
respectively.

I had tested it on i386, ppc64 with kernel-2.6.15 (support hw watchpoint) 
and ppc64 with kernel-2.6.9 (don't support hw watchpoint). On the first 
two configuration, it will report 44 pass. On the third configuatrion, it 
will report one fail and quit.

Here is the code:

============== gdb.base/hw-watch.exp ========================
# Copyright 2006
# Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  

# This file was written by Wu Zhou (woodzltc@cn.ibm.com).  Some of the code
# is got from recurse.exp.

if $tracelevel then {
    strace $tracelevel
}

set prms_id 0
set bug_id 0

set testfile "recurse"
set srcfile ${testfile}.c
set binfile ${objdir}/${subdir}/${testfile}
if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
}

# Start with a fresh gdb.

gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir
gdb_load ${binfile}

proc watch_tests {} {

    if [runto recurse] then {
	
	# To test if target support hardware watchpoint
	gdb_test "set can-use-hw-watchpoints 1" "" ""
	if [gdb_test "rwatch b" ".*Hardware read watchpoint.*" "rwatch b"] then {
	    unsupported "No hardware watchpoint support from target, skip this case."
	    exit
	}

	gdb_test "delete 2" "" ""
	gdb_test "next" "if \\(a == 1\\)" "watch_tests: next over b = 0"
	
	# To verify that "set can-use-hw-watchpoints 0" will disable h/w watchpoint
	gdb_test "set can-use-hw-watchpoints 0" "" ""
	if [gdb_test "watch b" ".*Watchpoint \[0-9]*: b" \
	    "watch_tests: set write watchpoint on b, this is a software one"] then {
	    gdb_suppress_tests;
	}
	
	#  To verify that "set can-use-hw-watchpoints 1" will enable h/w watchpoint
	gdb_test "delete 3" "" ""
	if [gdb_test "set can-use-hw-watchpoints 1" "" ""] then {
	    gdb_suppress_tests;
	}
	if [gdb_test "watch b" ".*Hardware watchpoint \[0-9]*: b" \
	    "watch_tests: reset write watchpoint on b, this is a hardware one"] then {
	    gdb_suppress_tests;
	}

	gdb_test "info watchpoints" "1\[ \]*breakpoint.*recurse.*\r\n4\[ \]*hw watchpoint.*b.*" \
	    "watch_tests: info watchpoints"

	# Continue until the first set of b
	if [gdb_test "continue" \
	    "Continuing.*Hardware watchpoint.*: b.*Old value = 0.*New value = 10.*" \
	    "watch_tests: continue to the h/w write watchpoint, first time"] then {
	    gdb_suppress_tests;
	}
	
	# Continue inward for a few iterations
	gdb_test "continue" "Breakpoint.* recurse \\(a=9\\).*" \
	    "watch_tests: continue to recurse (a = 9)"
	gdb_test "continue" "Breakpoint.* recurse \\(a=8\\).*" \
	    "watch_tests: continue to recurse (a = 8)"
	gdb_test "continue" "Breakpoint.* recurse \\(a=7\\).*" \
	    "watch_tests: continue to recurse (a = 7)"
	gdb_test "continue" "Breakpoint.* recurse \\(a=6\\).*" \
	    "watch_tests: continue to recurse (a = 6)"
	gdb_test "continue" "Breakpoint.* recurse \\(a=5\\).*" \
	    "watch_tests: continue to recurse (a = 5)"
	gdb_test "continue" "Breakpoint.* recurse \\(a=4\\).*" \
	    "watch_tests: continue to recurse (a = 4)"
	gdb_test "continue" "Breakpoint.* recurse \\(a=3\\).*" \
	    "watch_tests: continue to recurse (a = 3)"
	gdb_test "continue" "Breakpoint.* recurse \\(a=2\\).*" \
	    "watch_tests: continue to recurse (a = 2)"
	gdb_test "continue" "Breakpoint.* recurse \\(a=1\\).*" \
	    "watch_tests: continue to recurse (a = 1)"

	if [gdb_test "continue" \
	    "Continuing.*\[Ww\]atchpoint.*b.*Old value = 10.*New value = 3628800.*return.*" \
	    "watch_tests: continue to the h/w write watchpoint, second time"] then {
	    gdb_suppress_tests
	}

	# watchpoint is automatically deleted when the process is out of its scope
	if [gdb_test "continue" \
	    "Continuing.*\[Ww\]atchpoint.*deleted.*\(main \\(\\) \|21.*\}\).*" \
	    "watch_tests: hardware write watchpoint deleted when leaving scope"] then {
	    gdb_suppress_tests;
	}
    }
    gdb_stop_suppressing_tests;
}

proc rwatch_tests {} {

    if [runto recurse] then {
	
	if [gdb_test "rwatch b" ".*Hardware read watchpoint \[0-9]*: b" \
	    "rwatch_tests: set read watchpoint, this is a hardware one"] then {
	    gdb_suppress_tests;
	}

	# Continue inward for a few iterations
	gdb_test "continue" "Breakpoint.* recurse \\(a=9\\).*" \
	    "rwatch_tests: continue to recurse (a = 9)"
	gdb_test "continue" "Breakpoint.* recurse \\(a=8\\).*" \
	    "rwatch_tests: continue to recurse (a = 8)"
	gdb_test "continue" "Breakpoint.* recurse \\(a=7\\).*" \
	    "rwatch_tests: continue to recurse (a = 7)"
	gdb_test "continue" "Breakpoint.* recurse \\(a=6\\).*" \
	    "rwatch_tests: continue to recurse (a = 6)"
	gdb_test "continue" "Breakpoint.* recurse \\(a=5\\).*" \
	    "rwatch_tests: continue to recurse (a = 5)"
	gdb_test "continue" "Breakpoint.* recurse \\(a=4\\).*" \
	    "rwatch_tests: continue to recurse (a = 4)"
	gdb_test "continue" "Breakpoint.* recurse \\(a=3\\).*" \
	    "rwatch_tests: continue to recurse (a = 3)"
	gdb_test "continue" "Breakpoint.* recurse \\(a=2\\).*" \
	    "rwatch_tests: continue to recurse (a = 2)"
	gdb_test "continue" "Breakpoint.* recurse \\(a=1\\).*" \
	    "rwatch_tests: continue to recurse (a = 1)"

	gdb_test "continue" \
	    "Continuing.*Hardware read watchpoint.*b.*Value = 10.*recurse \\(a=10\\).*" \
	    "rwatch_tests: the hardware read watchpoint hit, first time"
	if [gdb_test "continue" \
	    "Continuing.*Hardware read watchpoint.*b.*Value = 3628800.*return.*" \
	    "rwatch_tests: the hardware read watchpoint hit, second time"] then {
	    gdb_suppress_tests
	}

	# watchpoint is automatically deleted when the process is out of its scope
	# if [gdb_test "continue" \
	#    "Continuing.*\[Ww\]atchpoint.*deleted because the program has left the block.*" \
	#    "Hardware read watchpoint deleted when leaving scope"] then {
	#    gdb_suppress_tests;
	# }
    }
    gdb_stop_suppressing_tests;
}

proc awatch_tests {} {

    if [runto recurse] then {
	
	gdb_test "next" "if \\(a == 1\\)" "awatch: next over b = 0"
	
	if [gdb_test "awatch b" "Hardware access.*watchpoint .*: b" \
	    "awatch_tests: set access watchpoint on b, this is a hardware one"] then {
	    gdb_suppress_tests;
	}

	# Continue until the first set of b.
	if [gdb_test "continue" \
	    "Continuing.*\[Ww\]atchpoint.*: b.*Old value = 0.*New value = 10.*" \
	    "awatch_tests: the h/w access watchpoint is hit by write operation, first time"] then {
	    gdb_suppress_tests;
	}
	
	# Continue inward for a few iterations
	gdb_test "continue" "Breakpoint.* recurse \\(a=9\\).*" \
	    "awatch_tests: continue to recurse (a = 9)"
	gdb_test "continue" "Breakpoint.* recurse \\(a=8\\).*" \
	    "awatch_tests: continue to recurse (a = 8)"
	gdb_test "continue" "Breakpoint.* recurse \\(a=7\\).*" \
	    "awatch_tests: continue to recurse (a = 7)"
	gdb_test "continue" "Breakpoint.* recurse \\(a=6\\).*" \
	    "awatch_tests: continue to recurse (a = 6)"
	gdb_test "continue" "Breakpoint.* recurse \\(a=5\\).*" \
	    "awatch_tests: continue to recurse (a = 5)"
	gdb_test "continue" "Breakpoint.* recurse \\(a=4\\).*" \
	    "awatch_tests: continue to recurse (a = 4)"
	gdb_test "continue" "Breakpoint.* recurse \\(a=3\\).*" \
	    "awatch_tests: continue to recurse (a = 3)"
	gdb_test "continue" "Breakpoint.* recurse \\(a=2\\).*" \
	    "awatch_tests: continue to recurse (a = 2)"
	gdb_test "continue" "Breakpoint.* recurse \\(a=1\\).*" \
	    "awatch_tests: continue to recurse (a = 1)"

	if [gdb_test "continue" \
	    "Continuing.*Hardware access.*watchpoint.*b.*Value = 10.*recurse \\(a=10\\).*" \
	    "awatch_tests: the access watchpoint is hit by read operation, first time"] then {
	    gdb_suppress_tests
	}

	if [gdb_test "continue" \
	    "Continuing.*\[Ww\]atchpoint.*b.*Old value = 10.*New value = 3628800.*return.*" \
	    "awatch_tests: the access watchpoint is hit by write operation, second time"] then {
	    gdb_suppress_tests
	}

	if [gdb_test "continue" \
	    "Continuing.*Hardware access.*watchpoint.*b.*Value = 3628800.*return.*" \
	    "awatch_tests: the access watchpoint is hit by read operation, second time"] then {
	    gdb_suppress_tests
	}
	# watchpoint is automatically deleted when the process is out of its scope
	# if [gdb_test "continue" \
	#    "Continuing.*\[Ww\]atchpoint.*deleted because the program has left the block.*" \
	#    "Hardware access watchpoint deleted when leaving scope"] then {
	#    gdb_suppress_tests;
	# }
    }
    gdb_stop_suppressing_tests;
}

# Preserve the old timeout, and set a new one that should be
# sufficient to avoid timing out during this test.
set oldtimeout $timeout
set timeout [expr "$timeout + 60"]
verbose "Timeout is now $timeout seconds" 2

watch_tests
rwatch_tests
awatch_tests

# Restore the preserved old timeout value.
set timeout $oldtimeout
verbose "Timeout is now $timeout seconds" 2


Any comments?  Thanks a lot!

Regards
- Wu Zhou


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