testsupport.sh 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. #!/usr/bin/env bash
  2. # Licensed to the Apache Software Foundation (ASF) under one or more
  3. # contributor license agreements. See the NOTICE file distributed with
  4. # this work for additional information regarding copyright ownership.
  5. # The ASF licenses this file to You under the Apache License, Version 2.0
  6. # (the "License"); you may not use this file except in compliance with
  7. # the License. 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. # limitations under the License.
  16. resourceDir=src/test/resources/
  17. accountSettingsFolderName=accountSettings
  18. combtestfile=$resourceDir
  19. combtestfile+=abfs-combination-test-configs.xml
  20. logdir=dev-support/testlogs/
  21. # Regex to filter out final test stats
  22. testresultsregex="Tests run: [0-9]+, Failures: [0-9]+, Errors: [0-9]+, Skipped: [0-9]+$"
  23. # Regex to filter out the test that failed due to unexpected output or error.
  24. failedTestRegex1="<<< FAILURE!$"
  25. # Regex to filter out the test that failed due to runtime exception.
  26. failedTestRegex2="<<< ERROR!$"
  27. # Regex to remove the formatting used by mvn output for better regex matching.
  28. removeFormattingRegex="s/\x1b\[[0-9;]*m//g"
  29. accountConfigFileSuffix="_settings.xml"
  30. separatorbar1="============================================================"
  31. separatorbar2="------------------------------"
  32. testOutputLogFolder=$logdir
  33. testlogfilename=combinationTestLogFile
  34. fullRunStartTime=$(date +%s)
  35. STARTTIME=$(date +%s)
  36. ENDTIME=$(date +%s)
  37. outputFormatOn="\033[0;95m"
  38. outputFormatOff="\033[0m"
  39. triggerRun()
  40. {
  41. echo ' '
  42. combination=$1
  43. accountName=$2
  44. runTest=$3
  45. processcount=$4
  46. cleanUpTestContainers=$5
  47. if [ -z "$accountName" ]; then
  48. logOutput "ERROR: Test account not configured. Re-run the script and choose SET_OR_CHANGE_TEST_ACCOUNT to configure the test account."
  49. exit 1;
  50. fi
  51. accountConfigFile=$accountSettingsFolderName/$accountName$accountConfigFileSuffix
  52. rm -rf $combtestfile
  53. cat > $combtestfile << ENDOFFILE
  54. <configuration>
  55. </configuration>
  56. ENDOFFILE
  57. propertiessize=${#PROPERTIES[@]}
  58. valuessize=${#VALUES[@]}
  59. if [ "$propertiessize" -ne "$valuessize" ]; then
  60. logOutput "Exiting. Number of properties and values differ for $combination"
  61. exit 1
  62. fi
  63. echo "$separatorbar1"
  64. echo "$combination"
  65. echo "$separatorbar1"
  66. # First include the account specific configurations.
  67. xmlstarlet ed -P -L -s /configuration -t elem -n include -v "" $combtestfile
  68. xmlstarlet ed -P -L -i /configuration/include -t attr -n href -v "$accountConfigFile" $combtestfile
  69. xmlstarlet ed -P -L -i /configuration/include -t attr -n xmlns -v "http://www.w3.org/2001/XInclude" $combtestfile
  70. # Override the combination specific configurations.
  71. for ((i = 0; i < propertiessize; i++)); do
  72. key=${PROPERTIES[$i]}
  73. val=${VALUES[$i]}
  74. echo "Combination specific property setting: [ key=$key , value=$val ]"
  75. changeconf "$key" "$val"
  76. done
  77. formatxml "$combtestfile"
  78. echo ' '
  79. echo "Activated [$combtestfile] - for account: $accountName for combination $combination"
  80. testlogfilename="$testOutputLogFolder/Test-Logs-$combination.txt"
  81. touch "$testlogfilename"
  82. if [ "$runTest" == true ]
  83. then
  84. STARTTIME=$(date +%s)
  85. echo "Running test for combination $combination on account $accountName [ProcessCount=$processcount]"
  86. logOutput "Test run report can be seen in $testlogfilename"
  87. mvn -T 1C -Dparallel-tests=abfs -Dscale -DtestsThreadCount="$processcount" verify >> "$testlogfilename" || true
  88. # Remove the formatting used by mvn output for better regex matching.
  89. sed -i "$removeFormattingRegex" "$testlogfilename"
  90. ENDTIME=$(date +%s)
  91. summary
  92. fi
  93. if [ "$cleanUpTestContainers" == true ]
  94. then
  95. mvn test -Dtest=org.apache.hadoop.fs.azurebfs.utils.CleanupTestContainers >> "$testlogfilename" || true
  96. if grep -q "There are test failures" "$testlogfilename";
  97. then logOutput "ERROR: All test containers could not be deleted. Detailed error cause in $testlogfilename"
  98. pcregrep -M "$testresultsregex" "$testlogfilename"
  99. exit 0
  100. fi
  101. logOutput "Delete test containers - complete. Test run logs in - $testlogfilename"
  102. fi
  103. }
  104. summary() {
  105. {
  106. echo ""
  107. echo "$separatorbar1"
  108. echo "$combination"
  109. echo "$separatorbar1"
  110. summarycontent
  111. } >> "$aggregatedTestResult"
  112. printf "\n----- Test results -----\n"
  113. summarycontent
  114. secondstaken=$((ENDTIME - STARTTIME))
  115. mins=$((secondstaken / 60))
  116. secs=$((secondstaken % 60))
  117. printf "\nTime taken: %s mins %s secs.\n" "$mins" "$secs"
  118. logOutput "For Error details refer to Test run report in: $testlogfilename"
  119. logOutput "Consolidated test result is saved in: $aggregatedTestResult"
  120. echo "$separatorbar2"
  121. }
  122. summarycontent() {
  123. output=$(pcregrep -M "$failedTestRegex1" "$testlogfilename" || true)
  124. if [ -n "$output" ]; then
  125. echo "$output"
  126. fi
  127. output=$(pcregrep -M "$failedTestRegex2" "$testlogfilename" || true)
  128. if [ -n "$output" ]; then
  129. echo ""
  130. echo "$output"
  131. fi
  132. output=$(pcregrep -M "$testresultsregex" "$testlogfilename" || true)
  133. if [ -n "$output" ]; then
  134. echo ""
  135. echo "$output"
  136. fi
  137. }
  138. checkdependencies() {
  139. if ! [ "$(command -v pcregrep)" ]; then
  140. logOutput "Exiting. pcregrep is required to run the script."
  141. exit 1
  142. fi
  143. if ! [ "$(command -v xmlstarlet)" ]; then
  144. logOutput "Exiting. xmlstarlet is required to run the script."
  145. exit 1
  146. fi
  147. }
  148. formatxml() {
  149. xmlstarlet fo -s 2 "$1" > "$1.tmp"
  150. mv "$1.tmp" "$1"
  151. }
  152. changeconf() {
  153. xmlstarlet ed -P -L -d "/configuration/property[name='$1']" "$combtestfile"
  154. xmlstarlet ed -P -L -s /configuration -t elem -n propertyTMP -v "" -s /configuration/propertyTMP -t elem -n name -v "$1" -r /configuration/propertyTMP -v property "$combtestfile"
  155. if ! xmlstarlet ed -P -L -s "/configuration/property[name='$1']" -t elem -n value -v "$2" "$combtestfile"
  156. then
  157. logOutput "Exiting. Changing config property failed."
  158. exit 1
  159. fi
  160. }
  161. init() {
  162. checkdependencies
  163. if ! mvn clean install -DskipTests
  164. then
  165. echo ""
  166. echo "Exiting. Build failed."
  167. exit 1
  168. fi
  169. starttime=$(date +"%Y-%m-%d_%H-%M-%S")
  170. testOutputLogFolder+=$starttime
  171. mkdir -p "$testOutputLogFolder"
  172. aggregatedTestResult="$testOutputLogFolder/Test-Results.txt"
  173. }
  174. printAggregate() {
  175. echo :::: AGGREGATED TEST RESULT ::::
  176. cat "$aggregatedTestResult"
  177. fullRunEndTime=$(date +%s)
  178. fullRunTimeInSecs=$((fullRunEndTime - fullRunStartTime))
  179. mins=$((fullRunTimeInSecs / 60))
  180. secs=$((fullRunTimeInSecs % 60))
  181. printf "\nTime taken: %s mins %s secs.\n" "$mins" "$secs"
  182. }
  183. logOutput() {
  184. echo -e "$outputFormatOn" "$1" "$outputFormatOff"
  185. }