Gentoo Archives: gentoo-commits

From: Mike Frysinger <vapier@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: eclass/tests/, eclass/
Date: Tue, 24 Nov 2015 17:04:08
Message-Id: 1448384629.ddd7a0bc1e06c0f7737799b784c110b7903f0a58.vapier@gentoo
1 commit: ddd7a0bc1e06c0f7737799b784c110b7903f0a58
2 Author: Mike Frysinger <vapier <AT> gentoo <DOT> org>
3 AuthorDate: Tue Nov 24 17:02:31 2015 +0000
4 Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org>
5 CommitDate: Tue Nov 24 17:03:49 2015 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=ddd7a0bc
7
8 multiprocessing.eclass: makeopts_loadavg: various fixes #543116
9
10 - Add support for --max-load option
11 - Fix default load value if not specified (999)
12 - Fix trailing flag consumption so we don't leave garbage behind
13 - Add tests!
14
15 eclass/multiprocessing.eclass | 7 +++--
16 eclass/tests/multiprocessing_makeopts_loadavg.sh | 36 ++++++++++++++++++++++++
17 2 files changed, 40 insertions(+), 3 deletions(-)
18
19 diff --git a/eclass/multiprocessing.eclass b/eclass/multiprocessing.eclass
20 index 534b35c..06e004a 100644
21 --- a/eclass/multiprocessing.eclass
22 +++ b/eclass/multiprocessing.eclass
23 @@ -86,9 +86,10 @@ makeopts_loadavg() {
24 # This assumes the first .* will be more greedy than the second .*
25 # since POSIX doesn't specify a non-greedy match (i.e. ".*?").
26 local lavg=$(echo " $* " | sed -r -n \
27 - -e 's:.*[[:space:]](-l|--load-average[=[:space:]])[[:space:]]*([0-9]+|[0-9]+\.[0-9]+)[^0-9.]*:\2:p' \
28 - -e 's:.*[[:space:]](-l|--load-average)[[:space:]].*:999:p')
29 - echo ${lavg:-1}
30 + -e 's:.*[[:space:]](-l|--(load-average|max-load)[=[:space:]])[[:space:]]*([0-9]+|[0-9]+\.[0-9]+).*:\3:p' \
31 + -e 's:.*[[:space:]](-l|--(load-average|max-load))[[:space:]].*:999:p')
32 + # Default to 999 since the default is to not use a load limit.
33 + echo ${lavg:-999}
34 }
35
36 # @FUNCTION: multijob_init
37
38 diff --git a/eclass/tests/multiprocessing_makeopts_loadavg.sh b/eclass/tests/multiprocessing_makeopts_loadavg.sh
39 new file mode 100755
40 index 0000000..12f9d01
41 --- /dev/null
42 +++ b/eclass/tests/multiprocessing_makeopts_loadavg.sh
43 @@ -0,0 +1,36 @@
44 +#!/bin/bash
45 +# Copyright 1999-2015 Gentoo Foundation
46 +# Distributed under the terms of the GNU General Public License v2
47 +# $Id$
48 +
49 +source tests-common.sh
50 +
51 +inherit multiprocessing
52 +
53 +test-makeopts_loadavg() {
54 + local exp=$1; shift
55 + tbegin "makeopts_loadavg($*) == ${exp}"
56 + local act=$(makeopts_loadavg "$@")
57 + [[ ${act} == "${exp}" ]]
58 + tend $? "Got back: ${act}"
59 +}
60 +
61 +tests=(
62 + 999 "-j"
63 + 999 "-l"
64 + 999 ""
65 + 9 "-l9 -w"
66 + 9 "-l 9 -w-j4"
67 + 3 "-l3 -j 4 -w"
68 + 5 "--load-average=5"
69 + 6 "--load-average 6"
70 + 7 "-l3 --load-average 7 -w"
71 + 4 "-j1 -j 2 --load-average 3 --load-average=4"
72 + 3 " --max-load=3 -x"
73 + 8 " -l 8 "
74 +)
75 +for (( i = 0; i < ${#tests[@]}; i += 2 )) ; do
76 + test-makeopts_loadavg "${tests[i]}" "${tests[i+1]}"
77 +done
78 +
79 +texit