Received: by 10.223.185.116 with SMTP id b49csp3587426wrg; Tue, 6 Mar 2018 01:23:11 -0800 (PST) X-Google-Smtp-Source: AG47ELtZ/vOQ+KO8ww7XwCEZcJ1n9X1FH3IMThdWIc5KuIwXlcZQM7SalEaDw+av7gWw201Q4twg X-Received: by 10.98.252.22 with SMTP id e22mr18331788pfh.235.1520328190965; Tue, 06 Mar 2018 01:23:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520328190; cv=none; d=google.com; s=arc-20160816; b=z7hj0Lt9SvstyCbf3Uhr8Y16vxhdINhgRR6wKryNgP/9PAwwHppYmrg+XgX4eJkXHX TOFzllkhDgmIZ/kACU5b/IjWjjteeB/vn3yqUXk7iT2lZJO0/oJYP74WCDt/BgB1F6En L2H1F1+bEI5VVTL1JL2Vr/TiTH1FgcFEiMCcCj2tCEvnNhEcXH+7FCrU9BCgWqY5EGKT J7zMAKFOHSbh9YcNnrUB39uI4Lz5owmuGXi7JsGfn0ZoLN0DnSNZEUhwxpyKWdS+RAyx 6tXIYZ+XSYMzUVJhPmDLGM25C7BfXAz3GxAvbRzwfqkx0he+ky8pkW1CsKK6qmLVPAB6 Y9MA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature:dkim-filter :arc-authentication-results; bh=imoRMKu88wbNK4+Fkmj5nOQQ3NoQnAEMx+9a4QmTDTo=; b=bQBBfkjV9NUmCqbPSHMuTiTd++0f6VImgcQv81AI+s05uwGCK0P5+yQDfWyVVbTHpk fq+etwqC+KnaGQinsoJFdq02adFiiP5zVREgsuKWI+kZ6u5301gOXSRjHbWyD24d4e5N Qt3fWSuHOFg2afe/jk1B4ofxTbY6uZtIshX382LsDgN6kE4eM1nbJINiP5lItzlaBq5N wgZGHDYWPWZbOU5AXxHIacjeeRs3fTUrzK2Q1P7tWMNXArDTcVzhKwl69aYAY7kc8I0j 3ZpjR/g2n9HQBmz2TkxD4BgtYgj14O7L6yU5LviYBQKfA3oVedDTZpQ3pHGCRdh+cAR/ 6oiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=UBzMhBVS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v4-v6si10898400plb.179.2018.03.06.01.22.57; Tue, 06 Mar 2018 01:23:10 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=UBzMhBVS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932410AbeCFJV6 (ORCPT + 99 others); Tue, 6 Mar 2018 04:21:58 -0500 Received: from conssluserg-02.nifty.com ([210.131.2.81]:47876 "EHLO conssluserg-02.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753210AbeCFJVy (ORCPT ); Tue, 6 Mar 2018 04:21:54 -0500 Received: from mail-ua0-f171.google.com (mail-ua0-f171.google.com [209.85.217.171]) (authenticated) by conssluserg-02.nifty.com with ESMTP id w269LkUF011307; Tue, 6 Mar 2018 18:21:47 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conssluserg-02.nifty.com w269LkUF011307 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1520328107; bh=imoRMKu88wbNK4+Fkmj5nOQQ3NoQnAEMx+9a4QmTDTo=; h=In-Reply-To:References:From:Date:Subject:To:Cc:From; b=UBzMhBVSF+kNomuwTx27eQJlgckProBpH5sy9OTsZuNtv3PvmnaTuoED+m0GUjY/e yOAoTSq5pVh3N9WnKA6nHcBLiG03/IghXTdKfFsIgWCNW97oXBBU56V7R9eER+Dlii 80lEjYdB6xBB2GApBpOSRaaKCDUYsHYCn4F5sLKV0nTakffyYzDGps6/r8W2ejnHI8 EiewFajnQ6bGPPj7GsrwXKrGgx6hKlmOrxA5iFQS7SM4cU35itC0z7F65rqe9u8t8K q65yUCGOZ736iabTZlA23eSskChVIYx9EHWI2JfbiXzVClN0JZWzLzo7NoZ8bKaC72 V5zYur9edp+GQ== X-Nifty-SrcIP: [209.85.217.171] Received: by mail-ua0-f171.google.com with SMTP id q12so2942809uae.4; Tue, 06 Mar 2018 01:21:47 -0800 (PST) X-Gm-Message-State: APf1xPBgSf6Pe+kbDJCkvTveRt9hVftTwcInKFTD25TI18wzwXeUM1X6 PBGT6PP2hdQU35IgKz4UqP9d8qsjDxCOVtRu08k= X-Received: by 10.159.59.111 with SMTP id j47mr12953959uah.140.1520328105901; Tue, 06 Mar 2018 01:21:45 -0800 (PST) MIME-Version: 1.0 Received: by 10.176.32.138 with HTTP; Tue, 6 Mar 2018 01:21:05 -0800 (PST) In-Reply-To: References: <1519965121-12017-1-git-send-email-yamada.masahiro@socionext.com> <1519965121-12017-9-git-send-email-yamada.masahiro@socionext.com> From: Masahiro Yamada Date: Tue, 6 Mar 2018 18:21:05 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 08/11] kconfig: unittest: test defconfig when two choices interact To: Ulf Magnusson Cc: Linux Kbuild mailing list , Sam Ravnborg , Michal Marek , Randy Dunlap , "Luis R . Rodriguez" , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2018-03-02 19:41 GMT+09:00 Ulf Magnusson : > On Fri, Mar 2, 2018 at 5:31 AM, Masahiro Yamada > wrote: >> Commit fbe98bb9ed3d ("kconfig: Fix defconfig when one choice menu >> selects options that another choice menu depends on") fixed defconfig >> when two choices interact (i.e. calculating the visibility of a choice >> requires to calculate another choice). >> >> The test code in that commit log was based on the real world example, >> and complicated. So, I shrunk it down to the following: >> >> defconfig.choice: >> ---8<--- >> CONFIG_CHOICE_VAL0=y >> ---8<--- >> >> ---8<--- >> config MODULES >> bool "Enable loadable module support" >> option modules >> default y >> >> choice >> prompt "Choice" >> >> config CHOICE_VAL0 >> tristate "Choice 0" >> >> config CHOICE_VAL1 >> tristate "Choice 1" >> >> endchoice >> >> choice >> prompt "Another choice" >> depends on CHOICE_VAL0 >> >> config DUMMY >> bool "dummy" >> >> endchoice >> ---8<--- >> >> Prior to commit fbe98bb9ed3d, >> >> $ scripts/kconfig/conf --defconfig=defconfig.choice Kconfig.choice >> >> resulted in: >> >> CONFIG_MODULES=y >> CONFIG_CHOICE_VAL0=m >> # CONFIG_CHOICE_VAL1 is not set >> CONFIG_DUMMY=y >> >> where the expected result would be: >> >> CONFIG_MODULES=y >> CONFIG_CHOICE_VAL0=y >> # CONFIG_CHOICE_VAL1 is not set >> CONFIG_DUMMY=y >> >> Roughly, this weird behavior happened like this: >> >> Symbols are calculated a couple of times. First, all symbols are >> calculated in conf_read(). The first 'choice' is evaluated to 'y' >> due to the SYMBOL_DEF_USER flag, but sym_calc_choice() clears it >> unless all of its choice values are explicitly set by the user. >> >> conf_set_all_new_symbols() clears all SYMBOL_VALID flags. Then, only >> choices are calculated. At this point, the SYMBOL_DEF_USER for the >> first choice is unset, so, it is evaluated to 'm'. (this is weird) > > This is because tristate choices start out in m mode btw (they have an > implicit select of 'm && ' on them, added add the end of > menu_finalize()). Ah, right. But indeed weird to forget SYMBOL_DEF_USER. >> set_all_choice_values() sets SYMBOL_DEF_USER again to choice symbols. >> >> When calculating the second choice, due to 'depends on CHOICE_VAL0', >> it triggers the calculation of CHOICE_VAL0. As a result, SYMBOL_VALID >> is set for CHOICE_VAL0. >> >> Symbols except choices get the final chance of re-calculation in >> conf_write(). In a normal case, CHOICE_VAL0 would be re-caluculated, >> then the first choice would be indirectly re-calculated with the >> SYMBOL_DEF_USER which has been set by set_all_choice_values(), which >> would be evaluated to 'y'. But, in this case, CHOICE_VAL0 has been >> marked SYMBOL_VALID, so it is simply skipped. Then, =m is written out >> to the .config file. >> >> Add a unit test for this naive case. > > At a high level, I think the problem is that the choice mode is > forgotten. It should be y because of the CONFIG_CHOICE_VAL0=y > assignment, but reverts back to m temporarily, and during that window > a choice symbol is evaluated and gets the wrong value. > > I wonder if all this twisty code and the weird flags > (SYMBOL_NEED_SET_CHOICE_VALUES... hmm) are required. Perhaps an extra > invalidation or the like would be enough. Agree. Probably, 5d09598d488f and fbe98bb9ed3d fixed issues in a bad way. I believe SYMBOL_DEF_USER should be set only in conf_read(_simple) and conf_set_all_new_symbols(). It is strange to set and clear SYMBOL_DEF_USER while calculating symbols. >> >> Signed-off-by: Masahiro Yamada >> --- >> >> Changes in v2: >> - Newly added >> >> scripts/kconfig/tests/inter_choice/Kconfig | 24 ++++++++++++++++++++++ >> scripts/kconfig/tests/inter_choice/__init__.py | 14 +++++++++++++ >> scripts/kconfig/tests/inter_choice/defconfig | 1 + >> scripts/kconfig/tests/inter_choice/expected_config | 4 ++++ >> 4 files changed, 43 insertions(+) >> create mode 100644 scripts/kconfig/tests/inter_choice/Kconfig >> create mode 100644 scripts/kconfig/tests/inter_choice/__init__.py >> create mode 100644 scripts/kconfig/tests/inter_choice/defconfig >> create mode 100644 scripts/kconfig/tests/inter_choice/expected_config >> >> diff --git a/scripts/kconfig/tests/inter_choice/Kconfig b/scripts/kconfig/tests/inter_choice/Kconfig >> new file mode 100644 >> index 0000000..57d55c4 >> --- /dev/null >> +++ b/scripts/kconfig/tests/inter_choice/Kconfig >> @@ -0,0 +1,24 @@ >> +config MODULES >> + bool "Enable loadable module support" >> + option modules >> + default y >> + >> +choice >> + prompt "Choice" >> + >> +config CHOICE_VAL0 >> + tristate "Choice 0" >> + >> +config CHOIVE_VAL1 >> + tristate "Choice 1" >> + >> +endchoice >> + >> +choice >> + prompt "Another choice" >> + depends on CHOICE_VAL0 >> + >> +config DUMMY >> + bool "dummy" >> + >> +endchoice >> diff --git a/scripts/kconfig/tests/inter_choice/__init__.py b/scripts/kconfig/tests/inter_choice/__init__.py >> new file mode 100644 >> index 0000000..5c7fc36 >> --- /dev/null >> +++ b/scripts/kconfig/tests/inter_choice/__init__.py >> @@ -0,0 +1,14 @@ >> +""" >> +Do not affect user-assigned choice value by another choice. >> + >> +Handling of state flags for choices is complecated. In old days, >> +the defconfig result of a choice could be affected by another choice >> +if those choices interact by 'depends on', 'select', etc. >> + >> +Related Linux commit: fbe98bb9ed3dae23e320c6b113e35f129538d14a >> +""" >> + >> + >> +def test(conf): >> + assert conf.defconfig('defconfig') == 0 >> + assert conf.config_contains('expected_config') >> diff --git a/scripts/kconfig/tests/inter_choice/defconfig b/scripts/kconfig/tests/inter_choice/defconfig >> new file mode 100644 >> index 0000000..162c414 >> --- /dev/null >> +++ b/scripts/kconfig/tests/inter_choice/defconfig >> @@ -0,0 +1 @@ >> +CONFIG_CHOICE_VAL0=y >> diff --git a/scripts/kconfig/tests/inter_choice/expected_config b/scripts/kconfig/tests/inter_choice/expected_config >> new file mode 100644 >> index 0000000..5dceefb >> --- /dev/null >> +++ b/scripts/kconfig/tests/inter_choice/expected_config >> @@ -0,0 +1,4 @@ >> +CONFIG_MODULES=y >> +CONFIG_CHOICE_VAL0=y >> +# CONFIG_CHOIVE_VAL1 is not set >> +CONFIG_DUMMY=y >> -- >> 2.7.4 >> > > Reviewed-by: Ulf Magnusson > > This reminded me of a bug I reported ages ago, which afaict hasn't > been fixed: https://lkml.org/lkml/2012/12/5/458 (in retrospect, > sym_clear_all_valid() is cheap). Fixed by fbe98bb9ed3dae23e320c6b113e35f129538d14a a.k.a v3.10-rc1-1-gfbe98bb The root cause is the same. > When manually patching all defconfig files in the kernel to disable > modules and running the Kconfiglib test suite, that bug triggers for a > few defconfigs. It has previously triggered for a few unpatched > defconfig files too -- see > https://github.com/ulfalizer/Kconfiglib#notes. > > I just add an extra sym_clear_all_valid() at the end of > conf_set_all_new_symbols() to fix it. It'd be worth checking if that > fixes this problem too. > > Cheers, > Ulf > -- > To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html -- Best Regards Masahiro Yamada