diff options
author | Orion Hodson <oth@google.com> | 2017-12-22 07:56:39 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-12-22 07:56:39 +0000 |
commit | 67bed50c99eafc86a75e8f25778c9b7534820828 (patch) | |
tree | 3f5db37ec4d7efadc6532cbd22c5c2f501b1c2e4 | |
parent | 9d054450e7b25af8f43d4dd9a8936613c4a14ebe (diff) | |
parent | 89941e09c6ec5cdb7c18a11b2b1d38ff9862d78f (diff) | |
download | dalvik-67bed50c99eafc86a75e8f25778c9b7534820828.tar.gz |
Merge "dx: Throttle run-all-tests script" am: dd452a4244
am: 89941e09c6
Change-Id: Ib82f454646766f5f7a9a6a561f73d76e5fc809c0
-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 |