-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestMotiExamplewithSlicing.java
188 lines (162 loc) · 6.21 KB
/
TestMotiExamplewithSlicing.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import java.awt.Point;
import java.util.ArrayList;
import java.util.List;
import jfuzz.JFuzz;
import monitor.MonitorWithDFA;
import property.analysis.Property;
import property.analysis.PropertyAnalysis;
import property.guided.tests.PropertyGuidedSEAbstractTest;
import util.Global;
import automata.State;
import automata.Transition;
import automata.fsa.FSATransition;
import automata.fsa.FiniteStateAutomaton;
import automata.fsa.NFAToDFA;
import slice.PathSlicer;
import util.Global;
public class TestMotiExamplewithSlicing extends PropertyGuidedSEAbstractTest {
public static void main(String[] args) {
/**args for jdart*/
String symMethod = "moti.Example.start()";
String symMethodSig = "moti.Example.start()";
String classname = "moti.Example";
/**args for static analysis*/
String includeFile = "src/example-motiexample/Include.txt";
String exclusionFile = "src/example-motiexample/Exclusions.txt";
String mainClassName = "Lmoti/Example";
String inputFile = "";
Global.DEBUG = false;
Global.experimentMode=false; // if true, then the pruned branches can still run!
if (args.length < 5) {
args = new String[]{"1", "1", "0", "-1", "0,0,10,0", "", "1"};
}
initArgs(args);
String[] testArgs = createArgsMotiExample(inputFile, symMethod, symMethodSig, classname, iterationNum, iterationPeriod,
includeFile, exclusionFile, mainClassName, callStringBound, propertyGuidedSE, refineAnalysisResult);
TestMotiExample tester = new TestMotiExample();
// set the configuration of path slicing
String Events[] = new String[]{
"<init>(Ljava/io/InputStream;)V",
"<init>(Ljava/io/InputStream;Ljava/lang/String;)V",
"<init>(Ljava/io/InputStream;Ljava/nio/charset/Charset;)V",
"<init>(Ljava/io/InputStream;Ljava/nio/charset/CharsetDecoder;)V",
"read()I",
"read([CII)I",
"ready()Z",
"close()V"
};
String mainclass="Lmoti/Example";
String Methods[] = new String[]{
"main",
"moti.Example.start()"
};
String include= "src/example-motiexample/Include.txt";
String exclusion = "src/example-motiexample/Exclusions.txt";
PathSlicer.config.Set(Events,mainclass,Methods,include,exclusion);
tester.startTest(testArgs);
}
public void setProperty() {
FiniteStateAutomaton dfa = getForwardFSA();
MonitorWithDFA forwardMonitor = new MonitorWithDFA(dfa);
String classSig = "Ljava/io/InputStreamReader;";
//init operations
String inits[] = new String[]{
"<init>(Ljava/io/InputStream;)V",
"<init>(Ljava/io/InputStream;Ljava/lang/String;)V",
"<init>(Ljava/io/InputStream;Ljava/nio/charset/Charset;)V",
"<init>(Ljava/io/InputStream;Ljava/nio/charset/CharsetDecoder;)V"
};
for(String i : inits){
forwardMonitor.addSensitiveEvent(classSig, i.trim());
}
//close operation
forwardMonitor.addSensitiveEvent(classSig, "close()V");
//read operations
String operations[] = new String[]{
"read()I",
"read([CII)I",
"ready()Z"
};
for(String w : operations){
forwardMonitor.addSensitiveEvent(classSig, w.trim());
}
//method name to char map
for(String i : inits) {
forwardMonitor.addMethodNameChar(i.trim(), 'I');
}
forwardMonitor.addMethodNameChar("close()V", 'C');
for(String w : operations) {
forwardMonitor.addMethodNameChar(w.trim(), 'R');
}
PropertyAnalysis.property = new Property(forwardMonitor);
}
public static FiniteStateAutomaton getForwardFSA() {
//create a FSA
FiniteStateAutomaton nfa = new FiniteStateAutomaton();
State s0 = nfa.createState(new Point(0,0)); // inited
nfa.setInitialState(s0);
State s1 = nfa.createState(new Point(0,0)); // close
State s2 = nfa.createState(new Point(0,0)); // error
nfa.addFinalState(s2);
List<Transition> trans = new ArrayList<Transition>();
trans.add(new FSATransition(s0, s0, "I"));
trans.add(new FSATransition(s0, s0, "R"));
trans.add(new FSATransition(s0, s1, "C"));
trans.add(new FSATransition(s1, s1, "C"));
trans.add(new FSATransition(s1, s2, "R"));
trans.add(new FSATransition(s2, s2, "R"));
trans.add(new FSATransition(s2, s1, "C"));
for(Transition t : trans) {
nfa.addTransition(t);
}
NFAToDFA to = new NFAToDFA();
FiniteStateAutomaton dfa = to.convertToDFA(nfa);
Global.shortestPathLength.put(s0.getID(), 2);
Global.shortestPathLength.put(s1.getID(), 1);
Global.shortestPathLength.put(s2.getID(), 0);
return dfa;
}
public static String[] createArgsMotiExample(String inputFile,
String symMethod,
String symMethodSig,
String className,
int numExec,
String period,
String analysisInputFile,
String analysisExclusionFile,
String mainClassname,
int callStringBound,
boolean propertyGuidedSE,
boolean refineAnalysisResult) {
return new String[] {"+" + JFuzz.JFUZZ_INPUT_PROP + "=" + inputFile,
"+jpf.basedir=../jpf-core",
"+symbolic.dp=z3bitvec",
"+classpath=build/example-motiexample",
"+vm.insn_factory.class=gov.nasa.jpf.jdart.ConcolicInstructionFactory",
"+listener=jfuzz.ConcolicListener,monitor.MonitorListener,gov.nasa.jpf.vm.JVMForwarder", //,slice.SliceListener",
"+symbolic.method=" + symMethod,
"+search.class=gov.nasa.jpf.search.Simulation",
"+jpf.report.console.finished=",
numExec != -1? "+" + JFuzz.JFUZZ_NUM_EXEC + "=" + numExec:
"+" + JFuzz.JFUZZ_TIME_EXEC + "=" + period,
"+" + JFuzz.JFUZZ_NO_DEL + "=",
"+" + "perturb.params=bar",
"+" + "perturb.bar.method=" + symMethodSig,
"+" + "perturb.class=" + "jfuzz.Producer",
"+target=" + className,
"+target_args=" + inputFile,
"+include.file=" + analysisInputFile,
"+exclusion.file=" + analysisExclusionFile,
"+main.class.name=" + mainClassname,
"+call.string.bound=" + callStringBound,
"+property.guided.symbolic.execution=" + propertyGuidedSE,
"+refine.analysis.result=" + refineAnalysisResult,
"+nhandler.clean=true",
"+native_classpath=build/example-motiexample",
"+nhandler.delegateUnhandledNative=true",
"+nhandler.resetVMState=true",
"+nhandler.spec.delegate=java.lang.Class.getProtectionDomain",
"+property.slicing.symbolic.execution=" + PropertyGuidedSEAbstractTest.doSlicing
};
}
}