diff options
author | Mike Frysinger <vapier@gentoo.org> | 2015-11-24 12:02:31 -0500 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2015-11-24 12:03:49 -0500 |
commit | ddd7a0bc1e06c0f7737799b784c110b7903f0a58 (patch) | |
tree | 7bb4daf0fd0283b464e61501104c674173ce4634 /eclass | |
parent | c32a35e8d8fea39c1445a6880656f850b110f4f7 (diff) | |
download | gentoo-ddd7a0bc1e06c0f7737799b784c110b7903f0a58.tar.gz gentoo-ddd7a0bc1e06c0f7737799b784c110b7903f0a58.tar.xz |
multiprocessing.eclass: makeopts_loadavg: various fixes #543116
- Add support for --max-load option
- Fix default load value if not specified (999)
- Fix trailing flag consumption so we don't leave garbage behind
- Add tests!
Diffstat (limited to 'eclass')
-rw-r--r-- | eclass/multiprocessing.eclass | 7 | ||||
-rwxr-xr-x | eclass/tests/multiprocessing_makeopts_loadavg.sh | 36 |
2 files changed, 40 insertions, 3 deletions
diff --git a/eclass/multiprocessing.eclass b/eclass/multiprocessing.eclass index 534b35c56b9..06e004aa166 100644 --- a/eclass/multiprocessing.eclass +++ b/eclass/multiprocessing.eclass @@ -86,9 +86,10 @@ makeopts_loadavg() { # This assumes the first .* will be more greedy than the second .* # since POSIX doesn't specify a non-greedy match (i.e. ".*?"). local lavg=$(echo " $* " | sed -r -n \ - -e 's:.*[[:space:]](-l|--load-average[=[:space:]])[[:space:]]*([0-9]+|[0-9]+\.[0-9]+)[^0-9.]*:\2:p' \ - -e 's:.*[[:space:]](-l|--load-average)[[:space:]].*:999:p') - echo ${lavg:-1} + -e 's:.*[[:space:]](-l|--(load-average|max-load)[=[:space:]])[[:space:]]*([0-9]+|[0-9]+\.[0-9]+).*:\3:p' \ + -e 's:.*[[:space:]](-l|--(load-average|max-load))[[:space:]].*:999:p') + # Default to 999 since the default is to not use a load limit. + echo ${lavg:-999} } # @FUNCTION: multijob_init diff --git a/eclass/tests/multiprocessing_makeopts_loadavg.sh b/eclass/tests/multiprocessing_makeopts_loadavg.sh new file mode 100755 index 00000000000..12f9d01f9fc --- /dev/null +++ b/eclass/tests/multiprocessing_makeopts_loadavg.sh @@ -0,0 +1,36 @@ +#!/bin/bash +# Copyright 1999-2015 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Id$ + +source tests-common.sh + +inherit multiprocessing + +test-makeopts_loadavg() { + local exp=$1; shift + tbegin "makeopts_loadavg($*) == ${exp}" + local act=$(makeopts_loadavg "$@") + [[ ${act} == "${exp}" ]] + tend $? "Got back: ${act}" +} + +tests=( + 999 "-j" + 999 "-l" + 999 "" + 9 "-l9 -w" + 9 "-l 9 -w-j4" + 3 "-l3 -j 4 -w" + 5 "--load-average=5" + 6 "--load-average 6" + 7 "-l3 --load-average 7 -w" + 4 "-j1 -j 2 --load-average 3 --load-average=4" + 3 " --max-load=3 -x" + 8 " -l 8 " +) +for (( i = 0; i < ${#tests[@]}; i += 2 )) ; do + test-makeopts_loadavg "${tests[i]}" "${tests[i+1]}" +done + +texit |