diff options
author | Yann E. MORIN <yann.morin.1998@free.fr> | 2013-04-13 11:18:36 -0400 |
---|---|---|
committer | Yann E. MORIN <yann.morin.1998@free.fr> | 2013-04-24 18:16:30 -0400 |
commit | e43956e607692f9b1c710311e4a6591ffba1edf0 (patch) | |
tree | c42d170aa789a5ff0758a32b328e82ccbaa22142 /scripts | |
parent | 0d8024c6ebadb68f1154377c2e1996b4e649e4c8 (diff) |
kconfig: implement KCONFIG_PROBABILITY for randconfig
Currently the odds to set each symbol is (rounded):
booleans: y: 50% n: 50%
tristates: y: 33% m: 33% n: 33%
Introduce a KCONFIG_PROBABILITY environment variable to tweak the
probabilities (in percentage), as such:
KCONFIG_PROBABILITY y:n split y:m:n split
-----------------------------------------------------------------
[1] unset or empty 50 : 50 33 : 33 : 34
[2] N N : 100-N N/2 : N/2 : 100-N
N:M N+M : 100-(N+M) N : M : 100-(N+M)
N:M:L N : 100-N M : L : 100-(M+L)
[1] The current behaviour is kept as default, for backward compatibility
[2] The solution initially implemented by Peter for Buildroot, see:
http://git.buildroot.org/buildroot/commit/?id=3435c1afb5
Signed-off-by: Peter Korsgaard <jacmet@uclibc.org>
[yann.morin.1998@free.fr: add to Documentation/]
Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/kconfig/confdata.c | 57 |
1 files changed, 54 insertions, 3 deletions
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index 89274809a826..fc45fc137875 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c | |||
@@ -1107,7 +1107,51 @@ static void set_all_choice_values(struct symbol *csym) | |||
1107 | void conf_set_all_new_symbols(enum conf_def_mode mode) | 1107 | void conf_set_all_new_symbols(enum conf_def_mode mode) |
1108 | { | 1108 | { |
1109 | struct symbol *sym, *csym; | 1109 | struct symbol *sym, *csym; |
1110 | int i, cnt; | 1110 | int i, cnt, pby, pty, ptm; /* pby: probability of boolean = y |
1111 | * pty: probability of tristate = y | ||
1112 | * ptm: probability of tristate = m | ||
1113 | */ | ||
1114 | |||
1115 | pby = 50; pty = ptm = 33; /* can't go as the default in switch-case | ||
1116 | * below, otherwise gcc whines about | ||
1117 | * -Wmaybe-uninitialized */ | ||
1118 | if (mode == def_random) { | ||
1119 | int n, p[3]; | ||
1120 | char *env = getenv("KCONFIG_PROBABILITY"); | ||
1121 | n = 0; | ||
1122 | while( env && *env ) { | ||
1123 | char *endp; | ||
1124 | int tmp = strtol( env, &endp, 10 ); | ||
1125 | if( tmp >= 0 && tmp <= 100 ) { | ||
1126 | p[n++] = tmp; | ||
1127 | } else { | ||
1128 | errno = ERANGE; | ||
1129 | perror( "KCONFIG_PROBABILITY" ); | ||
1130 | exit( 1 ); | ||
1131 | } | ||
1132 | env = (*endp == ':') ? endp+1 : endp; | ||
1133 | if( n >=3 ) { | ||
1134 | break; | ||
1135 | } | ||
1136 | } | ||
1137 | switch( n ) { | ||
1138 | case 1: | ||
1139 | pby = p[0]; ptm = pby/2; pty = pby-ptm; | ||
1140 | break; | ||
1141 | case 2: | ||
1142 | pty = p[0]; ptm = p[1]; pby = pty + ptm; | ||
1143 | break; | ||
1144 | case 3: | ||
1145 | pby = p[0]; pty = p[1]; ptm = p[2]; | ||
1146 | break; | ||
1147 | } | ||
1148 | |||
1149 | if( pty+ptm > 100 ) { | ||
1150 | errno = ERANGE; | ||
1151 | perror( "KCONFIG_PROBABILITY" ); | ||
1152 | exit( 1 ); | ||
1153 | } | ||
1154 | } | ||
1111 | 1155 | ||
1112 | for_all_symbols(i, sym) { | 1156 | for_all_symbols(i, sym) { |
1113 | if (sym_has_value(sym) || (sym->flags & SYMBOL_VALID)) | 1157 | if (sym_has_value(sym) || (sym->flags & SYMBOL_VALID)) |
@@ -1126,8 +1170,15 @@ void conf_set_all_new_symbols(enum conf_def_mode mode) | |||
1126 | sym->def[S_DEF_USER].tri = no; | 1170 | sym->def[S_DEF_USER].tri = no; |
1127 | break; | 1171 | break; |
1128 | case def_random: | 1172 | case def_random: |
1129 | cnt = sym->type == S_TRISTATE ? 3 : 2; | 1173 | sym->def[S_DEF_USER].tri = no; |
1130 | sym->def[S_DEF_USER].tri = (tristate)(rand() % cnt); | 1174 | cnt = rand() % 100; |
1175 | if (sym->type == S_TRISTATE) { | ||
1176 | if (cnt < pty) | ||
1177 | sym->def[S_DEF_USER].tri = yes; | ||
1178 | else if (cnt < (pty+ptm)) | ||
1179 | sym->def[S_DEF_USER].tri = mod; | ||
1180 | } else if (cnt < pby) | ||
1181 | sym->def[S_DEF_USER].tri = yes; | ||
1131 | break; | 1182 | break; |
1132 | default: | 1183 | default: |
1133 | continue; | 1184 | continue; |