test-patch.sh 63 KB

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