#!/bin/sh #bdemo mutant execution shell file #set -x # bdemo is a menu driven shell file to run the different tools of the # MOTHRA. The experiment name defines the names of all the files # used by MOTHRA. # # Written by: Jeff Offutt # # Translated from the ksh version kdemo. # # Date : 4/27/86. # ################################################################ # Variables: # # ExpName -- Base source file name and global experiment name. # MutTypes -- Mutant types. # MoreMuts -- Whether we've received more mutants or not. # MoreTCs -- Whether we've received more test cases or not. # MMask -- Result of mutmake. # NumTstCases -- Current number of test cases. # CurCase -- Current test case number to add. # Alive -- Number of mutants still alive. # Total -- Total number of mutants generated for this program. # NextMut -- The next mutant to generate. # Step -- Percentage of mutants executed. # Percent -- Percentage of mutants created. # ################################################################ # Tools: # # PARSER -- MOTHRA's parser. # ROSETTA -- MOTHRA's interpreter. # MAPPER -- MOTHRA's test case editor. # MUTMAKE -- MOTHRA's mutant maker. # MUTSTAT -- MOTHRA's mutant statistician. # NUMCASES -- Number of test cases in the tc file. # ################################################################ ################################################################ # Initialize variables # ################################################################ MEMDEFAULT=0 PAGER=/usr/ucb/more RM=/bin/rm PATH=/usr/ucb:/usr/bin:/bin:/usr/local/bin:/usr/local export PATH # The tools are: BIN=/local2/home1/ofut/mutate/bin PARSER=$BIN/parser ROSETTA=$BIN/rosetta MUTMAKE=$BIN/mutmake MUTSTAT=$BIN/mutstat MAPPER=$BIN/mapper BBGMUT=$BIN/bbgmut DECODE=$BIN/decode MUTEQUIV=$BIN/mutequiv NUMCASES=$BIN/numcases # The extensions are: SYMEXT=sym CODEEXT=code MDREXT=mdr TCEXT=tc SRCEXT=ftn EXPEXT=exp #These two tell ExecMut whether we've defined new mutants or Test cases. #Initialized to zero, set to one with new additions, and returned to #zero when ExecMut processes them. MoreMuts=0 MoreTCs=0 LastTC=0 Total=0 Alive=0 NumTstCases=0 CurCase=0 MMask="0" Percent=0 RoseOpts="" MORE=-dc umask 002 ################################################################ # Here's the main program. # # Print a nice introductory message. # ################################################################ clear echo "" echo "" echo " MOTHRA" echo "" echo " Fortran-77 Mutation System" echo "" echo " BDemo Interface" echo "" ################################################################ # Get the experiment name. # ################################################################ while true do echo -n "Enter experiment name: " read ExpName if test ! -z "$ExpName" then break #from loop fi done if test -f $ExpName.exp then echo "Continuing experiment ..." #Set up the global variables. if test -r $ExpName.$TCEXT then NumTstCases=`$NUMCASES "$ExpName"` else NumTstCases=0 fi ################################################## # Read experiment file. # ################################################## #ExpRead () set `cat $ExpName.$EXPEXT` LastTC=$1 shift MoreMuts=$1 shift MoreTCs=$1 shift Total=$1 shift Alive=$1 shift MMask=$1 shift Percent=$1 shift RoseOpts="$*" else echo "Initial experiment." echo "" echo -n "Enter Fortran-77 source file name: " read OrigSrc #Loop until a file is found. while true do # Check to see that the file to be tested exists. if test -f "$OrigSrc" then #File is found, go parse it. if test "$OrigSrc" != "$ExpName.$SRCEXT" then cp $OrigSrc $ExpName.$SRCEXT #echo "$OrigSrc copied to $ExpName.$SRCEXT." fi break #from loop elif test -f "$OrigSrc.$SRCEXT" then #File is found, go parse it. if test "$OrigSrc.$SRCEXT" != "$ExpName.$SRCEXT" then cp $OrigSrc.$SRCEXT $ExpName.$SRCEXT #echo "$OrigSrc.$SRCEXT copied to $ExpName.$SRCEXT." fi break #from loop else echo "" echo "Sorry, I can't find $OrigSrc." echo "Please enter a Fortran-77 source file name." echo -n 'Enter "q" to end MOTHRA: ' read OrigSrc fi if test "$OrigSrc" = "q" then exit 1 fi done ############################################ # Parse the program. # ############################################ echo "Parsing $OrigSrc..." $PARSER $ExpName "$ExpName.$SRCEXT" #Save any error messages in .t, count the output lines. #If any, bag it. if [ `$PARSER $ExpName "$ExpName.$SRCEXT" 2>&1 | tee $ExpName.t | wc -l` -gt 0 ] then cat $ExpName.t echo "ABORTING EXPERIMENT $ExpName." $RM -f $ExpName.* exit 1 else $RM -f $ExpName.t fi echo "" echo "Do you want to initialize your program's memory?" echo -n "Enter \"?\" to explain this option: [? y n](n) " read REPLY if test "$REPLY" = "?" then echo "" echo "On the Vax 11/780, all memory is automatically initialized to zeroes." echo "On some machines, memory is initialized to zeroes before being used." echo "On others, memory is left with whatever values were left from from previous" echo "processes. If your target machine initializes memory differently from" echo "your host machine, you may want to use this option for this experiment." echo "" echo "Initializing memory will make a difference in mutants that are killed" echo "versus mutants that are equivalent." echo "" echo "If you initialize memory, you will supply a value [0-255], and every" echo "byte in your program's memory space will be initialized to that" echo "value when your program is executed." echo "" echo -n "Do you want to initialize your program's memory? [yn](n) " read REPLY fi if test "$REPLY" = "y" -o "$REPLY" = "Y" then echo -n "What value do you want to use [0-255]? ($MEMDEFAULT) " read value if test -z "$value" then value=$MEMDEFAULT fi RoseOpts=$RoseOpts" -s "$value fi ################################################## # Writes the experiment file. # ################################################## #ExpWrite () echo $LastTC > $ExpName.$EXPEXT echo $MoreMuts >>$ExpName.$EXPEXT echo $MoreTCs >>$ExpName.$EXPEXT echo $Total >>$ExpName.$EXPEXT echo $Alive >>$ExpName.$EXPEXT echo $MMask >>$ExpName.$EXPEXT echo $Percent >>$ExpName.$EXPEXT echo $RoseOpts >>$ExpName.$EXPEXT fi ################################################################ # Main menu. # ################################################################ while true do echo "" echo "" echo " BDemo Main Menu" echo "" echo "" echo "1) Enter Test Case" echo "2) Execute Mutants" echo "3) View Live Mutants" echo "4) View Program Source" echo "5) Enable Mutants" echo "6) Status Menu" echo "7) Test Case Menu" echo "8) Execute Mutants in Background" echo "9) Exit BDemo" echo -n "Enter the number of your choice: " read REPLY case $REPLY in 1) ################################################################ # Get a test case from a file or interactively. # ################################################################ #GetTC () numoldtc=0 getout=0 opt="-a" echo -n "Initial values from [USER, OLD EXPERIMENT] (USER)? " read GTREPLY if test "$GTREPLY" = "o" -o "$GTREPLY" = "O" -o "$GTREPLY" = "old" -o "$GTREPLY" = "OLD" -o "$GTREPLY" = "old experiment" -o "$GTREPLY" = "OLD EXPERIMENT" then echo -n "Enter name of previous Mothra experiment: " read GTREPLY if test -f $GTREPLY.$TCEXT then opt="-f $GTREPLY.$TCEXT" numoldtc=`$NUMCASES "$GTREPLY"` else echo "I could not find the test case file for $GTREPLY." echo -n "Enter experiment name: " read GTREPLY if test -f $GTREPLY.$TCEXT then opt="-f $GTREPLY.$TCEXT" numoldtc=`$NUMCASES "$GTREPLY"` else echo "Couldn't find $GTREPLY." echo "Forget it." getout=1 fi fi fi echo "" if [ $getout -eq 0 ] then if test "$opt" = "-a" then echo -n "Run Time values from [USER, FILE] (USER)? " read GTREPLY else echo -n "Additional Run Time values from [USER, FILE] (USER)? " read GTREPLY fi if test "$GTREPLY" = "f" -o "$GTREPLY" = "F" -o "$GTREPLY" = "file" -o "$GTREPLY" = "FILE" then while true do echo -n "Enter input file name: " read INFILE if test ! -z "$INFILE" then break #from loop fi done if test ! -f $INFILE then echo "I could not find $INFILE." echo -n "Enter input file name: " read INFILE if test ! -f $INFILE then echo "Couldn't find $INFILE." echo "Forget it." getout=1 fi fi if [ $getout -eq 0 ] then echo "" echo -n "How many test cases are in $INFILE? " read LEN echo "" if [ $numoldtc -eq 0 ] then CurCase=`expr $NumTstCases + 1` OldCurCase=`expr $NumTstCases + 1` NumTstCases=`expr $NumTstCases + $LEN` while test $CurCase -le $NumTstCases do $MAPPER $opt $ExpName CurCase=`expr $CurCase + 1` done elif [ $numoldtc -eq $LEN ] then OldCurCase=`expr $NumTstCases + 1` NumTstCases=`expr $NumTstCases + $LEN` CurCase=$NumTstCases $MAPPER $opt $ExpName CurCase=`expr $CurCase + 1` else echo " There are $numoldtc cases in the old experiment and $LEN cases in the input file." echo " Sorry, but I don't know how to combine them." getout=1 fi fi if [ $getout -eq 0 ] then echo "" echo "" echo " Test cases # $OldCurCase through $NumTstCases" echo "" echo "Running original program..." echo "" (cat $INFILE | $ROSETTA -e $RoseOpts -c$OldCurCase $ExpName) 2>&1 | $PAGER echo -n "Are all of these the correct output? [yn](y) " read GTREPLY if test "$GTREPLY" = "n" -o "$GTREPLY" = "N" then echo "Skipping test cases $OldCurCase through $NumTstCases." CurCase=$OldCurCase while test $CurCase -le $NumTstCases do $MAPPER -r $CurCase $ExpName $RM -f $ExpName.output.$CurCase $RM -f $ExpName.tags.$CurCase CurCase=`expr $CurCase + 1` done NumTstCases=`expr $OldCurCase - 1` CurCase=`expr $OldCurCase - 1` fi fi #of [ $getout -eq 0] else #of if reply is file. $MAPPER $opt $ExpName CurCase=`expr $NumTstCases + 1` NumTstCases=`$NUMCASES "$ExpName"` while test $CurCase -le $NumTstCases do echo "" echo "" echo " Test case # "$CurCase. echo "" echo "Running original program..." echo "" $ROSETTA -e $RoseOpts -n$CurCase $ExpName echo -n "Is this the correct output? [yn](y) " read GTREPLY if test "$GTREPLY" = "n" -o "$GTREPLY" = "N" then echo "Skipping test case $CurCase." $MAPPER -r $CurCase $ExpName $RM -f $ExpName.output.$CurCase $RM -f $ExpName.tags.$CurCase NumTstCases=`expr $NumTstCases - 1` CurCase=`expr $CurCase - 1` fi CurCase=`expr $CurCase + 1` done #While CurCase < NumTstCases MoreTCs=`expr $MoreTCs + 1` fi fi # of [ $getout -eq 0] #GetTC end ################################################## # Writes the experiment file. # ################################################## #ExpWrite () echo $LastTC > $ExpName.$EXPEXT echo $MoreMuts >>$ExpName.$EXPEXT echo $MoreTCs >>$ExpName.$EXPEXT echo $Total >>$ExpName.$EXPEXT echo $Alive >>$ExpName.$EXPEXT echo $MMask >>$ExpName.$EXPEXT echo $Percent >>$ExpName.$EXPEXT echo $RoseOpts >>$ExpName.$EXPEXT ;; 2) ################################################################ # Execution phase. # # # # If MoreMuts != 0 then run all test cases. # # If MoreTCs != 0 then run new test cases. # # LastTC remembers the last test case executed. # ################################################################ #ExecMuts () if test $MoreMuts -ne 0 then LastTC=0 fi if test "$MMask" = "0" then echo "" echo "I must have a mutant type defined before execution." elif test $NumTstCases -eq 0 then echo "" echo "I must have a test case before execution." elif test $MoreTCs -ne 0 -o $MoreMuts -ne 0 then #Something new, execute. MoreTCs=0 MoreMuts=0 CurTC=`expr $LastTC + 1` # #For each test case. # while test $CurTC -le $NumTstCases # do # $ROSETTA $RoseOpts -n $CurTC -g -m $MMask $ExpName $ROSETTA $RoseOpts -c$CurTC -g -m$MMask $ExpName # CurTC=`expr $CurTC + 1` # done #While CurTC < NumTstCases # LastTC=`expr $CurTC - 1` LastTC=`expr $NumTstCases - 1` Alive=`$MUTSTAT -c $ExpName | tail -1 | awk '{print $2}'` else echo "" echo "I need a new test case or mutant to execute." fi #If $MoreTCs or $MoreMuts #ExecMuts end ################################################## # Writes the experiment file. # ################################################## #ExpWrite () echo $LastTC > $ExpName.$EXPEXT echo $MoreMuts >>$ExpName.$EXPEXT echo $MoreTCs >>$ExpName.$EXPEXT echo $Total >>$ExpName.$EXPEXT echo $Alive >>$ExpName.$EXPEXT echo $MMask >>$ExpName.$EXPEXT echo $Percent >>$ExpName.$EXPEXT echo $RoseOpts >>$ExpName.$EXPEXT ;; 3) $DECODE -m $ExpName | $PAGER; echo -n "[Press return to continue]"; read Que; ;; 4) $PAGER $ExpName.$SRCEXT ; echo -n "[Press return to continue]"; read Que; ;; 5) ################################################################ # Get mutants until mutmake gets a correct set. # ################################################################ #GetMuts () if test $Percent -eq 0 then while true do # Get a mutant percentage from the user. echo "" echo -n "What percentage of mutants would you like [1-100] (100)? " read GMREPLY if test -z "$GMREPLY" then Percent=100 break #from loop elif test "$GMREPLY" -ge "1" -a "$GMREPLY" -le "100" 2>/dev/null then Percent=$GMREPLY break #from loop else echo "Sorry, $GMREPLY is not between 1 and 100." echo "" fi done fi while true do # Ask which mutant types/classes the user would like to # generate. Allow the user to see a list of the allowable # mutants. echo "" echo " Mutant Names" echo "" echo "TYPES: aar abs acr aor asr car cnr crp csr der dsa" echo " glr lcr ror rsr san sar scr sdl src svr uoi" echo "" echo "CLASSES: ary con ctl dmn opm prd scl stm" echo "" echo "SUPER CLASSES: all cca pda sal" echo "" echo "Which Mutant types/classes would you like to generate?" echo "You may enter the complete list of mutants on one line, separated" echo "by blanks. Enter a blank line when you are finished selecting." echo "Enter a "?" to see a descriptions of the mutant types and classes." echo "" while true do echo -n "[? ]? " read GMREPLY if test ! "$GMREPLY" then break #from loop elif test "$GMREPLY" = "?" then $MUTMAKE -l | $PAGER else MutTypes="$MutTypes $GMREPLY" fi done echo "" ################################################################ # Make the mutants that the user wanted. # ################################################################ echo "Creating mutants..." MMask=`$MUTMAKE -p $Percent $ExpName $MutTypes` if test ! "$MMask" then #Error message is prnted inside mutmake. #echo "I don't understand the mutant types." MutTypes="" else NewAlive=`$MUTSTAT -c $ExpName | tail -1 | awk '{print $2}'` New=`expr $NewAlive - $Alive` echo "Created $New additional mutants for $ExpName." Total=`expr $Total + $New` Alive=$NewAlive break #From loop. Good input. fi done if test $New -gt 0 then MoreMuts=1 fi #GetMuts end ################################################## # Writes the experiment file. # ################################################## #ExpWrite () echo $LastTC > $ExpName.$EXPEXT echo $MoreMuts >>$ExpName.$EXPEXT echo $MoreTCs >>$ExpName.$EXPEXT echo $Total >>$ExpName.$EXPEXT echo $Alive >>$ExpName.$EXPEXT echo $MMask >>$ExpName.$EXPEXT echo $Percent >>$ExpName.$EXPEXT echo $RoseOpts >>$ExpName.$EXPEXT ;; 6) ################################################################ # Status menu # # # ################################################################ #Status () while true do echo "" echo "" echo "What status information do you want to see?" echo "" echo "1) View Mutant Status" echo "2) Print Mutant Status to a File" echo "3) Declare Mutants as Equivalent" echo "4) Declare One Mutant as Equivalent" echo "5) UnEquivalence One Mutant" echo "6) View Dead Mutants" echo "7) View Equivalent Mutants" echo "8) Print Live Mutants to a File" echo "9) Return to Main Menu" echo -n "Enter the number of your choice: " read STREPLY case $STREPLY in 1) $MUTSTAT -P $ExpName | $PAGER ; echo -n "[Press return to continue]"; read Que; ;; 2) echo -n "File name: " ; read Que; $MUTSTAT -P $ExpName >$Que; ;; 3) ############################################################ # Defining mutants to be equivalent. # # # ############################################################ #ExecEquiv () skip=0 for mutnum in `$MUTSTAT -l $ExpName | tail +3 | awk '{print $1}'` do if test $skip -le $mutnum then skip=0 elif test $skip -gt 0 then continue fi echo "Mutant number $mutnum of $Total total mutants." $DECODE -M $mutnum $ExpName echo "" EEREPLY="n" echo -n "Is this mutant equivalent? [yn#q](n) " read EEREPLY case $EEREPLY in *[A-z]*) if test "$EEREPLY" = "y" -o "$EEREPLY" = "Y" then $MUTEQUIV $ExpName $mutnum elif test "$EEREPLY" = "q" then break #from loop fi ;; "") ;; *) skip=$EEREPLY ; ;; esac echo "" done Alive=`$MUTSTAT -c $ExpName | tail -1 | awk '{print $2}'` #ExecEquiv end ;; 4) echo -n "Which mutant? " read Que $DECODE -M $Que $ExpName; echo -n "Is this mutant equivalent? [yn](y) "; read STREPLY; if test "$STREPLY" = "n" -o "$STREPLY" = "N" then echo "" >/dev/null; else $MUTEQUIV $ExpName $Que ; fi ;; 5) echo -n "Which mutant? " ; read Que; $DECODE -M $Que $ExpName; echo -n "Unequivalence this mutant? [yn](y) "; read STREPLY; if test "$STREPLY" = "n" -o "$STREPLY" = "N" then echo "" >/dev/null; else $MUTEQUIV -u $ExpName $Que ; fi # Execute all test cases on the one mutant. $ROSETTA $RoseOpts -M $Que -g -m $MMask $ExpName ; ;; 6) $DECODE -k $ExpName | $PAGER; echo -n "[Press return to continue]"; read Que; ;; 7) $DECODE -q $ExpName | $PAGER; echo -n "[Press return to continue]"; read Que; ;; 8) echo -n "File name: " ; read Que; $DECODE -m $ExpName >$Que; ;; 9) ;; *) echo "I did not understand that choice."; ;; esac if [ $STREPLY -eq 9 ] then break fi done #Status end ;; 7) ################################################################ # Test case menu. # ################################################################ #TCs () echo "" echo "" echo "Which test case operation?" echo "" echo "1) View Test Cases" echo "2) Print Test Cases to a File" echo "3) Delete a Test Case" echo "4) Return to Main Menu" echo -n "Enter the number of your choice: " read TCREPLY case $TCREPLY in 1) $MAPPER -s $ExpName | $PAGER ; echo -n "[Press return to continue]"; read Que; ;; 2) echo -n "File name: " ; read Que; $MAPPER -s $ExpName > $Que ; echo "Test cases saved in $Que"; ;; 3) ########################################################### # Delete a test case from the test case file. # ########################################################### #DelTC () if [ $NumTstCases -lt 1 ] then echo "No test cases to delete." else echo -n "Which test case? (1...$NumTstCases) " read Que if test $Que -le $NumTstCases -a $Que -gt 0 then $MAPPER -r $Que $ExpName $MAPPER -c $ExpName NumTstCases=`expr $NumTstCases - 1` if test $Que -le $LastTC then LastTC=`expr $LastTC - 1` fi if test $Que -le $CurCase then CurCase=`expr $CurCase - 1` fi if test $MoreTCs -gt 0 then MoreTCs=`expr $MoreTCs - 1` fi else echo "Sorry, I don't have a test case number $Que." fi fi #DelTC end ################################################## # Writes the experiment file. # ################################################## #ExpWrite () echo $LastTC > $ExpName.$EXPEXT echo $MoreMuts >>$ExpName.$EXPEXT echo $MoreTCs >>$ExpName.$EXPEXT echo $Total >>$ExpName.$EXPEXT echo $Alive >>$ExpName.$EXPEXT echo $MMask >>$ExpName.$EXPEXT echo $Percent >>$ExpName.$EXPEXT echo $RoseOpts >>$ExpName.$EXPEXT ;; 4) ;; *) echo "I did not understand that choice."; ;; esac #TCs end ;; 8) echo "Background execution started." ; echo "You shouldn't touch this experiment until the execution is finished." ; echo "If you do, no telling what will happen." ; ################################################## # Writes the experiment file. # ################################################## #ExpWrite () echo $LastTC > $ExpName.$EXPEXT echo $MoreMuts >>$ExpName.$EXPEXT echo $MoreTCs >>$ExpName.$EXPEXT echo $Total >>$ExpName.$EXPEXT echo $Alive >>$ExpName.$EXPEXT echo $MMask >>$ExpName.$EXPEXT echo $Percent >>$ExpName.$EXPEXT echo $RoseOpts >>$ExpName.$EXPEXT #Note that the exp file must be written before bbgmut starts. (nohup ./$BBGMUT $ExpName >>/dev/null&) ; exit 1 ;; 9) ################################################## # Writes the experiment file. # ################################################## #ExpWrite () echo "" echo "Saving experiment $ExpName." echo $LastTC > $ExpName.$EXPEXT echo $MoreMuts >>$ExpName.$EXPEXT echo $MoreTCs >>$ExpName.$EXPEXT echo $Total >>$ExpName.$EXPEXT echo $Alive >>$ExpName.$EXPEXT echo $MMask >>$ExpName.$EXPEXT echo $Percent >>$ExpName.$EXPEXT echo $RoseOpts >>$ExpName.$EXPEXT exit 1 ;; *) echo "Please choose a number from the menu." ; ;; esac echo "" done