[RFC] GDB testsuite script to simplify execution of testcases.

Manoj Iyer manjo@austin.ibm.com
Wed Nov 10 20:00:00 GMT 2004


I wrote this script (attached) that will make executing GDB testcases
easy. The script has options to do the following.

- generate a stand alone testsuite with sources from mainline CVS
- execute testcases in 32/64 bit mode.
- execute a perticular testcase or all testcase
- use a user defined gdb or default gdb installed on the system

Type the command with no options or -h to see all options. These options
may be provided in combinations.

This was useful for me to test a GDB that I built or test a gdb that came
with a distro. It generates a stand alone testsuite based on the mainline
sources. I just thought there may be others out there who would want the
same, the script need not necessarly be part of the GDB sources but
might be useful for someone wanting to run the testcases without going
into details of howto.

If the maintainers feel that it is nice to have it checked into cvs I will
be happy to do so. Script was tested on PowerPC (RedHat & SLES) and on X86
(Debian sarge).

Thanks
-----
manjo
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ Cognito ergo sum                                                          +
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-------------- next part --------------
#!/bin/sh
################################################################################
##                                                                            ##
## Copyright (c) International Business Machines  Corp., 2001                 ##
##                                                                            ##
## 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    ##
##                                                                            ##
################################################################################
#******************************************************************************#
#                                                                              #
# File: rungdbtest                                                             #
#                                                                              #
# Description: GDB testsuite driver                                            #
#              This script can be used to generate a stand alone testsuite,    #
#              execute a perticular test or all the testcases using the system #
#              GDB, ie GDB installed in the OS or user defined GDB in 32bit or #
#              64 bit mode.                                                    #
#                                                                              #
# Author: Manoj Iyer manjo@austin.ibm.com - 29 July 2004 - Created.            #
#         Manoj Iyer - 17 August 2004 - use config.guess to guess the arch     #
#         Manoj Iyer - 03 November 2004 - Create stand alone testsuite         #
#                                                                              #
#******************************************************************************#


