-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add artifact benchmarks to examples (#83)
* Add new targets
- Loading branch information
Showing
15 changed files
with
1,596 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
examples/src/test/java/cmu/pasta/mu2/examples/chocopy/ChocoPyTarget.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package cmu.pasta.mu2.examples.chocopy; | ||
|
||
import chocopy.ChocoPy; | ||
import chocopy.common.astnodes.Program; | ||
import chocopy.common.astnodes.Node; | ||
import chocopy.reference.RefAnalysis; | ||
import chocopy.reference.RefParser; | ||
import com.pholser.junit.quickcheck.From; | ||
import org.junit.runner.RunWith; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
|
||
import edu.berkeley.cs.jqf.fuzz.Fuzz; | ||
import edu.berkeley.cs.jqf.fuzz.JQF; | ||
import edu.berkeley.cs.jqf.fuzz.difffuzz.Comparison; | ||
import edu.berkeley.cs.jqf.fuzz.difffuzz.DiffFuzz; | ||
|
||
import edu.berkeley.cs.jqf.examples.chocopy.ChocoPySemanticGenerator; | ||
import java.io.IOException; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
import static org.junit.Assume.assumeTrue; | ||
import static org.junit.Assume.assumeNoException; | ||
|
||
@RunWith(JQF.class) | ||
public class ChocoPyTarget { | ||
|
||
@Fuzz(repro="${repro}") | ||
public void fuzzSemanticAnalysis(@From(ChocoPySemanticGenerator.class) String code) { | ||
Program program = RefParser.process(code, false); | ||
assumeTrue(!program.hasErrors()); | ||
Program refTypedProgram = RefAnalysis.process(program); | ||
try { | ||
Node.readTree(refTypedProgram.toJSON()); | ||
} catch (IOException e) { | ||
assumeNoException(e); | ||
} | ||
} | ||
|
||
@DiffFuzz | ||
public JsonNode testSemanticAnalysis(@From(ChocoPySemanticGenerator.class) String code) { | ||
Program program = RefParser.process(code, false); | ||
assumeTrue(!program.hasErrors()); | ||
Program refTypedProgram = RefAnalysis.process(program); | ||
JsonNode outputNode = null; | ||
try { | ||
outputNode = Node.readTree(refTypedProgram.toJSON()); | ||
} catch (IOException e) { | ||
assumeNoException(e); | ||
} | ||
return outputNode; | ||
} | ||
|
||
@DiffFuzz(cmp = "noncompare") | ||
public JsonNode testSemanticAnalysisNoncompare(@From(ChocoPySemanticGenerator.class) String code) { | ||
Program program = RefParser.process(code, false); | ||
assumeTrue(!program.hasErrors()); | ||
Program refTypedProgram = RefAnalysis.process(program); | ||
JsonNode outputNode = null; | ||
try { | ||
outputNode = Node.readTree(refTypedProgram.toJSON()); | ||
} catch (IOException e) { | ||
assumeNoException(e); | ||
} | ||
return outputNode; | ||
} | ||
|
||
@Comparison | ||
public static Boolean noncompare(JsonNode j1, JsonNode j2) { | ||
return true; | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
examples/src/test/java/cmu/pasta/mu2/examples/closure/ClosureTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package cmu.pasta.mu2.examples.closure; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.PrintStream; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.logging.LogManager; | ||
|
||
import com.google.javascript.jscomp.CompilationLevel; | ||
import com.google.javascript.jscomp.Compiler; | ||
import com.google.javascript.jscomp.CompilerOptions; | ||
import com.google.javascript.jscomp.Result; | ||
import com.google.javascript.jscomp.SourceFile; | ||
import com.pholser.junit.quickcheck.From; | ||
import edu.berkeley.cs.jqf.examples.common.AsciiStringGenerator; | ||
import edu.berkeley.cs.jqf.examples.js.JavaScriptCodeGenerator; | ||
import org.apache.commons.io.IOUtils; | ||
import org.junit.Assume; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import edu.berkeley.cs.jqf.fuzz.Fuzz; | ||
import edu.berkeley.cs.jqf.fuzz.JQF; | ||
import edu.berkeley.cs.jqf.fuzz.difffuzz.Comparison; | ||
import edu.berkeley.cs.jqf.fuzz.difffuzz.DiffFuzz; | ||
|
||
import static org.junit.Assume.assumeTrue; | ||
|
||
@RunWith(JQF.class) | ||
public class ClosureTest { | ||
|
||
static { | ||
// Disable all logging by Closure passes | ||
LogManager.getLogManager().reset(); | ||
} | ||
|
||
private Compiler compiler = new Compiler(new PrintStream(new ByteArrayOutputStream(), false)); | ||
private CompilerOptions options = new CompilerOptions(); | ||
private SourceFile externs = SourceFile.fromCode("externs", ""); | ||
|
||
@Before | ||
public void initCompiler() { | ||
// Don't use threads | ||
compiler.disableThreads(); | ||
// Don't print things | ||
options.setPrintConfig(false); | ||
// Enable all safe optimizations | ||
CompilationLevel.SIMPLE_OPTIMIZATIONS.setOptionsForCompilationLevel(options); | ||
} | ||
|
||
private void doCompile(SourceFile input) { | ||
Result result = compiler.compile(externs, input, options); | ||
Assume.assumeTrue(result.success); | ||
} | ||
|
||
public void testWithString(@From(AsciiStringGenerator.class) String code) { | ||
SourceFile input = SourceFile.fromCode("input", code); | ||
doCompile(input); | ||
} | ||
|
||
@DiffFuzz | ||
public String testWithGenerator(@From(JavaScriptCodeGenerator.class) String code) { | ||
testWithString(code); | ||
return compiler.toSource(); | ||
} | ||
|
||
@DiffFuzz(cmp = "noncompare") | ||
public String testWithGeneratorNoncompare(@From(JavaScriptCodeGenerator.class) String code) { | ||
testWithString(code); | ||
return compiler.toSource(); | ||
} | ||
|
||
@Fuzz(repro="${repro}") | ||
public void fuzzWithGenerator(@From(JavaScriptCodeGenerator.class) String code) { | ||
testWithString(code); | ||
compiler.toSource(); | ||
} | ||
|
||
@Comparison | ||
public static Boolean noncompare(String s1, String s2) { | ||
return true; | ||
} | ||
|
||
|
||
} |
66 changes: 66 additions & 0 deletions
66
examples/src/test/java/cmu/pasta/mu2/examples/gson/JsonTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package cmu.pasta.mu2.examples.gson; | ||
|
||
import edu.berkeley.cs.jqf.fuzz.Fuzz; | ||
import edu.berkeley.cs.jqf.fuzz.JQF; | ||
import edu.berkeley.cs.jqf.fuzz.difffuzz.Comparison; | ||
import edu.berkeley.cs.jqf.fuzz.difffuzz.DiffFuzz; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
import com.google.gson.JsonIOException; | ||
import com.google.gson.JsonSyntaxException; | ||
import com.pholser.junit.quickcheck.From; | ||
import edu.berkeley.cs.jqf.examples.common.AsciiStringGenerator; | ||
import org.junit.Assume; | ||
import org.junit.runner.RunWith; | ||
|
||
@RunWith(JQF.class) | ||
public class JsonTest { | ||
|
||
private GsonBuilder builder = new GsonBuilder(); | ||
private Gson gson = builder.setLenient().create(); | ||
|
||
@DiffFuzz | ||
public Object testJSONParser(@From(AsciiStringGenerator.class) String input) { | ||
Object out = null; | ||
try { | ||
out = gson.fromJson(input, Object.class); | ||
} catch (JsonSyntaxException e) { | ||
Assume.assumeNoException(e); | ||
} catch (JsonIOException e) { | ||
Assume.assumeNoException(e); | ||
} | ||
return out; | ||
} | ||
|
||
@Fuzz(repro="${repro}") | ||
public void fuzzJSONParser(@From(AsciiStringGenerator.class) String input) { | ||
Object out = null; | ||
try { | ||
out = gson.fromJson(input, Object.class); | ||
} catch (JsonSyntaxException e) { | ||
Assume.assumeNoException(e); | ||
} catch (JsonIOException e) { | ||
Assume.assumeNoException(e); | ||
} | ||
} | ||
|
||
@DiffFuzz(cmp = "noncompare") | ||
public Object testJSONParserNoncompare(@From(AsciiStringGenerator.class) String input) { | ||
Object out = null; | ||
try { | ||
out = gson.fromJson(input, Object.class); | ||
} catch (JsonSyntaxException e) { | ||
Assume.assumeNoException(e); | ||
} catch (JsonIOException e) { | ||
Assume.assumeNoException(e); | ||
} | ||
return out; | ||
} | ||
|
||
@Comparison | ||
public static Boolean noncompare(Object o1, Object o2) { | ||
return true; | ||
} | ||
|
||
} |
65 changes: 65 additions & 0 deletions
65
examples/src/test/java/cmu/pasta/mu2/examples/jackson/JsonTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package cmu.pasta.mu2.examples.jackson; | ||
|
||
import edu.berkeley.cs.jqf.fuzz.Fuzz; | ||
import edu.berkeley.cs.jqf.fuzz.JQF; | ||
import edu.berkeley.cs.jqf.fuzz.difffuzz.Comparison; | ||
import edu.berkeley.cs.jqf.fuzz.difffuzz.DiffFuzz; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.pholser.junit.quickcheck.From; | ||
import edu.berkeley.cs.jqf.examples.common.AsciiStringGenerator; | ||
|
||
import java.io.IOException; | ||
|
||
import org.junit.Assume; | ||
import org.junit.runner.RunWith; | ||
|
||
@RunWith(JQF.class) | ||
public class JsonTest { | ||
|
||
private ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
@DiffFuzz | ||
public Object testJsonReadValue(@From(AsciiStringGenerator.class) String input) { | ||
Object output = null; | ||
try { | ||
output = objectMapper.readValue(input, Object.class); | ||
} catch (JsonProcessingException e) { | ||
Assume.assumeNoException(e); | ||
} catch (IOException e) { | ||
Assume.assumeNoException(e); | ||
} | ||
return output; | ||
} | ||
|
||
@Fuzz(repro="${repro}") | ||
public void fuzzJsonReadValue(@From(AsciiStringGenerator.class) String input) { | ||
Object output = null; | ||
try { | ||
output = objectMapper.readValue(input, Object.class); | ||
} catch (JsonProcessingException e) { | ||
Assume.assumeNoException(e); | ||
} catch (IOException e) { | ||
Assume.assumeNoException(e); | ||
} | ||
} | ||
|
||
@DiffFuzz(cmp = "noncompare") | ||
public Object testJsonReadValueNoncompare(@From(AsciiStringGenerator.class) String input) { | ||
Object output = null; | ||
try { | ||
output = objectMapper.readValue(input, Object.class); | ||
} catch (JsonProcessingException e) { | ||
Assume.assumeNoException(e); | ||
} catch (IOException e) { | ||
Assume.assumeNoException(e); | ||
} | ||
return output; | ||
} | ||
|
||
@Comparison | ||
public static Boolean noncompare(Object o1, Object o2) { | ||
return true; | ||
} | ||
} |
Oops, something went wrong.