2013-04-24 22:30:22

by Yann E. MORIN

[permalink] [raw]
Subject: [pull request v2] Pull request for branch yem-kconfig-for-next

From: "Yann E. MORIN" <[email protected]>

Michal,

Here is the official pull-request for the kconfig-related changes I've
gathered from the linux-kbuild list, and those I've locally accumulated,
for inclusin in 3.10:

- memory leak fixed in mconf
- 3 randconfig fixes (randomising choices, setting tristates,
already set symbols)
- randconfig improvements: seed, and probability skew
- navigation breadcrumbs in mconf


Changes v1 -> v2:
- restore the previous probabilities per default
- use different probabilities for booleans and tristates
- two new fixes for randconfig
- Cc: lkml this time

Regards,
Yann E. MORIN

----------------------------------------------------------------
The following changes since commit a45c7dfb942b6c198d5cd283f8dcee145241a017:

merge_config.sh: Avoid creating unnessary source softlinks (2013-04-10 10:55:22 +0200)

are available in the git repository at:

git://gitorious.org/linux-kconfig/linux-kconfig.git yem-kconfig-for-next

for you to fetch changes up to e43956e607692f9b1c710311e4a6591ffba1edf0:

kconfig: implement KCONFIG_PROBABILITY for randconfig (2013-04-25 00:16:30 +0200)

----------------------------------------------------------------
Benjamin Poirier (2):
menuconfig: Fix memory leak introduced by jump keys feature
menuconfig: Add "breadcrumbs" navigation aid

Yann E. MORIN (6):
kconfig/lxdialog: rationalise the include paths where to find {.n}curses{,w}.h
kconfig: fix randconfig tristate detection
kconfig: do not override symbols already set
kconfig: fix randomising choice entries in presence of KCONFIG_ALLCONFIG
kconfig: allow specifying the seed for randconfig
kconfig: implement KCONFIG_PROBABILITY for randconfig

Documentation/kbuild/kconfig.txt | 36 ++++++++++++++
scripts/kconfig/conf.c | 12 ++++-
scripts/kconfig/confdata.c | 66 ++++++++++++++++++++++---
scripts/kconfig/list.h | 40 +++++++++++++++
scripts/kconfig/lxdialog/check-lxdialog.sh | 4 +-
scripts/kconfig/lxdialog/dialog.h | 7 +++
scripts/kconfig/lxdialog/util.c | 45 ++++++++++++++++-
scripts/kconfig/mconf.c | 74 +++++++++++++++++++++++++++-
8 files changed, 271 insertions(+), 13 deletions(-)