function usage()
{

   cat <<-EOF >&2
    usage: ./${0##*/} -d -h [ -m 32/64 * ] [ -p GDB ] -r [ -t TESTCASE ]
    -d          - generate GDB testsuite.
    -h          - help
    -m 32/64 *  - execute the testcases in 32bit or 64bit mode (use one option)
    -p GDB      - fully_qualified_path/gdb eg: /home/joe/src/gdb/gdb
    -r          - dont run ./configure, use it if u repeat any test.
    -t TESTCASE - execute a single testcase. (XXX.exp file). (default all tests)

    Example: 
            Download tests from cvs and execute test, using user's gdb 
            ./${0##*/} -d -m 64 -p /home/joe/src/gdb/gdb

            Create stand alone testsuite. Dont run any tests.
            ./${0##*/} -d

            Run all testcases in 64bit mode, using joes custom gdb.
            ./${0##*/} -m 64 -p /home/joe/src/gdb/gdb 

            Run test annota1.exp in 64bit mode, using joes custom gdb.
            ./${0##*/} -m 64 -p /home/joe/src/gdb/gdb -t annota1.exp

   * = indicates this option -m 32 or -m 64 MUST be provide.
	EOF
    exit 1;
}


function cleanup()
{
    rm -f /tmp/gdbtest.log.$$ >/dev/null 2>&1 ;
    rm -fr /tmp/test.$$ > /dev/null 2>&1
}


function get_source()
{
    local CMD=" "    # variable holds the cvs command.
    
    # create a temporary directory where GDB sources will be extraced.
    mkdir /tmp/tmp.$$ ||
    {
        echo "ERROR: unable to create tmp.$$ in /tmp";
        return -1;
    }   

    echo "INFO: pulling gdb testsuite, dejagnu,  install-sh, config.sub, and config.guess source from CVS"
    echo "INFO: This will be as slow as your network"

    CMD="cd /tmp/tmp.$$ && \
         cvs -Q -d :pserver:anoncvs@sources.redhat.com:/cvs/src co src/gdb/testsuite  src/dejagnu src/install-sh src/config.guess src/config.sub"

    (eval $CMD; echo $?) 2>&1 | tee -a /tmp/rungdbtest.$$.log

    [ "`tail -1 /tmp/rungdbtest.$$.log`" != "0" ] &&
    {
        echo "ERROR: Checkout of gdb sources from CVS failed.";
        echo "INFO: if you get 'Connection reset by peer' message wait few minutes and try again" ;
        return -1;
    }

    echo "INFO: creating stand alone testsuite"

    # copy testsuite to current directory.
    CMD="mv  /tmp/tmp.$$/src/gdb/testsuite/* ."
    (eval $CMD; echo $?) 2>&1 | tee -a /tmp/rungdbtest.$$.log

    [ "`tail -1 /tmp/rungdbtest.$$.log`" != "0" ] &&
    {
        echo "ERROR: failed setting up test sources";
        return -1;
    }

    # copy dejagnu to current directory.
    CMD="mv /tmp/tmp.$$/src/dejagnu ."
    (eval $CMD; echo $?) 2>&1 | tee -a /tmp/rungdbtest.$$.log

    [ "`tail -1 /tmp/rungdbtest.$$.log`" != "0" ] &&
    {
        echo "ERROR: failed setting up test sources";
        return -1;
    }

    # copy config.guess to current directory
    CMD="mv /tmp/tmp.$$/src/config.guess ."
    (eval $CMD; echo $?) 2>&1 | tee -a /tmp/rungdbtest.$$.log

    [ "`tail -1 /tmp/rungdbtest.$$.log`" != "0" ] &&
    {
        echo "ERROR: failed setting up test sources";
        return -1;
    }

    # HACKS!!! copy some files to current directory and testcase directories.

    echo "INFO: Applying hacks to scripts and Makefiles"

    CMD="mv /tmp/tmp.$$/src/install-sh ."
    (eval $CMD; echo $?) 2>&1 | tee -a /tmp/rungdbtest.$$.log

    [ "`tail -1 /tmp/rungdbtest.$$.log`" != "0" ] &&
    {
        echo "ERROR: failed setting up hacks to sources";
        return -1;
    }

    CMD="touch ./config.cache"
   (eval $CMD; echo $?) 2>&1 | tee -a /tmp/rungdbtest.$$.log

    [ "`tail -1 /tmp/rungdbtest.$$.log`" != "0" ] &&
    {
        echo "ERROR: failed setting up hacks to sources";
        return -1;
    }

   CMD="mv /tmp/tmp.$$/src/config.sub ."
   (eval $CMD; echo $?) 2>&1 | tee -a /tmp/rungdbtest.$$.log

    [ "`tail -1 /tmp/rungdbtest.$$.log`" != "0" ] &&
    {
        echo "ERROR: failed setting up hacks to sources";
        return -1;
    }

    CMD="cp ./dejagnu/runtest . ; cp ./dejagnu/runtest.exp ."
   (eval $CMD; echo $?) 2>&1 | tee -a /tmp/rungdbtest.$$.log

    [ "`tail -1 /tmp/rungdbtest.$$.log`" != "0" ] &&
    {
        echo "ERROR: failed setting up hacks to sources";
        return -1;
    }

    # HACKS!! to scripts and makefiles.
    sed '/^RUNTEST_FOR_TARGET/s//#RUNTEST_FOR_TARGET/' ./Makefile.in > \
    ./Makefile.in.sav || \
    {
        echo "ERROR: HACKS to scripts & makefiles failed" ;
    return -1;
    }

    sed '/#RUNTEST_FOR_TARGET/i RUNTEST_FOR_TARGET = .\/runtest' \
    ./Makefile.in.sav  > ./Makefile.in || \
    {
        echo "ERROR: HACKS to scripts & makefiles failed" ;
        return -1;
    }

    for config in $(find . -mindepth 2 -name configure)
    do
        sed '/^for ac_dir in/s/; do/ ..; do/'  config > \
        $config.sav || \
        {
            echo "ERROR: HACKS to scripts & makefiles failed" ;
            return -1;
        }

        mv $config.sav $config || \
        {
            echo "ERROR: HACKS to scripts & makefiles failed" ;
            return -1;
        }
    done

    echo "INFO: Done generating stand alone testsuite"
    return 0;

}
    

function main()
{
    REPEAT="NO"      # option to turn off running configure.
    MODE=" "         # Execute the testcase in 32bit mode or 64bit mode
    TARGET=" "       # Contains the string that is passed to make check
    GDB_CMD="NONE"   # Fully qualified path to custom GDB.
    TEST_CASE=" "    # Temporary place holder to testcase name.
    cmd=" "          # Command that needs to be executed to run testcases
    
    [ $# -lt 1 ] && { usage ; return $?; }

    # Parse options
    while getopts dhm:p:rt: arg
    do case $arg in
        d) get_source ; [ $# -lt 2 ] && return -1 ;;
        h) usage ;;

        m) case "$OPTARG" in
               32) TARGET="RUNTESTFLAGS=--target_board=unix/-m32"
                   MODE="32";;
               64) TARGET="RUNTESTFLAGS=--target_board=unix/-m64";
                   MODE="64";;
               *)  echo "WARN: Unrecognized mode, assuming 32 bit";
                   TARGET="RUNTESTFLAGS=--target_board=unix/-m32";
                   MODE="32";;
           esac;;

        p) [ -z "$OPTARG" ] && { usage ; } 

       # if the gdb provided by the user is not an executable complain
           [ ! -x "$OPTARG" ] && \
           {
               echo "ERROR: $OPTARG is not a valid executable";
               return -1;
           }

       # if 64-bit mode is chosen and 32-bit gdb is used complain
           [ "$MODE" == "64" ] && \
           { 

               [ "$(file -b "$OPTARG" | cut -f 2 -d " ")" == "64-bit" ] || \
               {
                   echo "ERROR: $OPTARG is not a 64 bit GDB" ;
                   return -1;
               }
           }
       
           GDB_CMD="$TARGET --tool_exec=$OPTARG";
       TARGET="$GDB_CMD";;

        r) REPEAT="YES";;

        t) [ -z "$OPTARG" ] && { usage ; }
           TEST_CASE="$TARGET $OPTARG";
           TARGET="$TEST_CASE" ;;
        \?) usage ;;
       esac
    done

  
    # If no source is found exit.
    [ -f ./configure ] || \
    {
        echo "FATAL: generate the testsuite first, use -d option";
        echo " ";
        usage;
        return -1;
    }

    # If expect is not installed complain.
    which expect >/dev/null 2>&1 || \
    {
        echo "FATAL: expect is required to run testcases, please install expect"
    return -1;
    }

    # If no gdb command is specified pick a gdb based on MODE 
    [ "$GDB_CMD" == "NONE" ] && \
    {
        echo "WARN: no custom gdb requested, using system gdb" ;
        [ "$MODE" == "32" ] && \
        { 
            [ -z "$(which gdb)" ] && { echo "ERROR: no gdb installed"; return -1; }
            GDB_CMD="$TARGET --tool_exec=$(which gdb)"; 
        echo "INFO: using $GDB_CMD";
        }

        [ "$MODE" == "64" ] && \
        { 
            GDB_CMD="$TARGET --tool_exec=$(which gdb64)"; 
            [ -z "$(which gdb64)" ] && \
            { 
                # 64-bit GDB could be installed under the name gdb 
                [ "$(file -b $(which gdb) | cut -f 2 -d " ")" == "64-bit" ] || \
                {
                    echo "ERROR: No 64-bit gdb found on the system";
                    return -1;
                }

                GDB_CMD="$TARGET --tool_exec=$(which gdb)"; 
            echo "INFO: using $GDB_CMD";
            }

        }

    TARGET="$GDB_CMD";
    }

    # If this script is executed outside of this testsuite dir complain
    [ -f ./configure ] || \
    {
        echo "ERROR: This script must be located under the testsuite dir" ;
        return -1;
    }

    # if the user is executing one testcase at a time, allow him to skip
    # repeating the configure step 
    [ "$REPEAT" == "YES" ] ||  \
    {
        echo "INFO: Executing make distclean";
        make distclean;

        echo "INFO: Removing any config.cache files"; 
        for config in $(find . -name config.cache)
        do
            rm -f $config 
        done 

        echo "INFO: executing ./configure on testcases."
        ./configure --host=$(./config.guess) --disable-tui --disable-tcl \
             > /tmp/gdbtest.log.$$ 2>&1 || \
        {
            echo "ERROR: Configuring testcase $(cat /tmp/gdbtest.log.$$)";
            return -1;
        }
    }

    cmd="make check '$TARGET'";

    echo "INFO: Using command $cmd"

    echo "INFO: Executing testcase command $cmd"
   (eval $cmd; echo $?) 2>&1 | tee -a /tmp/gdbtest.log.$$ 
   [ "`tail -1 /tmp/gdbtest.log.$$`" != "0" ] && \
   {
       echo "ERROR: certain errors encounterd executing testcases.";
       mv /tmp/gdbtest.log.$$ ./rungdbtest.err.log >/dev/null 2>&1 || \
       {
           echo "ERROR: creating ./rungdbtest.err.log";
       }
       echo "INFO: details in ./rungdbtest.err.log and gdb.log";
       return -1;
   }

   return 0
}


# cleanup temporaty files created in /tmp
trap "cleanup" 0

# entry point so to speak
main "$@"

# exit with return code.
exit $?


More information about the Gdb-patches mailing list