[Soot-list] purity test of java functions

dingsun xyz031702 at hotmail.com
Mon May 24 07:16:29 EDT 2010


Dear All       I'm trying to use the purity test package in soot (SootSrc2.3/src/soot/jimple/toolkits/annotation/purity) , the red code is my testing code, the blue part is the analysis result, the code in black is my program code.  I'm confused about the results. The my code the function f1 will modify the parameter , however the analysis result show both the function is "pure" and the parameter is "safe". Have anyone ever use soot for side-effect or purity testing?
Expecting suggestions.Best Regards,Ding Sun
Test Code:Class testCase1 {public void f1(StringBuffer strBuf) {	strBuf.delete(1, 3);}
public static void main(String [] args){	testCase1 tc=new testCase1 ();	StringBuffer strBuf =new StringBuffer("hello");	System.out.println(strBuf);	tc.f1(strBuf);	System.out.println(strBuf);}}-------------------------------------------------------------------------Analysis Result:|- method < testCase1 : void f1(java.lang.StringBuffer)> is pure  |   |- this is Safe  |   |- param 0 is safe
|- method < testCase1 : void main(java.lang.String[])> is impure  |   |- param 0 is safe--------------------------------------------------------------------------Program to call purtity test in Sootpublic void test(){		CallGraphBuilder cgb=new CallGraphBuilder();		cgb.build();		Map options=new HashMap();		options.put("print", "true");		PurityOptions opts = new PurityOptions(options);
		G.v().out.println("[AM] Analysing purity");
		CallGraph cg = Scene.v().getCallGraph();
		// Find main methods		List<SootMethod> heads = new LinkedList<SootMethod>();		Iterator getClassesIt = Scene.v().getApplicationClasses().iterator();		while (getClassesIt.hasNext()) {		    SootClass appClass = (SootClass)getClassesIt.next();		    Iterator getMethodsIt = appClass.getMethods().iterator();		    while (getMethodsIt.hasNext()) {			SootMethod method = (SootMethod) getMethodsIt.next();			if (method.getName().equals("main")) {			    heads.add(method);			    G.v().out.println("  |- will treat "+appClass.getName()+					      "."+method.getName());			}		    }		}
		// launch the analysis		PurityInterproceduralAnalysis p =		    new PurityInterproceduralAnalysis(cg, heads.iterator(), opts);     }


 		 	   		  
_________________________________________________________________
约会说不清地方?来试试微软地图最新msn互动功能!
http://ditu.live.com/?form=TL&swm=1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.cs.mcgill.ca/pipermail/soot-list/attachments/20100524/f96e3fe7/attachment-0001.html 


More information about the Soot-list mailing list