OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.0/] [gdb/] [testsuite/] [gdb.threads/] [linux-dp.exp] - Diff between revs 107 and 1765

Only display areas with differences | Details | Blame | View Log

Rev 107 Rev 1765
# Copyright (C) 1999 Free Software Foundation, Inc.
# Copyright (C) 1999 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# 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
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# (at your option) any later version.
#
#
# This program is distributed in the hope that it will be useful,
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# GNU General Public License for more details.
#
#
# You should have received a copy of the GNU General Public License
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# Please email any bugs, comments, and/or additions to this file to:
# Please email any bugs, comments, and/or additions to this file to:
# bug-gdb@gnu.org
# bug-gdb@gnu.org
#### Dining Philosophers, on LinuxThreads - Jim Blandy 
#### Dining Philosophers, on LinuxThreads - Jim Blandy 
####
####
#### At the moment, GDB's support for LinuxThreads is pretty
#### At the moment, GDB's support for LinuxThreads is pretty
#### idiosyncratic --- GDB's output doesn't look much like the output
#### idiosyncratic --- GDB's output doesn't look much like the output
#### it produces for other thread implementations, messages appear at
#### it produces for other thread implementations, messages appear at
#### different times, etc.  So these tests are specific to LinuxThreads.
#### different times, etc.  So these tests are specific to LinuxThreads.
####
####
#### However, if all goes well, Linux will soon have a libthread_db
#### However, if all goes well, Linux will soon have a libthread_db
#### interface, and GDB will manage it the same way it does other
#### interface, and GDB will manage it the same way it does other
#### libthread_db-based systems.  Then, we can adjust this file to
#### libthread_db-based systems.  Then, we can adjust this file to
#### work with any such system.
#### work with any such system.
### Other things we ought to test:
### Other things we ought to test:
### stepping a thread while others are running
### stepping a thread while others are running
### killing and restarting
### killing and restarting
### quitting gracefully
### quitting gracefully
if $tracelevel then {
if $tracelevel then {
        strace $tracelevel
        strace $tracelevel
}
}
set prms_id 0
set prms_id 0
set bug_id 0
set bug_id 0
# This only works with Linux configurations.
# This only works with Linux configurations.
if ![istarget *-*-linux-gnu] then {
if ![istarget *-*-linux-gnu] then {
    return
    return
}
}
set testfile "linux-dp"
set testfile "linux-dp"
set srcfile ${testfile}.c
set srcfile ${testfile}.c
set binfile ${objdir}/${subdir}/${testfile}
set binfile ${objdir}/${subdir}/${testfile}
if {[gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug libs=-lpthread}] != ""} {
if {[gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug libs=-lpthread}] != ""} {
    gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
    gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
}
}
gdb_start
gdb_start
gdb_reinitialize_dir $srcdir/$subdir
gdb_reinitialize_dir $srcdir/$subdir
gdb_load ${binfile}
gdb_load ${binfile}
send_gdb "set print sevenbit-strings\n" ; gdb_expect -re "$gdb_prompt $"
send_gdb "set print sevenbit-strings\n" ; gdb_expect -re "$gdb_prompt $"
runto_main
runto_main
# There should be no threads initially.
# There should be no threads initially.
gdb_test "info threads" "" "info threads 1"
gdb_test "info threads" "" "info threads 1"
# Try stepping over the thread creation function.
# Try stepping over the thread creation function.
gdb_breakpoint [gdb_get_line_number "linuxthreads.exp: create philosopher"]
gdb_breakpoint [gdb_get_line_number "linuxthreads.exp: create philosopher"]
for {set i 0} {$i < 5} {incr i} {
for {set i 0} {$i < 5} {incr i} {
    gdb_continue_to_breakpoint "about to create philosopher: $i"
    gdb_continue_to_breakpoint "about to create philosopher: $i"
    send_gdb "next\n"
    send_gdb "next\n"
    gdb_expect {
    gdb_expect {
        -re "\\\[New .*\\\].*$gdb_prompt $" {
        -re "\\\[New .*\\\].*$gdb_prompt $" {
            pass "create philosopher: $i"
            pass "create philosopher: $i"
        }
        }
        -re "Program received signal.*(Unknown signal|SIGUSR).*$gdb_prompt $" {
        -re "Program received signal.*(Unknown signal|SIGUSR).*$gdb_prompt $" {
            # It would be nice if we could catch the message that GDB prints
            # It would be nice if we could catch the message that GDB prints
            # when it first notices that the thread library doesn't support
            # when it first notices that the thread library doesn't support
            # debugging, or if we could explicitly ask GDB somehow.
            # debugging, or if we could explicitly ask GDB somehow.
            unsupported "This GDB does not support threads on this system."
            unsupported "This GDB does not support threads on this system."
            return -1
            return -1
        }
        }
        -re "$gdb_prompt $" {
        -re "$gdb_prompt $" {
            fail "create philosopher: $i"
            fail "create philosopher: $i"
        }
        }
        timeout {
        timeout {
            fail "(timeout) create philosopher: $i"
            fail "(timeout) create philosopher: $i"
        }
        }
    }
    }
}
}
# Run until there are some threads.
# Run until there are some threads.
gdb_breakpoint [gdb_get_line_number "linuxthreads.exp: info threads 2"]
gdb_breakpoint [gdb_get_line_number "linuxthreads.exp: info threads 2"]
gdb_continue_to_breakpoint "main thread's sleep"
gdb_continue_to_breakpoint "main thread's sleep"
gdb_test "info threads" "7 Thread .*6 Thread .*5 Thread .*4 Thread .*3 Thread .*2 Thread .*1 Thread .*" "info threads 2"
gdb_test "info threads" "7 Thread .*6 Thread .*5 Thread .*4 Thread .*3 Thread .*2 Thread .*1 Thread .*" "info threads 2"
# Try setting a thread-specific breakpoint.
# Try setting a thread-specific breakpoint.
gdb_breakpoint "print_philosopher thread 5"
gdb_breakpoint "print_philosopher thread 5"
gdb_continue_to_breakpoint "thread 5's print"
gdb_continue_to_breakpoint "thread 5's print"
gdb_test "where" "print_philosopher.*philosopher.*pthread_start_thread.*" \
gdb_test "where" "print_philosopher.*philosopher.*pthread_start_thread.*" \
        "first thread-specific breakpoint hit"
        "first thread-specific breakpoint hit"
