| #!/bin/bash -ex |
| # |
| # Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. |
| # |
| # This program and the accompanying materials are made available under the |
| # terms of the Eclipse Public License v. 2.0, which is available at |
| # http://www.eclipse.org/legal/epl-2.0. |
| # |
| # This Source Code may also be made available under the following Secondary |
| # Licenses when the conditions for such availability set forth in the |
| # Eclipse Public License v. 2.0 are satisfied: GNU General Public License, |
| # version 2 with the GNU Classpath Exception, which is available at |
| # https://www.gnu.org/software/classpath/license.html. |
| # |
| # SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 |
| # |
| |
| |
| # OS-specific section |
| if [ `uname | grep -i "sunos" | wc -l | awk '{print $1}'` -eq 1 ] ; then |
| GREP="ggrep" |
| AWK="gawk" |
| SED="gsed" |
| BC="gbc" |
| export PATH=/gf-hudson-tools/bin:${PATH} |
| else |
| GREP="grep" |
| AWK="awk" |
| SED="sed" |
| BC="bc" |
| fi |
| export GREP AWK SED BC |
| |
| kill_clean(){ |
| if [ ${#1} -ne 0 ] |
| then |
| kill -9 ${1} || true |
| fi |
| } |
| |
| kill_process(){ |
| printf "\n%s \n\n" "===== KILL THEM ALL =====" |
| kill_clean `jps | grep ASMain | awk '{print $1}'` |
| kill_clean `jps | grep DerbyControl | awk '{print $1}'` |
| kill_clean `jps | grep DirectoryServer | awk '{print $1}'` |
| } |
| test_init(){ |
| printf "\n%s \n\n" "===== V2 DEV TESTS INIT =====" |
| S1AS_HOME=$WORKSPACE/glassfish5/glassfish; export S1AS_HOME |
| APS_HOME=$WORKSPACE/main/appserver/tests/appserv-tests; export APS_HOME |
| TEST_RUN_LOG=tests-run.log; export TEST_RUN_LOG |
| export M2_HOME=$MAVEN_3_0_3 |
| #workaround for OSGI timestamp issue |
| find $S1AS_HOME -type f | xargs touch > /dev/null |
| echo S1AS_HOME is $S1AS_HOME |
| echo ANT_HOME is $ANT_HOME |
| echo M2_HOME is $M2_HOME |
| echo APS_HOME is $APS_HOME |
| PATH=$M2_HOME/bin:$ANT_HOME/bin:$PATH; export PATH |
| java -version |
| ant -version |
| rm -rf $WORKSPACE/results |
| mkdir -p $WORKSPACE/results/junitreports |
| } |
| |
| ql_init(){ |
| printf "\n%s \n\n" "===== QUICK LOOK INIT =====" |
| export M2_HOME=$MAVEN_3_0_3 |
| export PATH=$MAVEN_3_0_3/bin:$JAVA_HOME/bin:/usr/bin:/usr/local/bin:/usr/home/java_re/bin:$PATH |
| TEST_RUN_LOG=tests-run.log; export TEST_RUN_LOG |
| java -version |
| mvn -version |
| rm -rf $WORKSPACE/results |
| mkdir -p $WORKSPACE/results/junitreports |
| } |
| |
| download_test_resources(){ |
| printf "\n%s \n\n" "===== DOWNLOAD TEST RESOURCES =====" |
| for i in "$@"; do |
| echo downloading $i |
| scp -o "StrictHostKeyChecking no" ${PARENT_NODE}:${PARENT_WS_PATH}/bundles/$i bundles |
| done |
| } |
| |
| zip_test_results(){ |
| printf "\n%s \n\n" "===== ZIP THE TESTS RESULTS =====" |
| zip -r $WORKSPACE/results.zip $WORKSPACE/results > /dev/nul |
| } |
| |
| upload_test_results(){ |
| printf "\n%s \n\n" "===== UPLOADING THE TESTS RESULTS =====" |
| scp -o "StrictHostKeyChecking no" -r $WORKSPACE/results/ ${PARENT_NODE}:${PARENT_WS_PATH}/test-results/$TEST_ID/ |
| } |
| |
| unzip_test_resources(){ |
| printf "\n%s \n\n" "===== UNZIP TEST RESOURCES =====" |
| for i in "$@"; do |
| unzip $i > /dev/null |
| done |
| } |
| |
| |
| copy_test_artifects(){ |
| printf "\n%s \n\n" "===== COPY TEST ARTIFECTs =====" |
| zip -r $WORKSPACE/results/domainArchive.zip $S1AS_HOME/domains |
| cp $S1AS_HOME/domains/domain1/logs/server.log* $WORKSPACE/results/ || true |
| cp $TEST_RUN_LOG $WORKSPACE/results/ |
| cp $WORKSPACE/bundles/version-info.txt $WORKSPACE/results/ |
| cp $APS_HOME/test_results*.* $WORKSPACE/results/ || true |
| cp `pwd`/*/*logs.zip $WORKSPACE/results/ || true |
| cp `pwd`/*/*/*logs.zip $WORKSPACE/results/ || true |
| } |
| |
| |
| generate_junit_report(){ |
| printf "\n%s \n\n" "===== GENERATE JUNIT REPORT =====" |
| TD=$APS_HOME/test_resultsValid.xml |
| JUD=$APS_HOME/test_results_junit.xml |
| TESTSUITE_NAME=$1 |
| |
| cat ${TD} | ${AWK} -v suitename=${TESTSUITE_NAME} ' |
| BEGIN { |
| totaltests = 0; |
| totalfailures = 0; |
| totalerrors = 0; |
| } |
| function getPropVal(str){ |
| split(str, a, "="); |
| val = a[2]; |
| # remove quotes |
| gsub("\"","",val); |
| return val; |
| } |
| function removeXMLTag(str){ |
| # remove xml tag quotes |
| gsub("</.*>","",str); |
| gsub("<.*>","",str); |
| gsub(">","",str); |
| return str; |
| } |
| /status value=/ { |
| result=getPropVal($0); |
| result=removeXMLTag(result); |
| } |
| /<testsuite>/ { |
| getline; |
| getline; |
| testunit=removeXMLTag($0); |
| gsub("\"","",testunit); |
| } |
| /<testcase>/ { |
| getline; |
| testname=removeXMLTag($0); |
| gsub("\"","",testname); |
| } |
| /<\/testcase>/{ |
| classname=testunit |
| # printing testcase to out |
| out = out sprintf(" <testcase classname=\"%s\" name=\"%s\" time=\"0.0\">\n", classname, testname); |
| if (result == "fail") { |
| out = out " <failure message=\"NA\" type=\"NA\"/>\n"; |
| totalfailures++; |
| } else if (result == "did_not_run") { |
| out = out " <error message=\"NA\" type=\"NA\"/>\n"; |
| totalerrors++; |
| } |
| out = out " </testcase>\n"; |
| |
| totaltests++; |
| result=""; |
| testname=""; |
| } |
| END { |
| print "<?xml version=\"1.0\" ?>" |
| printf "<testsuite tests=\"%d\" failures=\"%d\" errors=\"%d\" name=\"%s\">\n", totaltests, totalfailures, totalerrors, suitename; |
| printf "%s", out; |
| print "</testsuite>" |
| }' > ${JUD} |
| cp $JUD $WORKSPACE/results/junitreports |
| } |
| |
| change_junit_report_class_names(){ |
| ${SED} -i 's/\([a-zA-Z-]\w*\)\./\1-/g' $WORKSPACE/results/junitreports/*.xml |
| ${SED} -i "s/\bclassname=\"/classname=\"${TEST_ID}./g" $WORKSPACE/results/junitreports/*.xml |
| } |
| |
| |
| check_successful_run(){ |
| printf "\n%s \n\n" "===== CHECK SUCCESSFUL RUN =====" |
| #checking that test_results.html is generated to make sure the build is not failed |
| FILE=$APS_HOME/test_results.html |
| if [ -f $FILE ];then |
| echo "File $FILE exists.Test build successful" |
| else |
| echo "File $FILE does not exist.There is problem in test build." |
| exit 1 |
| fi |
| } |
| |
| delete_gf(){ |
| printf "\n%s \n\n" "===== DELETE GLASSFISH AND MAVEN LOCAL REPO AND NUCLEUS =====" |
| rm -rf $WORKSPACE/glassfish5 |
| rm -rf $WORKSPACE/repository |
| rm -rf $WORKSPACE/nucleus |
| } |
| |
| delete_bundle(){ |
| printf "\n%s \n\n" "===== DELETE BUNDEL =====" |
| rm -rf $WORKSPACE/bundles |
| } |