Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFC] script to make testing easy
@ 2005-02-09 22:40 Manoj Iyer
  0 siblings, 0 replies; only message in thread
From: Manoj Iyer @ 2005-02-09 22:40 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: TEXT/PLAIN, Size: 704 bytes --]


Hi all.

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.




-----
manjo
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ Cognito ergo sum                                                          +
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

[-- Attachment #2: Test Case Generation and Executuion Script. --]
[-- Type: TEXT/PLAIN, Size: 11192 bytes --]

#!/bin/sh
#******************************************************************************#
#                                                                              #
# File: rungdbtest                                                             #
#                                                                              #
# Description: executes GDB testcases                                          #
#                                                                              #
# Author: Manoj Iyer - 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 
}


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 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 gdb+dejagnu" 

    (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.";
        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 ./install-sh ./gdb.stabs/. ; cp ./config.sub ./gdb.stabs/. "
   (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;
    }

    mv ./Makefile.in.sav ./Makefile.in || \
    {
        echo "ERROR: HACKS to scripts & makefiles failed" ;
        return -1;
    }

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

    mv ./Makefile.in.sav ./Makefile.in || \
    {
        echo "ERROR: HACKS to scripts & makefiles failed" ;
        return -1;
    }
     
    sed '/^for ac_dir in/s/; do/ .; do/'  ./gdb.stabs/configure > \
    ./gdb.stabs/configure.out || \
    {
        echo "ERROR: HACKS to scripts & makefiles failed" ;
        return -1;
    }

    mv ./gdb.stabs/configure.out ./gdb.stabs/configure || \
    {
        echo "ERROR: HACKS to scripts & makefiles failed" ;
        return -1;
    }

    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 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 $?

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2005-02-09 20:40 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-02-09 22:40 [RFC] script to make testing easy Manoj Iyer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox