testsupport.sh 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. testresultsregex="Results:(\n|.)*?Tests run:"
  22. accountConfigFileSuffix="_settings.xml"
  23. testOutputLogFolder=$logdir
  24. testlogfilename=combinationTestLogFile
  25. fullRunStartTime=$(date +%s)
  26. STARTTIME=$(date +%s)
  27. ENDTIME=$(date +%s)
  28. outputFormatOn="\033[0;95m"
  29. outputFormatOff="\033[0m"
  30. triggerRun()
  31. {
  32. echo ' '
  33. combination=$1
  34. accountName=$2
  35. runTest=$3
  36. processcount=$4
  37. cleanUpTestContainers=$5
  38. if [ -z "$accountName" ]; then
  39. logOutput "ERROR: Test account not configured. Re-run the script and choose SET_OR_CHANGE_TEST_ACCOUNT to configure the test account."
  40. exit 1;
  41. fi
  42. accountConfigFile=$accountSettingsFolderName/$accountName$accountConfigFileSuffix
  43. rm -rf $combtestfile
  44. cat > $combtestfile << ENDOFFILE
  45. <configuration>
  46. </configuration>
  47. ENDOFFILE
  48. propertiessize=${#PROPERTIES[@]}
  49. valuessize=${#VALUES[@]}
  50. if [ "$propertiessize" -ne "$valuessize" ]; then
  51. logOutput "Exiting. Number of properties and values differ for $combination"
  52. exit 1
  53. fi
  54. for ((i = 0; i < propertiessize; i++)); do
  55. key=${PROPERTIES[$i]}
  56. val=${VALUES[$i]}
  57. echo "Combination specific property setting: [ key=$key , value=$val ]"
  58. changeconf "$key" "$val"
  59. done
  60. formatxml "$combtestfile"
  61. xmlstarlet ed -P -L -s /configuration -t elem -n include -v "" $combtestfile
  62. xmlstarlet ed -P -L -i /configuration/include -t attr -n href -v "$accountConfigFile" $combtestfile
  63. xmlstarlet ed -P -L -i /configuration/include -t attr -n xmlns -v "http://www.w3.org/2001/XInclude" $combtestfile
  64. formatxml $combtestfile
  65. echo ' '
  66. echo "Activated [$combtestfile] - for account: $accountName for combination $combination"
  67. testlogfilename="$testOutputLogFolder/Test-Logs-$combination.txt"
  68. touch "$testlogfilename"
  69. if [ "$runTest" == true ]
  70. then
  71. STARTTIME=$(date +%s)
  72. echo "Running test for combination $combination on account $accountName [ProcessCount=$processcount]"
  73. logOutput "Test run report can be seen in $testlogfilename"
  74. mvn -T 1C -Dparallel-tests=abfs -Dscale -DtestsThreadCount="$processcount" verify >> "$testlogfilename" || true
  75. ENDTIME=$(date +%s)
  76. summary
  77. fi
  78. if [ "$cleanUpTestContainers" == true ]
  79. then
  80. mvn test -Dtest=org.apache.hadoop.fs.azurebfs.utils.CleanupTestContainers >> "$testlogfilename" || true
  81. if grep -q "There are test failures" "$testlogfilename";
  82. then logOutput "ERROR: All test containers could not be deleted. Detailed error cause in $testlogfilename"
  83. pcregrep -M "$testresultsregex" "$testlogfilename"
  84. exit 0
  85. fi
  86. logOutput "Delete test containers - complete. Test run logs in - $testlogfilename"
  87. fi
  88. }
  89. summary() {
  90. {
  91. echo ""
  92. echo "$combination"
  93. echo "========================"
  94. pcregrep -M "$testresultsregex" "$testlogfilename"
  95. } >> "$aggregatedTestResult"
  96. printf "\n----- Test results -----\n"
  97. pcregrep -M "$testresultsregex" "$testlogfilename"
  98. secondstaken=$((ENDTIME - STARTTIME))
  99. mins=$((secondstaken / 60))
  100. secs=$((secondstaken % 60))
  101. printf "\nTime taken: %s mins %s secs.\n" "$mins" "$secs"
  102. echo "Find test result for the combination ($combination) in: $testlogfilename"
  103. logOutput "Consolidated test result is saved in: $aggregatedTestResult"
  104. echo "------------------------"
  105. }
  106. checkdependencies() {
  107. if ! [ "$(command -v pcregrep)" ]; then
  108. logOutput "Exiting. pcregrep is required to run the script."
  109. exit 1
  110. fi
  111. if ! [ "$(command -v xmlstarlet)" ]; then
  112. logOutput "Exiting. xmlstarlet is required to run the script."
  113. exit 1
  114. fi
  115. }
  116. formatxml() {
  117. xmlstarlet fo -s 2 "$1" > "$1.tmp"
  118. mv "$1.tmp" "$1"
  119. }
  120. changeconf() {
  121. xmlstarlet ed -P -L -d "/configuration/property[name='$1']" "$combtestfile"
  122. 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"
  123. if ! xmlstarlet ed -P -L -s "/configuration/property[name='$1']" -t elem -n value -v "$2" "$combtestfile"
  124. then
  125. logOutput "Exiting. Changing config property failed."
  126. exit 1
  127. fi
  128. }
  129. init() {
  130. checkdependencies
  131. if ! mvn clean install -DskipTests
  132. then
  133. echo ""
  134. echo "Exiting. Build failed."
  135. exit 1
  136. fi
  137. starttime=$(date +"%Y-%m-%d_%H-%M-%S")
  138. testOutputLogFolder+=$starttime
  139. mkdir -p "$testOutputLogFolder"
  140. aggregatedTestResult="$testOutputLogFolder/Test-Results.txt"
  141. }
  142. printAggregate() {
  143. echo :::: AGGREGATED TEST RESULT ::::
  144. cat "$aggregatedTestResult"
  145. fullRunEndTime=$(date +%s)
  146. fullRunTimeInSecs=$((fullRunEndTime - fullRunStartTime))
  147. mins=$((fullRunTimeInSecs / 60))
  148. secs=$((fullRunTimeInSecs % 60))
  149. printf "\nTime taken: %s mins %s secs.\n" "$mins" "$secs"
  150. }
  151. logOutput() {
  152. echo -e "$outputFormatOn" "$1" "$outputFormatOff"
  153. }