Skip to content

Commit

Permalink
Add artifact benchmarks to examples (#83)
Browse files Browse the repository at this point in the history
* Add new targets
  • Loading branch information
vasumv authored Jul 26, 2023
1 parent 0262676 commit acd7d7d
Show file tree
Hide file tree
Showing 15 changed files with 1,596 additions and 0 deletions.
57 changes: 57 additions & 0 deletions examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>mu2-examples</artifactId>
<repositories>
<repository>
<id>central</id>
<url>https://repo1.maven.org/maven2</url>
</repository>
<repository>
<id>chocopy-artifacts</id>
<name>chocopy/chocopy artifacts</name>
<url>https://raw.githubusercontent.com/chocopy/artifacts/main</url>
</repository>
</repositories>

<dependencies>
<dependency>
Expand All @@ -29,16 +40,62 @@
<version>2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>edu.berkeley.cs.jqf</groupId>
<artifactId>jqf-examples</artifactId>
<version>2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.13.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.chocopy</groupId>
<artifactId>chocopy-artifacts</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-catalina</artifactId>
<version>10.1.0-M10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.javascript</groupId>
<artifactId>closure-compiler</artifactId>
<version>v20220202</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>edu.berkeley.cs.jqf</groupId>
<artifactId>jqf-maven-plugin</artifactId>
<version>2.0</version>
</plugin>
<plugin>
<groupId>cmu.pasta.mu2</groupId>
<artifactId>mu2-core</artifactId>
<version>1.0-SNAPSHOT</version>
</plugin>
<plugin>
<groupId>cmu.pasta.mu2</groupId>
<artifactId>mu2-core</artifactId>
Expand Down
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;
}
}
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 examples/src/test/java/cmu/pasta/mu2/examples/gson/JsonTest.java
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;
}

}
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;
}
}
Loading

0 comments on commit acd7d7d

Please sign in to comment.