From patchwork Fri Apr 13 05:06:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 133339 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp348324ljb; Thu, 12 Apr 2018 22:14:48 -0700 (PDT) X-Google-Smtp-Source: AIpwx48WkPiBmd8RRoMpCJJgR2CKTfS4Z282CyOTiuEkrb1pYJd8gSgrkCBzrny5i7qzNgsFiCx4 X-Received: by 10.99.112.91 with SMTP id a27mr2927435pgn.432.1523596488775; Thu, 12 Apr 2018 22:14:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523596488; cv=none; d=google.com; s=arc-20160816; b=MjQNUV8CSBiYT+EdJtYSXelUG1P6MySg857oVFPwYEoLiT2LO+x4jD1Wz75iuxtuSa CKgokyHHEXHuU8t8EJlupHMWUMRn4h9bOuhztFnZMfurQPvAusNFYDMOO9a7c81qAbxQ w878ApQKhe31aalkCNpu5kqoNZDwULolPRv026WKo1Ai/F2EmW5v1um1UrVnkJEw017n UlG5Io2Aj7fOwERjUY7I3GzrDhQl60uHAizdMttDPQq3sMZA/nLhw3xtMqplbJYpNN0e rqPBbpzcW6qUtIaovZM8HdPocLFlxopdts71btvNQUax8rf5oTdM8FIRgREelguovDAZ xLGA== 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=e7wUXuL5SzADNiL+yJaCSwzOhck6xulndTS6lyNvdms=; b=XXk4CQnohwRFaelxVUhjGRSjPEzSI+flZXx56Pwo135BSdz0h3h2AVZqIWHRWburIr IX32OVe/8KSMAaHyY8WZiFVgwgkQopBb3YNEVDrIuu905CAbDZezmQVyicAuTdmHVBLT I/B/jPdtd+HYFTJAasgdCi/CfVmtQKVn3KvRReZiQh/YTzqxubrFEhEjSsyS1my9nJVG HVD5luxFp4pPAzG8Yj2MXngAstS+zzu9AlMOTil/nApaF+0G0AgC9F8PrrHgvYrmHqnb wqIoObIOSEmpQe7KYWF1kFK2CyxQrAHK8ZSKSCIWx/Ryu7AqPwy3pTKz9C9663UZnV0r /1ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=Ek+DgHzx; 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 a64si3285839pgc.265.2018.04.12.22.14.48; Thu, 12 Apr 2018 22:14:48 -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=Ek+DgHzx; 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 S1753927AbeDMFOp (ORCPT + 29 others); Fri, 13 Apr 2018 01:14:45 -0400 Received: from conuserg-07.nifty.com ([210.131.2.74]:54470 "EHLO conuserg-07.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750989AbeDMFIP (ORCPT ); Fri, 13 Apr 2018 01:08:15 -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 w3D56lgC029209; Fri, 13 Apr 2018 14:07:04 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com w3D56lgC029209 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1523596024; bh=e7wUXuL5SzADNiL+yJaCSwzOhck6xulndTS6lyNvdms=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ek+DgHzxt6kTe8MzhlTUV07vfxFe9LKLx9RR158cJ1UqPG2jqBqyuMMaTvRGk09rg 3o+woO+7ZJcsyKY58o8qvwSSE3Jzd7qObOwcd21X5Fsw/EN2eJ+G5WxOdFlbcA+vzf ZbKUSggttccDTsYad4/0rLLQ8BYg5szlh/wQOmcpDgtz3puyHiyMI+LmVbhZx4jKpq PbQa99VWaKZgdE3rAMDPRn77Gxln3b1nU5SwDk9EzIe74wUPgKP4WeGKR9gvG2AxNX rMm/F53QxPQR1hUksd7qrNd51AsUJlyTjIgCO71dJl9e27TARvAp7mZi9H+qlkYJg1 y24o+N3jt0d6g== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Linus Torvalds , Sam Ravnborg , Ulf Magnusson , Nicholas Piggin , Kees Cook , Emese Revfy , x86@kernel.org, Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH 18/30] kconfig: test: test text expansion Date: Fri, 13 Apr 2018 14:06:27 +0900 Message-Id: <1523595999-27433-19-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1523595999-27433-1-git-send-email-yamada.masahiro@socionext.com> References: <1523595999-27433-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 Here are the test cases I used for developing the text expansion feature. I implemented a similar language as you see in Make. The implementation is different (the source code in GNU Make is much longer, so I did not want to pull it in), but the behavior is hopefully almost the same. I intentionally changed some behavior and syntax, but I tried to stick to the make-like behavior where possible. It might be interesting to compare the behavior between Make and Kconfig. [1] Variable test You can directly run scripts/kconfig/tests/preprocess/variable/Kconfig by make. Make and Kconfig produce the exactly the same output for the variable test. The output from Make: $ cd scripts/kconfig/tests/preprocess/variable && make -f Kconfig Kconfig:5: SIMPLE = 1 Kconfig:11: RECURSIVE = 2 Kconfig:17: SIMPLE = 1 3 Kconfig:23: RECURSIVE = 2 4 Kconfig:30: UNDEFINED_VARIABLE = 4 Kconfig:36: AB = 5 Kconfig:39: X = A make: *** No targets. Stop. [2] Built-in function test The output from Make: $ cd scripts/kconfig/tests/preprocess/builtin_func && make -f Kconfig hello,world 0 Kconfig:7: hello,world 1 Kconfig:11: hello, world 2 Kconfig:15: hello,world 3 Kconfig:19: hello, world 4 make: *** No targets. Stop. The output from "$(warning hello, world 2)" is different. "Kconfig:11: hello, world 2" vs "Kconfig:11: hello, world 2" Make strips all leading spaces from the first argument, but does not touch the other arguments. I thought this was inconsistent. So, I changed the behavior to not touch any arguments at all. [3] User-defined function test I changed the syntax for calling a user-defined function. In Make, it is invoked by using the 'call' built-in function as in $(call greeting,Hello,John) but in Kconfig it is invoked without 'call' as in $(greeting Hello,John). Except the syntax difference, the test case works exactly in the same way for Make and Kconfig. [4] Escape sequence test Except the syntax of user-defined function, Make and Kconfig work in the same way. The behavior of a standalone '$' is different among Make versions. By fixing the user-defined function syntax, Make 4.1 or older works like this: Kconfig:5: arg0= arg1= Kconfig:9: arg0=, arg1=, Kconfig:13: ' " '" ' ''' "'" Kconfig:16: $ Kconfig:20: $X Kconfig:26: nasty Kconfig:32: super_nasty Kconfig:41: Kconfig:46: X Kconfig:49: make: *** No targets. Stop. Make 4.2 or newer is like this: Kconfig:5: arg0= arg1= Kconfig:9: arg0=, arg1=, Kconfig:13: ' " '" ' ''' "'" Kconfig:16: $ Kconfig:20: $X Kconfig:26: nasty Kconfig:32: super_nasty Kconfig:41: $ Kconfig:46: $X Kconfig:49: nasty make: *** No targets. Stop. The last three lines are different. I adopted the behavior of the newer Make versions. Of course, you should not write such code. Signed-off-by: Masahiro Yamada --- Changes in v3: None Changes in v2: None .../kconfig/tests/preprocess/builtin_func/Kconfig | 19 +++++++++ .../tests/preprocess/builtin_func/__init__.py | 8 ++++ .../tests/preprocess/builtin_func/expected_stderr | 4 ++ .../tests/preprocess/builtin_func/expected_stdout | 1 + scripts/kconfig/tests/preprocess/escape/Kconfig | 49 ++++++++++++++++++++++ .../kconfig/tests/preprocess/escape/__init__.py | 9 ++++ .../tests/preprocess/escape/expected_stderr | 10 +++++ scripts/kconfig/tests/preprocess/user_func/Kconfig | 19 +++++++++ .../kconfig/tests/preprocess/user_func/__init__.py | 7 ++++ .../tests/preprocess/user_func/expected_stderr | 5 +++ scripts/kconfig/tests/preprocess/variable/Kconfig | 39 +++++++++++++++++ .../kconfig/tests/preprocess/variable/__init__.py | 7 ++++ .../tests/preprocess/variable/expected_stderr | 7 ++++ 13 files changed, 184 insertions(+) create mode 100644 scripts/kconfig/tests/preprocess/builtin_func/Kconfig create mode 100644 scripts/kconfig/tests/preprocess/builtin_func/__init__.py create mode 100644 scripts/kconfig/tests/preprocess/builtin_func/expected_stderr create mode 100644 scripts/kconfig/tests/preprocess/builtin_func/expected_stdout create mode 100644 scripts/kconfig/tests/preprocess/escape/Kconfig create mode 100644 scripts/kconfig/tests/preprocess/escape/__init__.py create mode 100644 scripts/kconfig/tests/preprocess/escape/expected_stderr create mode 100644 scripts/kconfig/tests/preprocess/user_func/Kconfig create mode 100644 scripts/kconfig/tests/preprocess/user_func/__init__.py create mode 100644 scripts/kconfig/tests/preprocess/user_func/expected_stderr create mode 100644 scripts/kconfig/tests/preprocess/variable/Kconfig create mode 100644 scripts/kconfig/tests/preprocess/variable/__init__.py create mode 100644 scripts/kconfig/tests/preprocess/variable/expected_stderr -- 2.7.4 diff --git a/scripts/kconfig/tests/preprocess/builtin_func/Kconfig b/scripts/kconfig/tests/preprocess/builtin_func/Kconfig new file mode 100644 index 0000000..5dc454e --- /dev/null +++ b/scripts/kconfig/tests/preprocess/builtin_func/Kconfig @@ -0,0 +1,19 @@ +# 'info' prints the argument to stdout. +# commas are treated verbatim instead of as argument separaters. +$(info hello,world 0) + +# 'warning' is similar, but it sends its argument to stderr, +# and the message is prefixed with the current file name and line number. +$(warning hello,world 1) + +# leading spaces of the first argument are preserved except +# the one right after the function name. (This is different from Make) +$(warning hello, world 2) + +# 'shell' executes a command, and returns its stdout. +# commas are treated verbatim instead of as argument separaters. +$(warning $(shell echo hello,world 3)) + +# Every newline in the output is replaced with a space, +# but any trailing newlines are deleted. +$(warning $(shell printf 'hello,\nworld\n\n4\n\n\n')) diff --git a/scripts/kconfig/tests/preprocess/builtin_func/__init__.py b/scripts/kconfig/tests/preprocess/builtin_func/__init__.py new file mode 100644 index 0000000..ec7c3e2 --- /dev/null +++ b/scripts/kconfig/tests/preprocess/builtin_func/__init__.py @@ -0,0 +1,8 @@ +""" +Built-in function tests. +""" + +def test(conf): + assert conf.oldaskconfig() == 0 + assert conf.stdout_contains('expected_stdout') + assert conf.stderr_matches('expected_stderr') diff --git a/scripts/kconfig/tests/preprocess/builtin_func/expected_stderr b/scripts/kconfig/tests/preprocess/builtin_func/expected_stderr new file mode 100644 index 0000000..b6c046e --- /dev/null +++ b/scripts/kconfig/tests/preprocess/builtin_func/expected_stderr @@ -0,0 +1,4 @@ +Kconfig:7: hello,world 1 +Kconfig:11: hello, world 2 +Kconfig:15: hello,world 3 +Kconfig:19: hello, world 4 diff --git a/scripts/kconfig/tests/preprocess/builtin_func/expected_stdout b/scripts/kconfig/tests/preprocess/builtin_func/expected_stdout new file mode 100644 index 0000000..036c34a --- /dev/null +++ b/scripts/kconfig/tests/preprocess/builtin_func/expected_stdout @@ -0,0 +1 @@ +hello,world 0 diff --git a/scripts/kconfig/tests/preprocess/escape/Kconfig b/scripts/kconfig/tests/preprocess/escape/Kconfig new file mode 100644 index 0000000..b99dfa2 --- /dev/null +++ b/scripts/kconfig/tests/preprocess/escape/Kconfig @@ -0,0 +1,49 @@ +foo = arg0=$1 arg1=$2 + +# You can not pass a comma directly as a argument since it is treated as an +# argument separator. In the following, $1 and $2 will be given a null string. +$(warning $(foo ,)) + +# Assign ',' to a variable, then use it if you want to pass in commas +comma := , +$(warning $(foo $(comma),$(comma))) + +# Like Make, single quotes, double quotes, spaces are treated verbatim. +# The following prints the text as-is. +$(warning ' " '" ' ''' "'") + +# You can use '$$' to escape '$' itself +$(warning $$) + +# The escaped '$' loses its special meaning. The following should print '$X'. +# Do not expand '$X' even further. +$(warning $$X) + +# In Make, a variable name can contain almost any characters. The only +# disallowed characters are : # and = +# '$' can be used as a variable name in Kconfig, although it is nasty +$$ = nasty +$(warning $($$)) + +# Even a space can be a variable name by using the following trick. +empty := +space := $(empty) $(empty) +$(space) = super_nasty +$(warning $($(space))) + +# The behavior of a standalone '$' at the end of a token is undefined. +# It is evaluated to an empty string in Make 4.1 or older, while +# to '$' as-is in Make 4.2 or newer. Kconfig follows the behavior of +# the newer Make version, but it is not important. + +# In the implementation of Kconfig, a standalone '$' at the end of a token +# is treated as-is. So, the following also prints '$' +$(warning $) + +# Likewise, a standalone '$' before a comma loses its special meaning. +# The following prints '$X'. Do not expand '$X' even further. +bar = $1$2 +$(warning $(bar $,X)) + +# The following prints the value of the variable '$'. +$(warning $($)) diff --git a/scripts/kconfig/tests/preprocess/escape/__init__.py b/scripts/kconfig/tests/preprocess/escape/__init__.py new file mode 100644 index 0000000..841a754 --- /dev/null +++ b/scripts/kconfig/tests/preprocess/escape/__init__.py @@ -0,0 +1,9 @@ +""" +Escape sequence tests. + +Test tricky cases related to escaping. +""" + +def test(conf): + assert conf.oldaskconfig() == 0 + assert conf.stderr_matches('expected_stderr') diff --git a/scripts/kconfig/tests/preprocess/escape/expected_stderr b/scripts/kconfig/tests/preprocess/escape/expected_stderr new file mode 100644 index 0000000..81df7e5 --- /dev/null +++ b/scripts/kconfig/tests/preprocess/escape/expected_stderr @@ -0,0 +1,10 @@ +Kconfig:5: arg0= arg1= +Kconfig:9: arg0=, arg1=, +Kconfig:13: ' " '" ' ''' "'" +Kconfig:16: $ +Kconfig:20: $X +Kconfig:26: nasty +Kconfig:32: super_nasty +Kconfig:41: $ +Kconfig:46: $X +Kconfig:49: nasty diff --git a/scripts/kconfig/tests/preprocess/user_func/Kconfig b/scripts/kconfig/tests/preprocess/user_func/Kconfig new file mode 100644 index 0000000..9d248ca --- /dev/null +++ b/scripts/kconfig/tests/preprocess/user_func/Kconfig @@ -0,0 +1,19 @@ +greeting = $(1), my name is $(2). +$(warning $(greeting Hello,John)) + +# It is allowed to pass more arguments than referenced. +# Unreferenced parameters are just ignored. +$(warning $(greeting Hello,John,ignored,ignored)) + +# It is also allowed to give fewer arguments. $(2) will be blank in this case. +$(warning $(greeting Hello)) + +# Passing zero argument is OK. In fact, a user-defined function +# is handle in the same way as a recursively expanded variable +$(warning $(greeting)) + +# However, if 1, 2 are defined as a global scope variable, +# user-defined function will use them where arguments are missing +1 = Hi +2 = Tom +$(warning $(greeting)) diff --git a/scripts/kconfig/tests/preprocess/user_func/__init__.py b/scripts/kconfig/tests/preprocess/user_func/__init__.py new file mode 100644 index 0000000..8da60f6 --- /dev/null +++ b/scripts/kconfig/tests/preprocess/user_func/__init__.py @@ -0,0 +1,7 @@ +""" +User-defined function tests. +""" + +def test(conf): + assert conf.oldaskconfig() == 0 + assert conf.stderr_matches('expected_stderr') diff --git a/scripts/kconfig/tests/preprocess/user_func/expected_stderr b/scripts/kconfig/tests/preprocess/user_func/expected_stderr new file mode 100644 index 0000000..1dd6684 --- /dev/null +++ b/scripts/kconfig/tests/preprocess/user_func/expected_stderr @@ -0,0 +1,5 @@ +Kconfig:2: Hello, my name is John. +Kconfig:6: Hello, my name is John. +Kconfig:9: Hello, my name is . +Kconfig:13: , my name is . +Kconfig:19: Hi, my name is Tom. diff --git a/scripts/kconfig/tests/preprocess/variable/Kconfig b/scripts/kconfig/tests/preprocess/variable/Kconfig new file mode 100644 index 0000000..df4446b --- /dev/null +++ b/scripts/kconfig/tests/preprocess/variable/Kconfig @@ -0,0 +1,39 @@ +# Simply expanded variable. +X := 1 +SIMPLE := $(X) +X := 2 +$(warning SIMPLE = $(SIMPLE)) + +# Recursively expanded variable. +X := 1 +RECURSIVE = $(X) +X := 2 +$(warning RECURSIVE = $(RECURSIVE)) + +# Append something to a simply expanded variable. +Y := 3 +SIMPLE += $(Y) +Y := 4 +$(warning SIMPLE = $(SIMPLE)) + +# Append something to a recursively expanded variable. +Y := 3 +RECURSIVE += $(Y) +Y := 4 +$(warning RECURSIVE = $(RECURSIVE)) + +# Use += operator to an undefined variable. +# This works as a recursively expanded variable. +Y := 3 +UNDEFINED_VARIABLE += $(Y) +Y := 4 +$(warning UNDEFINED_VARIABLE = $(UNDEFINED_VARIABLE)) + +# You can use variable references for the lefthand side of assignment statement. +X := A +Y := B +$(X)$(Y) := 5 +$(warning AB = $(AB)) + +# By the way, you can omit the parentheses for a single-letter variable +$(warning X = $X) diff --git a/scripts/kconfig/tests/preprocess/variable/__init__.py b/scripts/kconfig/tests/preprocess/variable/__init__.py new file mode 100644 index 0000000..e087698 --- /dev/null +++ b/scripts/kconfig/tests/preprocess/variable/__init__.py @@ -0,0 +1,7 @@ +""" +Variable tests. +""" + +def test(conf): + assert conf.oldaskconfig() == 0 + assert conf.stderr_matches('expected_stderr') diff --git a/scripts/kconfig/tests/preprocess/variable/expected_stderr b/scripts/kconfig/tests/preprocess/variable/expected_stderr new file mode 100644 index 0000000..61b06e1 --- /dev/null +++ b/scripts/kconfig/tests/preprocess/variable/expected_stderr @@ -0,0 +1,7 @@ +Kconfig:5: SIMPLE = 1 +Kconfig:11: RECURSIVE = 2 +Kconfig:17: SIMPLE = 1 3 +Kconfig:23: RECURSIVE = 2 4 +Kconfig:30: UNDEFINED_VARIABLE = 4 +Kconfig:36: AB = 5 +Kconfig:39: X = A