From patchwork Tue Mar 13 09:12:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 131419 Delivered-To: patch@linaro.org Received: by 10.46.84.17 with SMTP id i17csp484982ljb; Tue, 13 Mar 2018 02:16:41 -0700 (PDT) X-Google-Smtp-Source: AG47ELvCjMeBsvOhMxwk3vYlX09j6DxGN2gcLLIM9MKg7RtJjcZPy3FwETXpwS92ZnBnVQnMfuBE X-Received: by 10.99.158.9 with SMTP id s9mr859185pgd.64.1520932601393; Tue, 13 Mar 2018 02:16:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520932601; cv=none; d=google.com; s=arc-20160816; b=IRGlYRQ3je0q4Z8D5W0DRKGC2S4UE5mjENrXwZRdjSRvBC+K302DZN7ottfh20uJXa YZ8wQYkAWHagOqzH3X7c0zTlv9BH28A9Bu+VtQIDK4pXLOlObJo07642H2Tmke4Tn6dj vYTn69mmReTn7qTChU9TevP92aogBzjjmwgWzs13rTtAplAGjQXoJVRSEBxMw2FKnsfo MwSvrF4hjt1DHWMduJRrVf09gnl6ljxuePeHnY1b2VpAy5qscB865AKycW0fuM/cMbjf leMMdxWHhM8qB3XdF+C8O9NpejkzxFJhp4NOMEiAfD2OnaI1Cu4tJREyrcl6k+3POft4 K+8w== 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=2vORxESz0zbS14YMrcdfprrqUkp3JAvmRF89Udr0tmE=; b=KOorM7qIP4VodAStrZocvba8oS3JxA/HUtnKoLp4nrMCCh7JmqxeZUDWnUBPEsyson Q3MnjZFyUhT7sz7yADmMZVqiskzM7AgZ9x1OPOJUmPdNGFq6eJ295eI294RGWcrKSpQ0 lVxcUPQfSR/zpCh5a6oYFar6ErpDE/u0CAVft+Ha6pBj3uhAATM2PBZxvRLYznOYZIGG HGHfEoNY14ngS8JHuRABZeCHyZX+c1aJsDpAW5MCJsrJw+iixmo/U20ZxF2gW/Blhp+F XU/b1nRLyOUsFRNymlFWwS0UTqXPvGpqE/Jvm9maRMAjnz4mh+ZBksEmKWVKkVfQxIBJ 8GrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=ZlqxY9bG; 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 g13si2097627pgr.471.2018.03.13.02.16.41; Tue, 13 Mar 2018 02:16:41 -0700 (PDT) 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=ZlqxY9bG; 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 S1752673AbeCMJQi (ORCPT + 28 others); Tue, 13 Mar 2018 05:16:38 -0400 Received: from conuserg-07.nifty.com ([210.131.2.74]:41802 "EHLO conuserg-07.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752484AbeCMJOB (ORCPT ); Tue, 13 Mar 2018 05:14:01 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-07.nifty.com with ESMTP id w2D9CIo9016505; Tue, 13 Mar 2018 18:12:25 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com w2D9CIo9016505 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1520932345; bh=2vORxESz0zbS14YMrcdfprrqUkp3JAvmRF89Udr0tmE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZlqxY9bG92KmmVHpP5ynXaOa+LGA69Bu7P2gUYH+P8Bqqi3jimylrtFyytjCiUx37 8Hx6IQ4myTPBBe2cvTjAFTpCXGL1jEZ4YXygli7Nei6F03Dsn05PanniorSqAMd8y7 4gCJFAjslqbxJLekCr/s/9AIXwENP2dGhMvQ/J06y+D8g+nmpusyLmmZmMq0otvffJ VdA9YkDgMUtoFYY4/JHQ2RnKwkj9OD5UQ/6AUrYdlrEtDfrN+doCgH0Vxznm3DPaLR uj5gpH6bz5CrTtt6fxKCxtlPKRotburhE4pD6gpR6amta8EQLo9tWRN1PDbRkEeLPj z/uS4ynRp683Q== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Sam Ravnborg , Ulf Magnusson , Randy Dunlap , "Luis R . Rodriguez" , Tony Luck , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH v3 08/11] kconfig: tests: test defconfig when two choices interact Date: Tue, 13 Mar 2018 18:12:09 +0900 Message-Id: <1520932332-2449-9-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1520932332-2449-1-git-send-email-yamada.masahiro@socionext.com> References: <1520932332-2449-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 def_bool y option modules 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. Here, the SYMBOL_DEF_USER for the first choice has been forgotten, so it is evaluated to 'm'. 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-calculated, then the first choice would be indirectly re-calculated with the SYMBOL_DEF_USER which has been recalled by set_all_choice_values(), which would be evaluated to 'y'. But, in this case, CHOICE_VAL0 has already been marked as SYMBOL_VALID, so this re-calculation does not happen. Then, =m from the conf_set_all_new_symbols() phase is written out to the .config file. Add a unit test for this naive case. Signed-off-by: Masahiro Yamada Reviewed-by: Ulf Magnusson --- Changes in v3: - Use def_bool for MODULES Changes in v2: - Newly added scripts/kconfig/tests/inter_choice/Kconfig | 23 ++++++++++++++++++++++ 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, 42 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 diff --git a/scripts/kconfig/tests/inter_choice/Kconfig b/scripts/kconfig/tests/inter_choice/Kconfig new file mode 100644 index 0000000..e44449f --- /dev/null +++ b/scripts/kconfig/tests/inter_choice/Kconfig @@ -0,0 +1,23 @@ +config MODULES + def_bool y + option modules + +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