| #!/bin/bash |
| # Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file |
| # for details. All rights reserved. Use of this source code is governed by a |
| # BSD-style license that can be found in the LICENSE file. |
| |
| function generate_test() { |
| local name=$1 |
| local testClassName=$2 |
| local fileName=$3 |
| local compilerUnderTest=$4 |
| local classFile=$5 |
| local relativePackage=$6 |
| # The bash uppercase substitution ^^ is not supported on the bash version on Mac OS. |
| local compilerUnderTestEnum=$(echo ${compilerUnderTest} | tr /a-z/ /A-Z/) |
| |
| PACKAGE_PREFIX="com.google.jctf.test.lib.java." |
| |
| if [[ ! $name =~ ^$PACKAGE_PREFIX ]]; then |
| echo "Test full class name expected to start with \"$PACKAGE_PREFIX\" but it's \"$name\"" >&2 |
| exit 1 |
| fi |
| |
| mkdir -p $(dirname $fileName) |
| |
| cat <<EOF > $fileName |
| // Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file |
| // for details. All rights reserved. Use of this source code is governed by a |
| // BSD-style license that can be found in the LICENSE file. |
| package com.android.tools.r8.jctf.${compilerUnderTest}.${relativePackage}; |
| |
| import org.junit.Test; |
| import com.android.tools.r8.R8RunArtTestsTest; |
| |
| /** |
| * Auto-generated test for the jctf test: |
| * ${name} |
| * |
| * DO NOT EDIT THIS FILE. EDIT THE HERE DOCUMENT TEMPLATE IN scripts/create-jctf-tests.sh INSTEAD! |
| */ |
| public class ${testClassName} extends R8RunArtTestsTest { |
| |
| public ${testClassName}() { |
| super("${name:${#PACKAGE_PREFIX}}", DexTool.NONE); |
| } |
| |
| @Test |
| public void run${testClassName}() throws Exception { |
| // For testing with other Art VMs than the default set the system property 'dex_vm' |
| // to the desired VM string (e.g. '4.4.4', see ToolHelper.DexVm) |
| runJctfTest(CompilerUnderTest.${compilerUnderTestEnum}, |
| "$classFile", |
| "$name" |
| ); |
| } |
| } |
| EOF |
| } |
| |
| JCTFROOT="third_party/jctf" |
| DESTINATIONDIR="build/generated/test/java/com/android/tools/r8/jctf" |
| |
| if [ ! -e $JCTFROOT ]; then |
| echo "Missing jctf tests in $JCTFROOT." |
| exit |
| fi |
| |
| for d in $DESTINATIONDIR/r8 $DESTINATIONDIR/d8; do |
| rm -rf $d |
| mkdir -p $d |
| done |
| |
| RELATIVE_TESTDIR="LibTests/src/com/google/jctf/test/lib/java" |
| TESTDIR="$JCTFROOT/$RELATIVE_TESTDIR" |
| |
| COUNT=$(grep -r "@Test" "$TESTDIR" --include=*.java -l | wc -l) |
| echo "JCTF: $COUNT files to generate" |
| |
| grep -r "@Test" "$TESTDIR" --include=*.java -l | while read -r line; do |
| TESTNAME=$(basename $line .java) |
| TESTCLASSNAME="${TESTNAME//-/_}" |
| |
| RELATIVE_TEST_PATH=$(expr "$line" : ".*$RELATIVE_TESTDIR/\(.*$\)") |
| |
| PACKAGE=$(grep package $line | grep -o -m 1 "com[^;]*") |
| CLASSFILE="$(echo $PACKAGE | tr '.' '/')/$TESTNAME.class" |
| RELATIVE_PACKAGE=$(expr "$PACKAGE" : ".*\.java\.\(.*$\)") |
| |
| generate_test $PACKAGE.$TESTNAME $TESTCLASSNAME \ |
| "$DESTINATIONDIR/r8/$RELATIVE_TEST_PATH" r8 \ |
| $CLASSFILE $RELATIVE_PACKAGE |
| generate_test $PACKAGE.$TESTNAME $TESTCLASSNAME \ |
| "$DESTINATIONDIR/d8/$RELATIVE_TEST_PATH" d8 \ |
| $CLASSFILE $RELATIVE_PACKAGE |
| done |
| |