From 7d5dd7ac9b3265ad154eece58ed08889c8ed6f24 Mon Sep 17 00:00:00 2001 From: andrlos <80903703+andrlos@users.noreply.github.com> Date: Mon, 27 Nov 2023 19:47:21 +0100 Subject: [PATCH] multiplatforming testsuite (#4) ensuring that the testsuite runs on both windows and macos as well --- .github/workflows/test.yaml | 227 ++++++++++++++++++++++++++++++++++-- testHeadlessComponents.sh | 67 +++++++++-- 2 files changed, 274 insertions(+), 20 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 4341e0d..b446d96 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -12,8 +12,8 @@ env: WORKSPACE: /home/runner/workspace jobs: - test-temurin-sdk: - name: "Temurin jdk" + test-linux-sdk: + name: "Linux jdk" runs-on: "ubuntu-latest" strategy: fail-fast: false @@ -44,16 +44,16 @@ jobs: - name: Pack results if: ${{ always() }} run: | - tar -cf "results-jdk${{ matrix.jdkver || env.jdkver_latest }}.tar.gz" $WORKSPACE/testHeadlessComponent.log $WORKSPACE/testHeadlessComponent.jtr.xml + tar -cf "results-linux-jdk${{ matrix.jdkver || env.jdkver_latest }}.tar.gz" $WORKSPACE/testHeadlessComponent.log $WORKSPACE/testHeadlessComponent.jtr.xml - name: Upload results if: ${{ always() }} uses: actions/upload-artifact@v3 with: - path: "results-jdk${{ matrix.jdkver || env.jdkver_latest }}.tar.gz" + path: "results-linux-jdk${{ matrix.jdkver || env.jdkver_latest }}.tar.gz" continue-on-error: true - test-temurin-jre: - name: "Temurin jre" + test-linux-jre: + name: "Linux jre" runs-on: "ubuntu-latest" strategy: fail-fast: false @@ -84,11 +84,222 @@ jobs: - name: Pack results if: ${{ always() }} run: | - tar -cf "results-jre${{ matrix.jdkver || env.jdkver_latest }}.tar.gz" $WORKSPACE/testHeadlessComponent.log $WORKSPACE/testHeadlessComponent.jtr.xml + tar -cf "results-linux-jre${{ matrix.jdkver || env.jdkver_latest }}.tar.gz" $WORKSPACE/testHeadlessComponent.log $WORKSPACE/testHeadlessComponent.jtr.xml - name: Upload results if: ${{ always() }} uses: actions/upload-artifact@v3 with: - path: "results-jre${{ matrix.jdkver || env.jdkver_latest }}.tar.gz" + path: "results-linux-jre${{ matrix.jdkver || env.jdkver_latest }}.tar.gz" continue-on-error: true + test-windows-jre: + name: "Windows-jre" + runs-on: "windows-latest" + strategy: + fail-fast: false + matrix: + jdkconf: + - JDK 8 + - JDK 11 + - JDK 17 + - JDK Latest + include: + - jdkconf: JDK 8 + jdkver: "8" + - jdkconf: JDK 11 + jdkver: "11" + - jdkconf: JDK 17 + jdkver: "17" + steps: + - uses: actions/checkout@v3 + - uses: msys2/setup-msys2@v2 + with: + update: true + install: wget tar git unzip + + - uses: actions/checkout@v3 + - name: Set up JDK + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: ${{ matrix.jdkver || env.jdkver_latest }} + - name: Run + shell: msys2 {0} + run: | + export OJDK_VERSION_NUMBER=${{ matrix.jdkver || env.jdkver_latest }} BOOTJDK_DIR=~/bootjdk JRESDK="jre" + ./testHeadlessComponents.sh + - name: Pack results + if: ${{ always() }} + shell: msys2 {0} + run: | + tar -cf "results-windows-jre${{ matrix.jdkver || env.jdkver_latest }}.tar.gz" $WORKSPACE/testHeadlessComponent.log $WORKSPACE/testHeadlessComponent.jtr.xml + - name: Upload results + if: ${{ always() }} + uses: actions/upload-artifact@v3 + with: + path: "results-windows-jre${{ matrix.jdkver || env.jdkver_latest }}.tar.gz" + continue-on-error: true + + test-windows-jdk: + name: "Windows-jdk" + runs-on: "windows-latest" + strategy: + fail-fast: false + matrix: + jdkconf: + - JDK 8 + - JDK 11 + - JDK 17 + - JDK Latest + include: + - jdkconf: JDK 8 + jdkver: "8" + - jdkconf: JDK 11 + jdkver: "11" + - jdkconf: JDK 17 + jdkver: "17" + steps: + - uses: actions/checkout@v3 + - uses: msys2/setup-msys2@v2 + with: + update: true + install: wget tar git unzip + + - uses: actions/checkout@v3 + - name: Set up JDK + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: ${{ matrix.jdkver || env.jdkver_latest }} + - name: Run + shell: msys2 {0} + run: | + export OJDK_VERSION_NUMBER=${{ matrix.jdkver || env.jdkver_latest }} BOOTJDK_DIR=~/bootjdk JRESDK="jre" + ./testHeadlessComponents.sh + - name: Pack results + if: ${{ always() }} + shell: msys2 {0} + run: | + tar -cf "results-windows-jdk${{ matrix.jdkver || env.jdkver_latest }}.tar.gz" $WORKSPACE/testHeadlessComponent.log $WORKSPACE/testHeadlessComponent.jtr.xml + - name: Upload results + if: ${{ always() }} + uses: actions/upload-artifact@v3 + with: + path: "results-windows-jdk${{ matrix.jdkver || env.jdkver_latest }}.tar.gz" + continue-on-error: true + + test-macos-jre: + name: "MacOS-jre" + runs-on: "macos-latest" + strategy: + fail-fast: false + matrix: + jdkconf: + - JDK 8 + - JDK 11 + - JDK 17 + - JDK Latest + include: + - jdkconf: JDK 8 + jdkver: "8" + - jdkconf: JDK 11 + jdkver: "11" + - jdkconf: JDK 17 + jdkver: "17" + steps: + - uses: actions/checkout@v3 + - name: Install Homebrew + run: | + /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + echo 'eval $(/usr/local/bin/brew shellenv)' >> $HOME/.zprofile + eval $(/usr/local/bin/brew shellenv) + + - name: Install Bash with Homebrew + run: brew install bash + + - name: Update Shell Configuration + run: echo 'export PATH="/usr/local/bin:$PATH"' >> $HOME/.zprofile && exec -l $SHELL + + - name: Verify Bash Version + run: /usr/local/bin/bash --version + + - name: Set up JDK + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: ${{ matrix.jdkver || env.jdkver_latest }} + - name: Run + run: | + export OJDK_VERSION_NUMBER=${{ matrix.jdkver || env.jdkver_latest }} BOOTJDK_DIR=~/bootjdk JRESDK="jre" WORKSPACE=/Users/runner/workspace + /usr/local/bin/bash testHeadlessComponents.sh + - name: Pack results + if: ${{ always() }} + run: | + export WORKSPACE=/Users/runner/workspace + tar -cf "results-macos-jre${{ matrix.jdkver || env.jdkver_latest }}.tar.gz" $WORKSPACE/testHeadlessComponent.log $WORKSPACE/testHeadlessComponent.jtr.xml + - name: Upload results + if: ${{ always() }} + uses: actions/upload-artifact@v3 + with: + path: "results-macos-jre${{ matrix.jdkver || env.jdkver_latest }}.tar.gz" + continue-on-error: true + + test-macos-jdk: + name: "MacOS-jdk" + runs-on: "macos-latest" + env: + WORKSPACE: /home/runner/workspace + strategy: + fail-fast: false + matrix: + jdkconf: + - JDK 8 + - JDK 11 + - JDK 17 + - JDK Latest + include: + - jdkconf: JDK 8 + jdkver: "8" + - jdkconf: JDK 11 + jdkver: "11" + - jdkconf: JDK 17 + jdkver: "17" + steps: + - uses: actions/checkout@v3 + - name: Install Homebrew + run: | + /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + echo 'eval $(/usr/local/bin/brew shellenv)' >> $HOME/.zprofile + eval $(/usr/local/bin/brew shellenv) + + - name: Install Bash with Homebrew + run: brew install bash + + - name: Update Shell Configuration + run: echo 'export PATH="/usr/local/bin:$PATH"' >> $HOME/.zprofile && exec -l $SHELL + + - name: Verify Bash Version + run: /usr/local/bin/bash --version + + - name: Set up JDK + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: ${{ matrix.jdkver || env.jdkver_latest }} + - name: Run + run: | + export OJDK_VERSION_NUMBER=${{ matrix.jdkver || env.jdkver_latest }} BOOTJDK_DIR=~/bootjdk JRESDK="jdk" WORKSPACE=/Users/runner/workspace + /usr/local/bin/bash testHeadlessComponents.sh + - name: Pack results + if: ${{ always() }} + run: | + export WORKSPACE=/Users/runner/workspace + tar -cf "results-macos-jdk${{ matrix.jdkver || env.jdkver_latest }}.tar.gz" $WORKSPACE/testHeadlessComponent.log $WORKSPACE/testHeadlessComponent.jtr.xml + - name: Upload results + if: ${{ always() }} + uses: actions/upload-artifact@v3 + with: + path: "results-macos-jdk${{ matrix.jdkver || env.jdkver_latest }}.tar.gz" + continue-on-error: true + + diff --git a/testHeadlessComponents.sh b/testHeadlessComponents.sh index cbbcc49..a0c667a 100755 --- a/testHeadlessComponents.sh +++ b/testHeadlessComponents.sh @@ -18,6 +18,44 @@ while [ -h "$SCRIPT_SOURCE" ]; do # resolve $SOURCE until the file is no longer done readonly SCRIPT_DIR="$( cd -P "$( dirname "$SCRIPT_SOURCE" )" && pwd )" +# detecting platform +platform="$(uname)" +if [ "$platform" == "Linux" ]; then + # Linux-specific code + OS="linux" + JAVA=$JAVA_HOME/bin/java +elif [ "$platform" == "Darwin" ]; then + # Mac-specific code + OS="mac" + JAVA=$JAVA_HOME/bin/java + #JAVA=java +elif [ "${platform#"MINGW64_NT"}" != "$platform" ]; then + # Windows (Cygwin) specific code + OS="windows" + JAVA=$JAVA_HOME/bin/java +else + echo "Unsupported platform" + exit 1 +fi + +function unwrap_file_to_location() { + if [ "$OS" == "mac" -o "$OS" == "linux" ]; then + tar --strip-components=1 -xf $1 -C $2 + elif [ "$OS" == "windows" ]; then + unzip $1 -d $2 + # Get the name of the extracted folder (assuming only one folder is present) + ls $2 + extracted_folder_name=$(ls $2) + + # Ensure only one folder is found + if [ "$(ls $2 | wc -l)" -eq 1 ]; then + # Move the contents to the desired destination without creating a new directory + mv "$2/$extracted_folder_name"/* "$2" + else + echo "Error: More than one directory found in $2." + fi + fi +} function installAlternativeJDK() { ARCH=$( uname -m ) @@ -32,21 +70,21 @@ function installAlternativeJDK() { BOOTJDK_ARCHIVE_DIR=$WORKSPACE/bootjdkarchive mkdir -p $BOOTJDK_ARCHIVE_DIR cd $BOOTJDK_ARCHIVE_DIR - curl -OLJks "https://api.adoptopenjdk.net/v3/binary/latest/$OJDK_VERSION_NUMBER/ga/linux/$ARCH/jdk/hotspot/normal/adoptopenjdk" + curl -OLJks "https://api.adoptopenjdk.net/v3/binary/latest/$OJDK_VERSION_NUMBER/ga/$OS/$ARCH/jdk/hotspot/normal/adoptopenjdk" rm -rf ${BOOTJDK_DIR} mkdir -p ${BOOTJDK_DIR} - tar --strip-components=1 -xf ${BOOTJDK_ARCHIVE_DIR}/*.tar.gz -C ${BOOTJDK_DIR} + unwrap_file_to_location ${BOOTJDK_ARCHIVE_DIR}/* ${BOOTJDK_DIR} else rm -rf ${BOOTJDK_DIR} mkdir -p ${BOOTJDK_DIR} ls ${BOOTJDK_ARCHIVE_DIR} - tar --strip-components=1 -xf ${BOOTJDK_ARCHIVE_DIR}/*${ARCH}.tarxz -C ${BOOTJDK_DIR} + unwrap_file_to_location ${BOOTJDK_ARCHIVE_DIR}/*${ARCH}.tarxz ${BOOTJDK_DIR} fi } function run_java_with_headless { COMPONENTS_TO_TEST=$2 - java -cp $cp -Djava.awt.headless=$1 MainRunner -test=$COMPONENTS_TO_TEST -jreSdkHeadless=$JRESDK -displayValue=$DISPLAY + $JAVA -cp $cp -Djava.awt.headless=$1 MainRunner -test=$COMPONENTS_TO_TEST -jreSdkHeadless=$JRESDK -displayValue=$DISPLAY } function run_swing_component_test_unset { @@ -88,15 +126,13 @@ function processResults { if [ $1 -eq 0 ]; then let "PASSED+=1" - TEST=$(printXmlTest "tps" "$2" "0") - BODY+="$TEST - " # new line to improve clarity, also is used in TPS/tesultsToJtregs.sh + TEST=$(printXmlTest "thc" "$2" "0") + BODY+="$TEST" echo "$2 PASSED\n" else let "FAILED+=1" - TEST=$(printXmlTest "tps" "$2" "0" "$LOGFILE" "$LOGFILE") - BODY+="$TEST - " # new line to improve clarity, also is used in TPS/tesultsToJtregs.sh + TEST=$(printXmlTest "thc" "$2" "0" "$LOGFILE" "$LOGFILE") + BODY+="$TEST" echo "$2 FAILED\n" fi @@ -137,14 +173,18 @@ LOGFILE=$TMPRESULTS/testHeadlessComponent.log installAlternativeJDK JAVAC_BINARY="${BOOTJDK_DIR}/bin/javac" +if [ "$OS" == "mac" ]; then + JAVAC_BINARY="${BOOTJDK_DIR}/Contents/Home/bin/javac" +fi #use bootjdk javac #other classes depend on this one, so we might as well just compile the main class -cp -r $SCRIPT_DIR/testHeadlessComponents/ $WORKSPACE +cp -r $SCRIPT_DIR/testHeadlessComponents $WORKSPACE +ls $WORKSPACE pushd $WORKSPACE/testHeadlessComponents/jreTestingSwingComponents/src cp=`mktemp -d` -$JAVAC_BINARY `find -type f | grep .java` -d $cp +$JAVAC_BINARY `find . -type f -name "*.java"` -d $cp declare -A resArray set +e @@ -189,6 +229,9 @@ XMLREPORT=$TMPRESULTS/testHeadlessComponent.jtr.xml printXmlHeader $PASSED $FAILED $TESTS $IGNORED "testHeadlessComponent" > $XMLREPORT echo "$BODY" >> $XMLREPORT printXmlFooter >> $XMLREPORT +ls -la $XMLREPORT + +ls for val in ${resArray[@]}; do if [[ "$val" -ne "0" ]]; then