Skip to content

Commit

Permalink
Merge tag 'thunderdome1.0.0'
Browse files Browse the repository at this point in the history
1.0.0
  • Loading branch information
Lyuben Todorov committed May 8, 2022
2 parents 8730aed + 6aad594 commit cac319b
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 2 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
name: Upload custom evosuite jar

on:
push:
branches:
- 'release/**'

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'adopt'
- run: mvn package -e -B -DskipTests=true
- run: zip -j release master/target/evosuite-master-*-SNAPSHOT.jar
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false
- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./release.zip
asset_name: release.zip
asset_content_type: application/zip
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import java.util.Map;
import java.util.Set;

class TestGenerationResultImpl<T extends Chromosome<T>> implements TestGenerationResult<T> {
public class TestGenerationResultImpl<T extends Chromosome<T>> implements TestGenerationResult<T> {

private static final long serialVersionUID = 1306033906557741929L;

Expand Down Expand Up @@ -230,6 +230,10 @@ public Set<Integer> getCoveredLines(String name) {
return testLineCoverage.get(name);
}

public Set<String> getTestCaseKeySet() {
return testCases.keySet();
}

@Override
public String toString() {
StringBuilder builder = new StringBuilder();
Expand Down
6 changes: 6 additions & 0 deletions master/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@
<artifactId>javax.activation-api</artifactId>
<version>1.2.0</version>
</dependency>
<!-- Serializing output in quiet mode -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.9.0</version>
</dependency>
</dependencies>


Expand Down
7 changes: 7 additions & 0 deletions master/src/main/java/org/evosuite/CommandLineParameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ public static Options getCommandLineOptions() {
parallel.setArgs(3);
parallel.setArgName("n i x");

Option serializeResult = new Option("serializeResult", "Serialize test generation result object to a file. Requires -serializeResultPath.");
Option serializeResultPath = new Option("serializeResultPath", true,"Path to the file where the test generation result object will be serialized to.");



@SuppressWarnings("static-access")
Option property = OptionBuilder.withArgName("property=value").hasArgs(2).withValueSeparator().withDescription("use value for given property").create("D");
Expand Down Expand Up @@ -161,6 +165,9 @@ public static Options getCommandLineOptions() {
options.addOption(startedByCtg);
options.addOption(parallel);

options.addOption(serializeResult);
options.addOption(serializeResultPath);

return options;
}

Expand Down
29 changes: 28 additions & 1 deletion master/src/main/java/org/evosuite/EvoSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,30 @@

package org.evosuite;

import com.google.gson.Gson;
import org.apache.commons.cli.*;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.SystemUtils;
import org.evosuite.classpath.ClassPathHacker;
import org.evosuite.executionmode.*;
import org.evosuite.junit.writer.TestSuiteWriterUtils;
import org.evosuite.result.TestGenerationResult;
import org.evosuite.result.TestGenerationResultImpl;
import org.evosuite.runtime.sandbox.MSecurityManager;
import org.evosuite.runtime.util.JavaExecCmdUtil;
import org.evosuite.setup.InheritanceTree;
import org.evosuite.setup.InheritanceTreeGenerator;
import org.evosuite.utils.LoggingUtils;
import org.evosuite.utils.Randomness;
import org.evosuite.utils.SpawnProcessKeepAliveChecker;
import org.evosuite.utils.CompactReport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -332,8 +338,29 @@ public Object parseCommandLine(String[] args) {
return Continuous.execute(options, javaOpts, line);
}

return TestGeneration.executeTestGeneration(options, javaOpts, line);

logger.info("TEST GENERATION START");
List<List<TestGenerationResult>> result = TestGeneration.executeTestGeneration(options, javaOpts, line);
logger.info("TEST GENERATION OVER");

if (line.hasOption("serializeResult")) {
String serializePath = line.getOptionValue("serializeResultPath");

logger.info("Serializing test generation report to " + serializePath);

TestGenerationResultImpl testGenerationResult = (TestGenerationResultImpl) result.get(0).get(0);

try (PrintWriter out = new PrintWriter(new FileWriter(serializePath))) {
Gson gson = new Gson();
CompactReport compactReport = new CompactReport(testGenerationResult);
String jsonReport = gson.toJson(compactReport);
out.write(jsonReport);
} catch (IOException e) {
logger.error("Error writing file to output stream: " + e);
}
}

return result;
} catch (ParseException exp) {
// oops, something went wrong
logger.error("Parsing failed. Reason: " + exp.getMessage());
Expand Down
35 changes: 35 additions & 0 deletions master/src/main/java/org/evosuite/utils/CompactReport.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.evosuite.utils;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Set;

import org.evosuite.result.BranchInfo;
import org.evosuite.result.MutationInfo;
import org.evosuite.result.TestGenerationResultImpl;

public class CompactReport implements Serializable {
public String UUT;
public String testSuiteCode;
public Set<Integer> allCoveredLines;
public Set<Integer> allUncoveredLines;
public Set<BranchInfo> allCoveredBranches;
public Set<BranchInfo> allUncoveredBranches;
public Set<MutationInfo> allCoveredMutation;
public Set<MutationInfo> allUncoveredMutation;

public HashMap<String, CompactTestCase> testCaseList;

public CompactReport(TestGenerationResultImpl<?> testGenerationResult) {
this.allCoveredLines = testGenerationResult.getCoveredLines();
this.UUT = testGenerationResult.getClassUnderTest();
this.testSuiteCode = testGenerationResult.getTestSuiteCode();
this.testCaseList = CompactTestCase.buildTestCaseList(testGenerationResult);
this.allUncoveredLines = testGenerationResult.getUncoveredLines();
this.allCoveredBranches = testGenerationResult.getCoveredBranches();
this.allUncoveredBranches = testGenerationResult.getUncoveredBranches();
this.allCoveredMutation = testGenerationResult.getCoveredMutants();
this.allUncoveredMutation = testGenerationResult.getUncoveredMutants();
}
}

50 changes: 50 additions & 0 deletions master/src/main/java/org/evosuite/utils/CompactTestCase.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.evosuite.utils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;
import org.evosuite.coverage.mutation.Mutation;
import org.evosuite.result.BranchInfo;
import org.evosuite.result.MutationInfo;
import org.evosuite.result.TestGenerationResultImpl;
import org.evosuite.testcase.TestCase;

public class CompactTestCase implements Serializable {
public String testName;
public String testCode;
public Set<Integer> coveredLines;
public Set<BranchInfo> coveredBranches;
public Set<MutationInfo> coveredMutants;

public CompactTestCase(String testName, String testCode, Set<Integer> coveredLines, Set<BranchInfo> coveredBranches, Set<MutationInfo> coveredMutants) {
this.testName = testName;
this.testCode = testCode;
this.coveredLines = coveredLines;
this.coveredBranches = coveredBranches;
this.coveredMutants = coveredMutants;
}

public static HashMap<String, CompactTestCase> buildTestCaseList(TestGenerationResultImpl<?> testGenerationResult) {
HashMap<String, CompactTestCase> map = new HashMap<>();

Set<String> keySet = testGenerationResult.getTestCaseKeySet();

for(String key: keySet){
TestCase testCase = testGenerationResult.getTestCase(key);
// see what is exposed by TestCase
String testCode = testGenerationResult.getTestCode(key);
Set<Integer> coveredLines = testGenerationResult.getCoveredLines(key);
Set<BranchInfo> coveredBranches = testGenerationResult.getCoveredBranches(key);
Set<MutationInfo> coveredMutants = testGenerationResult.getCoveredMutants(key);

CompactTestCase compactTestCase = new CompactTestCase(key, testCode, coveredLines, coveredBranches, coveredMutants);
map.put(key, compactTestCase);
}


return map;
}


}

0 comments on commit cac319b

Please sign in to comment.