Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

SpinOptions.java

00001 package edu.ksu.cis.bandera.spin;
00002 
00003 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00004  * Bandera, a Java(TM) analysis and transformation toolkit           *
00005  * Copyright (C) 1999   Matthew Dwyer (dwyer@cis.ksu.edu)            *
00006  * All rights reserved.                                              *
00007  *                                                                   *
00008  * This work was done as a project in the SAnToS Laboratory,         *
00009  * Department of Computing and Information Sciences, Kansas State    *
00010  * University, USA (http://www.cis.ksu.edu/santos).                  *
00011  * It is understood that any modification not identified as such is  *
00012  * not covered by the preceding statement.                           *
00013  *                                                                   *
00014  * This work is free software; you can redistribute it and/or        *
00015  * modify it under the terms of the GNU Library General Public       *
00016  * License as published by the Free Software Foundation; either      *
00017  * version 2 of the License, or (at your option) any later version.  *
00018  *                                                                   *
00019  * This work is distributed in the hope that it will be useful,      *
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of    *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU *
00022  * Library General Public License for more details.                  *
00023  *                                                                   *
00024  * You should have received a copy of the GNU Library General Public *
00025  * License along with this toolkit; if not, write to the             *
00026  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,      *
00027  * Boston, MA  02111-1307, USA.                                      *
00028  *                                                                   *
00029  * Java is a trademark of Sun Microsystems, Inc.                     *
00030  *                                                                   *
00031  * To submit a bug report, send a comment, or get the latest news on *
00032  * this project and other SAnToS projects, please visit the web-site *
00033  *                http://www.cis.ksu.edu/santos                      *
00034  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00035 /**
00036  * SpinOptions is used to configure the options to be used in invoking
00037  * the SPIN model checker on generated PROMELA systems.
00038  * <p>
00039  * Most user setable options available through the XSPIN interface
00040  * can be configured through this class.  Default values for those
00041  * options are as follows: 
00042  * <ul> 
00043  * <li> <tt>Safety</tt> : false
00044  * <li> <tt>AcceptanceCycles</tt> : true
00045  * <li> <tt>ApplyNeverClaim</tt> : true
00046  * <li> <tt>SearchMode</tt> : <tt>Exhaustive</tt><br>
00047  *  [out of <tt>{Exhaustive, SuperTrace, HashCompact}</tt>]
00048  * <li> <tt>StopAtError</tt> : 1
00049  * <li> <tt>SaveAllTrails</tt> : true
00050  * <li> <tt>FindShortestTrail</tt> : false
00051  * <li> <tt>MemoryLimit</tt> : 128 (MBytes)
00052  * <li> <tt>SpaceEstimate</tt> : 500 (x10^3)
00053  * <li> <tt>SearchDepth</tt> : 10000
00054  * <li> <tt>POReduction</tt> : false
00055  * <li> <tt>Compression</tt> : false
00056  * </ul>
00057  * <p>
00058  * Some options do not make sense when used with Bandera generated
00059  * models.
00060  * <ul> 
00061  * <li> Bandera models will not contain "progress" state labels
00062  * <li> unreachable model code should not be reported to the user
00063  * <li> weak-fairness is not supported either 
00064  * </ul>
00065  * <p>
00066  * Some basic guidelines for setting SPIN options are:
00067  * <p>
00068  * If a temporal formula is checked then never claims should be applied, 
00069  * otherwise it is a deadlock check.  If the temporal formula is known
00070  * to be a safety property then <tt>Safety</tt> should be set, otherwise
00071  * <tt>AcceptanceCycles</tt> should be set.  
00072  * <p>
00073  * Some option settings are linked:
00074  * <ul>
00075  * <li> Setting <tt>Safety</tt> to true automatically 
00076  * sets <tt>AcceptanceCycles</tt> to be false, and vice-versa.
00077  * </ul>
00078  */
00079 
00080 import java.util.*; // *** robbyjo's modification
00081 import edu.ksu.cis.bandera.checker.*;
00082 
00083 public class SpinOptions extends CheckerOption {
00084     boolean Safety = false;
00085     boolean AcceptanceCycles = true;
00086     boolean ApplyNeverClaim = true;
00087     public static final int Exhaustive = 0;
00088     public static final int SuperTrace = 1;
00089     public static final int HashCompact = 2;
00090     int SearchMode = Exhaustive;
00091     int StopAtError = 1;
00092     boolean SaveAllTrails = true;
00093     boolean FindShortestTrail = false;
00094     int MemoryLimit = 128;
00095     int MemoryCount = 31;
00096     int VectorSize = 1024;
00097     int SpaceEstimate = 500;
00098     int SearchDepth = 10000;
00099     boolean POReduction = false;
00100     boolean Compression = false;
00101     boolean ResourceBounded = true;
00102     public SpinOptions() {
00103     }
00104     public SpinOptions(String opt) {
00105         parseOptions(opt);
00106     }
00107 public String compileOptions() {
00108     String co = compileOptions2();
00109     if (!ResourceBounded) co = co + " -DNORESOURCEBOUNDED";
00110     return co;
00111     }
00112 public String compileOptions2() {
00113     String co;
00114     switch (SearchMode) {
00115     case SuperTrace : 
00116         co = "-DBITSTATE -DMEMCNT=" + MemoryCount + " -DVECTORSZ=" + VectorSize;
00117         break;
00118     case HashCompact : 
00119         co = "-DHC -DMEMCNT=" + MemoryCount + " -DVECTORSZ=" + VectorSize;
00120         break;
00121     default : 
00122         co = "-DMEMCNT=" + MemoryCount + " -DVECTORSZ=" + VectorSize;
00123         break;
00124     }
00125     if (Safety) co = co + " -DSAFETY";
00126     if (!ApplyNeverClaim) co = co + " -DNOCLAIM";
00127     if (!POReduction) co = co + " -DNOREDUCE";
00128     if (Compression) co = co + " -DCOLLAPSE";
00129     return co;
00130     }
00131 /**
00132  * 
00133  * @return int
00134  */
00135 public int getMemoryCount() {
00136     return MemoryCount;
00137 }
00138 /**
00139  * 
00140  * @return int
00141  */
00142 public int getMemoryLimit() {
00143     return MemoryLimit;
00144 }
00145 /**
00146  * 
00147  * @return boolean
00148  */
00149 public boolean getResourceBounded() {
00150     return ResourceBounded;
00151 }
00152 /**
00153  * 
00154  * @return int
00155  */
00156 public int getSearchDepth() {
00157     return SearchDepth;
00158 }
00159 /**
00160  * 
00161  * @return int
00162  */
00163 public int getSpaceEstimate() {
00164     return SpaceEstimate;
00165 }
00166 /**
00167  * 
00168  * @return int
00169  */
00170 public int getStopAtError() {
00171     return StopAtError;
00172 }
00173 /**
00174  * 
00175  * @return int
00176  */
00177 public int getVectorSize() {
00178     return VectorSize;
00179 }
00180     int log2(int x) {
00181     int log = 0;
00182     for (int total = 1; total < x; log++) {
00183         total = total * 2;
00184     }
00185     return log-1;
00186     }
00187     public static void main (String argv[]) {
00188     SpinOptions so = new SpinOptions();
00189     System.out.println("Default compile options :" + so.compileOptions());
00190     System.out.println("Default pan options :" + so.panOptions());
00191     (so = new SpinOptions()).setSearchMode(SuperTrace);
00192     System.out.println("Supertrace compile options :" + so.compileOptions());
00193     System.out.println("Supertrace pan options :" + so.panOptions());
00194     (so = new SpinOptions()).setSearchMode(HashCompact);
00195     System.out.println("Hash-compact compile options :" + so.compileOptions());
00196     System.out.println("Hash-compact pan options :" + so.panOptions());
00197     (so = new SpinOptions()).setSafety(true);
00198     System.out.println("Safety compile options :" + so.compileOptions());
00199     System.out.println("Safety pan options :" + so.panOptions());
00200     (so = new SpinOptions()).setMemoryLimit(1000);
00201     so.setSearchDepth(50000);
00202     so.setSpaceEstimate(2050);
00203     System.out.println("Limits compile options :" + so.compileOptions());
00204     System.out.println("Limits pan options :" + so.panOptions());
00205     (so = new SpinOptions()).setApplyNeverClaim(false);
00206     so.setPOReduction(true);
00207     so.setCompression(true);
00208     System.out.println("No never, po, compress compile options :" + so.compileOptions());
00209     System.out.println("No never, po, compress pan options :" + so.panOptions());
00210     }
00211     public String panOptions() {
00212     String po;
00213     po = "-n -m" + SearchDepth + " -w" + (10 + log2(SpaceEstimate));
00214     if (AcceptanceCycles) po = po + " -a";
00215     if (StopAtError>1) po = po + " -c" + StopAtError;
00216     if (SaveAllTrails) po = po + " -e";
00217     if (FindShortestTrail) po = po + " -I";
00218     return po;
00219     }
00220 /**
00221  * 
00222  * Leeched directly from bandera.bui by robbyjo
00223  */
00224 private void parseCompileOptions(String param) {
00225     Vector vector = new Vector();
00226     StringTokenizer st = new StringTokenizer(param);
00227     while (st.hasMoreTokens()) {
00228         vector.add(st.nextToken());
00229     }
00230     for (int i = 0; i < vector.size(); i++) {
00231         String s = ((String) vector.elementAt(i));
00232         if (s.equals("-DBITSTATE"))
00233             setSearchMode(SuperTrace);
00234         else if (s.equals("-DHC"))
00235             setSearchMode(HashCompact);
00236         else if (s.startsWith("-DVECTORSZ")) {
00237             String temp = s.substring(11);
00238             try {
00239                 setVectorSize(Integer.parseInt(temp));
00240             } catch (Exception e) {
00241                 System.out.println("Vector size error in DVECTORSZ " + getVectorSize());
00242             }
00243         } else if (s.startsWith("-DMEMCNT")) {
00244             String temp = s.substring(9);
00245             try {
00246                 setMemoryCount(Integer.parseInt(temp));
00247             } catch (Exception e) {
00248                 System.out.println("Memory limit error in DMEMCNT " + getMemoryCount());
00249             }
00250         } else if (s.startsWith("-DMEMLIM")) {
00251             String temp = s.substring(9);
00252             try {
00253                 setMemoryLimit(Integer.parseInt(temp));
00254             } catch (Exception e) {
00255                 System.out.println("Memory limit error in DMEMLIM " + getMemoryLimit());
00256             }
00257         } else if (s.equals("-DSAFETY")) {
00258             setAcceptanceCycles(false);
00259             setSafety(true);
00260         } else if (s.equals("-DNOREDUCE")) {
00261         } else if (s.equals("-DCOLLAPSE")) {
00262             setCompression(true);
00263         } else if (s.equals("-DNORESOURCEBOUNDED")) {
00264             setResourceBounded(false);
00265         } else if (s.equals("-DNOCLAIM")) {
00266             setApplyNeverClaim(false);
00267         }
00268     }
00269 }
00270     /**
00271  * Parsing spin options -- Robbyjo's Modification
00272  */
00273 public void parseOptions(String opt)
00274 {
00275     Safety = false;
00276     AcceptanceCycles = true;
00277     ApplyNeverClaim = true;
00278     
00279     SearchMode = Exhaustive;
00280     
00281     StopAtError = 1;
00282     SaveAllTrails = true;
00283     FindShortestTrail = false;
00284     
00285     MemoryLimit = 128;
00286     MemoryCount = 31;
00287     VectorSize = 1024;
00288     SpaceEstimate = 500;
00289     SearchDepth = 10000;
00290     
00291     POReduction = false;
00292     Compression = false;
00293 
00294     ResourceBounded = true;
00295     
00296     StringTokenizer t = new StringTokenizer(opt, "+");
00297     parseCompileOptions(t.nextToken());
00298     parsepaneOptions(t.nextToken());
00299 }
00300 /**
00301  * 
00302  * @param para java.lang.String
00303    Leeched by robbyjo
00304  */
00305 private void parsepaneOptions(String para) {
00306     Vector vector = new Vector();
00307     StringTokenizer st = new StringTokenizer(para);
00308     while(st.hasMoreTokens()){
00309         vector.add(st.nextToken());
00310     }
00311     for(int i =0; i < vector.size(); i++){
00312         if(((String)vector.elementAt(i)).equals("-n")){
00313             i++;
00314             if( i==vector.size() || !((String)(vector.elementAt(i))).startsWith("-m")){
00315                     System.out.println("Your input should be -n -mSearchDepth");
00316                     
00317             }
00318             else{
00319                 String temp = ((String)vector.elementAt(i)).substring(2);
00320                 try{
00321                     setSearchDepth(Integer.parseInt(temp));
00322                 }catch(Exception e){
00323                     System.out.println("Error search depth option: "+getSearchDepth());
00324                 }
00325             }
00326         }
00327         if(((String)vector.elementAt(i)).equals("-a")){
00328             setAcceptanceCycles(true);
00329         }
00330         if(((String)vector.elementAt(i)).equals("-c")){     
00331             i++;
00332             if( i==vector.size()){
00333                     System.out.println("Your input should be -c StopAtErrors");
00334                     
00335             }
00336             else{
00337                 String temp = (String)vector.elementAt(i);
00338                 try{
00339                     setStopAtError(Integer.parseInt(temp));
00340                 }catch(Exception e){
00341                     System.out.println("Error "+getStopAtError());
00342                 }
00343             }
00344         }
00345         if(((String)vector.elementAt(i)).equals("-e")){
00346             setSaveAllTrails(true);
00347         }
00348         if(((String)vector.elementAt(i)).equals("-I")){
00349             setFindShortestTrail(true);
00350         }
00351     }
00352 }
00353     public void setAcceptanceCycles(boolean ac) { 
00354     AcceptanceCycles = ac;
00355     Safety = !ac; 
00356     }
00357     public void setApplyNeverClaim(boolean nc) { ApplyNeverClaim = nc; }
00358     public void setCompression(boolean c) { Compression = c;}
00359     public void setFindShortestTrail(boolean st) { FindShortestTrail = st; }
00360     public void setMemoryCount(int c) { MemoryCount = c;}
00361     public void setMemoryLimit(int l) { MemoryLimit = l;}
00362     public void setPOReduction(boolean po) { POReduction = po;}
00363 /**
00364  * 
00365  * @param b boolean
00366  */
00367 public void setResourceBounded(boolean b) {
00368     ResourceBounded = b;
00369 }
00370     public void setSafety(boolean s) { 
00371     Safety = s; 
00372     AcceptanceCycles = !s;
00373     ApplyNeverClaim = !s;
00374     }
00375     public void setSaveAllTrails(boolean at) { SaveAllTrails = at; }
00376     public void setSearchDepth(int d) { SearchDepth = d;}
00377     public void setSearchMode(int m) { SearchMode = m; }
00378     public void setSpaceEstimate(int e) { SpaceEstimate = e;}
00379     public void setStopAtError(int e) { StopAtError = 1; }
00380     public void setVectorSize(int s) { VectorSize = s;}
00381 }

Generated at Thu Feb 7 06:55:29 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001