@ -15,11 +15,13 @@
##
##
REPORTS_DIR = " $1 "
REPORTS_DIR = " $1 "
SPLIT_COUNT = $2
REPORT_STRIP_PREFIX = " $2 "
SPLIT_INDEX = $3
REPORT_STRIP_SUFFIX = " $3 "
SPLIT_COUNT = $4
SPLIT_INDEX = $5
# extract tests time from Junit XML reports
# extract tests time from Junit XML reports
find " $REPORTS_DIR " -type f -name TEST-*.xml | xargs -I{ } bash -c "xmlstarlet sel -t -v 'sum(//testcase/@time)' '{}'; echo '{}' | sed 's/.*TEST\-\(.*\)\.xml/ \1/' " > tmp/timing.tsv
find " $REPORTS_DIR " -type f -name TEST-*.xml | xargs -I{ } bash -c " xmlstarlet sel -t -v 'concat(sum(//testcase/@time), \" \", //testsuite/@name)' '{}'; echo '{}' | sed \"s# ${ REPORT_STRIP_PREFIX } /\(.*\)/ ${ REPORT_STRIP_SUFFIX } .*# \1#\" " > tmp/timing.tsv
# Sort times in descending order
# Sort times in descending order
IFS = $'\n' sorted = ( $( sort -nr tmp/timing.tsv) )
IFS = $'\n' sorted = ( $( sort -nr tmp/timing.tsv) )
@ -34,15 +36,18 @@ do
sums[ $i ] = 0
sums[ $i ] = 0
done
done
echo -n '' > tmp/processedTests.list
# add tests to groups trying to balance the sum of execution time of each group
# add tests to groups trying to balance the sum of execution time of each group
for line in " ${ sorted [@] } " ; do
for line in " ${ sorted [@] } " ; do
line_parts = ( $line )
line_parts = ( $line )
test_time = ${ line_parts [0]//./ } # convert to millis
test_time = $( echo " ${ line_parts [0] } * 1000 / 1 " | bc ) # convert to millis without decimals
test_time = ${ test_time ##0 } # remove leading zeros
test_name = ${ line_parts [1] }
test_name = ${ line_parts [1] }
module_dir = ${ line_parts [2] }
test_with_module = " $test_name $module_dir "
# Does the test still exists?
# Does the test still exists?
if grep -F -q --line-regexp " $test_nam e " tmp/currentTests.list
if grep -F -q --line-regexp " $test_with_modul e " tmp/currentTests.list
then
then
# Find index of min sum
# Find index of min sum
idx_min_sum = 0
idx_min_sum = 0
@ -58,26 +63,60 @@ for line in "${sorted[@]}"; do
# Add the test to the min sum list
# Add the test to the min sum list
min_sum_tests = ${ tests [ $idx_min_sum ] }
min_sum_tests = ${ tests [ $idx_min_sum ] }
tests[ $idx_min_sum ] = " ${ min_sum_tests } ${ test_nam e } , "
tests[ $idx_min_sum ] = " ${ min_sum_tests } ${ test_with_modul e } , "
# Update the sums
# Update the sums
( ( sums[ idx_min_sum] += test_time) )
( ( sums[ idx_min_sum] += test_time) )
echo " $test_nam e " >> tmp/processedTests.list
echo " $test_with_modul e " >> tmp/processedTests.list
fi
fi
done
done
# Any new test?
# Any new test?
grep -F --line-regexp -v -f tmp/processedTests.list tmp/currentTests.list > tmp/newTests.list
grep -F --line-regexp -v -f tmp/processedTests.list tmp/currentTests.list > tmp/newTests.list
idx_new_test = 0
idx_new_test = 0
while read -r new_test_nam e
while read -r new_test_with_modul e
do
do
idx_group = $(( idx_new_test % SPLIT_COUNT ))
idx_group = $(( idx_new_test % SPLIT_COUNT ))
group = ${ tests [ $idx_group ] }
group = ${ tests [ $idx_group ] }
tests[ $idx_group ] = " ${ group } ${ new_test_nam e } , "
tests[ $idx_group ] = " ${ group } ${ new_test_with_modul e } , "
idx_new_test = $(( idx_new_test + 1 ))
idx_new_test = $(( idx_new_test + 1 ))
done < tmp/newTests.list
done < tmp/newTests.list
# remove last comma
for ( ( i = 0; i<SPLIT_COUNT; i++) )
do
test_list = ${ tests [ $i ]%, }
tests[ $i ] = " $test_list "
done
# group tests by module
module_list = ( $( echo " ${ tests [ $SPLIT_INDEX ] } " | tr "," "\n" | awk '{print $2}' | sort -u ) )
declare -A group_by_module
for module_dir in " ${ module_list [@] } "
do
group_by_module[ $module_dir ] = ""
done
IFS = "," test_list = ( ${ tests [ $SPLIT_INDEX ] } )
unset IFS
for line in " ${ test_list [@] } "
do
line_parts = ( $line )
test_name = ${ line_parts [0] }
module_dir = ${ line_parts [1] }
module_group = ${ group_by_module [ $module_dir ] }
group_by_module[ $module_dir ] = " $module_group $test_name "
done
# return the requests index, without quotes to drop the last trailing space
# return the requests index, without quotes to drop the last trailing space
echo ${ tests [ $SPLIT_INDEX ]//,/ }
for module_dir in " ${ module_list [@] } "
do
module_test_task = " : ${ module_dir // \/ / : } :test "
module_tests = $( echo " ${ group_by_module [ $module_dir ]% } " | sed -e 's/^\| / --tests /g' )
echo " $module_test_task $module_tests "
done