testsupport.sh 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. # Function to check if the blob config file exists and create one if it doesn't.
  40. fnsBlobConfigFileCheck() {
  41. baseFileName=$1
  42. targetWord=".dfs."
  43. replacementWord=".blob."
  44. accountSettingsDir="src/test/resources/accountSettings/"
  45. accountConfigFileSuffix="_settings.xml"
  46. sourceFilePath="${accountSettingsDir}${baseFileName}${accountConfigFileSuffix}"
  47. targetFilePath="${accountSettingsDir}${baseFileName}_blob${accountConfigFileSuffix}"
  48. if [ ! -f "$targetFilePath" ]; then
  49. cp "$sourceFilePath" "$targetFilePath"
  50. sed -i "s/$targetWord/$replacementWord/g" "$targetFilePath"
  51. echo "File created and word replaced."
  52. else
  53. echo "File already exists."
  54. fi
  55. }
  56. triggerRun()
  57. {
  58. echo ' '
  59. combination=$1
  60. accountName=$2
  61. runTest=$3
  62. processcount=$4
  63. cleanUpTestContainers=$5
  64. if [ -z "$accountName" ]; then
  65. logOutput "ERROR: Test account not configured. Re-run the script and choose SET_OR_CHANGE_TEST_ACCOUNT to configure the test account."
  66. exit 1;
  67. fi
  68. accountConfigFile=$accountSettingsFolderName/$accountName$accountConfigFileSuffix
  69. rm -rf $combtestfile
  70. cat > $combtestfile << ENDOFFILE
  71. <configuration>
  72. </configuration>
  73. ENDOFFILE
  74. propertiessize=${#PROPERTIES[@]}
  75. valuessize=${#VALUES[@]}
  76. if [ "$propertiessize" -ne "$valuessize" ]; then
  77. logOutput "Exiting. Number of properties and values differ for $combination"
  78. exit 1
  79. fi
  80. echo "$separatorbar1"
  81. echo "$combination"
  82. echo "$separatorbar1"
  83. # First include the account specific configurations.
  84. xmlstarlet ed -P -L -s /configuration -t elem -n include -v "" $combtestfile
  85. xmlstarlet ed -P -L -i /configuration/include -t attr -n href -v "$accountConfigFile" $combtestfile
  86. xmlstarlet ed -P -L -i /configuration/include -t attr -n xmlns -v "http://www.w3.org/2001/XInclude" $combtestfile
  87. # Override the combination specific configurations.
  88. for ((i = 0; i < propertiessize; i++)); do
  89. key=${PROPERTIES[$i]}
  90. val=${VALUES[$i]}
  91. echo "Combination specific property setting: [ key=$key , value=$val ]"
  92. changeconf "$key" "$val"
  93. done
  94. formatxml "$combtestfile"
  95. echo ' '
  96. echo "Activated [$combtestfile] - for account: $accountName for combination $combination"
  97. testlogfilename="$testOutputLogFolder/Test-Logs-$combination.txt"
  98. touch "$testlogfilename"
  99. if [ "$runTest" == true ]
  100. then
  101. STARTTIME=$(date +%s)
  102. echo "Running test for combination $combination on account $accountName [ProcessCount=$processcount]"
  103. logOutput "Test run report can be seen in $testlogfilename"
  104. mvn -T 1C -Dparallel-tests=abfs -Dscale -DtestsThreadCount="$processcount" verify >> "$testlogfilename" || true
  105. # Remove the formatting used by mvn output for better regex matching.
  106. sed -i "$removeFormattingRegex" "$testlogfilename"
  107. ENDTIME=$(date +%s)
  108. summary
  109. fi
  110. if [ "$cleanUpTestContainers" == true ]
  111. then
  112. mvn test -Dtest=org.apache.hadoop.fs.azurebfs.utils.CleanupTestContainers >> "$testlogfilename" || true
  113. if grep -q "There are test failures" "$testlogfilename";
  114. then logOutput "ERROR: All test containers could not be deleted. Detailed error cause in $testlogfilename"
  115. pcregrep -M "$testresultsregex" "$testlogfilename"
  116. exit 0
  117. fi
  118. logOutput "Delete test containers - complete. Test run logs in - $testlogfilename"
  119. fi
  120. }
  121. summary() {
  122. {
  123. echo ""
  124. echo "$separatorbar1"
  125. echo "$combination"
  126. echo "$separatorbar1"
  127. summarycontent
  128. } >> "$aggregatedTestResult"
  129. printf "\n----- Test results -----\n"
  130. summarycontent
  131. secondstaken=$((ENDTIME - STARTTIME))
  132. mins=$((secondstaken / 60))
  133. secs=$((secondstaken % 60))
  134. printf "\nTime taken: %s mins %s secs.\n" "$mins" "$secs"
  135. logOutput "For Error details refer to Test run report in: $testlogfilename"
  136. logOutput "Consolidated test result is saved in: $aggregatedTestResult"
  137. echo "$separatorbar2"
  138. }
  139. summarycontent() {
  140. output=$(pcregrep -M "$failedTestRegex1" "$testlogfilename" || true)
  141. if [ -n "$output" ]; then
  142. echo "$output"
  143. fi
  144. output=$(pcregrep -M "$failedTestRegex2" "$testlogfilename" || true)
  145. if [ -n "$output" ]; then
  146. echo ""
  147. echo "$output"
  148. fi
  149. output=$(pcregrep -M "$testresultsregex" "$testlogfilename" || true)
  150. if [ -n "$output" ]; then
  151. echo ""
  152. echo "$output"
  153. fi
  154. }
  155. checkdependencies() {
  156. if ! [ "$(command -v pcregrep)" ]; then
  157. logOutput "Exiting. pcregrep is required to run the script."
  158. exit 1
  159. fi
  160. if ! [ "$(command -v xmlstarlet)" ]; then
  161. logOutput "Exiting. xmlstarlet is required to run the script."
  162. exit 1
  163. fi
  164. }
  165. formatxml() {
  166. xmlstarlet fo -s 2 "$1" > "$1.tmp"
  167. mv "$1.tmp" "$1"
  168. }
  169. changeconf() {
  170. xmlstarlet ed -P -L -d "/configuration/property[name='$1']" "$combtestfile"
  171. 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"
  172. if ! xmlstarlet ed -P -L -s "/configuration/property[name='$1']" -t elem -n value -v "$2" "$combtestfile"
  173. then
  174. logOutput "Exiting. Changing config property failed."
  175. exit 1
  176. fi
  177. }
  178. init() {
  179. checkdependencies
  180. if ! mvn clean install -DskipTests
  181. then
  182. echo ""
  183. echo "Exiting. Build failed."
  184. exit 1
  185. fi
  186. starttime=$(date +"%Y-%m-%d_%H-%M-%S")
  187. testOutputLogFolder+=$starttime
  188. mkdir -p "$testOutputLogFolder"
  189. aggregatedTestResult="$testOutputLogFolder/Test-Results.txt"
  190. }
  191. printAggregate() {
  192. echo :::: AGGREGATED TEST RESULT ::::
  193. cat "$aggregatedTestResult"
  194. fullRunEndTime=$(date +%s)
  195. fullRunTimeInSecs=$((fullRunEndTime - fullRunStartTime))
  196. mins=$((fullRunTimeInSecs / 60))
  197. secs=$((fullRunTimeInSecs % 60))
  198. printf "\nTime taken: %s mins %s secs.\n" "$mins" "$secs"
  199. }
  200. logOutput() {
  201. echo -e "$outputFormatOn" "$1" "$outputFormatOff"
  202. }