--
.-----------------.--------------------.------------------.--------------------.
| Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software Designer | \ / CAMPAIGN | ___ |
| +33 223 225 172 `------------.-------: X AGAINST | \e/ There is no |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL | v conspiracy. |
'------------------------------^-------^------------------^--------------------'


2013-04-24 22:30:50

by Yann E. MORIN

[permalink] [raw]
Subject: [PATCH 8/8] kconfig: implement KCONFIG_PROBABILITY for randconfig

From: "Yann E. MORIN" <[email protected]>

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 <[email protected]>
[[email protected]: add to Documentation/]
Signed-off-by: "Yann E. MORIN" <[email protected]>
---
Documentation/kbuild/kconfig.txt | 27 ++++++++++++++++++
scripts/kconfig/confdata.c | 57 ++++++++++++++++++++++++++++++++++++--
2 files changed, 81 insertions(+), 3 deletions(-)

diff --git a/Documentation/kbuild/kconfig.txt b/Documentation/kbuild/kconfig.txt
index dbf746b..3f429ed 100644
--- a/Documentation/kbuild/kconfig.txt
+++ b/Documentation/kbuild/kconfig.txt
@@ -98,6 +98,33 @@ You can set this to the integer value used to seed the RNG, if you want
to somehow debug the behaviour of the kconfig parser/frontends.
If not set, the current time will be used.

+KCONFIG_PROBABILITY
+--------------------------------------------------
+This variable can be used to skew the probabilities. This variable can
+be unset or empty, or set to three different formats:
+ KCONFIG_PROBABILITY y:n split y:m:n split
+ -----------------------------------------------------------------
+ unset or empty 50 : 50 33 : 33 : 34
+ N N : 100-N N/2 : N/2 : 100-N
+ [1] N:M N+M : 100-(N+M) N : M : 100-(N+M)
+ [2] N:M:L N : 100-N M : L : 100-(M+L)
+
+where N, M and L are integers (in base 10) in the range [0,100], and so
+that:
+ [1] N+M is in the range [0,100]
+ [2] M+L is in the range [0,100]
+
+Examples:
+ KCONFIG_PROBABILITY=10
+ 10% of booleans will be set to 'y', 90% to 'n'
+ 5% of tristates will be set to 'y', 5% to 'm', 90% to 'n'
+ KCONFIG_PROBABILITY=15:25
+ 40% of booleans will be set to 'y', 60% to 'n'
+ 15% of tristates will be set to 'y', 25% to 'm', 60% to 'n'
+ KCONFIG_PROBABILITY=10:15:15
+ 10% of booleans will be set to 'y', 90% to 'n'
+ 15% of tristates will be set to 'y', 15% to 'm', 70% to 'n'
+
______________________________________________________________________
Environment variables for 'silentoldconfig'

diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index 8927480..fc45fc1 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -1107,7 +1107,51 @@ static void set_all_choice_values(struct symbol *csym)
void conf_set_all_new_symbols(enum conf_def_mode mode)
{
struct symbol *sym, *csym;
- int i, cnt;
+ int i, cnt, pby, pty, ptm; /* pby: probability of boolean = y
+ * pty: probability of tristate = y
+ * ptm: probability of tristate = m
+ */
+
+ pby = 50; pty = ptm = 33; /* can't go as the default in switch-case
+ * below, otherwise gcc whines about
+ * -Wmaybe-uninitialized */
+ if (mode == def_random) {
+ int n, p[3];
+ char *env = getenv("KCONFIG_PROBABILITY");
+ n = 0;
+ while( env && *env ) {
+ char *endp;
+ int tmp = strtol( env, &endp, 10 );
+ if( tmp >= 0 && tmp <= 100 ) {
+ p[n++] = tmp;
+ } else {
+ errno = ERANGE;
+ perror( "KCONFIG_PROBABILITY" );
+ exit( 1 );
+ }
+ env = (*endp == ':') ? endp+1 : endp;
+ if( n >=3 ) {
+ break;
+ }
+ }
+ switch( n ) {
+ case 1:
+ pby = p[0]; ptm = pby/2; pty = pby-ptm;
+ break;
+ case 2:
+ pty = p[0]; ptm = p[1]; pby = pty + ptm;
+ break;
+ case 3:
+ pby = p[0]; pty = p[1]; ptm = p[2];
+ break;
+ }
+
+ if( pty+ptm > 100 ) {
+ errno = ERANGE;
+ perror( "KCONFIG_PROBABILITY" );
+ exit( 1 );
+ }
+ }

for_all_symbols(i, sym) {
if (sym_has_value(sym) || (sym->flags & SYMBOL_VALID))
@@ -1126,8 +1170,15 @@ void conf_set_all_new_symbols(enum conf_def_mode mode)
sym->def[S_DEF_USER].tri = no;
break;
case def_random:
- cnt = sym->type == S_TRISTATE ? 3 : 2;
- sym->def[S_DEF_USER].tri = (tristate)(rand() % cnt);
+ sym->def[S_DEF_USER].tri = no;
+ cnt = rand() % 100;
+ if (sym->type == S_TRISTATE) {
+ if (cnt < pty)
+ sym->def[S_DEF_USER].tri = yes;
+ else if (cnt < (pty+ptm))
+ sym->def[S_DEF_USER].tri = mod;
+ } else if (cnt < pby)
+ sym->def[S_DEF_USER].tri = yes;
break;
default:
continue;
--
1.7.10.4

2013-04-24 22:30:48

by Yann E. MORIN

[permalink] [raw]
Subject: [PATCH 7/8] kconfig: allow specifying the seed for randconfig

From: "Yann E. MORIN" <[email protected]>

For reproducibility, it can be useful to be able to specify the
seed to use to seed the RNG.

Add a new KCONFIG_SEED environment variable which can be set to
the seed to use:
$ make KCONFIG_SEED=42 randconfig
$ sha1sum .config
70a128c8dcc61303069e1be352cce64114dfcbca .config
$ make KCONFIG_SEED=42 randconfig
$ sha1sum .config
70a128c8dcc61303069e1be352cce64114dfcbca .config

It's very usefull for eg. debugging the kconfig parser.

Signed-off-by: "Yann E. MORIN" <[email protected]>
---
Documentation/kbuild/kconfig.txt | 9 +++++++++
scripts/kconfig/conf.c | 12 +++++++++++-
2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/Documentation/kbuild/kconfig.txt b/Documentation/kbuild/kconfig.txt
index b8b77bb..dbf746b 100644
--- a/Documentation/kbuild/kconfig.txt
+++ b/Documentation/kbuild/kconfig.txt
@@ -90,6 +90,15 @@ disable the options that are explicitly listed in the specified
mini-config files.

______________________________________________________________________
+Environment variables for 'randconfig'
+
+KCONFIG_SEED
+--------------------------------------------------
+You can set this to the integer value used to seed the RNG, if you want
+to somehow debug the behaviour of the kconfig parser/frontends.
+If not set, the current time will be used.
+
+______________________________________________________________________
Environment variables for 'silentoldconfig'

KCONFIG_NOSILENTUPDATE
diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c
index e39fcd8..bde5b95 100644
--- a/scripts/kconfig/conf.c
+++ b/scripts/kconfig/conf.c
@@ -13,6 +13,7 @@
#include <getopt.h>
#include <sys/stat.h>
#include <sys/time.h>
+#include <errno.h>

#include "lkc.h"

@@ -514,14 +515,23 @@ int main(int ac, char **av)
{
struct timeval now;
unsigned int seed;
+ char *seed_env;

/*
* Use microseconds derived seed,
* compensate for systems where it may be zero
*/
gettimeofday(&now, NULL);
-
seed = (unsigned int)((now.tv_sec + 1) * (now.tv_usec + 1));
+
+ seed_env = getenv("KCONFIG_SEED");
+ if( seed_env && *seed_env ) {
+ char *endp;
+ int tmp = (int)strtol(seed_env, &endp, 10);
+ if (*endp == '\0') {
+ seed = tmp;
+ }
+ }
srand(seed);
break;
}
--
1.7.10.4

2013-04-24 22:30:47

by Yann E. MORIN

[permalink] [raw]
Subject: [PATCH 6/8] kconfig: fix randomising choice entries in presence of KCONFIG_ALLCONFIG

From: "Yann E. MORIN" <[email protected]>

Currently, randconfig does randomise choice entries, unless KCONFIG_ALLCONFIG
is specified.

For example, given those two files (Thomas' test-case):

---8<--- Config.test.in
config OPTIONA
bool "Option A"

choice
prompt "This is a choice"

config CHOICE_OPTIONA
bool "Choice Option A"

config CHOICE_OPTIONB
bool "Choice Option B"

endchoice

config OPTIONB
bool "Option B"
---8<--- Config.test.in

---8<--- config.defaults
CONFIG_OPTIONA=y
---8<--- config.defaults

And running:
./scripts/kconfig/conf --randconfig Config.test.in

does properly randomise the two choice symbols (and the two booleans).

However, running:
KCONFIG_ALLCONFIG=config.defaults \
./scripts/kconfig/conf --randconfig Config.test.in

does *not* reandomise the two choice entries, and only CHOICE_OPTIONA
will ever be selected. (OPTIONA will always be set (expected), and
OPTIONB will be be properly randomised (expected).)

This patch defers setting that a choice has a value until a symbol for
that choice is indeed set, so that choices are properly randomised when
KCONFIG_ALLCONFIG is set, but not if a symbol for that choice is set.

Also, as a side-efect, this patch fixes the following case:

---8<---
choice
config OPTION_A
bool "Option A"
config OPTION_B
bool "Option B"
config OPTION_C
bool "Option C"
endchoice
---8<---

which could previously generate such .config files:

---8<--- ---8<---
CONFIG_OPTION_A=y CONFIG_OPTION_A=y
CONFIG_OPTION_B=y # CONFIG_OPTION_B is not set
# CONFIG_OPTION_C is not set CONFIG_OPTION_C=y
---8<--- ---8<---

Ie., the first entry in a choice is always set, plus zero or one of
the other options may be set.

This patch ensures that only one option may be set for a choice.

Reported-by: Thomas Petazzoni <[email protected]>
Signed-off-by: "Yann E. MORIN" <[email protected]>
Cc: Thomas Petazzoni <[email protected]>
Cc: Michal Marek <[email protected]>
Cc: Sam Ravnborg <[email protected]>
Cc: Arnaud Lacombe <[email protected]>

---
Changes v2 -> v3
- ensure only one symbol is set in a choice

Changes v1 -> v2:
- further postpone setting that a choice has a value until
one is indeed set
- do not print symbols that are part of an invisible choice
---
scripts/kconfig/confdata.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index 2e35d4b..8927480 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -288,8 +288,6 @@ load:
for_all_symbols(i, sym) {
sym->flags |= SYMBOL_CHANGED;
sym->flags &= ~(def_flags|SYMBOL_VALID);
- if (sym_is_choice(sym))
- sym->flags |= def_flags;
switch (sym->type) {
case S_INT:
case S_HEX:
@@ -379,13 +377,13 @@ setsym:
case mod:
if (cs->def[def].tri == yes) {
conf_warning("%s creates inconsistent choice state", sym->name);
- cs->flags &= ~def_flags;
}
break;
case yes:
if (cs->def[def].tri != no)
conf_warning("override: %s changes choice state", sym->name);
cs->def[def].val = sym;
+ cs->flags |= def_flags;
break;
}
cs->def[def].tri = EXPR_OR(cs->def[def].tri, sym->def[def].tri);
@@ -791,6 +789,8 @@ int conf_write(const char *name)
sym_calc_value(sym);
if (!(sym->flags & SYMBOL_WRITE))
goto next;
+ if (sym_is_choice_value(sym) && !menu_is_visible(menu->parent))
+ goto next;
sym->flags &= ~SYMBOL_WRITE;

conf_write_symbol(out, sym, &kconfig_printer_cb, NULL);
@@ -1077,6 +1077,7 @@ static void randomize_choice_values(struct symbol *csym)
else {
sym->def[S_DEF_USER].tri = no;
}
+ sym->flags &= ~(SYMBOL_VALID);
}
csym->flags |= SYMBOL_DEF_USER;
/* clear VALID to get value calculated */
--
1.7.10.4

2013-04-24 22:30:45

by Yann E. MORIN

[permalink] [raw]
Subject: [PATCH 1/8] menuconfig: Fix memory leak introduced by jump keys feature

From: Benjamin Poirier <[email protected]>

Fixes the memory leak of struct jump_key allocated in get_prompt_str()

Signed-off-by: Benjamin Poirier <[email protected]>
Tested-by: "Yann E. MORIN" <[email protected]>
Reviewed-by: "Yann E. MORIN" <[email protected]>
Signed-off-by: "Yann E. MORIN" <[email protected]>
Cc: [email protected]
---
scripts/kconfig/list.h | 13 +++++++++++++
scripts/kconfig/mconf.c | 3 +++
2 files changed, 16 insertions(+)

diff --git a/scripts/kconfig/list.h b/scripts/kconfig/list.h
index 0ae730b..b87206c 100644
--- a/scripts/kconfig/list.h
+++ b/scripts/kconfig/list.h
@@ -51,6 +51,19 @@ struct list_head {
pos = list_entry(pos->member.next, typeof(*pos), member))

/**
+ * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
+ * @pos: the type * to use as a loop cursor.
+ * @n: another type * to use as temporary storage
+ * @head: the head for your list.
+ * @member: the name of the list_struct within the struct.
+ */
+#define list_for_each_entry_safe(pos, n, head, member) \
+ for (pos = list_entry((head)->next, typeof(*pos), member), \
+ n = list_entry(pos->member.next, typeof(*pos), member); \
+ &pos->member != (head); \
+ pos = n, n = list_entry(n->member.next, typeof(*n), member))
+
+/**
* list_empty - tests whether a list is empty
* @head: the list to test.
*/
diff --git a/scripts/kconfig/mconf.c b/scripts/kconfig/mconf.c
index 566288a..c5418d6 100644
--- a/scripts/kconfig/mconf.c
+++ b/scripts/kconfig/mconf.c
@@ -389,6 +389,7 @@ again:
.targets = targets,
.keys = keys,
};
+ struct jump_key *pos, *tmp;

res = get_relations_str(sym_arr, &head);
dres = show_textbox_ext(_("Search Results"), (char *)
@@ -402,6 +403,8 @@ again:
again = true;
}
str_free(&res);
+ list_for_each_entry_safe(pos, tmp, &head, entries)
+ free(pos);
} while (again);
free(sym_arr);
str_free(&title);
--
1.7.10.4

2013-04-24 22:30:44

by Yann E. MORIN

[permalink] [raw]
Subject: [PATCH 5/8] kconfig: do not override symbols already set

From: "Yann E. MORIN" <[email protected]>

For randconfig, if a list of required symbols is specified with
KCONFIG_ALLCONFIG, such symbols do not "have a value" as per
sym_has_value(), but have the "valid" flag set.

Signed-off-by: "Yann E. MORIN" <[email protected]>
---
scripts/kconfig/confdata.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index 306cbc1..2e35d4b 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -1109,7 +1109,7 @@ void conf_set_all_new_symbols(enum conf_def_mode mode)
int i, cnt;

for_all_symbols(i, sym) {
- if (sym_has_value(sym))
+ if (sym_has_value(sym) || (sym->flags & SYMBOL_VALID))
continue;
switch (sym_get_type(sym)) {
case S_BOOLEAN:
--
1.7.10.4

2013-04-24 22:30:43

by Yann E. MORIN

[permalink] [raw]
Subject: [PATCH 4/8] kconfig: fix randconfig tristate detection

From: "Yann E. MORIN" <[email protected]>

Because the modules' symbole (CONFIG_MODULES) may not yet be set when
we check a symbol's tristate capabilty, we'll always find that tristate
symbols are booleans, even if we randomly decided that to enable modules:
sym_get_type(sym) always return boolean for tristates when modules_sym
has not been previously set to 'y' *and* its value calculated *and* its
visibility calculated, both of which only occur after we randomly assign
values to symbols.

Fix that by looking at the raw type of symbols. Tristate set to 'm' will
be promoted to 'y' when their values will be later calculated.

Signed-off-by: "Yann E. MORIN" <[email protected]>
---
scripts/kconfig/confdata.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index 13ddf11..306cbc1 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -1125,7 +1125,7 @@ void conf_set_all_new_symbols(enum conf_def_mode mode)
sym->def[S_DEF_USER].tri = no;
break;
case def_random:
- cnt = sym_get_type(sym) == S_TRISTATE ? 3 : 2;
+ cnt = sym->type == S_TRISTATE ? 3 : 2;
sym->def[S_DEF_USER].tri = (tristate)(rand() % cnt);
break;
default:
--
1.7.10.4

2013-04-24 22:30:41

by Yann E. MORIN

[permalink] [raw]
Subject: [PATCH 3/8] kconfig/lxdialog: rationalise the include paths where to find {.n}curses{,w}.h

From: "Yann E. MORIN" <[email protected]>

The current code does this:

if [ -f /usr/include/ncursesw/curses.h ]; then
echo '-I/usr/include/ncursesw -DCURSES_LOC="<ncursesw/curses.h>"'
elif [ -f /usr/include/ncurses/ncurses.h ]; then
echo '-I/usr/include/ncurses -DCURSES_LOC="<ncurses.h>"'
elif [ -f /usr/include/ncurses/curses.h ]; then
echo '-I/usr/include/ncurses -DCURSES_LOC="<ncurses/curses.h>"'
[...]

This is merely inconsistent:
- adding the full path to the directory in the -I directive,
- especially since that path is already a sub-path of the system
include path,
- and then repeating the sub-path in the #include directive.

Rationalise each include directive:
- only use the filename in the #include directive,
- keep the -I directives: they are always searched for before the
system include path; this ensures the correct header is used.

Using the -I directives and the filename-only in #include is more in
line with how pkg-config behaves, eg.:
$ pkg-config --cflags ncursesw
-I/usr/include/ncursesw

This paves the way for using pkg-config for CFLAGS, too, now we use it
to find the libraries.

Signed-off-by: "Yann E. MORIN" <[email protected]>
---
scripts/kconfig/lxdialog/check-lxdialog.sh | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/scripts/kconfig/lxdialog/check-lxdialog.sh b/scripts/kconfig/lxdialog/check-lxdialog.sh
index 782d200..9d2a4c5 100644
--- a/scripts/kconfig/lxdialog/check-lxdialog.sh
+++ b/scripts/kconfig/lxdialog/check-lxdialog.sh
@@ -22,12 +22,12 @@ ldflags()
ccflags()
{
if [ -f /usr/include/ncursesw/curses.h ]; then
- echo '-I/usr/include/ncursesw -DCURSES_LOC="<ncursesw/curses.h>"'
+ echo '-I/usr/include/ncursesw -DCURSES_LOC="<curses.h>"'
echo ' -DNCURSES_WIDECHAR=1'
elif [ -f /usr/include/ncurses/ncurses.h ]; then
echo '-I/usr/include/ncurses -DCURSES_LOC="<ncurses.h>"'
elif [ -f /usr/include/ncurses/curses.h ]; then
- echo '-I/usr/include/ncurses -DCURSES_LOC="<ncurses/curses.h>"'
+ echo '-I/usr/include/ncurses -DCURSES_LOC="<curses.h>"'
elif [ -f /usr/include/ncurses.h ]; then
echo '-DCURSES_LOC="<ncurses.h>"'
else
--
1.7.10.4

2013-04-24 22:30:39

by Yann E. MORIN

[permalink] [raw]
Subject: [PATCH 2/8] menuconfig: Add "breadcrumbs" navigation aid

From: Benjamin Poirier <[email protected]>

Displays a trail of the menu entries used to get to the current menu.

Signed-off-by: Benjamin Poirier <[email protected]>
Tested-by: "Yann E. MORIN" <[email protected]>
[[email protected]: small, trivial code re-ordering]
Signed-off-by: "Yann E. MORIN" <[email protected]>
---
scripts/kconfig/list.h | 27 ++++++++++++++
scripts/kconfig/lxdialog/dialog.h | 7 ++++
scripts/kconfig/lxdialog/util.c | 45 +++++++++++++++++++++--
scripts/kconfig/mconf.c | 71 ++++++++++++++++++++++++++++++++++++-
4 files changed, 147 insertions(+), 3 deletions(-)

diff --git a/scripts/kconfig/list.h b/scripts/kconfig/list.h
index b87206c..ea1d581 100644
--- a/scripts/kconfig/list.h
+++ b/scripts/kconfig/list.h
@@ -101,4 +101,31 @@ static inline void list_add_tail(struct list_head *_new, struct list_head *head)
__list_add(_new, head->prev, head);
}

+/*
+ * Delete a list entry by making the prev/next entries
+ * point to each other.
+ *
+ * This is only for internal list manipulation where we know
+ * the prev/next entries already!
+ */
+static inline void __list_del(struct list_head *prev, struct list_head *next)
+{
+ next->prev = prev;
+ prev->next = next;
+}
+
+#define LIST_POISON1 ((void *) 0x00100100)
+#define LIST_POISON2 ((void *) 0x00200200)
+/**
+ * list_del - deletes entry from list.
+ * @entry: the element to delete from the list.
+ * Note: list_empty() on entry does not return true after this, the entry is
+ * in an undefined state.
+ */
+static inline void list_del(struct list_head *entry)
+{
+ __list_del(entry->prev, entry->next);
+ entry->next = LIST_POISON1;
+ entry->prev = LIST_POISON2;
+}
#endif
diff --git a/scripts/kconfig/lxdialog/dialog.h b/scripts/kconfig/lxdialog/dialog.h
index 307022a..10993370 100644
--- a/scripts/kconfig/lxdialog/dialog.h
+++ b/scripts/kconfig/lxdialog/dialog.h
@@ -106,8 +106,14 @@ struct dialog_color {
int hl; /* highlight this item */
};

+struct subtitle_list {
+ struct subtitle_list *next;
+ const char *text;
+};
+
struct dialog_info {
const char *backtitle;
+ struct subtitle_list *subtitles;
struct dialog_color screen;
struct dialog_color shadow;
struct dialog_color dialog;
@@ -196,6 +202,7 @@ int on_key_resize(void);

int init_dialog(const char *backtitle);
void set_dialog_backtitle(const char *backtitle);
+void set_dialog_subtitles(struct subtitle_list *subtitles);
void end_dialog(int x, int y);
void attr_clear(WINDOW * win, int height, int width, chtype attr);
void dialog_clear(void);
diff --git a/scripts/kconfig/lxdialog/util.c b/scripts/kconfig/lxdialog/util.c
index 109d531..a0e97c2 100644
--- a/scripts/kconfig/lxdialog/util.c
+++ b/scripts/kconfig/lxdialog/util.c
@@ -257,12 +257,48 @@ void dialog_clear(void)
attr_clear(stdscr, LINES, COLS, dlg.screen.atr);
/* Display background title if it exists ... - SLH */
if (dlg.backtitle != NULL) {
- int i;
+ int i, len = 0, skip = 0;
+ struct subtitle_list *pos;

wattrset(stdscr, dlg.screen.atr);
mvwaddstr(stdscr, 0, 1, (char *)dlg.backtitle);
+
+ for (pos = dlg.subtitles; pos != NULL; pos = pos->next) {
+ /* 3 is for the arrow and spaces */
+ len += strlen(pos->text) + 3;
+ }
+
wmove(stdscr, 1, 1);
- for (i = 1; i < COLS - 1; i++)
+ if (len > COLS - 2) {
+ const char *ellipsis = "[...] ";
+ waddstr(stdscr, ellipsis);
+ skip = len - (COLS - 2 - strlen(ellipsis));
+ }
+
+ for (pos = dlg.subtitles; pos != NULL; pos = pos->next) {
+ if (skip == 0)
+ waddch(stdscr, ACS_RARROW);
+ else
+ skip--;
+
+ if (skip == 0)
+ waddch(stdscr, ' ');
+ else
+ skip--;
+
+ if (skip < strlen(pos->text)) {
+ waddstr(stdscr, pos->text + skip);
+ skip = 0;
+ } else
+ skip -= strlen(pos->text);
+
+ if (skip == 0)
+ waddch(stdscr, ' ');
+ else
+ skip--;
+ }
+
+ for (i = len + 1; i < COLS - 1; i++)
waddch(stdscr, ACS_HLINE);
}
wnoutrefresh(stdscr);
@@ -302,6 +338,11 @@ void set_dialog_backtitle(const char *backtitle)
dlg.backtitle = backtitle;
}

+void set_dialog_subtitles(struct subtitle_list *subtitles)
+{
+ dlg.subtitles = subtitles;
+}
+
/*
* End using dialog functions.
*/
diff --git a/scripts/kconfig/mconf.c b/scripts/kconfig/mconf.c
index c5418d6..387dc8d 100644
--- a/scripts/kconfig/mconf.c
+++ b/scripts/kconfig/mconf.c
@@ -311,6 +311,50 @@ static void set_config_filename(const char *config_filename)
filename[sizeof(filename)-1] = '\0';
}

+struct subtitle_part {
+ struct list_head entries;
+ const char *text;
+};
+static LIST_HEAD(trail);
+
+static struct subtitle_list *subtitles;
+static void set_subtitle(void)
+{
+ struct subtitle_part *sp;
+ struct subtitle_list *pos, *tmp;
+
+ for (pos = subtitles; pos != NULL; pos = tmp) {
+ tmp = pos->next;
+ free(pos);
+ }
+
+ subtitles = NULL;
+ list_for_each_entry(sp, &trail, entries) {
+ if (sp->text) {
+ if (pos) {
+ pos->next = xcalloc(sizeof(*pos), 1);
+ pos = pos->next;
+ } else {
+ subtitles = pos = xcalloc(sizeof(*pos), 1);
+ }
+ pos->text = sp->text;
+ }
+ }
+
+ set_dialog_subtitles(subtitles);
+}
+
+static void reset_subtitle(void)
+{
+ struct subtitle_list *pos, *tmp;
+
+ for (pos = subtitles; pos != NULL; pos = tmp) {
+ tmp = pos->next;
+ free(pos);
+ }
+ subtitles = NULL;
+ set_dialog_subtitles(subtitles);
+}

struct search_data {
struct list_head *head;
@@ -353,6 +397,8 @@ static void search_conf(void)
char *dialog_input;
int dres, vscroll = 0, hscroll = 0;
bool again;
+ struct gstr sttext;
+ struct subtitle_part stpart;

title = str_new();
str_printf( &title, _("Enter %s (sub)string to search for "
@@ -379,6 +425,11 @@ again:
if (strncasecmp(dialog_input_result, CONFIG_, strlen(CONFIG_)) == 0)
dialog_input += strlen(CONFIG_);

+ sttext = str_new();
+ str_printf(&sttext, "Search (%s)", dialog_input_result);
+ stpart.text = str_get(&sttext);
+ list_add_tail(&stpart.entries, &trail);
+
sym_arr = sym_re_search(dialog_input);
do {
LIST_HEAD(head);
@@ -392,6 +443,7 @@ again:
struct jump_key *pos, *tmp;

res = get_relations_str(sym_arr, &head);
+ set_subtitle();
dres = show_textbox_ext(_("Search Results"), (char *)
str_get(&res), 0, 0, keys, &vscroll,
&hscroll, &update_text, (void *)
@@ -408,6 +460,8 @@ again:
} while (again);
free(sym_arr);
str_free(&title);
+ list_del(trail.prev);
+ str_free(&sttext);
}

static void build_conf(struct menu *menu)
@@ -592,16 +646,24 @@ static void conf(struct menu *menu, struct menu *active_menu)
{
struct menu *submenu;
const char *prompt = menu_get_prompt(menu);
+ struct subtitle_part stpart;
struct symbol *sym;
int res;
int s_scroll = 0;

+ if (menu != &rootmenu)
+ stpart.text = menu_get_prompt(menu);
+ else
+ stpart.text = NULL;
+ list_add_tail(&stpart.entries, &trail);
+
while (1) {
item_reset();
current_menu = menu;
build_conf(menu);
if (!child_count)
break;
+ set_subtitle();
dialog_clear();
res = dialog_menu(prompt ? _(prompt) : _("Main Menu"),
_(menu_instructions),
@@ -643,13 +705,17 @@ static void conf(struct menu *menu, struct menu *active_menu)
case 2:
if (sym)
show_help(submenu);
- else
+ else {
+ reset_subtitle();
show_helptext(_("README"), _(mconf_readme));
+ }
break;
case 3:
+ reset_subtitle();
conf_save();
break;
case 4:
+ reset_subtitle();
conf_load();
break;
case 5:
@@ -682,6 +748,8 @@ static void conf(struct menu *menu, struct menu *active_menu)
break;
}
}
+
+ list_del(trail.prev);
}

static int show_textbox_ext(const char *title, char *text, int r, int c, int
@@ -884,6 +952,7 @@ static int handle_exit(void)
int res;

save_and_exit = 1;
+ reset_subtitle();
dialog_clear();
if (conf_get_changed())
res = dialog_yesno(NULL,
--
1.7.10.4

2013-04-25 08:57:30

by Michal Marek

[permalink] [raw]
Subject: Re: [PATCH 8/8] kconfig: implement KCONFIG_PROBABILITY for randconfig

On 25.4.2013 00:29, Yann E. MORIN wrote:
> From: "Yann E. MORIN" <[email protected]>
>
> 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)

I did a naive test with the current kconfig branch and with
yem-kconfig-for-next:

$ git checkout a45c7df
$ echo CONFIG_MODULES=y >all.config
$ >test-orig; for i in `seq 1000`; do KCONFIG_ALLCONFIG=1 make
randconfig || break; grep -c '=m' .config >>test-orig; done
...
$ git checkout e43956e
$ >test-new; ...

$ awk '{ sum += $1; num++ } END { print sum / num}' test-orig
573.247
$ awk '{ sum += $1; num++ } END { print sum / num}' test-new
565.194

I am not a statistician, but this looks OK to me. For reference, the
figure was ~340 with the previous patch.

I pulled your changes to kbuild.git#kconfig.

Thanks,
Michal

2013-04-26 12:06:04

by Arnd Bergmann

[permalink] [raw]
Subject: Re: [PATCH 6/8] kconfig: fix randomising choice entries in presence of KCONFIG_ALLCONFIG

On Thursday 25 April 2013 00:29:53 Yann E. MORIN wrote:
> From: "Yann E. MORIN" <[email protected]>
>
> Currently, randconfig does randomise choice entries, unless KCONFIG_ALLCONFIG
> is specified.
>
> For example, given those two files (Thomas' test-case):

This patch has made it into linux-next today, and while I agree with
the basic idea, it seems to cause regressions for me.

For these ARM defconfigs, 'make' always asks about USB_GADGET now
after doing any of these defconfigs:

am200epdkit_defconfig
at91_dt_defconfig
at91rm9200_defconfig
at91sam9260_defconfig
at91sam9261_defconfig
at91sam9263_defconfig
at91sam9g20_defconfig
at91sam9g45_defconfig
corgi_defconfig
ezx_defconfig
h5000_defconfig
imote2_defconfig
kzm9g_defconfig
lpc32xx_defconfig
lubbock_defconfig
mackerel_defconfig
magician_defconfig
mini2440_defconfig
msm_defconfig
omap1_defconfig
prima2_defconfig
sama5_defconfig
tct_hammer_defconfig

~/arm-soc$ make at91_dt_defconfig
make[1]: Entering directory `/git/arm-soc'
GEN /git/arm-soc/obj-tmp/Makefile
HOSTCC scripts/kconfig/zconf.tab.o
HOSTLD scripts/kconfig/conf
#
# configuration written to .config
#
make[1]: Leaving directory `/git/arm-soc'
~/arm-soc$ make -sj40
make[1]: Entering directory `/git/arm-soc'
GEN /git/arm-soc/obj-tmp/Makefile
scripts/kconfig/conf --silentoldconfig Kconfig
*
* Restart config...
*
*
* USB Gadget Support
*
USB Gadget Support (USB_GADGET) [Y/n/m/?] y
Debugging messages (DEVELOPMENT) (USB_GADGET_DEBUG) [N/y/?] n
Debugging information files (DEVELOPMENT) (USB_GADGET_DEBUG_FILES) [N/y/?] n
Debugging information files in debugfs (DEVELOPMENT) (USB_GADGET_DEBUG_FS) [N/y/?] n
Maximum VBUS Power usage (2-500 mA) (USB_GADGET_VBUS_DRAW) [2] 2
Number of storage pipeline buffers (USB_GADGET_STORAGE_NUM_BUFFERS) [2] 2
USB Gadget Drivers [M/y/?] (NEW)

