1#! /bin/bash 2# 3# Copyright (C) 2024 The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# 16 17# Allows testing of a locally publish uber jar with against an 18# arbitrary Java version using the JUnit console test runner (which 19# will be downloaded if not present). 20# 21# First build and locally publish an uber jar, e.g. using 22# publishLocalUber.sh 23# 24# Second set up the version of Java to be used for testing, e.g. by 25# setting JAVA_HOME 26# 27# Then run this script which will download the JUnit runner if needed, 28# build the Conscrypt testJar and then run the tests. 29# 30# Essentially these are the same steps as the final test matrix in the 31# Github CI script. 32 33CONSCRYPT_HOME="${CONSCRYPT_HOME:-$HOME/src/conscrypt}" 34BUILD="$CONSCRYPT_HOME/build.gradle" 35M2_REPO="${M2_REPO:-$HOME/.m2/repository}" 36PUBLISH_DIR="${M2_REPO}/org/conscrypt" 37TMPDIR="${TMPDIR:-$HOME/tmp/conscrypt}" 38JUNITJAR="$TMPDIR/junit-platform-console-standalone.jar" 39 40die() { 41 echo "*** " $@ 42 exit 1 43} 44 45usage() { 46 echo "testLocalUber.sh [args]" 47 echo "" 48 echo "-h, --help Help" 49 echo "-v, --verbose Verbose test output" 50 echo "-d, --debug Wait for debugger on test startup" 51 exit 0 52} 53 54while [ "$1" ]; do 55 case "$1" in 56 -v|--verbose) 57 VERBOSE="--details=verbose" 58 ;; 59 -d|--debug) 60 JAVADEBUG="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005" 61 ;; 62 -h|--help) 63 usage 64 ;; 65 *) 66 die "Unknown argument $1 - try --help" 67 ;; 68 esac 69 shift 70done 71 72mkdir -p "$TMPDIR" || die "Unable to create ${TMPDIR}." 73 74test -f "$BUILD" || die "Conscrypt build.gradle file not found. Check CONSCRYPT_HOME." 75VERSION=$(sed -nE 's/^ *version *= *"(.*)"/\1/p' $BUILD) 76test "$VERSION" || die "Unable to figure out Conscrypt version." 77echo "Conscrypt version ${VERSION}." 78 79echo "Java version:" 80java -version || die "Cannot run Java." 81 82UBERJAR="${PUBLISH_DIR}/conscrypt-openjdk-uber/$VERSION/conscrypt-openjdk-uber-${VERSION}.jar" 83TESTJAR="${CONSCRYPT_HOME}/openjdk/build/libs/conscrypt-openjdk-${VERSION}-tests.jar" 84test -f "$UBERJAR" || die "Uber jar not found: ${UBERJAR}." 85 86 87if [ -f "$JUNITJAR" ]; then 88 echo "JUnit console runner: ${JUNITJAR}." 89else 90 echo "Downloading JUnit console runner." 91 mvn org.apache.maven.plugins:maven-dependency-plugin:3.8.0:copy \ 92 -Dartifact=org.junit.platform:junit-platform-console-standalone:1.11.2 \ 93 -DoutputDirectory="$TMPDIR" \ 94 -Dmdep.stripVersion=true \ 95 || die "Maven download of junit failed." 96fi 97test -f "$JUNITJAR" || die "JUnit not found." 98 99echo "Building test jar." 100cd $CONSCRYPT_HOME 101./gradlew :conscrypt-openjdk:testJar --console=plain 102test -f "$TESTJAR" || die "Test jar not built." 103 104echo "Running tests." 105java $JAVADEBUG -jar "$JUNITJAR" execute -cp "${UBERJAR}:${TESTJAR}" \ 106 -n='org.conscrypt.ConscryptOpenJdkSuite' \ 107 --scan-classpath --reports-dir=. \ 108 --fail-if-no-tests $VERBOSE 109