Skip to content

Commit

Permalink
kconfig: fix randomising choice entries in presence of KCONFIG_ALLCONFIG
Browse files Browse the repository at this point in the history
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.

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: Sedat Dilek <[email protected]>
Cc: Arnd Bergmann <[email protected]>
Cc: Stephen Rothwell <[email protected]>

---
Changes v3 -> v4
  - fix previous issue where some choices would not be set, which would
    cause silentoldconfig to ask for them and was then breaking this
    workflow (as reported by Arnd and Sedat):
        KCONFIG_ALLCONFIG=foo.defconfig make randconfig
        make silentoldconfig </dev/nullo
    which I have tested (3h28min!) with:
        touch defconfig
        for(( i=0; i<10000; i++ )); do
            KCONFIG_ALLCONFIG=$(pwd)/defconfig make randconfig >/dev/null 2>&1
            make silentoldconfig </dev/null >/dev/null 2>&1 || break
        done
    which did not break at all.
  - change done in v3 (below) is already fixed by a previous patch

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
  • Loading branch information
yann-morin-1998 committed Jun 24, 2013
1 parent 3b9a19e commit 8357b48
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions scripts/kconfig/confdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,6 @@ int conf_read_simple(const char *name, int def)
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:
Expand Down Expand Up @@ -379,13 +377,13 @@ int conf_read_simple(const char *name, int def)
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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 8357b48

Please sign in to comment.