test-patch.sh 79 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816
  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. ### BUILD_URL is set by Hudson if it is run by patch process
  17. this="${BASH_SOURCE-$0}"
  18. BINDIR=$(cd -P -- "$(dirname -- "${this}")" >/dev/null && pwd -P)
  19. CWD=$(pwd)
  20. USER_PARAMS=("$@")
  21. GLOBALTIMER=$(date +"%s")
  22. ## @description Setup the default global variables
  23. ## @audience public
  24. ## @stability stable
  25. ## @replaceable no
  26. function setup_defaults
  27. {
  28. if [[ -z "${MAVEN_HOME:-}" ]]; then
  29. MVN=mvn
  30. else
  31. MVN=${MAVEN_HOME}/bin/mvn
  32. fi
  33. # This parameter needs to be kept as an array
  34. MAVEN_ARGS=()
  35. PROJECT_NAME=hadoop
  36. HOW_TO_CONTRIBUTE="https://wiki.apache.org/hadoop/HowToContribute"
  37. JENKINS=false
  38. BASEDIR=$(pwd)
  39. RELOCATE_PATCH_DIR=false
  40. USER_PLUGIN_DIR=""
  41. LOAD_SYSTEM_PLUGINS=true
  42. FINDBUGS_HOME=${FINDBUGS_HOME:-}
  43. FINDBUGS_WARNINGS_FAIL_PRECHECK=false
  44. ECLIPSE_HOME=${ECLIPSE_HOME:-}
  45. BUILD_NATIVE=${BUILD_NATIVE:-true}
  46. PATCH_BRANCH=""
  47. PATCH_BRANCH_DEFAULT="trunk"
  48. CHANGED_MODULES=""
  49. USER_MODULE_LIST=""
  50. OFFLINE=false
  51. CHANGED_FILES=""
  52. REEXECED=false
  53. RESETREPO=false
  54. ISSUE=""
  55. ISSUE_RE='^(HADOOP|YARN|MAPREDUCE|HDFS)-[0-9]+$'
  56. TIMER=$(date +"%s")
  57. PATCHURL=""
  58. OSTYPE=$(uname -s)
  59. # Solaris needs POSIX, not SVID
  60. case ${OSTYPE} in
  61. SunOS)
  62. PS=${PS:-ps}
  63. AWK=${AWK:-/usr/xpg4/bin/awk}
  64. SED=${SED:-/usr/xpg4/bin/sed}
  65. WGET=${WGET:-wget}
  66. GIT=${GIT:-git}
  67. EGREP=${EGREP:-/usr/xpg4/bin/egrep}
  68. GREP=${GREP:-/usr/xpg4/bin/grep}
  69. PATCH=${PATCH:-patch}
  70. DIFF=${DIFF:-/usr/gnu/bin/diff}
  71. JIRACLI=${JIRA:-jira}
  72. FILE=${FILE:-file}
  73. ;;
  74. *)
  75. PS=${PS:-ps}
  76. AWK=${AWK:-awk}
  77. SED=${SED:-sed}
  78. WGET=${WGET:-wget}
  79. GIT=${GIT:-git}
  80. EGREP=${EGREP:-egrep}
  81. GREP=${GREP:-grep}
  82. PATCH=${PATCH:-patch}
  83. DIFF=${DIFF:-diff}
  84. JIRACLI=${JIRA:-jira}
  85. FILE=${FILE:-file}
  86. ;;
  87. esac
  88. declare -a JIRA_COMMENT_TABLE
  89. declare -a JIRA_FOOTER_TABLE
  90. declare -a JIRA_HEADER
  91. declare -a JIRA_TEST_TABLE
  92. JFC=0
  93. JTC=0
  94. JTT=0
  95. RESULT=0
  96. }
  97. ## @description Print a message to stderr
  98. ## @audience public
  99. ## @stability stable
  100. ## @replaceable no
  101. ## @param string
  102. function hadoop_error
  103. {
  104. echo "$*" 1>&2
  105. }
  106. ## @description Print a message to stderr if --debug is turned on
  107. ## @audience public
  108. ## @stability stable
  109. ## @replaceable no
  110. ## @param string
  111. function hadoop_debug
  112. {
  113. if [[ -n "${HADOOP_SHELL_SCRIPT_DEBUG}" ]]; then
  114. echo "[$(date) DEBUG]: $*" 1>&2
  115. fi
  116. }
  117. ## @description Activate the local timer
  118. ## @audience public
  119. ## @stability stable
  120. ## @replaceable no
  121. function start_clock
  122. {
  123. hadoop_debug "Start clock"
  124. TIMER=$(date +"%s")
  125. }
  126. ## @description Print the elapsed time in seconds since the start of the local timer
  127. ## @audience public
  128. ## @stability stable
  129. ## @replaceable no
  130. function stop_clock
  131. {
  132. local -r stoptime=$(date +"%s")
  133. local -r elapsed=$((stoptime-TIMER))
  134. hadoop_debug "Stop clock"
  135. echo ${elapsed}
  136. }
  137. ## @description Print the elapsed time in seconds since the start of the global timer
  138. ## @audience private
  139. ## @stability stable
  140. ## @replaceable no
  141. function stop_global_clock
  142. {
  143. local -r stoptime=$(date +"%s")
  144. local -r elapsed=$((stoptime-GLOBALTIMER))
  145. hadoop_debug "Stop global clock"
  146. echo ${elapsed}
  147. }
  148. ## @description Add time to the local timer
  149. ## @audience public
  150. ## @stability stable
  151. ## @replaceable no
  152. ## @param seconds
  153. function offset_clock
  154. {
  155. ((TIMER=TIMER-$1))
  156. }
  157. ## @description Add to the header of the display
  158. ## @audience public
  159. ## @stability stable
  160. ## @replaceable no
  161. ## @param string
  162. function add_jira_header
  163. {
  164. JIRA_HEADER[${JHC}]="| $* |"
  165. JHC=$(( JHC+1 ))
  166. }
  167. ## @description Add to the output table. If the first parameter is a number
  168. ## @description that is the vote for that column and calculates the elapsed time
  169. ## @description based upon the last start_clock(). If it the string null, then it is
  170. ## @description a special entry that signifies extra
  171. ## @description content for the final column. The second parameter is the reporting
  172. ## @description subsystem (or test) that is providing the vote. The second parameter
  173. ## @description is always required. The third parameter is any extra verbage that goes
  174. ## @description with that subsystem.
  175. ## @audience public
  176. ## @stability stable
  177. ## @replaceable no
  178. ## @param +1/0/-1/null
  179. ## @param subsystem
  180. ## @param string
  181. ## @return Elapsed time display
  182. function add_jira_table
  183. {
  184. local value=$1
  185. local subsystem=$2
  186. shift 2
  187. local color
  188. local calctime=0
  189. local -r elapsed=$(stop_clock)
  190. if [[ ${elapsed} -lt 0 ]]; then
  191. calctime="N/A"
  192. else
  193. printf -v calctime "%3sm %02ss" $((elapsed/60)) $((elapsed%60))
  194. fi
  195. echo ""
  196. echo "Elapsed time: ${calctime}"
  197. echo ""
  198. case ${value} in
  199. 1|+1)
  200. value="+1"
  201. color="green"
  202. ;;
  203. -1)
  204. color="red"
  205. ;;
  206. 0)
  207. color="blue"
  208. ;;
  209. null)
  210. ;;
  211. esac
  212. if [[ -z ${color} ]]; then
  213. JIRA_COMMENT_TABLE[${JTC}]="| | ${subsystem} | | ${*:-} |"
  214. JTC=$(( JTC+1 ))
  215. else
  216. JIRA_COMMENT_TABLE[${JTC}]="| {color:${color}}${value}{color} | ${subsystem} | ${calctime} | $* |"
  217. JTC=$(( JTC+1 ))
  218. fi
  219. }
  220. ## @description Put the final environment information at the bottom
  221. ## @description of the footer table
  222. ## @stability stable
  223. ## @audience private
  224. ## @replaceable yes
  225. function close_jira_footer
  226. {
  227. # shellcheck disable=SC2016
  228. local -r javaversion=$("${JAVA_HOME}/bin/java" -version 2>&1 | head -1 | ${AWK} '{print $NF}' | tr -d \")
  229. local -r unamea=$(uname -a)
  230. add_jira_footer "Java" "${javaversion}"
  231. add_jira_footer "uname" "${unamea}"
  232. }
  233. ## @description Put the final elapsed time at the bottom of the table.
  234. ## @audience private
  235. ## @stability stable
  236. ## @replaceable no
  237. function close_jira_table
  238. {
  239. local -r elapsed=$(stop_global_clock)
  240. if [[ ${elapsed} -lt 0 ]]; then
  241. calctime="N/A"
  242. else
  243. printf -v calctime "%3sm %02ss" $((elapsed/60)) $((elapsed%60))
  244. fi
  245. echo ""
  246. echo "Total Elapsed time: ${calctime}"
  247. echo ""
  248. JIRA_COMMENT_TABLE[${JTC}]="| | | ${calctime} | |"
  249. JTC=$(( JTC+1 ))
  250. }
  251. ## @description Add to the footer of the display. @@BASE@@ will get replaced with the
  252. ## @description correct location for the local filesystem in dev mode or the URL for
  253. ## @description Jenkins mode.
  254. ## @audience public
  255. ## @stability stable
  256. ## @replaceable no
  257. ## @param subsystem
  258. ## @param string
  259. function add_jira_footer
  260. {
  261. local subsystem=$1
  262. shift 1
  263. JIRA_FOOTER_TABLE[${JFC}]="| ${subsystem} | $* |"
  264. JFC=$(( JFC+1 ))
  265. }
  266. ## @description Special table just for unit test failures
  267. ## @audience public
  268. ## @stability stable
  269. ## @replaceable no
  270. ## @param failurereason
  271. ## @param testlist
  272. function add_jira_test_table
  273. {
  274. local failure=$1
  275. shift 1
  276. JIRA_TEST_TABLE[${JTT}]="| ${failure} | $* |"
  277. JTT=$(( JTT+1 ))
  278. }
  279. ## @description Large display for the user console
  280. ## @audience public
  281. ## @stability stable
  282. ## @replaceable no
  283. ## @param string
  284. ## @return large chunk of text
  285. function big_console_header
  286. {
  287. local text="$*"
  288. local spacing=$(( (75+${#text}) /2 ))
  289. printf "\n\n"
  290. echo "============================================================================"
  291. echo "============================================================================"
  292. printf "%*s\n" ${spacing} "${text}"
  293. echo "============================================================================"
  294. echo "============================================================================"
  295. printf "\n\n"
  296. }
  297. ## @description Remove {color} tags from a string
  298. ## @audience public
  299. ## @stability stable
  300. ## @replaceable no
  301. ## @param string
  302. ## @return string
  303. function colorstripper
  304. {
  305. local string=$1
  306. shift 1
  307. local green=""
  308. local white=""
  309. local red=""
  310. local blue=""
  311. echo "${string}" | \
  312. ${SED} -e "s,{color:red},${red},g" \
  313. -e "s,{color:green},${green},g" \
  314. -e "s,{color:blue},${blue},g" \
  315. -e "s,{color},${white},g"
  316. }
  317. ## @description Find the largest size of a column of an array
  318. ## @audience private
  319. ## @stability evolving
  320. ## @replaceable no
  321. ## @return size
  322. function findlargest
  323. {
  324. local column=$1
  325. shift
  326. local a=("$@")
  327. local sizeofa=${#a[@]}
  328. local i=0
  329. until [[ ${i} -gt ${sizeofa} ]]; do
  330. # shellcheck disable=SC2086
  331. string=$( echo ${a[$i]} | cut -f$((column + 1)) -d\| )
  332. if [[ ${#string} -gt $maxlen ]]; then
  333. maxlen=${#string}
  334. fi
  335. i=$((i+1))
  336. done
  337. echo "${maxlen}"
  338. }
  339. ## @description Verify that ${JAVA_HOME} is defined
  340. ## @audience public
  341. ## @stability stable
  342. ## @replaceable no
  343. ## @return 1 - no JAVA_HOME
  344. ## @return 0 - JAVA_HOME defined
  345. function find_java_home
  346. {
  347. start_clock
  348. if [[ -z ${JAVA_HOME:-} ]]; then
  349. case $(uname -s) in
  350. Darwin)
  351. if [[ -z "${JAVA_HOME}" ]]; then
  352. if [[ -x /usr/libexec/java_home ]]; then
  353. JAVA_HOME="$(/usr/libexec/java_home)"
  354. export JAVA_HOME
  355. else
  356. export JAVA_HOME=/Library/Java/Home
  357. fi
  358. fi
  359. ;;
  360. *)
  361. ;;
  362. esac
  363. fi
  364. if [[ -z ${JAVA_HOME:-} ]]; then
  365. echo "JAVA_HOME is not defined."
  366. add_jira_table -1 pre-patch "JAVA_HOME is not defined."
  367. return 1
  368. fi
  369. return 0
  370. }
  371. ## @description Write the contents of a file to jenkins
  372. ## @params filename
  373. ## @stability stable
  374. ## @audience public
  375. ## @returns ${JIRACLI} exit code
  376. function write_to_jira
  377. {
  378. local -r commentfile=${1}
  379. shift
  380. local retval
  381. if [[ ${OFFLINE} == false
  382. && ${JENKINS} == true ]]; then
  383. export USER=hudson
  384. # shellcheck disable=SC2086
  385. ${JIRACLI} --comment "$(cat ${commentfile})" \
  386. -s https://issues.apache.org/jira \
  387. -a addcomment -u hadoopqa \
  388. -p "${JIRA_PASSWD}" \
  389. --issue "${ISSUE}"
  390. retval=$?
  391. ${JIRACLI} -s https://issues.apache.org/jira \
  392. -a logout -u hadoopqa \
  393. -p "${JIRA_PASSWD}"
  394. fi
  395. return ${retval}
  396. }
  397. ## @description Verify that the patch directory is still in working order
  398. ## @description since bad actors on some systems wipe it out. If not,
  399. ## @description recreate it and then exit
  400. ## @audience private
  401. ## @stability evolving
  402. ## @replaceable yes
  403. ## @returns may exit on failure
  404. function verify_patchdir_still_exists
  405. {
  406. local -r commentfile=/tmp/testpatch.$$.${RANDOM}
  407. local extra=""
  408. if [[ ! -d ${PATCH_DIR} ]]; then
  409. rm "${commentfile}" 2>/dev/null
  410. echo "(!) The patch artifact directory has been removed! " > "${commentfile}"
  411. echo "This is a fatal error for test-patch.sh. Aborting. " >> "${commentfile}"
  412. echo
  413. cat ${commentfile}
  414. echo
  415. if [[ ${JENKINS} == true ]]; then
  416. if [[ -n ${NODE_NAME} ]]; then
  417. extra=" (node ${NODE_NAME})"
  418. fi
  419. echo "Jenkins${extra} information at ${BUILD_URL} may provide some hints. " >> "${commentfile}"
  420. write_to_jira ${commentfile}
  421. fi
  422. rm "${commentfile}"
  423. cleanup_and_exit ${RESULT}
  424. fi
  425. }
  426. ## @description generate a list of all files and line numbers that
  427. ## @description that were added/changed in the source repo
  428. ## @audience private
  429. ## @stability stable
  430. ## @params filename
  431. ## @replaceable no
  432. function compute_gitdiff
  433. {
  434. local outfile=$1
  435. local file
  436. local line
  437. local startline
  438. local counter
  439. local numlines
  440. local actual
  441. pushd "${BASEDIR}" >/dev/null
  442. while read line; do
  443. if [[ ${line} =~ ^\+\+\+ ]]; then
  444. file="./"$(echo "${line}" | cut -f2- -d/)
  445. continue
  446. elif [[ ${line} =~ ^@@ ]]; then
  447. startline=$(echo "${line}" | cut -f3 -d' ' | cut -f1 -d, | tr -d + )
  448. numlines=$(echo "${line}" | cut -f3 -d' ' | cut -s -f2 -d, )
  449. # if this is empty, then just this line
  450. # if it is 0, then no lines were added and this part of the patch
  451. # is strictly a delete
  452. if [[ ${numlines} == 0 ]]; then
  453. continue
  454. elif [[ -z ${numlines} ]]; then
  455. numlines=1
  456. fi
  457. counter=0
  458. until [[ ${counter} -gt ${numlines} ]]; do
  459. ((actual=counter+startline))
  460. echo "${file}:${actual}:" >> "${outfile}"
  461. ((counter=counter+1))
  462. done
  463. fi
  464. done < <("${GIT}" diff --unified=0 --no-color)
  465. popd >/dev/null
  466. }
  467. ## @description Print the command to be executing to the screen. Then
  468. ## @description run the command, sending stdout and stderr to the given filename
  469. ## @description This will also ensure that any directories in ${BASEDIR} have
  470. ## @description the exec bit set as a pre-exec step.
  471. ## @audience public
  472. ## @stability stable
  473. ## @param filename
  474. ## @param command
  475. ## @param [..]
  476. ## @replaceable no
  477. ## @returns $?
  478. function echo_and_redirect
  479. {
  480. local logfile=$1
  481. shift
  482. verify_patchdir_still_exists
  483. find "${BASEDIR}" -type d -exec chmod +x {} \;
  484. echo "${*} > ${logfile} 2>&1"
  485. "${@}" > "${logfile}" 2>&1
  486. }
  487. ## @description is PATCH_DIR relative to BASEDIR?
  488. ## @audience public
  489. ## @stability stable
  490. ## @replaceable yes
  491. ## @returns 1 - no, PATCH_DIR
  492. ## @returns 0 - yes, PATCH_DIR - BASEDIR
  493. function relative_patchdir
  494. {
  495. local p=${PATCH_DIR#${BASEDIR}}
  496. if [[ ${#p} -eq ${#PATCH_DIR} ]]; then
  497. echo ${p}
  498. return 1
  499. fi
  500. p=${p#/}
  501. echo ${p}
  502. return 0
  503. }
  504. ## @description Print the usage information
  505. ## @audience public
  506. ## @stability stable
  507. ## @replaceable no
  508. function hadoop_usage
  509. {
  510. local -r up=$(echo ${PROJECT_NAME} | tr '[:lower:]' '[:upper:]')
  511. echo "Usage: test-patch.sh [options] patch-file | issue-number | http"
  512. echo
  513. echo "Where:"
  514. echo " patch-file is a local patch file containing the changes to test"
  515. echo " issue-number is a 'Patch Available' JIRA defect number (e.g. '${up}-9902') to test"
  516. echo " http is an HTTP address to download the patch file"
  517. echo
  518. echo "Options:"
  519. echo "--basedir=<dir> The directory to apply the patch to (default current directory)"
  520. echo "--branch=<ref> Forcibly set the branch"
  521. echo "--branch-default=<ref> If the branch isn't forced and we don't detect one in the patch name, use this branch (default 'trunk')"
  522. echo "--build-native=<bool> If true, then build native components (default 'true')"
  523. echo "--contrib-guide=<url> URL to point new users towards project conventions. (default Hadoop's wiki)"
  524. echo "--debug If set, then output some extra stuff to stderr"
  525. echo "--dirty-workspace Allow the local git workspace to have uncommitted changes"
  526. echo "--findbugs-home=<path> Findbugs home directory (default FINDBUGS_HOME environment variable)"
  527. echo "--findbugs-strict-precheck If there are Findbugs warnings during precheck, fail"
  528. echo "--issue-re=<expr> Bash regular expression to use when trying to find a jira ref in the patch name (default '^(HADOOP|YARN|MAPREDUCE|HDFS)-[0-9]+$')"
  529. echo "--modulelist=<list> Specify additional modules to test (comma delimited)"
  530. echo "--offline Avoid connecting to the Internet"
  531. echo "--patch-dir=<dir> The directory for working and output files (default '/tmp/${PROJECT_NAME}-test-patch/pid')"
  532. echo "--plugins=<dir> A directory of user provided plugins. see test-patch.d for examples (default empty)"
  533. echo "--project=<name> The short name for project currently using test-patch (default 'hadoop')"
  534. echo "--resetrepo Forcibly clean the repo"
  535. echo "--run-tests Run all relevant tests below the base directory"
  536. echo "--skip-system-plugins Do not load plugins from ${BINDIR}/test-patch.d"
  537. echo "--testlist=<list> Specify which subsystem tests to use (comma delimited)"
  538. echo "--test-parallel=<bool> Run multiple tests in parallel (default false in developer mode, true in Jenkins mode)"
  539. echo "--test-threads=<int> Number of tests to run in parallel (default defined in ${PROJECT_NAME} build)"
  540. echo "Shell binary overrides:"
  541. echo "--awk-cmd=<cmd> The 'awk' command to use (default 'awk')"
  542. echo "--diff-cmd=<cmd> The GNU-compatible 'diff' command to use (default 'diff')"
  543. echo "--file-cmd=<cmd> The 'file' command to use (default 'file')"
  544. echo "--git-cmd=<cmd> The 'git' command to use (default 'git')"
  545. echo "--grep-cmd=<cmd> The 'grep' command to use (default 'grep')"
  546. echo "--mvn-cmd=<cmd> The 'mvn' command to use (default \${MAVEN_HOME}/bin/mvn, or 'mvn')"
  547. echo "--patch-cmd=<cmd> The 'patch' command to use (default 'patch')"
  548. echo "--ps-cmd=<cmd> The 'ps' command to use (default 'ps')"
  549. echo "--sed-cmd=<cmd> The 'sed' command to use (default 'sed')"
  550. echo
  551. echo "Jenkins-only options:"
  552. echo "--jenkins Run by Jenkins (runs tests and posts results to JIRA)"
  553. echo "--eclipse-home=<path> Eclipse home directory (default ECLIPSE_HOME environment variable)"
  554. echo "--jira-cmd=<cmd> The 'jira' command to use (default 'jira')"
  555. echo "--jira-password=<pw> The password for the 'jira' command"
  556. echo "--mv-patch-dir Move the patch-dir into the basedir during cleanup."
  557. echo "--wget-cmd=<cmd> The 'wget' command to use (default 'wget')"
  558. }
  559. ## @description Interpret the command line parameters
  560. ## @audience private
  561. ## @stability stable
  562. ## @replaceable no
  563. ## @params $@
  564. ## @return May exit on failure
  565. function parse_args
  566. {
  567. local i
  568. local j
  569. for i in "$@"; do
  570. case ${i} in
  571. --awk-cmd=*)
  572. AWK=${i#*=}
  573. ;;
  574. --basedir=*)
  575. BASEDIR=${i#*=}
  576. ;;
  577. --branch=*)
  578. PATCH_BRANCH=${i#*=}
  579. ;;
  580. --branch-default=*)
  581. PATCH_BRANCH_DEFAULT=${i#*=}
  582. ;;
  583. --build-native=*)
  584. BUILD_NATIVE=${i#*=}
  585. ;;
  586. --contrib-guide=*)
  587. HOW_TO_CONTRIBUTE=${i#*=}
  588. ;;
  589. --debug)
  590. HADOOP_SHELL_SCRIPT_DEBUG=true
  591. ;;
  592. --diff-cmd=*)
  593. DIFF=${i#*=}
  594. ;;
  595. --dirty-workspace)
  596. DIRTY_WORKSPACE=true
  597. ;;
  598. --eclipse-home=*)
  599. ECLIPSE_HOME=${i#*=}
  600. ;;
  601. --file-cmd=*)
  602. FILE=${i#*=}
  603. ;;
  604. --findbugs-home=*)
  605. FINDBUGS_HOME=${i#*=}
  606. ;;
  607. --findbugs-strict-precheck)
  608. FINDBUGS_WARNINGS_FAIL_PRECHECK=true
  609. ;;
  610. --git-cmd=*)
  611. GIT=${i#*=}
  612. ;;
  613. --grep-cmd=*)
  614. GREP=${i#*=}
  615. ;;
  616. --help|-help|-h|help|--h|--\?|-\?|\?)
  617. hadoop_usage
  618. exit 0
  619. ;;
  620. --issue-re=*)
  621. ISSUE_RE=${i#*=}
  622. ;;
  623. --java-home=*)
  624. JAVA_HOME=${i#*=}
  625. ;;
  626. --jenkins)
  627. JENKINS=true
  628. TEST_PARALLEL=${TEST_PARALLEL:-true}
  629. ;;
  630. --jira-cmd=*)
  631. JIRACLI=${i#*=}
  632. ;;
  633. --jira-password=*)
  634. JIRA_PASSWD=${i#*=}
  635. ;;
  636. --modulelist=*)
  637. USER_MODULE_LIST=${i#*=}
  638. USER_MODULE_LIST=${USER_MODULE_LIST//,/ }
  639. hadoop_debug "Manually forcing modules ${USER_MODULE_LIST}"
  640. ;;
  641. --mvn-cmd=*)
  642. MVN=${i#*=}
  643. ;;
  644. --mv-patch-dir)
  645. RELOCATE_PATCH_DIR=true;
  646. ;;
  647. --offline)
  648. OFFLINE=true
  649. ;;
  650. --patch-cmd=*)
  651. PATCH=${i#*=}
  652. ;;
  653. --patch-dir=*)
  654. USER_PATCH_DIR=${i#*=}
  655. ;;
  656. --plugins=*)
  657. USER_PLUGIN_DIR=${i#*=}
  658. ;;
  659. --project=*)
  660. PROJECT_NAME=${i#*=}
  661. ;;
  662. --ps-cmd=*)
  663. PS=${i#*=}
  664. ;;
  665. --reexec)
  666. REEXECED=true
  667. start_clock
  668. add_jira_table 0 reexec "dev-support patch detected."
  669. ;;
  670. --resetrepo)
  671. RESETREPO=true
  672. ;;
  673. --run-tests)
  674. RUN_TESTS=true
  675. ;;
  676. --skip-system-plugins)
  677. LOAD_SYSTEM_PLUGINS=false
  678. ;;
  679. --testlist=*)
  680. testlist=${i#*=}
  681. testlist=${testlist//,/ }
  682. for j in ${testlist}; do
  683. hadoop_debug "Manually adding patch test subsystem ${j}"
  684. add_test "${j}"
  685. done
  686. ;;
  687. --test-parallel=*)
  688. TEST_PARALLEL=${i#*=}
  689. ;;
  690. --test-threads=*)
  691. TEST_THREADS=${i#*=}
  692. ;;
  693. --wget-cmd=*)
  694. WGET=${i#*=}
  695. ;;
  696. *)
  697. PATCH_OR_ISSUE=${i}
  698. ;;
  699. esac
  700. done
  701. # if we requested offline, pass that to mvn
  702. if [[ ${OFFLINE} == "true" ]] ; then
  703. MAVEN_ARGS=(${MAVEN_ARGS[@]} --offline)
  704. fi
  705. # we need absolute dir for ${BASEDIR}
  706. cd "${CWD}"
  707. BASEDIR=$(cd -P -- "${BASEDIR}" >/dev/null && pwd -P)
  708. if [[ ${BUILD_NATIVE} == "true" ]] ; then
  709. NATIVE_PROFILE=-Pnative
  710. REQUIRE_TEST_LIB_HADOOP=-Drequire.test.libhadoop
  711. fi
  712. if [[ -z "${PATCH_OR_ISSUE}" ]]; then
  713. hadoop_usage
  714. exit 1
  715. fi
  716. if [[ ${JENKINS} == "true" ]] ; then
  717. echo "Running in Jenkins mode"
  718. ISSUE=${PATCH_OR_ISSUE}
  719. RESETREPO=true
  720. # shellcheck disable=SC2034
  721. ECLIPSE_PROPERTY="-Declipse.home=${ECLIPSE_HOME}"
  722. else
  723. if [[ ${RESETREPO} == "true" ]] ; then
  724. echo "Running in destructive (--resetrepo) developer mode"
  725. else
  726. echo "Running in developer mode"
  727. fi
  728. JENKINS=false
  729. fi
  730. if [[ -n ${USER_PATCH_DIR} ]]; then
  731. PATCH_DIR="${USER_PATCH_DIR}"
  732. else
  733. PATCH_DIR=/tmp/${PROJECT_NAME}-test-patch/$$
  734. fi
  735. cd "${CWD}"
  736. if [[ ! -d ${PATCH_DIR} ]]; then
  737. mkdir -p "${PATCH_DIR}"
  738. if [[ $? == 0 ]] ; then
  739. echo "${PATCH_DIR} has been created"
  740. else
  741. echo "Unable to create ${PATCH_DIR}"
  742. cleanup_and_exit 1
  743. fi
  744. fi
  745. # we need absolute dir for PATCH_DIR
  746. PATCH_DIR=$(cd -P -- "${PATCH_DIR}" >/dev/null && pwd -P)
  747. GITDIFFLINES=${PATCH_DIR}/gitdifflines.txt
  748. if [[ ${TEST_PARALLEL} == "true" ]] ; then
  749. PARALLEL_TESTS_PROFILE=-Pparallel-tests
  750. if [[ -n ${TEST_THREADS:-} ]]; then
  751. TESTS_THREAD_COUNT="-DtestsThreadCount=$TEST_THREADS"
  752. fi
  753. fi
  754. }
  755. ## @description Locate the pom.xml file for a given directory
  756. ## @audience private
  757. ## @stability stable
  758. ## @replaceable no
  759. ## @return directory containing the pom.xml
  760. function find_pom_dir
  761. {
  762. local dir
  763. dir=$(dirname "$1")
  764. hadoop_debug "Find pom dir for: ${dir}"
  765. while builtin true; do
  766. if [[ -f "${dir}/pom.xml" ]];then
  767. echo "${dir}"
  768. hadoop_debug "Found: ${dir}"
  769. return
  770. else
  771. dir=$(dirname "${dir}")
  772. fi
  773. done
  774. }
  775. ## @description List of files that ${PATCH_DIR}/patch modifies
  776. ## @audience private
  777. ## @stability stable
  778. ## @replaceable no
  779. ## @return None; sets ${CHANGED_FILES}
  780. function find_changed_files
  781. {
  782. # get a list of all of the files that have been changed,
  783. # except for /dev/null (which would be present for new files).
  784. # Additionally, remove any a/ b/ patterns at the front
  785. # of the patch filenames and any revision info at the end
  786. # shellcheck disable=SC2016
  787. CHANGED_FILES=$(${GREP} -E '^(\+\+\+|---) ' "${PATCH_DIR}/patch" \
  788. | ${SED} \
  789. -e 's,^....,,' \
  790. -e 's,^[ab]/,,' \
  791. | ${GREP} -v /dev/null \
  792. | ${AWK} '{print $1}' \
  793. | sort -u)
  794. }
  795. ## @description Find the modules of the maven build that ${PATCH_DIR}/patch modifies
  796. ## @audience private
  797. ## @stability stable
  798. ## @replaceable no
  799. ## @return None; sets ${CHANGED_MODULES}
  800. function find_changed_modules
  801. {
  802. # Come up with a list of changed files into ${TMP}
  803. local pomdirs
  804. local module
  805. local pommods
  806. # Now find all the modules that were changed
  807. for file in ${CHANGED_FILES}; do
  808. #shellcheck disable=SC2086
  809. pomdirs="${pomdirs} $(find_pom_dir ${file})"
  810. done
  811. # Filter out modules without code
  812. for module in ${pomdirs}; do
  813. ${GREP} "<packaging>pom</packaging>" "${module}/pom.xml" > /dev/null
  814. if [[ "$?" != 0 ]]; then
  815. pommods="${pommods} ${module}"
  816. fi
  817. done
  818. #shellcheck disable=SC2086
  819. CHANGED_MODULES=$(echo ${pommods} ${USER_MODULE_LIST} | tr ' ' '\n' | sort -u)
  820. }
  821. ## @description git checkout the appropriate branch to test. Additionally, this calls
  822. ## @description 'determine_issue' and 'determine_branch' based upon the context provided
  823. ## @description in ${PATCH_DIR} and in git after checkout.
  824. ## @audience private
  825. ## @stability stable
  826. ## @replaceable no
  827. ## @return 0 on success. May exit on failure.
  828. function git_checkout
  829. {
  830. local currentbranch
  831. local exemptdir
  832. big_console_header "Confirming git environment"
  833. cd "${BASEDIR}"
  834. if [[ ! -d .git ]]; then
  835. hadoop_error "ERROR: ${BASEDIR} is not a git repo."
  836. cleanup_and_exit 1
  837. fi
  838. if [[ ${RESETREPO} == "true" ]] ; then
  839. ${GIT} reset --hard
  840. if [[ $? != 0 ]]; then
  841. hadoop_error "ERROR: git reset is failing"
  842. cleanup_and_exit 1
  843. fi
  844. # if PATCH_DIR is in BASEDIR, then we don't want
  845. # git wiping it out.
  846. exemptdir=$(relative_patchdir)
  847. if [[ $? == 1 ]]; then
  848. ${GIT} clean -xdf
  849. else
  850. # we do, however, want it emptied of all _files_.
  851. # we need to leave _directories_ in case we are in
  852. # re-exec mode (which places a directory full of stuff in it)
  853. hadoop_debug "Exempting ${exemptdir} from clean"
  854. rm "${PATCH_DIR}/*" 2>/dev/null
  855. ${GIT} clean -xdf -e "${exemptdir}"
  856. fi
  857. if [[ $? != 0 ]]; then
  858. hadoop_error "ERROR: git clean is failing"
  859. cleanup_and_exit 1
  860. fi
  861. ${GIT} checkout --force "${PATCH_BRANCH_DEFAULT}"
  862. if [[ $? != 0 ]]; then
  863. hadoop_error "ERROR: git checkout --force ${PATCH_BRANCH_DEFAULT} is failing"
  864. cleanup_and_exit 1
  865. fi
  866. determine_branch
  867. if [[ ${PATCH_BRANCH} =~ ^git ]]; then
  868. PATCH_BRANCH=$(echo "${PATCH_BRANCH}" | cut -dt -f2)
  869. fi
  870. # we need to explicitly fetch in case the
  871. # git ref hasn't been brought in tree yet
  872. if [[ ${OFFLINE} == false ]]; then
  873. ${GIT} pull --rebase
  874. if [[ $? != 0 ]]; then
  875. hadoop_error "ERROR: git pull is failing"
  876. cleanup_and_exit 1
  877. fi
  878. fi
  879. # forcibly checkout this branch or git ref
  880. ${GIT} checkout --force "${PATCH_BRANCH}"
  881. if [[ $? != 0 ]]; then
  882. hadoop_error "ERROR: git checkout ${PATCH_BRANCH} is failing"
  883. cleanup_and_exit 1
  884. fi
  885. # if we've selected a feature branch that has new changes
  886. # since our last build, we'll need to rebase to see those changes.
  887. if [[ ${OFFLINE} == false ]]; then
  888. ${GIT} pull --rebase
  889. if [[ $? != 0 ]]; then
  890. hadoop_error "ERROR: git pull is failing"
  891. cleanup_and_exit 1
  892. fi
  893. fi
  894. else
  895. status=$(${GIT} status --porcelain)
  896. if [[ "${status}" != "" && -z ${DIRTY_WORKSPACE} ]] ; then
  897. hadoop_error "ERROR: --dirty-workspace option not provided."
  898. hadoop_error "ERROR: can't run in a workspace that contains the following modifications"
  899. hadoop_error "${status}"
  900. cleanup_and_exit 1
  901. fi
  902. determine_branch
  903. if [[ ${PATCH_BRANCH} =~ ^git ]]; then
  904. PATCH_BRANCH=$(echo "${PATCH_BRANCH}" | cut -dt -f2)
  905. fi
  906. currentbranch=$(${GIT} rev-parse --abbrev-ref HEAD)
  907. if [[ "${currentbranch}" != "${PATCH_BRANCH}" ]];then
  908. echo "WARNING: Current git branch is ${currentbranch} but patch is built for ${PATCH_BRANCH}."
  909. echo "WARNING: Continuing anyway..."
  910. PATCH_BRANCH=${currentbranch}
  911. fi
  912. fi
  913. determine_issue
  914. GIT_REVISION=$(${GIT} rev-parse --verify --short HEAD)
  915. # shellcheck disable=SC2034
  916. VERSION=${GIT_REVISION}_${ISSUE}_PATCH-${patchNum}
  917. if [[ "${ISSUE}" == 'Unknown' ]]; then
  918. echo "Testing patch on ${PATCH_BRANCH}."
  919. else
  920. echo "Testing ${ISSUE} patch on ${PATCH_BRANCH}."
  921. fi
  922. add_jira_footer "git revision" "${PATCH_BRANCH} / ${GIT_REVISION}"
  923. if [[ ! -f ${BASEDIR}/pom.xml ]]; then
  924. hadoop_error "ERROR: This verison of test-patch.sh only supports Maven-based builds. Aborting."
  925. add_jira_table -1 pre-patch "Unsupported build system."
  926. output_to_jira 1
  927. cleanup_and_exit 1
  928. fi
  929. return 0
  930. }
  931. ## @description Confirm the source environment is compilable
  932. ## @audience private
  933. ## @stability stable
  934. ## @replaceable no
  935. ## @return 0 on success
  936. ## @return 1 on failure
  937. function precheck_without_patch
  938. {
  939. local -r mypwd=$(pwd)
  940. big_console_header "Pre-patch ${PATCH_BRANCH} Java verification"
  941. start_clock
  942. verify_needed_test javac
  943. if [[ $? == 1 ]]; then
  944. echo "Compiling ${mypwd}"
  945. echo_and_redirect "${PATCH_DIR}/${PATCH_BRANCH}JavacWarnings.txt" "${MVN}" "${MAVEN_ARGS[@]}" clean test -DskipTests -D${PROJECT_NAME}PatchProcess -Ptest-patch
  946. if [[ $? != 0 ]] ; then
  947. echo "${PATCH_BRANCH} compilation is broken?"
  948. add_jira_table -1 pre-patch "${PATCH_BRANCH} compilation may be broken."
  949. return 1
  950. fi
  951. else
  952. echo "Patch does not appear to need javac tests."
  953. fi
  954. verify_needed_test javadoc
  955. if [[ $? == 1 ]]; then
  956. echo "Javadoc'ing ${mypwd}"
  957. echo_and_redirect "${PATCH_DIR}/${PATCH_BRANCH}JavadocWarnings.txt" "${MVN}" "${MAVEN_ARGS[@]}" clean test javadoc:javadoc -DskipTests -Pdocs -D${PROJECT_NAME}PatchProcess
  958. if [[ $? != 0 ]] ; then
  959. echo "Pre-patch ${PATCH_BRANCH} javadoc compilation is broken?"
  960. add_jira_table -1 pre-patch "Pre-patch ${PATCH_BRANCH} JavaDoc compilation may be broken."
  961. return 1
  962. fi
  963. else
  964. echo "Patch does not appear to need javadoc tests."
  965. fi
  966. verify_needed_test site
  967. if [[ $? == 1 ]]; then
  968. echo "site creation for ${mypwd}"
  969. echo_and_redirect "${PATCH_DIR}/${PATCH_BRANCH}SiteWarnings.txt" "${MVN}" "${MAVEN_ARGS[@]}" clean site site:stage -DskipTests -Dmaven.javadoc.skip=true -D${PROJECT_NAME}PatchProcess
  970. if [[ $? != 0 ]] ; then
  971. echo "Pre-patch ${PATCH_BRANCH} site compilation is broken?"
  972. add_jira_table -1 pre-patch "Pre-patch ${PATCH_BRANCH} site compilation may be broken."
  973. return 1
  974. fi
  975. else
  976. echo "Patch does not appear to need site tests."
  977. fi
  978. precheck_findbugs
  979. if [[ $? != 0 ]] ; then
  980. return 1
  981. fi
  982. add_jira_table 0 pre-patch "Pre-patch ${PATCH_BRANCH} compilation is healthy."
  983. return 0
  984. }
  985. ## @description Confirm the given branch is a member of the list of space
  986. ## @description delimited branches or a git ref
  987. ## @audience private
  988. ## @stability evolving
  989. ## @replaceable no
  990. ## @param branch
  991. ## @param branchlist
  992. ## @return 0 on success
  993. ## @return 1 on failure
  994. function verify_valid_branch
  995. {
  996. local branches=$1
  997. local check=$2
  998. local i
  999. # shortcut some common
  1000. # non-resolvable names
  1001. if [[ -z ${check} ]]; then
  1002. return 1
  1003. fi
  1004. if [[ ${check} == patch ]]; then
  1005. return 1
  1006. fi
  1007. if [[ ${check} =~ ^git ]]; then
  1008. ref=$(echo "${check}" | cut -f2 -dt)
  1009. count=$(echo "${ref}" | wc -c | tr -d ' ')
  1010. if [[ ${count} == 8 || ${count} == 41 ]]; then
  1011. return 0
  1012. fi
  1013. return 1
  1014. fi
  1015. for i in ${branches}; do
  1016. if [[ "${i}" == "${check}" ]]; then
  1017. return 0
  1018. fi
  1019. done
  1020. return 1
  1021. }
  1022. ## @description Try to guess the branch being tested using a variety of heuristics
  1023. ## @audience private
  1024. ## @stability evolving
  1025. ## @replaceable no
  1026. ## @return 0 on success, with PATCH_BRANCH updated appropriately
  1027. ## @return 1 on failure, with PATCH_BRANCH updated to PATCH_BRANCH_DEFAULT
  1028. function determine_branch
  1029. {
  1030. local allbranches
  1031. local patchnamechunk
  1032. hadoop_debug "Determine branch"
  1033. # something has already set this, so move on
  1034. if [[ -n ${PATCH_BRANCH} ]]; then
  1035. return
  1036. fi
  1037. pushd "${BASEDIR}" > /dev/null
  1038. # developer mode, existing checkout, whatever
  1039. if [[ "${DIRTY_WORKSPACE}" == true ]];then
  1040. PATCH_BRANCH=$(${GIT} rev-parse --abbrev-ref HEAD)
  1041. echo "dirty workspace mode; applying against existing branch"
  1042. return
  1043. fi
  1044. allbranches=$(${GIT} branch -r | tr -d ' ' | ${SED} -e s,origin/,,g)
  1045. for j in "${PATCHURL}" "${PATCH_OR_ISSUE}"; do
  1046. hadoop_debug "Determine branch: starting with ${j}"
  1047. # shellcheck disable=SC2016
  1048. patchnamechunk=$(echo "${j}" | ${AWK} -F/ '{print $NF}')
  1049. # ISSUE.branch.##.patch
  1050. hadoop_debug "Determine branch: ISSUE.branch.##.patch"
  1051. PATCH_BRANCH=$(echo "${patchnamechunk}" | cut -f2 -d. )
  1052. verify_valid_branch "${allbranches}" "${PATCH_BRANCH}"
  1053. if [[ $? == 0 ]]; then
  1054. return
  1055. fi
  1056. # ISSUE-branch-##.patch
  1057. hadoop_debug "Determine branch: ISSUE-branch-##.patch"
  1058. PATCH_BRANCH=$(echo "${patchnamechunk}" | cut -f3- -d- | cut -f1,2 -d-)
  1059. verify_valid_branch "${allbranches}" "${PATCH_BRANCH}"
  1060. if [[ $? == 0 ]]; then
  1061. return
  1062. fi
  1063. # ISSUE-##.patch.branch
  1064. hadoop_debug "Determine branch: ISSUE-##.patch.branch"
  1065. # shellcheck disable=SC2016
  1066. PATCH_BRANCH=$(echo "${patchnamechunk}" | ${AWK} -F. '{print $NF}')
  1067. verify_valid_branch "${allbranches}" "${PATCH_BRANCH}"
  1068. if [[ $? == 0 ]]; then
  1069. return
  1070. fi
  1071. # ISSUE-branch.##.patch
  1072. hadoop_debug "Determine branch: ISSUE-branch.##.patch"
  1073. # shellcheck disable=SC2016
  1074. PATCH_BRANCH=$(echo "${patchnamechunk}" | cut -f3- -d- | ${AWK} -F. '{print $(NF-2)}' 2>/dev/null)
  1075. verify_valid_branch "${allbranches}" "${PATCH_BRANCH}"
  1076. if [[ $? == 0 ]]; then
  1077. return
  1078. fi
  1079. done
  1080. PATCH_BRANCH="${PATCH_BRANCH_DEFAULT}"
  1081. popd >/dev/null
  1082. }
  1083. ## @description Try to guess the issue being tested using a variety of heuristics
  1084. ## @audience private
  1085. ## @stability evolving
  1086. ## @replaceable no
  1087. ## @return 0 on success, with ISSUE updated appropriately
  1088. ## @return 1 on failure, with ISSUE updated to "Unknown"
  1089. function determine_issue
  1090. {
  1091. local patchnamechunk
  1092. local maybeissue
  1093. hadoop_debug "Determine issue"
  1094. # we can shortcut jenkins
  1095. if [[ ${JENKINS} == true ]]; then
  1096. ISSUE=${PATCH_OR_ISSUE}
  1097. return 0
  1098. fi
  1099. # shellcheck disable=SC2016
  1100. patchnamechunk=$(echo "${PATCH_OR_ISSUE}" | ${AWK} -F/ '{print $NF}')
  1101. maybeissue=$(echo "${patchnamechunk}" | cut -f1,2 -d-)
  1102. if [[ ${maybeissue} =~ ${ISSUE_RE} ]]; then
  1103. ISSUE=${maybeissue}
  1104. return 0
  1105. fi
  1106. ISSUE="Unknown"
  1107. return 1
  1108. }
  1109. ## @description Add the given test type
  1110. ## @audience public
  1111. ## @stability stable
  1112. ## @replaceable yes
  1113. ## @param test
  1114. function add_test
  1115. {
  1116. local testname=$1
  1117. hadoop_debug "Testing against ${testname}"
  1118. if [[ -z ${NEEDED_TESTS} ]]; then
  1119. hadoop_debug "Setting tests to ${testname}"
  1120. NEEDED_TESTS=${testname}
  1121. elif [[ ! ${NEEDED_TESTS} =~ ${testname} ]] ; then
  1122. hadoop_debug "Adding ${testname}"
  1123. NEEDED_TESTS="${NEEDED_TESTS} ${testname}"
  1124. fi
  1125. }
  1126. ## @description Verify if a given test was requested
  1127. ## @audience public
  1128. ## @stability stable
  1129. ## @replaceable yes
  1130. ## @param test
  1131. ## @return 1 = yes
  1132. ## @return 0 = no
  1133. function verify_needed_test
  1134. {
  1135. local i=$1
  1136. if [[ ${NEEDED_TESTS} =~ $i ]]; then
  1137. return 1
  1138. fi
  1139. return 0
  1140. }
  1141. ## @description Use some heuristics to determine which long running
  1142. ## @description tests to run
  1143. ## @audience private
  1144. ## @stability stable
  1145. ## @replaceable no
  1146. function determine_needed_tests
  1147. {
  1148. local i
  1149. for i in ${CHANGED_FILES}; do
  1150. if [[ ${i} =~ src/main/webapp ]]; then
  1151. hadoop_debug "tests/webapp: ${i}"
  1152. elif [[ ${i} =~ \.sh
  1153. || ${i} =~ \.cmd
  1154. ]]; then
  1155. hadoop_debug "tests/shell: ${i}"
  1156. elif [[ ${i} =~ \.md$
  1157. || ${i} =~ \.md\.vm$
  1158. || ${i} =~ src/site
  1159. || ${i} =~ src/main/docs
  1160. ]]; then
  1161. hadoop_debug "tests/site: ${i}"
  1162. add_test site
  1163. elif [[ ${i} =~ \.c$
  1164. || ${i} =~ \.cc$
  1165. || ${i} =~ \.h$
  1166. || ${i} =~ \.hh$
  1167. || ${i} =~ \.proto$
  1168. || ${i} =~ src/test
  1169. || ${i} =~ \.cmake$
  1170. || ${i} =~ CMakeLists.txt
  1171. ]]; then
  1172. hadoop_debug "tests/units: ${i}"
  1173. add_test javac
  1174. add_test unit
  1175. elif [[ ${i} =~ pom.xml$
  1176. || ${i} =~ \.java$
  1177. || ${i} =~ src/main
  1178. ]]; then
  1179. hadoop_debug "tests/javadoc+units: ${i}"
  1180. add_test javadoc
  1181. add_test javac
  1182. add_test unit
  1183. fi
  1184. if [[ ${i} =~ \.java$ ]]; then
  1185. add_test findbugs
  1186. fi
  1187. for plugin in ${PLUGINS}; do
  1188. if declare -f ${plugin}_filefilter >/dev/null 2>&1; then
  1189. "${plugin}_filefilter" "${i}"
  1190. fi
  1191. done
  1192. done
  1193. add_jira_footer "Optional Tests" "${NEEDED_TESTS}"
  1194. }
  1195. ## @description Given ${PATCH_ISSUE}, determine what type of patch file is in use, and do the
  1196. ## @description necessary work to place it into ${PATCH_DIR}/patch.
  1197. ## @audience private
  1198. ## @stability evolving
  1199. ## @replaceable no
  1200. ## @return 0 on success
  1201. ## @return 1 on failure, may exit
  1202. function locate_patch
  1203. {
  1204. local notSureIfPatch=false
  1205. hadoop_debug "locate patch"
  1206. if [[ -f ${PATCH_OR_ISSUE} ]]; then
  1207. PATCH_FILE="${PATCH_OR_ISSUE}"
  1208. else
  1209. if [[ ${PATCH_OR_ISSUE} =~ ^http ]]; then
  1210. echo "Patch is being downloaded at $(date) from"
  1211. PATCHURL="${PATCH_OR_ISSUE}"
  1212. else
  1213. ${WGET} -q -O "${PATCH_DIR}/jira" "http://issues.apache.org/jira/browse/${PATCH_OR_ISSUE}"
  1214. if [[ $? != 0 ]];then
  1215. hadoop_error "ERROR: Unable to determine what ${PATCH_OR_ISSUE} may reference."
  1216. cleanup_and_exit 1
  1217. fi
  1218. if [[ $(${GREP} -c 'Patch Available' "${PATCH_DIR}/jira") == 0 ]] ; then
  1219. if [[ ${JENKINS} == true ]]; then
  1220. hadoop_error "ERROR: ${PATCH_OR_ISSUE} is not \"Patch Available\"."
  1221. cleanup_and_exit 1
  1222. else
  1223. hadoop_error "WARNING: ${PATCH_OR_ISSUE} is not \"Patch Available\"."
  1224. fi
  1225. fi
  1226. relativePatchURL=$(${GREP} -o '"/jira/secure/attachment/[0-9]*/[^"]*' "${PATCH_DIR}/jira" | ${GREP} -v -e 'htm[l]*$' | sort | tail -1 | ${GREP} -o '/jira/secure/attachment/[0-9]*/[^"]*')
  1227. PATCHURL="http://issues.apache.org${relativePatchURL}"
  1228. if [[ ! ${PATCHURL} =~ \.patch$ ]]; then
  1229. notSureIfPatch=true
  1230. fi
  1231. patchNum=$(echo "${PATCHURL}" | ${GREP} -o '[0-9]*/' | ${GREP} -o '[0-9]*')
  1232. echo "${ISSUE} patch is being downloaded at $(date) from"
  1233. fi
  1234. echo "${PATCHURL}"
  1235. add_jira_footer "Patch URL" "${PATCHURL}"
  1236. ${WGET} -q -O "${PATCH_DIR}/patch" "${PATCHURL}"
  1237. if [[ $? != 0 ]];then
  1238. hadoop_error "ERROR: ${PATCH_OR_ISSUE} could not be downloaded."
  1239. cleanup_and_exit 1
  1240. fi
  1241. PATCH_FILE="${PATCH_DIR}/patch"
  1242. fi
  1243. if [[ ! -f "${PATCH_DIR}/patch" ]]; then
  1244. cp "${PATCH_FILE}" "${PATCH_DIR}/patch"
  1245. if [[ $? == 0 ]] ; then
  1246. echo "Patch file ${PATCH_FILE} copied to ${PATCH_DIR}"
  1247. else
  1248. hadoop_error "ERROR: Could not copy ${PATCH_FILE} to ${PATCH_DIR}"
  1249. cleanup_and_exit 1
  1250. fi
  1251. fi
  1252. if [[ ${notSureIfPatch} == "true" ]]; then
  1253. guess_patch_file "${PATCH_DIR}/patch"
  1254. if [[ $? != 0 ]]; then
  1255. hadoop_error "ERROR: ${PATCHURL} is not a patch file."
  1256. cleanup_and_exit 1
  1257. else
  1258. hadoop_debug "The patch ${PATCHURL} was not named properly, but it looks like a patch file. proceeding, but issue/branch matching might go awry."
  1259. add_jira_table 0 patch "The patch file was not named according to ${PROJECT_NAME}'s naming conventions. Please see ${HOW_TO_CONTRIBUTE} for instructions."
  1260. fi
  1261. fi
  1262. }
  1263. ## @description Given a possible patch file, guess if it's a patch file without using smart-apply-patch
  1264. ## @audience private
  1265. ## @stability evolving
  1266. ## @param path to patch file to test
  1267. ## @return 0 we think it's a patch file
  1268. ## @return 1 we think it's not a patch file
  1269. function guess_patch_file
  1270. {
  1271. local patch=$1
  1272. local fileOutput
  1273. hadoop_debug "Trying to guess is ${patch} is a patch file."
  1274. fileOutput=$("${FILE}" "${patch}")
  1275. if [[ $fileOutput =~ \ diff\ ]]; then
  1276. hadoop_debug "file magic says it's a diff."
  1277. return 0
  1278. fi
  1279. fileOutput=$(head -n 1 "${patch}" | "${EGREP}" "^(From [a-z0-9]* Mon Sep 17 00:00:00 2001)|(diff .*)|(Index: .*)$")
  1280. if [[ $? == 0 ]]; then
  1281. hadoop_debug "first line looks like a patch file."
  1282. return 0
  1283. fi
  1284. return 1
  1285. }
  1286. ## @description Given ${PATCH_DIR}/patch, verify the patch is good using ${BINDIR}/smart-apply-patch.sh
  1287. ## @description in dryrun mode.
  1288. ## @audience private
  1289. ## @stability evolving
  1290. ## @replaceable no
  1291. ## @return 0 on success
  1292. ## @return 1 on failure
  1293. function verify_patch_file
  1294. {
  1295. # Before building, check to make sure that the patch is valid
  1296. export PATCH
  1297. "${BINDIR}/smart-apply-patch.sh" "${PATCH_DIR}/patch" dryrun
  1298. if [[ $? != 0 ]] ; then
  1299. echo "PATCH APPLICATION FAILED"
  1300. add_jira_table -1 patch "The patch command could not apply the patch during dryrun."
  1301. return 1
  1302. else
  1303. return 0
  1304. fi
  1305. }
  1306. ## @description Given ${PATCH_DIR}/patch, apply the patch using ${BINDIR}/smart-apply-patch.sh
  1307. ## @audience private
  1308. ## @stability evolving
  1309. ## @replaceable no
  1310. ## @return 0 on success
  1311. ## @return exit on failure
  1312. function apply_patch_file
  1313. {
  1314. big_console_header "Applying patch"
  1315. export PATCH
  1316. "${BINDIR}/smart-apply-patch.sh" "${PATCH_DIR}/patch"
  1317. if [[ $? != 0 ]] ; then
  1318. echo "PATCH APPLICATION FAILED"
  1319. ((RESULT = RESULT + 1))
  1320. add_jira_table -1 patch "The patch command could not apply the patch."
  1321. output_to_console 1
  1322. output_to_jira 1
  1323. cleanup_and_exit 1
  1324. fi
  1325. return 0
  1326. }
  1327. ## @description If this actually patches the files used for the QA process
  1328. ## @description under dev-support and its subdirectories, then
  1329. ## @description run with the patched version for the test.
  1330. ## @audience private
  1331. ## @stability evolving
  1332. ## @replaceable no
  1333. ## @return none; otherwise relaunches
  1334. function check_reexec
  1335. {
  1336. local commentfile=${PATCH_DIR}/tp.${RANDOM}
  1337. if [[ ${REEXECED} == true ]]; then
  1338. big_console_header "Re-exec mode detected. Continuing."
  1339. return
  1340. fi
  1341. if [[ ! ${CHANGED_FILES} =~ dev-support/test-patch
  1342. && ! ${CHANGED_FILES} =~ dev-support/smart-apply ]] ; then
  1343. return
  1344. fi
  1345. big_console_header "dev-support patch detected"
  1346. if [[ ${RESETREPO} == false ]]; then
  1347. ((RESULT = RESULT + 1))
  1348. hadoop_debug "can't destructively change the working directory. run with '--resetrepo' please. :("
  1349. add_jira_table -1 dev-support "Couldn't test dev-support changes because we aren't configured to destructively change the working directory."
  1350. return
  1351. fi
  1352. printf "\n\nRe-executing against patched versions to test.\n\n"
  1353. apply_patch_file
  1354. if [[ ${JENKINS} == true ]]; then
  1355. rm "${commentfile}" 2>/dev/null
  1356. echo "(!) A patch to the files used for the QA process has been detected. " > "${commentfile}"
  1357. echo "Re-executing against the patched versions to perform further tests. " >> "${commentfile}"
  1358. echo "The console is at ${BUILD_URL}console in case of problems." >> "${commentfile}"
  1359. write_to_jira "${commentfile}"
  1360. rm "${commentfile}"
  1361. fi
  1362. cd "${CWD}"
  1363. mkdir -p "${PATCH_DIR}/dev-support-test"
  1364. cp -pr "${BASEDIR}"/dev-support/test-patch* "${PATCH_DIR}/dev-support-test"
  1365. cp -pr "${BASEDIR}"/dev-support/smart-apply* "${PATCH_DIR}/dev-support-test"
  1366. big_console_header "exec'ing test-patch.sh now..."
  1367. exec "${PATCH_DIR}/dev-support-test/test-patch.sh" \
  1368. --reexec \
  1369. --branch="${PATCH_BRANCH}" \
  1370. --patch-dir="${PATCH_DIR}" \
  1371. "${USER_PARAMS[@]}"
  1372. }
  1373. ## @description Check the current directory for @author tags
  1374. ## @audience private
  1375. ## @stability evolving
  1376. ## @replaceable no
  1377. ## @return 0 on success
  1378. ## @return 1 on failure
  1379. function check_author
  1380. {
  1381. local authorTags
  1382. big_console_header "Checking there are no @author tags in the patch."
  1383. start_clock
  1384. if [[ ${CHANGED_FILES} =~ dev-support/test-patch ]]; then
  1385. add_jira_table 0 @author "Skipping @author checks as test-patch has been patched."
  1386. return 0
  1387. fi
  1388. authorTags=$("${GREP}" -c -i '^[^-].*@author' "${PATCH_DIR}/patch")
  1389. echo "There appear to be ${authorTags} @author tags in the patch."
  1390. if [[ ${authorTags} != 0 ]] ; then
  1391. add_jira_table -1 @author \
  1392. "The patch appears to contain ${authorTags} @author tags which the Hadoop" \
  1393. " community has agreed to not allow in code contributions."
  1394. return 1
  1395. fi
  1396. add_jira_table +1 @author "The patch does not contain any @author tags."
  1397. return 0
  1398. }
  1399. ## @description Check the patch file for changed/new tests
  1400. ## @audience private
  1401. ## @stability evolving
  1402. ## @replaceable no
  1403. ## @return 0 on success
  1404. ## @return 1 on failure
  1405. function check_modified_unittests
  1406. {
  1407. local testReferences=0
  1408. local i
  1409. verify_needed_test unit
  1410. if [[ $? == 0 ]]; then
  1411. return 0
  1412. fi
  1413. big_console_header "Checking there are new or changed tests in the patch."
  1414. start_clock
  1415. for i in ${CHANGED_FILES}; do
  1416. if [[ ${i} =~ /test/ ]]; then
  1417. ((testReferences=testReferences + 1))
  1418. fi
  1419. done
  1420. echo "There appear to be ${testReferences} test file(s) referenced in the patch."
  1421. if [[ ${testReferences} == 0 ]] ; then
  1422. add_jira_table -1 "tests included" \
  1423. "The patch doesn't appear to include any new or modified tests. " \
  1424. "Please justify why no new tests are needed for this patch." \
  1425. "Also please list what manual steps were performed to verify this patch."
  1426. return 1
  1427. fi
  1428. add_jira_table +1 "tests included" \
  1429. "The patch appears to include ${testReferences} new or modified test files."
  1430. return 0
  1431. }
  1432. ## @description Helper for check_javadoc
  1433. ## @audience private
  1434. ## @stability evolving
  1435. ## @replaceable no
  1436. ## @return 0 on success
  1437. ## @return 1 on failure
  1438. function count_javadoc_warns
  1439. {
  1440. local warningfile=$1
  1441. #shellcheck disable=SC2016,SC2046
  1442. return $(${EGREP} "^[0-9]+ warnings$" "${warningfile}" | ${AWK} '{sum+=$1} END {print sum}')
  1443. }
  1444. ## @description Count and compare the number of JavaDoc warnings pre- and post- patch
  1445. ## @audience private
  1446. ## @stability evolving
  1447. ## @replaceable no
  1448. ## @return 0 on success
  1449. ## @return 1 on failure
  1450. function check_javadoc
  1451. {
  1452. local numBranchJavadocWarnings
  1453. local numPatchJavadocWarnings
  1454. verify_needed_test javadoc
  1455. if [[ $? == 0 ]]; then
  1456. echo "This patch does not appear to need javadoc checks."
  1457. return 0
  1458. fi
  1459. big_console_header "Determining number of patched javadoc warnings"
  1460. start_clock
  1461. if [[ -d hadoop-project ]]; then
  1462. (cd hadoop-project; "${MVN}" "${MAVEN_ARGS[@]}" install > /dev/null 2>&1)
  1463. fi
  1464. if [[ -d hadoop-common-project/hadoop-annotations ]]; then
  1465. (cd hadoop-common-project/hadoop-annotations; "${MVN}" "${MAVEN_ARGS[@]}" install > /dev/null 2>&1)
  1466. fi
  1467. echo_and_redirect "${PATCH_DIR}/patchJavadocWarnings.txt" "${MVN}" "${MAVEN_ARGS[@]}" clean test javadoc:javadoc -DskipTests -Pdocs -D${PROJECT_NAME}PatchProcess
  1468. count_javadoc_warns "${PATCH_DIR}/${PATCH_BRANCH}JavadocWarnings.txt"
  1469. numBranchJavadocWarnings=$?
  1470. count_javadoc_warns "${PATCH_DIR}/patchJavadocWarnings.txt"
  1471. numPatchJavadocWarnings=$?
  1472. echo "There appear to be ${numBranchJavadocWarnings} javadoc warnings before the patch and ${numPatchJavadocWarnings} javadoc warnings after applying the patch."
  1473. if [[ ${numBranchJavadocWarnings} != "" && ${numPatchJavadocWarnings} != "" ]] ; then
  1474. if [[ ${numPatchJavadocWarnings} -gt ${numBranchJavadocWarnings} ]] ; then
  1475. ${GREP} -i warning "${PATCH_DIR}/${PATCH_BRANCH}JavadocWarnings.txt" > "${PATCH_DIR}/${PATCH_BRANCH}JavadocWarningsFiltered.txt"
  1476. ${GREP} -i warning "${PATCH_DIR}/patchJavadocWarnings.txt" > "${PATCH_DIR}/patchJavadocWarningsFiltered.txt"
  1477. ${DIFF} -u "${PATCH_DIR}/${PATCH_BRANCH}JavadocWarningsFiltered.txt" \
  1478. "${PATCH_DIR}/patchJavadocWarningsFiltered.txt" \
  1479. > "${PATCH_DIR}/diffJavadocWarnings.txt"
  1480. rm -f "${PATCH_DIR}/${PATCH_BRANCH}JavadocWarningsFiltered.txt" "${PATCH_DIR}/patchJavadocWarningsFiltered.txt"
  1481. add_jira_table -1 javadoc "The applied patch generated "\
  1482. "$((numPatchJavadocWarnings-numBranchJavadocWarnings))" \
  1483. " additional warning messages."
  1484. add_jira_footer javadoc "@@BASE@@/diffJavadocWarnings.txt"
  1485. return 1
  1486. fi
  1487. fi
  1488. add_jira_table +1 javadoc "There were no new javadoc warning messages."
  1489. return 0
  1490. }
  1491. ## @description Make sure site still compiles
  1492. ## @audience private
  1493. ## @stability evolving
  1494. ## @replaceable no
  1495. ## @return 0 on success
  1496. ## @return 1 on failure
  1497. function check_site
  1498. {
  1499. local -r mypwd=$(pwd)
  1500. verify_needed_test site
  1501. if [[ $? == 0 ]]; then
  1502. echo "This patch does not appear to need site checks."
  1503. return 0
  1504. fi
  1505. big_console_header "Determining if patched site still builds"
  1506. start_clock
  1507. echo "site creation for ${mypwd}"
  1508. echo_and_redirect "${PATCH_DIR}/patchSiteWarnings.txt" "${MVN}" "${MAVEN_ARGS[@]}" clean site site:stage -DskipTests -Dmaven.javadoc.skip=true -D${PROJECT_NAME}PatchProcess
  1509. if [[ $? != 0 ]] ; then
  1510. echo "Site compilation is broken"
  1511. add_jira_table -1 site "Site compilation is broken."
  1512. add_jira_footer site "@@BASE@@/patchSiteWarnings.txt"
  1513. return 1
  1514. fi
  1515. add_jira_table +1 site "Site still builds."
  1516. return 0
  1517. }
  1518. ## @description Helper for check_javac
  1519. ## @audience private
  1520. ## @stability evolving
  1521. ## @replaceable no
  1522. ## @return 0 on success
  1523. ## @return 1 on failure
  1524. function count_javac_warns
  1525. {
  1526. local warningfile=$1
  1527. #shellcheck disable=SC2016,SC2046
  1528. return $(${AWK} 'BEGIN {total = 0} {total += 1} END {print total}' "${warningfile}")
  1529. }
  1530. ## @description Count and compare the number of javac warnings pre- and post- patch
  1531. ## @audience private
  1532. ## @stability evolving
  1533. ## @replaceable no
  1534. ## @return 0 on success
  1535. ## @return 1 on failure
  1536. function check_javac
  1537. {
  1538. local branchJavacWarnings
  1539. local patchJavacWarnings
  1540. verify_needed_test javac
  1541. if [[ $? == 0 ]]; then
  1542. echo "This patch does not appear to need javac checks."
  1543. return 0
  1544. fi
  1545. big_console_header "Determining number of patched javac warnings."
  1546. start_clock
  1547. echo_and_redirect "${PATCH_DIR}/patchJavacWarnings.txt" "${MVN}" "${MAVEN_ARGS[@]}" clean test -DskipTests -D${PROJECT_NAME}PatchProcess ${NATIVE_PROFILE} -Ptest-patch
  1548. if [[ $? != 0 ]] ; then
  1549. add_jira_table -1 javac "The patch appears to cause the build to fail."
  1550. return 2
  1551. fi
  1552. ### Compare ${PATCH_BRANCH} and patch javac warning numbers
  1553. if [[ -f ${PATCH_DIR}/patchJavacWarnings.txt ]] ; then
  1554. ${GREP} '\[WARNING\]' "${PATCH_DIR}/${PATCH_BRANCH}JavacWarnings.txt" > "${PATCH_DIR}/filtered${PATCH_BRANCH}JavacWarnings.txt"
  1555. ${GREP} '\[WARNING\]' "${PATCH_DIR}/patchJavacWarnings.txt" > "${PATCH_DIR}/filteredPatchJavacWarnings.txt"
  1556. count_javac_warns "${PATCH_DIR}/filtered${PATCH_BRANCH}JavacWarnings.txt"
  1557. branchJavacWarnings=$?
  1558. count_javac_warns "${PATCH_DIR}/filteredPatchJavacWarnings.txt"
  1559. patchJavacWarnings=$?
  1560. echo "There appear to be ${branchJavacWarnings} javac compiler warnings before the patch and ${patchJavacWarnings} javac compiler warnings after applying the patch."
  1561. if [[ ${patchJavacWarnings} != "" && ${branchJavacWarnings} != "" ]] ; then
  1562. if [[ ${patchJavacWarnings} -gt ${branchJavacWarnings} ]] ; then
  1563. ${DIFF} "${PATCH_DIR}/filtered${PATCH_BRANCH}JavacWarnings.txt" \
  1564. "${PATCH_DIR}/filteredPatchJavacWarnings.txt" \
  1565. > "${PATCH_DIR}/diffJavacWarnings.txt"
  1566. add_jira_table -1 javac "The applied patch generated "\
  1567. "$((patchJavacWarnings-branchJavacWarnings))" \
  1568. " additional warning messages."
  1569. add_jira_footer javac "@@BASE@@/diffJavacWarnings.txt"
  1570. return 1
  1571. fi
  1572. fi
  1573. fi
  1574. add_jira_table +1 javac "There were no new javac warning messages."
  1575. return 0
  1576. }
  1577. ## @description Verify all files have an Apache License
  1578. ## @audience private
  1579. ## @stability evolving
  1580. ## @replaceable no
  1581. ## @return 0 on success
  1582. ## @return 1 on failure
  1583. function check_apachelicense
  1584. {
  1585. big_console_header "Determining number of patched release audit warnings."
  1586. start_clock
  1587. echo_and_redirect "${PATCH_DIR}/patchReleaseAuditOutput.txt" "${MVN}" "${MAVEN_ARGS[@]}" apache-rat:check -D${PROJECT_NAME}PatchProcess
  1588. #shellcheck disable=SC2038
  1589. find "${BASEDIR}" -name rat.txt | xargs cat > "${PATCH_DIR}/patchReleaseAuditWarnings.txt"
  1590. ### Compare ${PATCH_BRANCH} and patch release audit warning numbers
  1591. if [[ -f ${PATCH_DIR}/patchReleaseAuditWarnings.txt ]] ; then
  1592. patchReleaseAuditWarnings=$("${GREP}" -c '\!?????' "${PATCH_DIR}/patchReleaseAuditWarnings.txt")
  1593. echo ""
  1594. echo ""
  1595. echo "There appear to be ${patchReleaseAuditWarnings} release audit warnings after applying the patch."
  1596. if [[ ${patchReleaseAuditWarnings} != "" ]] ; then
  1597. if [[ ${patchReleaseAuditWarnings} -gt 0 ]] ; then
  1598. add_jira_table -1 "release audit" "The applied patch generated ${patchReleaseAuditWarnings} release audit warnings."
  1599. ${GREP} '\!?????' "${PATCH_DIR}/patchReleaseAuditWarnings.txt" \
  1600. > "${PATCH_DIR}/patchReleaseAuditProblems.txt"
  1601. echo "Lines that start with ????? in the release audit "\
  1602. "report indicate files that do not have an Apache license header." \
  1603. >> "${PATCH_DIR}/patchReleaseAuditProblems.txt"
  1604. add_jira_footer "Release Audit" "@@BASE@@/patchReleaseAuditProblems.txt"
  1605. return 1
  1606. fi
  1607. fi
  1608. fi
  1609. add_jira_table 1 "release audit" "The applied patch does not increase the total number of release audit warnings."
  1610. return 0
  1611. }
  1612. ## @description Verify mvn install works
  1613. ## @audience private
  1614. ## @stability evolving
  1615. ## @replaceable no
  1616. ## @return 0 on success
  1617. ## @return 1 on failure
  1618. function check_mvn_install
  1619. {
  1620. local retval
  1621. verify_needed_test javadoc
  1622. retval=$?
  1623. verify_needed_test javac
  1624. ((retval = retval + $? ))
  1625. if [[ ${retval} == 0 ]]; then
  1626. echo "This patch does not appear to need mvn install checks."
  1627. return 0
  1628. fi
  1629. big_console_header "Installing all of the jars"
  1630. start_clock
  1631. echo_and_redirect "${PATCH_DIR}/jarinstall.txt" "${MVN}" "${MAVEN_ARGS[@]}" install -Dmaven.javadoc.skip=true -DskipTests -D${PROJECT_NAME}PatchProcess
  1632. retval=$?
  1633. if [[ ${retval} != 0 ]]; then
  1634. add_jira_table -1 install "The patch causes mvn install to fail."
  1635. else
  1636. add_jira_table +1 install "mvn install still works."
  1637. fi
  1638. return ${retval}
  1639. }
  1640. ## @description are the needed bits for findbugs present?
  1641. ## @audience private
  1642. ## @stability evolving
  1643. ## @replaceable no
  1644. ## @return 0 findbugs will work for our use
  1645. ## @return 1 findbugs is missing some component
  1646. function findbugs_is_installed
  1647. {
  1648. if [[ ! -e "${FINDBUGS_HOME}/bin/findbugs" ]]; then
  1649. printf "\n\n%s is not executable.\n\n" "${FINDBUGS_HOME}/bin/findbugs"
  1650. add_jira_table -1 findbugs "Findbugs is not installed."
  1651. return 1
  1652. fi
  1653. return 0
  1654. }
  1655. ## @description Run the maven findbugs plugin and record found issues in a bug database
  1656. ## @audience private
  1657. ## @stability evolving
  1658. ## @replaceable no
  1659. ## @return 0 on success
  1660. ## @return 1 on failure
  1661. function findbugs_mvnrunner
  1662. {
  1663. local name=$1
  1664. local logfile=$2
  1665. local warnings_file=$3
  1666. echo_and_redirect "${logfile}" "${MVN}" "${MAVEN_ARGS[@]}" clean test findbugs:findbugs -DskipTests \
  1667. "-D${PROJECT_NAME}PatchProcess" < /dev/null
  1668. if [[ $? != 0 ]]; then
  1669. return 1
  1670. fi
  1671. cp target/findbugsXml.xml "${warnings_file}.xml"
  1672. "${FINDBUGS_HOME}/bin/setBugDatabaseInfo" -name "${name}" \
  1673. "${warnings_file}.xml" "${warnings_file}.xml"
  1674. if [[ $? != 0 ]]; then
  1675. return 1
  1676. fi
  1677. "${FINDBUGS_HOME}/bin/convertXmlToText" -html "${warnings_file}.xml" \
  1678. "${warnings_file}.html"
  1679. if [[ $? != 0 ]]; then
  1680. return 1
  1681. fi
  1682. return 0
  1683. }
  1684. ## @description Track pre-existing findbugs warnings
  1685. ## @audience private
  1686. ## @stability evolving
  1687. ## @replaceable no
  1688. ## @return 0 on success
  1689. ## @return 1 on failure
  1690. function precheck_findbugs
  1691. {
  1692. local -r mypwd=$(pwd)
  1693. local module_suffix
  1694. local modules=${CHANGED_MODULES}
  1695. local module
  1696. local findbugs_version
  1697. local rc=0
  1698. local module_findbugs_warnings
  1699. local findbugs_warnings=0
  1700. verify_needed_test findbugs
  1701. if [[ $? == 0 ]]; then
  1702. echo "Patch does not appear to need findbugs tests."
  1703. return 0
  1704. fi
  1705. echo "findbugs baseline for ${mypwd}"
  1706. findbugs_is_installed
  1707. if [[ $? != 0 ]]; then
  1708. return 1
  1709. fi
  1710. for module in ${modules}
  1711. do
  1712. pushd "${module}" >/dev/null
  1713. echo " Running findbugs in ${module}"
  1714. module_suffix=$(basename "${module}")
  1715. findbugs_mvnrunner "${PATCH_BRANCH}" \
  1716. "${PATCH_DIR}/${PATCH_BRANCH}FindBugsOutput${module_suffix}.txt" \
  1717. "${PATCH_DIR}/${PATCH_BRANCH}FindbugsWarnings${module_suffix}"
  1718. (( rc = rc + $? ))
  1719. if [[ "${FINDBUGS_WARNINGS_FAIL_PRECHECK}" == "true" ]]; then
  1720. #shellcheck disable=SC2016
  1721. module_findbugs_warnings=$("${FINDBUGS_HOME}/bin/filterBugs" -first \
  1722. "${PATCH_BRANCH}" \
  1723. "${PATCH_DIR}/${PATCH_BRANCH}FindbugsWarnings${module_suffix}".xml \
  1724. "${PATCH_DIR}/${PATCH_BRANCH}FindbugsWarnings${module_suffix}".xml \
  1725. | ${AWK} '{print $1}')
  1726. if [[ $? != 0 ]]; then
  1727. popd >/dev/null
  1728. return 1
  1729. fi
  1730. findbugs_warnings=$((findbugs_warnings+module_findbugs_warnings))
  1731. if [[ ${module_findbugs_warnings} -gt 0 ]] ; then
  1732. add_jira_footer "Pre-patch Findbugs warnings" "@@BASE@@/${PATCH_BRANCH}FindbugsWarnings${module_suffix}.html"
  1733. fi
  1734. fi
  1735. popd >/dev/null
  1736. done
  1737. #shellcheck disable=SC2016
  1738. findbugs_version=$(${AWK} 'match($0, /findbugs-maven-plugin:[^:]*:findbugs/) { print substr($0, RSTART + 22, RLENGTH - 31); exit }' "${PATCH_DIR}/${PATCH_BRANCH}FindBugsOutput${module_suffix}.txt")
  1739. if [[ ${rc} -ne 0 ]]; then
  1740. echo "Pre-patch ${PATCH_BRANCH} findbugs is broken?"
  1741. add_jira_table -1 pre-patch "Findbugs (version ${findbugs_version}) appears to be broken on ${PATCH_BRANCH}."
  1742. return 1
  1743. fi
  1744. if [[ "${FINDBUGS_WARNINGS_FAIL_PRECHECK}" == "true" && \
  1745. ${findbugs_warnings} -gt 0 ]] ; then
  1746. echo "Pre-patch ${PATCH_BRANCH} findbugs has ${findbugs_warnings} warnings."
  1747. add_jira_table -1 pre-patch "Pre-patch ${PATCH_BRANCH} has ${findbugs_warnings} extant Findbugs (version ${findbugs_version}) warnings."
  1748. return 1
  1749. fi
  1750. return 0
  1751. }
  1752. ## @description Verify patch does not trigger any findbugs warnings
  1753. ## @audience private
  1754. ## @stability evolving
  1755. ## @replaceable no
  1756. ## @return 0 on success
  1757. ## @return 1 on failure
  1758. function check_findbugs
  1759. {
  1760. local rc=0
  1761. local module
  1762. local modules=${CHANGED_MODULES}
  1763. local module_suffix
  1764. local combined_xml
  1765. local newBugs
  1766. local new_findbugs_warnings
  1767. local new_findbugs_fixed_warnings
  1768. local findbugs_warnings=0
  1769. local findbugs_fixed_warnings=0
  1770. local line
  1771. local firstpart
  1772. local secondpart
  1773. local findbugs_version
  1774. verify_needed_test findbugs
  1775. if [[ $? == 0 ]]; then
  1776. return 0
  1777. fi
  1778. big_console_header "Determining number of patched Findbugs warnings."
  1779. start_clock
  1780. findbugs_is_installed
  1781. if [[ $? != 0 ]]; then
  1782. return 1
  1783. fi
  1784. for module in ${modules}
  1785. do
  1786. pushd "${module}" >/dev/null
  1787. echo " Running findbugs in ${module}"
  1788. module_suffix=$(basename "${module}")
  1789. findbugs_mvnrunner patch \
  1790. "${PATCH_DIR}/patchFindBugsOutput${module_suffix}.txt" \
  1791. "${PATCH_DIR}/patchFindbugsWarnings${module_suffix}"
  1792. if [[ $? != 0 ]] ; then
  1793. ((rc = rc +1))
  1794. echo "Post-patch findbugs compilation is broken."
  1795. add_jira_table -1 findbugs "Post-patch findbugs ${module} compilation is broken."
  1796. continue
  1797. fi
  1798. combined_xml="$PATCH_DIR/combinedFindbugsWarnings${module_suffix}.xml"
  1799. newBugs="${PATCH_DIR}/newPatchFindbugsWarnings${module_suffix}"
  1800. "${FINDBUGS_HOME}/bin/computeBugHistory" -useAnalysisTimes -withMessages \
  1801. -output "${combined_xml}" \
  1802. "${PATCH_DIR}/${PATCH_BRANCH}FindbugsWarnings${module_suffix}.xml" \
  1803. "${PATCH_DIR}/patchFindbugsWarnings${module_suffix}.xml"
  1804. if [[ $? != 0 ]]; then
  1805. popd >/dev/null
  1806. return 1
  1807. fi
  1808. #shellcheck disable=SC2016
  1809. new_findbugs_warnings=$("${FINDBUGS_HOME}/bin/filterBugs" -first patch \
  1810. "${combined_xml}" "${newBugs}.xml" | ${AWK} '{print $1}')
  1811. if [[ $? != 0 ]]; then
  1812. popd >/dev/null
  1813. return 1
  1814. fi
  1815. #shellcheck disable=SC2016
  1816. new_findbugs_fixed_warnings=$("${FINDBUGS_HOME}/bin/filterBugs" -fixed patch \
  1817. "${combined_xml}" "${newBugs}.xml" | ${AWK} '{print $1}')
  1818. if [[ $? != 0 ]]; then
  1819. popd >/dev/null
  1820. return 1
  1821. fi
  1822. echo "Found ${new_findbugs_warnings} new Findbugs warnings and ${new_findbugs_fixed_warnings} newly fixed warnings."
  1823. findbugs_warnings=$((findbugs_warnings+new_findbugs_warnings))
  1824. findbugs_fixed_warnings=$((findbugs_fixed_warnings+new_findbugs_fixed_warnings))
  1825. "${FINDBUGS_HOME}/bin/convertXmlToText" -html "${newBugs}.xml" \
  1826. "${newBugs}.html"
  1827. if [[ $? != 0 ]]; then
  1828. popd >/dev/null
  1829. return 1
  1830. fi
  1831. if [[ ${new_findbugs_warnings} -gt 0 ]] ; then
  1832. populate_test_table FindBugs "module:${module_suffix}"
  1833. while read line; do
  1834. firstpart=$(echo "${line}" | cut -f2 -d:)
  1835. secondpart=$(echo "${line}" | cut -f9- -d' ')
  1836. add_jira_test_table "" "${firstpart}:${secondpart}"
  1837. done < <("${FINDBUGS_HOME}/bin/convertXmlToText" "${newBugs}.xml")
  1838. add_jira_footer "Findbugs warnings" "@@BASE@@/newPatchFindbugsWarnings${module_suffix}.html"
  1839. fi
  1840. popd >/dev/null
  1841. done
  1842. #shellcheck disable=SC2016
  1843. findbugs_version=$(${AWK} 'match($0, /findbugs-maven-plugin:[^:]*:findbugs/) { print substr($0, RSTART + 22, RLENGTH - 31); exit }' "${PATCH_DIR}/patchFindBugsOutput${module_suffix}.txt")
  1844. if [[ ${findbugs_warnings} -gt 0 ]] ; then
  1845. add_jira_table -1 findbugs "The patch appears to introduce ${findbugs_warnings} new Findbugs (version ${findbugs_version}) warnings."
  1846. return 1
  1847. fi
  1848. if [[ ${findbugs_fixed_warnings} -gt 0 ]] ; then
  1849. add_jira_table +1 findbugs "The patch does not introduce any new Findbugs (version ${findbugs_version}) warnings, and fixes ${findbugs_fixed_warnings} pre-existing warnings."
  1850. else
  1851. add_jira_table +1 findbugs "The patch does not introduce any new Findbugs (version ${findbugs_version}) warnings."
  1852. fi
  1853. return 0
  1854. }
  1855. ## @description Make sure Maven's eclipse generation works.
  1856. ## @audience private
  1857. ## @stability evolving
  1858. ## @replaceable no
  1859. ## @return 0 on success
  1860. ## @return 1 on failure
  1861. function check_mvn_eclipse
  1862. {
  1863. big_console_header "Running mvn eclipse:eclipse."
  1864. verify_needed_test javac
  1865. if [[ $? == 0 ]]; then
  1866. echo "Patch does not touch any java files. Skipping mvn eclipse:eclipse"
  1867. return 0
  1868. fi
  1869. start_clock
  1870. echo_and_redirect "${PATCH_DIR}/patchEclipseOutput.txt" "${MVN}" "${MAVEN_ARGS[@]}" eclipse:eclipse -D${PROJECT_NAME}PatchProcess
  1871. if [[ $? != 0 ]] ; then
  1872. add_jira_table -1 eclipse:eclipse "The patch failed to build with eclipse:eclipse."
  1873. return 1
  1874. fi
  1875. add_jira_table +1 eclipse:eclipse "The patch built with eclipse:eclipse."
  1876. return 0
  1877. }
  1878. ## @description Utility to push many tests into the failure list
  1879. ## @audience private
  1880. ## @stability evolving
  1881. ## @replaceable no
  1882. ## @param testdesc
  1883. ## @param testlist
  1884. function populate_test_table
  1885. {
  1886. local reason=$1
  1887. shift
  1888. local first=""
  1889. local i
  1890. for i in "$@"; do
  1891. if [[ -z "${first}" ]]; then
  1892. add_jira_test_table "${reason}" "${i}"
  1893. first="${reason}"
  1894. else
  1895. add_jira_test_table " " "${i}"
  1896. fi
  1897. done
  1898. }
  1899. ## @description Run and verify the output of the appropriate unit tests
  1900. ## @audience private
  1901. ## @stability evolving
  1902. ## @replaceable no
  1903. ## @return 0 on success
  1904. ## @return 1 on failure
  1905. function check_unittests
  1906. {
  1907. verify_needed_test unit
  1908. if [[ $? == 0 ]]; then
  1909. echo "Existing unit tests do not test patched files. Skipping."
  1910. return 0
  1911. fi
  1912. big_console_header "Running unit tests"
  1913. start_clock
  1914. local failed_tests=""
  1915. local modules=${CHANGED_MODULES}
  1916. local building_common=0
  1917. local hdfs_modules
  1918. local ordered_modules=""
  1919. local failed_test_builds=""
  1920. local test_timeouts=""
  1921. local test_logfile
  1922. local test_build_result
  1923. local module_test_timeouts=""
  1924. local result
  1925. local totalresult=0
  1926. local module_prefix
  1927. #
  1928. # If we are building hadoop-hdfs-project, we must build the native component
  1929. # of hadoop-common-project first. In order to accomplish this, we move the
  1930. # hadoop-hdfs subprojects to the end of the list so that common will come
  1931. # first.
  1932. #
  1933. # Of course, we may not be building hadoop-common at all-- in this case, we
  1934. # explicitly insert a mvn compile -Pnative of common, to ensure that the
  1935. # native libraries show up where we need them.
  1936. #
  1937. for module in ${modules}; do
  1938. if [[ ${module} == hadoop-hdfs-project* ]]; then
  1939. hdfs_modules="${hdfs_modules} ${module}"
  1940. elif [[ ${module} == hadoop-common-project* ]]; then
  1941. ordered_modules="${ordered_modules} ${module}"
  1942. building_common=1
  1943. else
  1944. ordered_modules="${ordered_modules} ${module}"
  1945. fi
  1946. done
  1947. if [[ -n "${hdfs_modules}" ]]; then
  1948. ordered_modules="${ordered_modules} ${hdfs_modules}"
  1949. if [[ ${building_common} -eq 0 ]]; then
  1950. echo " Building hadoop-common with -Pnative in order to provide libhadoop.so to the hadoop-hdfs unit tests."
  1951. echo_and_redirect "${PATCH_DIR}/testrun_native.txt" "${MVN}" "${MAVEN_ARGS[@]}" compile ${NATIVE_PROFILE} "-D${PROJECT_NAME}PatchProcess"
  1952. if [[ $? != 0 ]]; then
  1953. add_jira_table -1 "native" "Failed to build the native portion " \
  1954. "of hadoop-common prior to running the unit tests in ${ordered_modules}"
  1955. return 1
  1956. else
  1957. add_jira_table +1 "native" "Pre-build of native portion"
  1958. fi
  1959. fi
  1960. fi
  1961. for module in ${ordered_modules}; do
  1962. result=0
  1963. start_clock
  1964. pushd "${module}" >/dev/null
  1965. module_suffix=$(basename "${module}")
  1966. module_prefix=$(echo "${module}" | cut -f2 -d- )
  1967. test_logfile=${PATCH_DIR}/testrun_${module_suffix}.txt
  1968. echo " Running tests in ${module_suffix}"
  1969. # Temporary hack to run the parallel tests profile only for hadoop-common.
  1970. # This code will be removed once hadoop-hdfs is ready for parallel test
  1971. # execution.
  1972. if [[ ${module} == "hadoop-common-project/hadoop-common" ]] ; then
  1973. OPTIONAL_PARALLEL_TESTS_PROFILE=${PARALLEL_TESTS_PROFILE}
  1974. else
  1975. unset OPTIONAL_PARALLEL_TESTS_PROFILE
  1976. fi
  1977. # shellcheck disable=2086
  1978. echo_and_redirect "${test_logfile}" "${MVN}" "${MAVEN_ARGS[@]}" clean install -fae ${NATIVE_PROFILE} ${REQUIRE_TEST_LIB_HADOOP} ${OPTIONAL_PARALLEL_TESTS_PROFILE} ${TESTS_THREAD_COUNT} -D${PROJECT_NAME}PatchProcess
  1979. test_build_result=$?
  1980. add_jira_footer "${module_suffix} test log" "@@BASE@@/testrun_${module_suffix}.txt"
  1981. # shellcheck disable=2016
  1982. module_test_timeouts=$(${AWK} '/^Running / { array[$NF] = 1 } /^Tests run: .* in / { delete array[$NF] } END { for (x in array) { print x } }' "${test_logfile}")
  1983. if [[ -n "${module_test_timeouts}" ]] ; then
  1984. test_timeouts="${test_timeouts} ${module_test_timeouts}"
  1985. result=1
  1986. fi
  1987. #shellcheck disable=SC2026,SC2038,SC2016
  1988. module_failed_tests=$(find . -name 'TEST*.xml'\
  1989. | xargs "${GREP}" -l -E "<failure|<error"\
  1990. | ${AWK} -F/ '{sub("TEST-org.apache.",""); sub(".xml",""); print $NF}')
  1991. if [[ -n "${module_failed_tests}" ]] ; then
  1992. failed_tests="${failed_tests} ${module_failed_tests}"
  1993. result=1
  1994. fi
  1995. if [[ ${test_build_result} != 0 && -z "${module_failed_tests}" && -z "${module_test_timeouts}" ]] ; then
  1996. failed_test_builds="${failed_test_builds} ${module_suffix}"
  1997. result=1
  1998. fi
  1999. popd >/dev/null
  2000. if [[ $result == 1 ]]; then
  2001. add_jira_table -1 "${module_prefix} tests" "Tests failed in ${module_suffix}."
  2002. else
  2003. add_jira_table +1 "${module_prefix} tests" "Tests passed in ${module_suffix}."
  2004. fi
  2005. ((totalresult = totalresult + result))
  2006. done
  2007. if [[ -n "${failed_tests}" ]] ; then
  2008. # shellcheck disable=SC2086
  2009. populate_test_table "Failed unit tests" ${failed_tests}
  2010. fi
  2011. if [[ -n "${test_timeouts}" ]] ; then
  2012. # shellcheck disable=SC2086
  2013. populate_test_table "Timed out tests" ${test_timeouts}
  2014. fi
  2015. if [[ -n "${failed_test_builds}" ]] ; then
  2016. # shellcheck disable=SC2086
  2017. populate_test_table "Failed build" ${failed_test_builds}
  2018. fi
  2019. if [[ ${JENKINS} == true ]]; then
  2020. add_jira_footer "Test Results" "${BUILD_URL}testReport/"
  2021. fi
  2022. if [[ ${totalresult} -gt 0 ]]; then
  2023. return 1
  2024. else
  2025. return 0
  2026. fi
  2027. }
  2028. ## @description Print out the finished details on the console
  2029. ## @audience private
  2030. ## @stability evolving
  2031. ## @replaceable no
  2032. ## @param runresult
  2033. ## @return 0 on success
  2034. ## @return 1 on failure
  2035. function output_to_console
  2036. {
  2037. local result=$1
  2038. shift
  2039. local i
  2040. local ourstring
  2041. local vote
  2042. local subs
  2043. local ela
  2044. local comment
  2045. local commentfile1="${PATCH_DIR}/comment.1"
  2046. local commentfile2="${PATCH_DIR}/comment.2"
  2047. local normaltop
  2048. local line
  2049. local seccoladj=0
  2050. local spcfx=${PATCH_DIR}/spcl.txt
  2051. if [[ ${result} == 0 ]]; then
  2052. if [[ ${JENKINS} == false ]]; then
  2053. {
  2054. printf "IF9fX19fX19fX18gCjwgU3VjY2VzcyEgPgogLS0tLS0tLS0tLSAKIFwgICAg";
  2055. printf "IC9cICBfX18gIC9cCiAgXCAgIC8vIFwvICAgXC8gXFwKICAgICAoKCAgICBP";
  2056. printf "IE8gICAgKSkKICAgICAgXFwgLyAgICAgXCAvLwogICAgICAgXC8gIHwgfCAg";
  2057. printf "XC8gCiAgICAgICAgfCAgfCB8ICB8ICAKICAgICAgICB8ICB8IHwgIHwgIAog";
  2058. printf "ICAgICAgIHwgICBvICAgfCAgCiAgICAgICAgfCB8ICAgfCB8ICAKICAgICAg";
  2059. printf "ICB8bXwgICB8bXwgIAo"
  2060. } > "${spcfx}"
  2061. fi
  2062. printf "\n\n+1 overall\n\n"
  2063. else
  2064. if [[ ${JENKINS} == false ]]; then
  2065. {
  2066. printf "IF9fX19fICAgICBfIF8gICAgICAgICAgICAgICAgXyAKfCAgX19ffF8gXyhf";
  2067. printf "KSB8XyAgIF8gXyBfXyBfX198IHwKfCB8XyAvIF9gIHwgfCB8IHwgfCB8ICdf";
  2068. printf "Xy8gXyBcIHwKfCAgX3wgKF98IHwgfCB8IHxffCB8IHwgfCAgX18vX3wKfF98";
  2069. printf "ICBcX18sX3xffF98XF9fLF98X3wgIFxfX18oXykKICAgICAgICAgICAgICAg";
  2070. printf "ICAgICAgICAgICAgICAgICAK"
  2071. } > "${spcfx}"
  2072. fi
  2073. printf "\n\n-1 overall\n\n"
  2074. fi
  2075. if [[ -f ${spcfx} ]]; then
  2076. if which base64 >/dev/null 2>&1; then
  2077. base64 --decode "${spcfx}" 2>/dev/null
  2078. elif which openssl >/dev/null 2>&1; then
  2079. openssl enc -A -d -base64 -in "${spcfx}" 2>/dev/null
  2080. fi
  2081. echo
  2082. echo
  2083. rm "${spcfx}"
  2084. fi
  2085. seccoladj=$(findlargest 2 "${JIRA_COMMENT_TABLE[@]}")
  2086. if [[ ${seccoladj} -lt 10 ]]; then
  2087. seccoladj=10
  2088. fi
  2089. seccoladj=$((seccoladj + 2 ))
  2090. i=0
  2091. until [[ $i -eq ${#JIRA_HEADER[@]} ]]; do
  2092. printf "%s\n" "${JIRA_HEADER[${i}]}"
  2093. ((i=i+1))
  2094. done
  2095. printf "| %s | %*s | %s | %s\n" "Vote" ${seccoladj} Subsystem Runtime "Comment"
  2096. echo "============================================================================"
  2097. i=0
  2098. until [[ $i -eq ${#JIRA_COMMENT_TABLE[@]} ]]; do
  2099. ourstring=$(echo "${JIRA_COMMENT_TABLE[${i}]}" | tr -s ' ')
  2100. vote=$(echo "${ourstring}" | cut -f2 -d\|)
  2101. vote=$(colorstripper "${vote}")
  2102. subs=$(echo "${ourstring}" | cut -f3 -d\|)
  2103. ela=$(echo "${ourstring}" | cut -f4 -d\|)
  2104. comment=$(echo "${ourstring}" | cut -f5 -d\|)
  2105. echo "${comment}" | fold -s -w $((78-seccoladj-22)) > "${commentfile1}"
  2106. normaltop=$(head -1 "${commentfile1}")
  2107. ${SED} -e '1d' "${commentfile1}" > "${commentfile2}"
  2108. printf "| %4s | %*s | %-10s |%-s\n" "${vote}" ${seccoladj} \
  2109. "${subs}" "${ela}" "${normaltop}"
  2110. while read line; do
  2111. printf "| | %*s | | %-s\n" ${seccoladj} " " "${line}"
  2112. done < "${commentfile2}"
  2113. ((i=i+1))
  2114. rm "${commentfile2}" "${commentfile1}" 2>/dev/null
  2115. done
  2116. if [[ ${#JIRA_TEST_TABLE[@]} -gt 0 ]]; then
  2117. seccoladj=$(findlargest 1 "${JIRA_TEST_TABLE[@]}")
  2118. printf "\n\n%*s | Tests\n" "${seccoladj}" "Reason"
  2119. i=0
  2120. until [[ $i -eq ${#JIRA_TEST_TABLE[@]} ]]; do
  2121. ourstring=$(echo "${JIRA_TEST_TABLE[${i}]}" | tr -s ' ')
  2122. vote=$(echo "${ourstring}" | cut -f2 -d\|)
  2123. subs=$(echo "${ourstring}" | cut -f3 -d\|)
  2124. printf "%*s | %s\n" "${seccoladj}" "${vote}" "${subs}"
  2125. ((i=i+1))
  2126. done
  2127. fi
  2128. printf "\n\n|| Subsystem || Report/Notes ||\n"
  2129. echo "============================================================================"
  2130. i=0
  2131. until [[ $i -eq ${#JIRA_FOOTER_TABLE[@]} ]]; do
  2132. comment=$(echo "${JIRA_FOOTER_TABLE[${i}]}" |
  2133. ${SED} -e "s,@@BASE@@,${PATCH_DIR},g")
  2134. printf "%s\n" "${comment}"
  2135. ((i=i+1))
  2136. done
  2137. }
  2138. ## @description Print out the finished details to the JIRA issue
  2139. ## @audience private
  2140. ## @stability evolving
  2141. ## @replaceable no
  2142. ## @param runresult
  2143. function output_to_jira
  2144. {
  2145. local result=$1
  2146. local i
  2147. local commentfile=${PATCH_DIR}/commentfile
  2148. local comment
  2149. rm "${commentfile}" 2>/dev/null
  2150. if [[ ${JENKINS} != "true" ]] ; then
  2151. return 0
  2152. fi
  2153. big_console_header "Adding comment to JIRA"
  2154. add_jira_footer "Console output" "${BUILD_URL}console"
  2155. if [[ ${result} == 0 ]]; then
  2156. add_jira_header "(/) *{color:green}+1 overall{color}*"
  2157. else
  2158. add_jira_header "(x) *{color:red}-1 overall{color}*"
  2159. fi
  2160. { echo "\\\\" ; echo "\\\\"; } >> "${commentfile}"
  2161. i=0
  2162. until [[ $i -eq ${#JIRA_HEADER[@]} ]]; do
  2163. printf "%s\n" "${JIRA_HEADER[${i}]}" >> "${commentfile}"
  2164. ((i=i+1))
  2165. done
  2166. { echo "\\\\" ; echo "\\\\"; } >> "${commentfile}"
  2167. echo "|| Vote || Subsystem || Runtime || Comment ||" >> "${commentfile}"
  2168. i=0
  2169. until [[ $i -eq ${#JIRA_COMMENT_TABLE[@]} ]]; do
  2170. printf "%s\n" "${JIRA_COMMENT_TABLE[${i}]}" >> "${commentfile}"
  2171. ((i=i+1))
  2172. done
  2173. if [[ ${#JIRA_TEST_TABLE[@]} -gt 0 ]]; then
  2174. { echo "\\\\" ; echo "\\\\"; } >> "${commentfile}"
  2175. echo "|| Reason || Tests ||" >> "${commentfile}"
  2176. i=0
  2177. until [[ $i -eq ${#JIRA_TEST_TABLE[@]} ]]; do
  2178. printf "%s\n" "${JIRA_TEST_TABLE[${i}]}" >> "${commentfile}"
  2179. ((i=i+1))
  2180. done
  2181. fi
  2182. { echo "\\\\" ; echo "\\\\"; } >> "${commentfile}"
  2183. echo "|| Subsystem || Report/Notes ||" >> "${commentfile}"
  2184. i=0
  2185. until [[ $i -eq ${#JIRA_FOOTER_TABLE[@]} ]]; do
  2186. comment=$(echo "${JIRA_FOOTER_TABLE[${i}]}" |
  2187. ${SED} -e "s,@@BASE@@,${BUILD_URL}artifact/patchprocess,g")
  2188. printf "%s\n" "${comment}" >> "${commentfile}"
  2189. ((i=i+1))
  2190. done
  2191. printf "\n\nThis message was automatically generated.\n\n" >> "${commentfile}"
  2192. write_to_jira "${commentfile}"
  2193. }
  2194. ## @description Clean the filesystem as appropriate and then exit
  2195. ## @audience private
  2196. ## @stability evolving
  2197. ## @replaceable no
  2198. ## @param runresult
  2199. function cleanup_and_exit
  2200. {
  2201. local result=$1
  2202. if [[ ${JENKINS} == "true" && ${RELOCATE_PATCH_DIR} == "true" && \
  2203. -e ${PATCH_DIR} && -d ${PATCH_DIR} ]] ; then
  2204. # if PATCH_DIR is already inside BASEDIR, then
  2205. # there is no need to move it since we assume that
  2206. # Jenkins or whatever already knows where it is at
  2207. # since it told us to put it there!
  2208. relative_patchdir >/dev/null
  2209. if [[ $? == 1 ]]; then
  2210. hadoop_debug "mv ${PATCH_DIR} ${BASEDIR}"
  2211. mv "${PATCH_DIR}" "${BASEDIR}"
  2212. fi
  2213. fi
  2214. big_console_header "Finished build."
  2215. # shellcheck disable=SC2086
  2216. exit ${result}
  2217. }
  2218. ## @description Driver to execute _postcheckout routines
  2219. ## @audience private
  2220. ## @stability evolving
  2221. ## @replaceable no
  2222. function postcheckout
  2223. {
  2224. local routine
  2225. local plugin
  2226. for routine in find_java_home verify_patch_file
  2227. do
  2228. verify_patchdir_still_exists
  2229. hadoop_debug "Running ${routine}"
  2230. ${routine}
  2231. (( RESULT = RESULT + $? ))
  2232. if [[ ${RESULT} != 0 ]] ; then
  2233. output_to_console 1
  2234. output_to_jira 1
  2235. cleanup_and_exit 1
  2236. fi
  2237. done
  2238. for plugin in ${PLUGINS}; do
  2239. verify_patchdir_still_exists
  2240. if declare -f ${plugin}_postcheckout >/dev/null 2>&1; then
  2241. hadoop_debug "Running ${plugin}_postcheckout"
  2242. #shellcheck disable=SC2086
  2243. ${plugin}_postcheckout
  2244. (( RESULT = RESULT + $? ))
  2245. if [[ ${RESULT} != 0 ]] ; then
  2246. output_to_console 1
  2247. output_to_jira 1
  2248. cleanup_and_exit 1
  2249. fi
  2250. fi
  2251. done
  2252. }
  2253. ## @description Driver to execute _preapply routines
  2254. ## @audience private
  2255. ## @stability evolving
  2256. ## @replaceable no
  2257. function preapply
  2258. {
  2259. local routine
  2260. local plugin
  2261. for routine in precheck_without_patch check_author \
  2262. check_modified_unittests
  2263. do
  2264. verify_patchdir_still_exists
  2265. hadoop_debug "Running ${routine}"
  2266. ${routine}
  2267. (( RESULT = RESULT + $? ))
  2268. done
  2269. for plugin in ${PLUGINS}; do
  2270. verify_patchdir_still_exists
  2271. if declare -f ${plugin}_preapply >/dev/null 2>&1; then
  2272. hadoop_debug "Running ${plugin}_preapply"
  2273. #shellcheck disable=SC2086
  2274. ${plugin}_preapply
  2275. (( RESULT = RESULT + $? ))
  2276. fi
  2277. done
  2278. }
  2279. ## @description Driver to execute _postapply routines
  2280. ## @audience private
  2281. ## @stability evolving
  2282. ## @replaceable no
  2283. function postapply
  2284. {
  2285. local routine
  2286. local plugin
  2287. local retval
  2288. compute_gitdiff "${GITDIFFLINES}"
  2289. check_javac
  2290. retval=$?
  2291. if [[ ${retval} -gt 1 ]] ; then
  2292. output_to_console 1
  2293. output_to_jira 1
  2294. cleanup_and_exit 1
  2295. fi
  2296. ((RESULT = RESULT + retval))
  2297. for routine in check_javadoc check_apachelicense check_site
  2298. do
  2299. verify_patchdir_still_exists
  2300. hadoop_debug "Running ${routine}"
  2301. $routine
  2302. (( RESULT = RESULT + $? ))
  2303. done
  2304. for plugin in ${PLUGINS}; do
  2305. verify_patchdir_still_exists
  2306. if declare -f ${plugin}_postapply >/dev/null 2>&1; then
  2307. hadoop_debug "Running ${plugin}_postapply"
  2308. #shellcheck disable=SC2086
  2309. ${plugin}_postapply
  2310. (( RESULT = RESULT + $? ))
  2311. fi
  2312. done
  2313. }
  2314. ## @description Driver to execute _postinstall routines
  2315. ## @audience private
  2316. ## @stability evolving
  2317. ## @replaceable no
  2318. function postinstall
  2319. {
  2320. local routine
  2321. local plugin
  2322. for routine in check_mvn_eclipse check_findbugs
  2323. do
  2324. verify_patchdir_still_exists
  2325. hadoop_debug "Running ${routine}"
  2326. ${routine}
  2327. (( RESULT = RESULT + $? ))
  2328. done
  2329. for plugin in ${PLUGINS}; do
  2330. verify_patchdir_still_exists
  2331. if declare -f ${plugin}_postinstall >/dev/null 2>&1; then
  2332. hadoop_debug "Running ${plugin}_postinstall"
  2333. #shellcheck disable=SC2086
  2334. ${plugin}_postinstall
  2335. (( RESULT = RESULT + $? ))
  2336. fi
  2337. done
  2338. }
  2339. ## @description Driver to execute _tests routines
  2340. ## @audience private
  2341. ## @stability evolving
  2342. ## @replaceable no
  2343. function runtests
  2344. {
  2345. local plugin
  2346. ### Run tests for Jenkins or if explictly asked for by a developer
  2347. if [[ ${JENKINS} == "true" || ${RUN_TESTS} == "true" ]] ; then
  2348. verify_patchdir_still_exists
  2349. check_unittests
  2350. (( RESULT = RESULT + $? ))
  2351. fi
  2352. for plugin in ${PLUGINS}; do
  2353. verify_patchdir_still_exists
  2354. if declare -f ${plugin}_tests >/dev/null 2>&1; then
  2355. hadoop_debug "Running ${plugin}_tests"
  2356. #shellcheck disable=SC2086
  2357. ${plugin}_tests
  2358. (( RESULT = RESULT + $? ))
  2359. fi
  2360. done
  2361. }
  2362. ## @description Import content from test-patch.d and optionally
  2363. ## @description from user provided plugin directory
  2364. ## @audience private
  2365. ## @stability evolving
  2366. ## @replaceable no
  2367. function importplugins
  2368. {
  2369. local i
  2370. local files=()
  2371. if [[ ${LOAD_SYSTEM_PLUGINS} == "true" ]]; then
  2372. if [[ -d "${BINDIR}/test-patch.d" ]]; then
  2373. files=(${BINDIR}/test-patch.d/*.sh)
  2374. fi
  2375. fi
  2376. if [[ -n "${USER_PLUGIN_DIR}" && -d "${USER_PLUGIN_DIR}" ]]; then
  2377. hadoop_debug "Loading user provided plugins from ${USER_PLUGIN_DIR}"
  2378. files=("${files[@]}" ${USER_PLUGIN_DIR}/*.sh)
  2379. fi
  2380. for i in "${files[@]}"; do
  2381. hadoop_debug "Importing ${i}"
  2382. . "${i}"
  2383. done
  2384. }
  2385. ## @description Register test-patch.d plugins
  2386. ## @audience public
  2387. ## @stability stable
  2388. ## @replaceable no
  2389. function add_plugin
  2390. {
  2391. PLUGINS="${PLUGINS} $1"
  2392. }
  2393. ###############################################################################
  2394. ###############################################################################
  2395. ###############################################################################
  2396. big_console_header "Bootstrapping test harness"
  2397. setup_defaults
  2398. parse_args "$@"
  2399. importplugins
  2400. locate_patch
  2401. find_changed_files
  2402. determine_needed_tests
  2403. # from here on out, we'll be in ${BASEDIR} for cwd
  2404. # routines need to pushd/popd if they change.
  2405. git_checkout
  2406. RESULT=$?
  2407. if [[ ${JENKINS} == "true" ]] ; then
  2408. if [[ ${RESULT} != 0 ]] ; then
  2409. exit 100
  2410. fi
  2411. fi
  2412. check_reexec
  2413. postcheckout
  2414. find_changed_modules
  2415. preapply
  2416. apply_patch_file
  2417. postapply
  2418. check_mvn_install
  2419. postinstall
  2420. runtests
  2421. close_jira_footer
  2422. close_jira_table
  2423. output_to_console ${RESULT}
  2424. output_to_jira ${RESULT}
  2425. cleanup_and_exit ${RESULT}