# Make sure it's catching the right thread.  Try hitting the
# Make sure it's catching the right thread.  Try hitting the
# breakpoint ten times, and make sure we don't get anyone else.
# breakpoint ten times, and make sure we don't get anyone else.
set only_five 1
set only_five 1
for {set i 0} {$only_five > 0 && $i < 10} {incr i} {
for {set i 0} {$only_five > 0 && $i < 10} {incr i} {
    gdb_continue_to_breakpoint "thread 5's print, pass: $i"
    gdb_continue_to_breakpoint "thread 5's print, pass: $i"
    send_gdb "info threads\n"
    send_gdb "info threads\n"
    gdb_expect {
    gdb_expect {
        -re "\\* 5 Thread .*  print_philosopher .*\r\n$gdb_prompt $" {
        -re "\\* 5 Thread .*  print_philosopher .*\r\n$gdb_prompt $" {
            # Okay this time.
            # Okay this time.
        }
        }
        -re ".*$gdb_prompt $" {
        -re ".*$gdb_prompt $" {
            set only_five 0
            set only_five 0
        }
        }
        timeout {
        timeout {
            set only_five -1
            set only_five -1
        }
        }
    }
    }
}
}
set name "thread-specific breakpoint is thread-specific"
set name "thread-specific breakpoint is thread-specific"
if {$only_five ==  1} { pass $name }
if {$only_five ==  1} { pass $name }
if {$only_five ==  0} { fail $name }
if {$only_five ==  0} { fail $name }
if {$only_five == -1} { fail "$name (timeout)" }
if {$only_five == -1} { fail "$name (timeout)" }
### Select a particular thread.
### Select a particular thread.
proc select_thread {thread} {
proc select_thread {thread} {
    global gdb_prompt
    global gdb_prompt
    send_gdb "thread $thread\n"
    send_gdb "thread $thread\n"
    gdb_expect {
    gdb_expect {
        -re "\\\[Switching to thread .*\\\].*\r\n$gdb_prompt $" {
        -re "\\\[Switching to thread .*\\\].*\r\n$gdb_prompt $" {
            pass "selected thread: $thread"
            pass "selected thread: $thread"
        }
        }
        -re "$gdb_prompt $" {
        -re "$gdb_prompt $" {
            fail "selected thread: $thread"
            fail "selected thread: $thread"
        }
        }
        timeout {
        timeout {
            fail "selected thread: $thread (timeout)"
            fail "selected thread: $thread (timeout)"
        }
        }
    }
    }
}
}
### Select THREAD, check for a plausible backtrace, and make sure
### Select THREAD, check for a plausible backtrace, and make sure
### we're actually selecting a different philosopher each time.
### we're actually selecting a different philosopher each time.
### Return true if the thread had a stack which was not only
### Return true if the thread had a stack which was not only
### acceptable, but interesting.  SEEN should be an array in which
### acceptable, but interesting.  SEEN should be an array in which
### SEEN(N) exists iff we have found philosopher number N before.
### SEEN(N) exists iff we have found philosopher number N before.
proc check_philosopher_stack {thread seen_name} {
proc check_philosopher_stack {thread seen_name} {
    global gdb_prompt
    global gdb_prompt
    upvar $seen_name seen
    upvar $seen_name seen
    set name "philosopher is distinct: $thread"
    set name "philosopher is distinct: $thread"
    set interesting 0
    set interesting 0
    select_thread $thread
    select_thread $thread
    send_gdb "where\n"
    send_gdb "where\n"
    gdb_expect {
    gdb_expect {
        -re ".* in philosopher \\(data=(0x\[0-9a-f\]+).*\r\n$gdb_prompt $" {
        -re ".* in philosopher \\(data=(0x\[0-9a-f\]+).*\r\n$gdb_prompt $" {
            set data $expect_out(1,string)
            set data $expect_out(1,string)
            if {[info exists seen($data)]} {
            if {[info exists seen($data)]} {
                fail $name
                fail $name
            } else {
            } else {
                pass $name
                pass $name
                set seen($data) yep
                set seen($data) yep
            }
            }
            set interesting 1
            set interesting 1
        }
        }
        -re "pthread_start_thread.*\r\n$gdb_prompt $" {
        -re "pthread_start_thread.*\r\n$gdb_prompt $" {
            ## Maybe the thread hasn't started yet.
            ## Maybe the thread hasn't started yet.
            pass $name
            pass $name
        }
        }
        -re " in \\?\\?.*\r\n$gdb_prompt $" {
        -re " in \\?\\?.*\r\n$gdb_prompt $" {
            ## Sometimes we can't get a backtrace.  I'm going to call
            ## Sometimes we can't get a backtrace.  I'm going to call
            ## this a pass, since we do verify that at least one
            ## this a pass, since we do verify that at least one
            ## thread was interesting, so we can get more consistent
            ## thread was interesting, so we can get more consistent
            ## test suite totals.  But in my heart, I think it should
            ## test suite totals.  But in my heart, I think it should
            ## be an xfail.
            ## be an xfail.
            pass $name
            pass $name
        }
        }
        -re "$gdb_prompt $" {
        -re "$gdb_prompt $" {
            fail $name
            fail $name
        }
        }
        timeout {
        timeout {
            fail "$name (timeout)"
            fail "$name (timeout)"
        }
        }
    }
    }
    return $interesting
    return $interesting
}
}
set any_interesting 0
set any_interesting 0
array set seen {}
array set seen {}
for {set i 3} {$i <= 7} {incr i} {
for {set i 3} {$i <= 7} {incr i} {
    if [check_philosopher_stack $i seen] {
    if [check_philosopher_stack $i seen] {
        set any_interesting 1
        set any_interesting 1
    }
    }
}
}
if {$any_interesting} {
if {$any_interesting} {
    pass "found an interesting thread"
    pass "found an interesting thread"
} else {
} else {
    fail "found an interesting thread"
    fail "found an interesting thread"
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.