I'm taking Greg on Cc here so he's aware of the problem and knows it's
not caused by any of the USB Kconfig changes that I and others submitted
recently. It took me a while to confirm that it's just your patch and
not mine that caused the problem.

Arnd

2013-04-26 12:11:08

by Yann E. MORIN

[permalink] [raw]
Subject: Re: [PATCH 6/8] kconfig: fix randomising choice entries in presence of KCONFIG_ALLCONFIG

Arnd, All,

On Fri, Apr 26, 2013 at 02:05:37PM +0200, Arnd Bergmann wrote:
> On Thursday 25 April 2013 00:29:53 Yann E. MORIN wrote:
> > From: "Yann E. MORIN" <[email protected]>
> >
> > Currently, randconfig does randomise choice entries, unless KCONFIG_ALLCONFIG
> > is specified.
> >
> > For example, given those two files (Thomas' test-case):
>
> This patch has made it into linux-next today, and while I agree with
> the basic idea, it seems to cause regressions for me.

Yes, this has already been noticed. Thanks for the report.

So far, we have a plan B (which is to revert that patch). I'll work on
plan A when I'm back home after work (GMT+2 here, so in about 5h from
now).

Sorry for the annoyance...

Regards,
Yann E. MORIN.

--
.-----------------.--------------------.------------------.--------------------.
| Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software Designer | \ / CAMPAIGN | ___ |
| +33 223 225 172 `------------.-------: X AGAINST | \e/ There is no |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL | v conspiracy. |
'------------------------------^-------^------------------^--------------------'

2013-04-26 22:09:20

by Yann E. MORIN

[permalink] [raw]
Subject: Re: [PATCH 6/8] kconfig: fix randomising choice entries in presence of KCONFIG_ALLCONFIG

On Fri, Apr 26, 2013 at 02:05:37PM +0200, Arnd Bergmann wrote:
> On Thursday 25 April 2013 00:29:53 Yann E. MORIN wrote:
> > From: "Yann E. MORIN" <[email protected]>
> >
> > Currently, randconfig does randomise choice entries, unless KCONFIG_ALLCONFIG
> > is specified.
> >
> > For example, given those two files (Thomas' test-case):
>
> This patch has made it into linux-next today, and while I agree with
> the basic idea, it seems to cause regressions for me.
>
> For these ARM defconfigs, 'make' always asks about USB_GADGET now

OK, I threw in the towel on that one for tonight.
I'll send a patch to revert this changeset, in the coming minutes.

It will have to be revisited later on, and hopefully we can come to a
proper solution during the pre-rc1 window, or at worst, early during the
-rc phase (as I'm on holidays the next two weeks, I should find sometime
to gather what remains of my courage to look at that again).

Really sorry for the inconvenience... :-(

Regards,
Yann E. MORIN.

--
.-----------------.--------------------.------------------.--------------------.
| Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software Designer | \ / CAMPAIGN | ___ |
| +33 223 225 172 `------------.-------: X AGAINST | \e/ There is no |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL | v conspiracy. |
'------------------------------^-------^------------------^--------------------'

