Skip to content

Commit

Permalink
Consolidate version-3 and Java-11 branches (#594)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Michael Ernst <[email protected]>
  • Loading branch information
rjust and mernst authored Sep 6, 2024
1 parent b26d272 commit 951c360
Show file tree
Hide file tree
Showing 23 changed files with 247 additions and 173 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ jobs:
- run: carton exec ./test_bug_mining.sh
name: test_bug_mining.sh
working-directory: "./framework/test"
- run: carton exec ./test_style.sh
name: test_style.sh
working-directory: "./framework/test"

# Verify a few select bugs to detect serious breakages early.
- run: carton exec ./test_verify_bugs.sh -p Collections -b 10 -A
Expand Down
32 changes: 17 additions & 15 deletions framework/lib/test_generation/bin/_tool.source
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/bin/bash
#
# This file provides helper functions for the wrapper shell scripts of the test
# generation tools. This file should be included in each wrapper shell script:
Expand All @@ -22,56 +23,57 @@ die() {
# Check whether an environment variable is set -- if not, die with an error message
check_env() {
local var="$1"
local val=$(eval echo \$$var)
local val
val="$(eval echo \$$var)"
[ -z "$val" ] && die "Variable $var not set!"
}

# Get the relative path (relative to the Defects4J working directory) to the
# source file of the provided class name.
get_rel_src_path() {
local class="$1"
local src_dir=$($D4J_HOME/framework/bin/defects4j \
export -p dir.src.classes -w $D4J_DIR_WORKDIR 2> /dev/null)
echo "$src_dir/$(echo $class | tr '.' '/').java"
local src_dir; src_dir=$("$D4J_HOME"/framework/bin/defects4j \
export -p dir.src.classes -w "$D4J_DIR_WORKDIR" 2> /dev/null)
echo "$src_dir/$(echo "$class" | tr '.' '/').java"
}

# Get the absolute path to the source file of the provided class name.
get_abs_src_path() {
local class="$1"
echo "$D4J_DIR_WORKDIR/$(get_rel_src_path $class)"
echo "$D4J_DIR_WORKDIR/$(get_rel_src_path "$class")"
}

# Get the project classpath -- that is, the classpath to compile and run the
# checked-out Defects4J project version.
get_project_cp() {
$D4J_HOME/framework/bin/defects4j \
export -p cp.compile -w $D4J_DIR_WORKDIR 2> /dev/null
"$D4J_HOME"/framework/bin/defects4j \
export -p cp.compile -w "$D4J_DIR_WORKDIR" 2> /dev/null
}

# Parse a tool's config file: ignore comments and replace newlines with spaces.
parse_config() {
local file=$1
grep -v "\s*#" $file | tr '\n' ' '
grep -v "\s*#" "$file" | tr '\n' ' '
}

# Returns the list of all classes for the current bug
get_all_classes() {
local src_dir=$($D4J_HOME/framework/bin/defects4j \
export -p dir.src.classes -w $D4J_DIR_WORKDIR 2> /dev/null)
(cd $D4J_DIR_WORKDIR/$src_dir && \
local src_dir; src_dir=$("$D4J_HOME"/framework/bin/defects4j \
export -p dir.src.classes -w "$D4J_DIR_WORKDIR" 2> /dev/null)
(cd "$D4J_DIR_WORKDIR/$src_dir" && \
find . -name "*.java" | tr '/' '.' | sed -e 's/^\.*//g' | sed -e 's/\.java//g')
}

# Returns the list of all relevant classes for the current bug
get_relevant_classes() {
$D4J_HOME/framework/bin/defects4j \
export -p classes.relevant -w $D4J_DIR_WORKDIR 2> /dev/null
"$D4J_HOME"/framework/bin/defects4j \
export -p classes.relevant -w "$D4J_DIR_WORKDIR" 2> /dev/null
}

# Returns the list of all modified classes for the current bug
get_modified_classes() {
$D4J_HOME/framework/bin/defects4j \
export -p classes.modified -w $D4J_DIR_WORKDIR 2> /dev/null
"$D4J_HOME"/framework/bin/defects4j \
export -p classes.modified -w "$D4J_DIR_WORKDIR" 2> /dev/null
}

# Output a command, execute it, and print whether it succeeded or failed.
Expand Down
18 changes: 9 additions & 9 deletions framework/lib/test_generation/bin/_tool.template
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
#
# Wrapper script for <generator name>
#
Expand Down Expand Up @@ -26,25 +26,25 @@ if [ -z "$D4J_DIR_TESTGEN_BIN" ]; then
fi

# General helper functions
source $D4J_DIR_TESTGEN_BIN/_tool.source
source "$D4J_DIR_TESTGEN_BIN"/_tool.source

# The classpath to compile and run the project
project_cp=$(get_project_cp)
project_cp="$(get_project_cp)"

# Read all additional configuration parameters
add_config=$(parse_config $D4J_DIR_TESTGEN_BIN/<generator id>.config)
add_config=$(parse_config "$D4J_DIR_TESTGEN_BIN"/<generator id>.config)

# Make sure the provided test mode is supported
if [ $D4J_TEST_MODE == "regression" ]; then
...
elif [ $D4J_TEST_MODE == "error-revealing" ]; then
...
if [ "$D4J_TEST_MODE" = "regression" ]; then
: # TODO ...
elif [ "$D4J_TEST_MODE" = "error-revealing" ]; then
: # TODO ...
else
die "Unsupported test mode: $D4J_TEST_MODE"
fi

# The command that invokes the test generator
cmd="... $add_config"
cmd="... $add_config ... $project_cp ..."

# Run the test-generation command
if ! exec_cmd "$cmd"; then
Expand Down
12 changes: 7 additions & 5 deletions framework/lib/test_generation/bin/evosuite.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ if [ -z "$D4J_DIR_TESTGEN_BIN" ]; then
fi

# General helper functions
source $D4J_DIR_TESTGEN_BIN/_tool.source
source "$D4J_DIR_TESTGEN_BIN"/_tool.source

# The classpath to compile and run the project
project_cp=$(get_project_cp)

# Read all additional configuration parameters
add_config=$(parse_config $D4J_DIR_TESTGEN_BIN/evosuite.config)
add_config=$(parse_config "$D4J_DIR_TESTGEN_BIN"/evosuite.config)

# Make sure the provided test mode is supported
if [ $D4J_TEST_MODE != "regression" ]; then
if [ "$D4J_TEST_MODE" != "regression" ]; then
die "Unsupported test mode: $D4J_TEST_MODE"
fi

Expand All @@ -47,10 +47,12 @@ if [[ $(tail -c1 "$D4J_FILE_TARGET_CLASSES" | wc -l) -eq 0 ]]; then
fi

# Compute the budget per target class; evenly split the time for search and assertions
num_classes=$(cat $D4J_FILE_TARGET_CLASSES | wc -l)
num_classes=$(wc -l < "$D4J_FILE_TARGET_CLASSES")
budget=$(echo "$D4J_TOTAL_BUDGET/2/$num_classes" | bc)

for class in $(cat $D4J_FILE_TARGET_CLASSES); do
# shellcheck disable=SC2013 # reading words rather than lines, I suppose
for class in $(cat "$D4J_FILE_TARGET_CLASSES"); do
#shellcheck disable=SC2153 # D4J_DIR_TESTGEN_LIB is not a typo of D4J_DIR_TESTGEN_BIN
cmd="java -cp $D4J_DIR_TESTGEN_LIB/evosuite-current.jar org.evosuite.EvoSuite \
-class $class \
-projectCP $project_cp \
Expand Down
2 changes: 2 additions & 0 deletions framework/lib/test_generation/bin/randoop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ REG_BASE_NAME=RegressionTest
ERR_BASE_NAME=ErrorTest

# Print Randoop version
#shellcheck disable=SC2153 # D4J_DIR_TESTGEN_LIB is not a typo of D4J_DIR_TESTGEN_BIN
version=$(java -cp "$D4J_DIR_TESTGEN_LIB/randoop-current.jar" randoop.main.Main | head -1)
printf "\n(%s)" "$version" >&2
# shellcheck disable=SC1083
printf ".%.0s" {1..expr 73 - length "$version"} >&2
printf " " >&2

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/src/test/java/com/fasterxml/jackson/databind/interop/IllegalTypesCheckTest.java b/src/test/java/com/fasterxml/jackson/databind/interop/IllegalTypesCheckTest.java
index f7d1517ed..0fc5e357d 100644
--- a/src/test/java/com/fasterxml/jackson/databind/interop/IllegalTypesCheckTest.java
+++ b/src/test/java/com/fasterxml/jackson/databind/interop/IllegalTypesCheckTest.java
@@ -80,7 +80,7 @@ public class IllegalTypesCheckTest extends BaseMapTest
public void testJDKTypes1855() throws Exception
{
// apparently included by JDK?
- _testIllegalType("com.sun.org.apache.bcel.internal.util.ClassLoader");
+// _testIllegalType("com.sun.org.apache.bcel.internal.util.ClassLoader");

// also: we can try some form of testing, even if bit contrived...
_testIllegalType(BogusPointcutAdvisor.class);
13 changes: 13 additions & 0 deletions framework/projects/JacksonDatabind/compile-errors/test-93-97.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/src/test/java/com/fasterxml/jackson/databind/interop/IllegalTypesCheckTest.java b/src/test/java/com/fasterxml/jackson/databind/interop/IllegalTypesCheckTest.java
index f7d1517ed..0fc5e357d 100644
--- a/src/test/java/com/fasterxml/jackson/databind/interop/IllegalTypesCheckTest.java
+++ b/src/test/java/com/fasterxml/jackson/databind/interop/IllegalTypesCheckTest.java
@@ -80,7 +80,7 @@ public class IllegalTypesCheckTest extends BaseMapTest
public void testJDKTypes1855() throws Exception
{
// apparently included by JDK?
- _testIllegalType("com.sun.org.apache.bcel.internal.util.ClassLoader");
+// _testIllegalType("com.sun.org.apache.bcel.internal.util.ClassLoader");

// also: we can try some form of testing, even if bit contrived...
_testIllegalType(BogusPointcutAdvisor.class);
13 changes: 13 additions & 0 deletions framework/projects/JacksonDatabind/compile-errors/test-99-109.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/src/test/java/com/fasterxml/jackson/databind/interop/IllegalTypesCheckTest.java b/src/test/java/com/fasterxml/jackson/databind/interop/IllegalTypesCheckTest.java
index f7d1517ed..0fc5e357d 100644
--- a/src/test/java/com/fasterxml/jackson/databind/interop/IllegalTypesCheckTest.java
+++ b/src/test/java/com/fasterxml/jackson/databind/interop/IllegalTypesCheckTest.java
@@ -80,7 +80,7 @@ public class IllegalTypesCheckTest extends BaseMapTest
public void testJDKTypes1855() throws Exception
{
// apparently included by JDK?
- _testIllegalType("com.sun.org.apache.bcel.internal.util.ClassLoader");
+// _testIllegalType("com.sun.org.apache.bcel.internal.util.ClassLoader");

// also: we can try some form of testing, even if bit contrived...
_testIllegalType(BogusPointcutAdvisor.class);
6 changes: 3 additions & 3 deletions framework/projects/Mockito/chooseDepedencyVersion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
# $1 = workDir
# $2 = D4J_HOME

cd $1
cd "$1" || (echo "cannot cd to workdir $1" && exit 1)
./gradlew dependencies >> tmpDepend.txt
if grep -q buddy tmpDepend.txt; then
version=`cat tmpDepend.txt | grep buddy | cut -d: -f 3 | head -1`
cp $2/framework/projects/Mockito/byte-buddy/byte-buddy-$version.jar $1/compileLib/
version=$(grep buddy tmpDepend.txt | head -1 | cut -d: -f 3)
cp "$2/framework/projects/Mockito/byte-buddy/byte-buddy-$version.jar" "$1/compileLib/"
fi
rm tmpDepend.txt
12 changes: 7 additions & 5 deletions framework/projects/Mockito/setMutationCompiler.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
# $1 = working directory
# $2 = location of Defects4J (D4J_HOME)

WORK_DIR=$1
D4J_HOME=$2
WORK_DIR="$1"
D4J_HOME="$2"

BUILD_FILE="build.gradle"

echo >> $WORK_DIR/$BUILD_FILE
echo "compileJava.options.fork = true" >> $WORK_DIR/$BUILD_FILE
echo "compileJava.options.forkOptions.executable = '$D4J_HOME/major/bin/major'" >> $WORK_DIR/$BUILD_FILE
{
echo;
echo "compileJava.options.fork = true";
echo "compileJava.options.forkOptions.executable = '$D4J_HOME/major/bin/major'";
} >> "$WORK_DIR/$BUILD_FILE"
15 changes: 9 additions & 6 deletions framework/test/get_klocs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
################################################################################

# Must use Java version 8.
JAVA_VERSION_STRING=`java -version 2>&1 | head -1`
JAVA_RELEASE_NUMBER=`echo $JAVA_VERSION_STRING | sed 's/^.*1\.\(.\).*/\1/'`
JAVA_VERSION_STRING=$(java -version 2>&1 | head -1)
# shellcheck disable=SC2001 # variable substitution does not suffice; needs sed.
JAVA_RELEASE_NUMBER=$(echo "$JAVA_VERSION_STRING" | sed 's/^.*1\.\(.\).*/\1/')
if [[ "$JAVA_RELEASE_NUMBER" != "8" ]]; then
echo Must use Java version 8
exit
Expand Down Expand Up @@ -37,18 +38,20 @@ if [ -z "$1" ] ; then
bids=( 1 2 3 4 5 )
else
# Generate tests for supplied project list
# shellcheck disable=SC2206
projects=( $1 )
if [ -z "$2" ] ; then
# Generate tests for all bids
bids=( 1 2 3 4 5 )
else
# Generate tests for supplied bid list
# shellcheck disable=SC2206
bids=( $2 )
fi
fi

echo "Projects: ${projects[@]}"
echo "Bug ids: ${bids[@]}"
echo "Projects: " "${projects[@]}"
echo "Bug ids: " "${bids[@]}"

# We want the 'fixed' version of the sample.
type=f
Expand All @@ -57,9 +60,9 @@ for pid in "${projects[@]}"; do
for bid in "${bids[@]}"; do
vid=${bid}$type

run_klocs.pl -p $pid -v $vid -n 1 -o $randoop_dir || die "run klocs on $pid-$vid"
run_klocs.pl -p "$pid" -v "$vid" -n 1 -o "$randoop_dir" || die "run klocs on $pid-$vid"
done
done

# delete tmp file directory
rm -rf $randoop_dir
rm -rf "$randoop_dir"
3 changes: 2 additions & 1 deletion framework/test/test.include
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ print_result() {
printf "\n$text\n" 1>&2
}

# Print and log error message, and terminate script if HALT_ON_ERROR is set
# Print and log error message, and set ERROR.
# Terminate script if HALT_ON_ERROR is set.
# die <error_text>
die() {
echo "Error: $1" 1>&2
Expand Down
Loading

0 comments on commit 951c360

Please sign in to comment.