From patchwork Fri Mar 2 04:31:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 130463 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp858886lja; Thu, 1 Mar 2018 20:36:57 -0800 (PST) X-Google-Smtp-Source: AG47ELuvk9nE0fxaYClKF/Oo3Yfz57owsadOJVxZrCUH10KvgGhzYcMG8nzpZxzWhLKlEnA+19uT X-Received: by 2002:a17:902:1486:: with SMTP id k6-v6mr4215392pla.376.1519965417150; Thu, 01 Mar 2018 20:36:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519965417; cv=none; d=google.com; s=arc-20160816; b=0egrcgSZDZ4rZYOlxevMdcS2RoUVjI7Lkt9nf/MMsDmrv5ppNoCeSSS5o4sdsITH5C xrhByTJMvQht2U+WjEfX+ilVCBXDc7hHsYQkF6bl8q0McHlAWiLpAMM8F5r3ACrIURPx mijeVT1hnjZuhR4L05bZVR1voGxSf7V9SKJUGREkz/WDzN4NyPKhtIMwKPhG6rlo/tre i2oRosGpIbwodWOyuX8zy8SYMIYyxgLPnRHClykKq30RUUX2g9fqezbJCzNev/+qXmQ7 3mQRrIV7u13y/MK5/YrfnmAPy11HyQd7q6NCCn1yy1qhIclDgE5c4heKWxi9R+TOSvx3 WeyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter :arc-authentication-results; bh=3XisxRvHTbi0hGrJpl0Mw57UQMYPCqtZhDqgSx/2BTc=; b=iHZwYVL9XpZpkKmCQVhSMHdEGkmuGTFstEKmRvXo6211FdV2zSAp/utCqXv9Fk29R9 M8Qf9QAUDoT7aqmjPikHDkOUgnsNtrf3+54VbpYyDdU2rZ0BHXQJvpqtxopBCQDkhC/3 rqeQt8u3q/iQP8bJ1hrd6hc6lYCjCEWn1H1NPf2wuwWB6YtXGR7gQ7PPMaNuXpxHtQ5b fTzW7Ujn/TCLhfoQ6PYbq0MOYfbaHlWPrK27aIXc5MlRXjl9hh5yv6XOjdUiBnhXCpWi jooZbo+2i301iqEaz52ENPhNsWeh4QHj9zx7DS0kNb1MxFyDuLw78EDSuEYuo5mfkAS6 5TSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=AjRoeyuT; 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 y38-v6si4199690plh.448.2018.03.01.20.36.56; Thu, 01 Mar 2018 20:36:57 -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=AjRoeyuT; 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 S1422757AbeCBEgY (ORCPT + 28 others); Thu, 1 Mar 2018 23:36:24 -0500 Received: from conuserg-08.nifty.com ([210.131.2.75]:53163 "EHLO conuserg-08.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1164987AbeCBEdr (ORCPT ); Thu, 1 Mar 2018 23:33:47 -0500 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-08.nifty.com with ESMTP id w224WURJ022085; Fri, 2 Mar 2018 13:32:37 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-08.nifty.com w224WURJ022085 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1519965157; bh=3XisxRvHTbi0hGrJpl0Mw57UQMYPCqtZhDqgSx/2BTc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AjRoeyuTuwGcs2uejyOGDmxGMXzDPzfIK0WZ/aspThM5FOF4Ygdn+XGhcoVT99ml4 1aT+VL/O0Gl3U61uwgpTuUxDAoRr92Xyh7b+nn5E0434W8/SffW2SWw33RCfvWCYzL EVBsrcfg0X/sK8APvsUEk7Ii8TesDG0UbuR1ms0kdlM1oRB4Hy7ekw2yXnyjy3QiGy 0PryKky3d6JYxVMRG2VE0yhgVQUJxlJfQu91nzMvnxHs/hUBdSBwgMAcaYVo8uh+OM mLabiyUUdViQ+aWwUjnoOJPI2pATTRMfLGGIaUe4Q8mQQdiT9mV1+EHmEX7rMp13jq ljffhZYQdqz+g== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Sam Ravnborg , Michal Marek , Ulf Magnusson , Randy Dunlap , "Luis R . Rodriguez" , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH v2 08/11] kconfig: unittest: test defconfig when two choices interact Date: Fri, 2 Mar 2018 13:31:58 +0900 Message-Id: <1519965121-12017-9-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519965121-12017-1-git-send-email-yamada.masahiro@socionext.com> References: <1519965121-12017-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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) 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. 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 -- 2.7.4 Reviewed-by: Ulf Magnusson 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