2013-04-27 21:01:13

by Arnd Bergmann

[permalink] [raw]
Subject: Re: [PATCH 6/8] kconfig: fix randomising choice entries in presence of KCONFIG_ALLCONFIG

On Saturday 27 April 2013, Yann E. MORIN wrote:
>
> On Fri, Apr 26, 2013 at 02:05:37PM +0200, Arnd Bergmann wrote:
> > On Thursday 25 April 2013 00:29:53 Yann E. MORIN wrote:
> > > From: "Yann E. MORIN" <[email protected]>
> > >
> > > Currently, randconfig does randomise choice entries, unless KCONFIG_ALLCONFIG
> > > is specified.
> > >
> > > For example, given those two files (Thomas' test-case):
> >
> > This patch has made it into linux-next today, and while I agree with
> > the basic idea, it seems to cause regressions for me.
> >
> > For these ARM defconfigs, 'make' always asks about USB_GADGET now
>
> OK, I threw in the towel on that one for tonight.
> I'll send a patch to revert this changeset, in the coming minutes.
>
> It will have to be revisited later on, and hopefully we can come to a
> proper solution during the pre-rc1 window, or at worst, early during the
> -rc phase (as I'm on holidays the next two weeks, I should find sometime
> to gather what remains of my courage to look at that again).

Ok, fair enough. For my own testing, I've actually started relying on the
behavior that is meant to be changed by the patch, even though I realize
that we should really randomize choice statements.

It's easy enough for me to change my script to always select
CONFIG_ARCH_MUTLIPLATFORM for ARM testing in the future.

Arnd

2013-04-27 22:32:06

by Yann E. MORIN

[permalink] [raw]
Subject: Re: [PATCH 6/8] kconfig: fix randomising choice entries in presence of KCONFIG_ALLCONFIG

Arnd, All,

On Sat, Apr 27, 2013 at 11:01:00PM +0200, Arnd Bergmann wrote:
> On Saturday 27 April 2013, Yann E. MORIN wrote:
> >
> > On Fri, Apr 26, 2013 at 02:05:37PM +0200, Arnd Bergmann wrote:
> > > On Thursday 25 April 2013 00:29:53 Yann E. MORIN wrote:
> > > > From: "Yann E. MORIN" <[email protected]>
> > > >
> > > > Currently, randconfig does randomise choice entries, unless KCONFIG_ALLCONFIG
> > > > is specified.
> > > >
> > > > For example, given those two files (Thomas' test-case):
> > >
> > > This patch has made it into linux-next today, and while I agree with
> > > the basic idea, it seems to cause regressions for me.
> > >
> > > For these ARM defconfigs, 'make' always asks about USB_GADGET now
> >
> > OK, I threw in the towel on that one for tonight.
> > I'll send a patch to revert this changeset, in the coming minutes.
> >
> > It will have to be revisited later on, and hopefully we can come to a
> > proper solution during the pre-rc1 window, or at worst, early during the
> > -rc phase (as I'm on holidays the next two weeks, I should find sometime
> > to gather what remains of my courage to look at that again).
>
> Ok, fair enough. For my own testing, I've actually started relying on the
> behavior that is meant to be changed by the patch, even though I realize
> that we should really randomize choice statements.
>
> It's easy enough for me to change my script to always select
> CONFIG_ARCH_MUTLIPLATFORM for ARM testing in the future.

Fact is, choices are properly randomised, unless KCONFIG_ALLCONFIG is
passed.

So, if you currently rely on choices not being randomised, it means
you're using KCONFIG_ALLCONFIG [*] so you can set CONFIG_ARCH_MULTIPLATFORM
in the defconfig you use.

Which should not change your workflow by much, I believe.

[*] If not, then we have another issue. Can you confirm you're already
using KCONFIG_ALLCONFIG? If not, can you explain how you handle
CONFIG_ARCH_MULTIPLATFORM always being set?

Regards,
Yann E. MORIN.

--
.-----------------.--------------------.------------------.--------------------.
| Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software Designer | \ / CAMPAIGN | ___ |
| +33 223 225 172 `------------.-------: X AGAINST | \e/ There is no |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL | v conspiracy. |
'------------------------------^-------^------------------^--------------------'

2013-04-28 01:06:07

by Arnd Bergmann

[permalink] [raw]
Subject: Re: [PATCH 6/8] kconfig: fix randomising choice entries in presence of KCONFIG_ALLCONFIG

On Sunday 28 April 2013, Yann E. MORIN wrote:
> Fact is, choices are properly randomised, unless KCONFIG_ALLCONFIG is
> passed.
>
> So, if you currently rely on choices not being randomised, it means
> you're using KCONFIG_ALLCONFIG [*] so you can set CONFIG_ARCH_MULTIPLATFORM
> in the defconfig you use.

Yes, you are right, I can easily do this.

Arnd