Received: by 10.223.185.116 with SMTP id b49csp8900075wrg; Fri, 2 Mar 2018 09:49:30 -0800 (PST) X-Google-Smtp-Source: AG47ELvaRmu24dDjTlL5b1N8sm/PQH7i48jOBump5TJTQMb1MlFvmDZfhy0vbOE+xP4NwUrT4T7V X-Received: by 2002:a17:902:6504:: with SMTP id b4-v6mr5944847plk.451.1520012970690; Fri, 02 Mar 2018 09:49:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520012970; cv=none; d=google.com; s=arc-20160816; b=jO7a/udfzMnqNVf/dkEeUf3bV1KNPV4PORg9kqckZnOkwlBv0dSi3ocVJZyZ1KZR3G ePdCgxRn2+KfWFam3qEotSHY2hrtjltV8Mk0G1JAXboLU3g3k6geWA2QbNvra0O6Yfnh GqgAIyvJV2DtWEO4CqIGBy+x9T1bzVhdXbIUNogKErieYs1+3j/YPUjZwf0LUzthKsLl mh2N+t2+SJUm3tMbTR8tO8ciJnGOBlahuey0IAXVzYVlHeyxN/auBxezLQyEByP3BaMo 9DUztphLlGW9kbHjizX1GgNpDCT8dPn4iSljsleWELlEPCaJZnA1ivNqa/VmgCK2lnLa 7wag== 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 :arc-authentication-results; bh=rsp0prI4/bOliplvppIBEMQ7lvTXh01WM4pc3FAP118=; b=xj0rSh/snqs0RCbWJHrwFakKfECb72VMcoSySeqShwd6DtNpMNWHEJaFvR7MUdaE2m KQRV0tk60G2JtgFB4J/C+eDuNhKNSzaGx3+KYAsk5SSLZ2f+WiA886plB5QJlEpAG8wO ZUCqcSxOsl2AcUSfVmwicFRGWexp9/HvOdRPdyiFqQUo7AYg7wCRG+a0pzqDlYsymBLF iTx1FuhC8WNaA5uoF45E1XCD98SHTROxywqnrAlEAc6V9M1SAXQpSZShFbfGY79aiRBV c2aUGtBwZ5PoUuCUCLsVsd8K5J7+WtFz0D7enQd4LMOa0EFCrrnG01R6a1Nnq7fKfAL4 uzqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Sw+U0JlC; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t25si4294194pge.26.2018.03.02.09.49.15; Fri, 02 Mar 2018 09:49:30 -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=@gmail.com header.s=20161025 header.b=Sw+U0JlC; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1426489AbeCBKlZ (ORCPT + 99 others); Fri, 2 Mar 2018 05:41:25 -0500 Received: from mail-ua0-f193.google.com ([209.85.217.193]:36421 "EHLO mail-ua0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1424139AbeCBKlT (ORCPT ); Fri, 2 Mar 2018 05:41:19 -0500 Received: by mail-ua0-f193.google.com with SMTP id i15so5792571uak.3; Fri, 02 Mar 2018 02:41:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=rsp0prI4/bOliplvppIBEMQ7lvTXh01WM4pc3FAP118=; b=Sw+U0JlCmBMBI3oUBO4PB251IptAQMj+8ezwrJHC6lkYW+2CtufCtTn/wMzXIOjevK VEKjj0OAmcRgofMo63s9udljnqiR3FX4K023L1yOQn6M1ZWiqoPTERtZ9Diq4neY7jfO VxaNv1gpQ/syOlae/RU4bMJLDscjZU97J+cjhjHS8G2hl2cWvDxHddBq6dqJ3C4CV5hS cIKHWEeYLD7P5IehIARUKUpcoWnwEfAEW2zpdWr7akacUqzkYg8HuKkry7STOZpIQYjm qqn3oIK9MIlARzqJIJ/3RTdNjoL4+lnb6+3sVIRoyAXb7i0yoaxaT7+0+DMOP8eWc8zh QwXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=rsp0prI4/bOliplvppIBEMQ7lvTXh01WM4pc3FAP118=; b=ce++MGQO5CbPDwvA/ptqTIubZYMkdlx5oxTmszDSD1f8h7E9zkSARbWqeiqcgPpiTP Bcn2q5jM59p5w/Y6VVzHLyI7v7vABn1vc1TsNgIYrhBmzxcAwek4mgbE2Cx4S7prVdeN VR/MAnTjVgCRWVq1/++c80hhd9abzrQKDK6xwK9sjPCngEkJSsrVACuCgWaKjUZIo1vY CovDn5KxALQM3eMIKya7clpljKqjx/ItEopR2jCzWtBR+COQK8ZEQJxDiUO5kYJ1pxpT 87YHV0Sr0xYfGqSnKJsf2bG3mb7k7uDNIB/ODoPEAM3QxgkhrTfDTl7qUjTAjFamU9u3 sbqA== X-Gm-Message-State: AElRT7GqTzEY5iIF2Bz0DVwG8WH0Q4ZHaIuoV8Sx46SVBAcyPetH594A N0gCeur/sUihHrLeuLdGu0BBSuJEjFI1OYcG+Cg= X-Received: by 10.176.21.46 with SMTP id o43mr3733640uae.78.1519987278218; Fri, 02 Mar 2018 02:41:18 -0800 (PST) MIME-Version: 1.0 Received: by 10.103.220.145 with HTTP; Fri, 2 Mar 2018 02:41:17 -0800 (PST) In-Reply-To: <1519965121-12017-9-git-send-email-yamada.masahiro@socionext.com> References: <1519965121-12017-1-git-send-email-yamada.masahiro@socionext.com> <1519965121-12017-9-git-send-email-yamada.masahiro@socionext.com> From: Ulf Magnusson Date: Fri, 2 Mar 2018 11:41:17 +0100 Message-ID: Subject: Re: [PATCH v2 08/11] kconfig: unittest: test defconfig when two choices interact To: Masahiro Yamada 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 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()). > 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. > > 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). 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