diff options
author | Orion Hodson <oth@google.com> | 2017-12-19 11:50:03 +0000 |
---|---|---|
committer | Orion Hodson <oth@google.com> | 2017-12-21 22:12:44 +0000 |
commit | 2a41730baa7bcade5260260a0ca43f2c9d6fa66e (patch) | |
tree | 59d9d172ae9c66b0d52cc8a5ab02c2482561fc52 | |
parent | 3e1cdec3e6e6a34c80a714d14075ac217b0d1f11 (diff) | |
download | dalvik-2a41730baa7bcade5260260a0ca43f2c9d6fa66e.tar.gz |
dx: Throttle run-all-tests script
Use file locks to limit the load of the run-all-tests script.
Propagate terminate request to child processes when SIGINT is
received.
Test: . build/envsetup.sh; lunch; art/tools/buildbot-build.sh --host -j32; dalvik/dx/tests/run-all-tests
Bug: 70525148
Change-Id: Ibedfd06786505f1e93152cc694d8cb3c1db17311
-rwxr-xr-x | dx/tests/run-all-tests | 53 |
1 files changed, 35 insertions, 18 deletions
diff --git a/dx/tests/run-all-tests b/dx/tests/run-all-tests index d24ef7a5b..3734a98f1 100755 --- a/dx/tests/run-all-tests +++ b/dx/tests/run-all-tests @@ -105,9 +105,10 @@ function list_files { } function update_result { - test_name=$1 - output=$2 - result=$3 + local -r test_name=$1 + local -r output=$2 + local -r result=$3 + local expectFail if [[ "$known_bad" == *"$test_name"* ]]; then expectFail=1 @@ -134,33 +135,46 @@ function update_result { fi } +function run_one_test_with_flock { + local -r output_dir=$1 + local -r test_name=$2 + local -r lock_file=$3 + + # Wait for the lock and run the test when acquired + flock "${lock_file}" ./run-test --output_dir "${output_dir}" "${test_name}" +} + function run_tests { + readonly test_root=$(mktemp -d) + trap "rm -rf ${test_root}" EXIT if [[ "$sequential" = "yes" ]]; then for test_name in *; do if [[ "$skip_tests" = *"$test_name"* ]]; then - skipped+=(${test_name}) - continue + skipped+=(${test_name}) + continue fi if [ -d "$test_name" -a -r "$test_name" ]; then - output=/tmp/$$/$test_name - ./run-test --output_dir "$output" "$test_name" - update_result $test_name $output $? + output="${test_root}/${test_name}" + ./run-test --output_dir "${output}" "${test_name}" + update_result "${test_name}" "${output}" $? fi done else - i=0 + readonly num_workers=4 + local i=0 for test_name in *; do if [[ "$skip_tests" = *"$test_name"* ]]; then - skipped+=(${test_name}) - continue + skipped+=(${test_name}) + continue fi - if [ -d "$test_name" -a -r "$test_name" ]; then - output=/tmp/$$/$test_name - ./run-test --output_dir "$output" "$test_name" & - test_pids[i]=$! - test_names[test_pids[i]]="$test_name" - test_outputs[test_pids[i]]="output" - let i+=1 + local lock_file=${test_root}/lock.$((i % num_workers)) + if [ -d "${test_name}" -a -r "${test_name}" ]; then + output="${test_root}/${test_name}" + run_one_test_with_flock "$output" "$test_name" "$lock_file" & + test_pids[i]=$! + test_names[test_pids[i]]="$test_name" + test_outputs[test_pids[i]]="output" + let i+=1 fi done @@ -174,6 +188,9 @@ function run_tests { function handle_interrupt { trap INT display_results + if [ ! -z "${test_pids}" ]; then + killall ${test_pids} + fi } trap handle_interrupt INT |