kconfig: test: add Kconfig macro language tests
Here are the test cases I used for developing the text expansion feature. Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
This commit is contained in:
parent
316d55d55f
commit
2bece88f89
27
scripts/kconfig/tests/preprocess/builtin_func/Kconfig
Normal file
27
scripts/kconfig/tests/preprocess/builtin_func/Kconfig
Normal file
|
@ -0,0 +1,27 @@
|
|||
# SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
# 'info' prints the argument to stdout.
|
||||
$(info,hello world 0)
|
||||
|
||||
# 'warning-if', if the first argument is y, sends the second argument to stderr,
|
||||
# and the message is prefixed with the current file name and line number.
|
||||
$(warning-if,y,hello world 1)
|
||||
|
||||
# 'error-if' is similar, but it terminates the parsing immediately.
|
||||
# The following is just no-op since the first argument is not y.
|
||||
$(error-if,n,this should not be printed)
|
||||
|
||||
# Shorthand
|
||||
warning = $(warning-if,y,$(1))
|
||||
|
||||
# 'shell' executes a command, and returns its stdout.
|
||||
$(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'))
|
||||
|
||||
# 'filename' is expanded to the currently parsed file name,
|
||||
# 'lineno' to the line number.
|
||||
$(warning,filename=$(filename))
|
||||
$(warning,lineno=$(lineno))
|
|
@ -0,0 +1,9 @@
|
|||
# SPDX-License-Identifier: GPL-2.0
|
||||
"""
|
||||
Built-in function tests.
|
||||
"""
|
||||
|
||||
def test(conf):
|
||||
assert conf.oldaskconfig() == 0
|
||||
assert conf.stdout_contains('expected_stdout')
|
||||
assert conf.stderr_matches('expected_stderr')
|
|
@ -0,0 +1,5 @@
|
|||
Kconfig:8: hello world 1
|
||||
Kconfig:18: hello world 3
|
||||
Kconfig:22: hello world 4
|
||||
Kconfig:26: filename=Kconfig
|
||||
Kconfig:27: lineno=27
|
|
@ -0,0 +1 @@
|
|||
hello world 0
|
|
@ -0,0 +1,5 @@
|
|||
# SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
X = $(Y)
|
||||
Y = $(X)
|
||||
$(info $(X))
|
|
@ -0,0 +1,11 @@
|
|||
# SPDX-License-Identifier: GPL-2.0
|
||||
"""
|
||||
Detect circular variable expansion.
|
||||
|
||||
If a recursively expanded variable references itself (eventually),
|
||||
it should fail with an error message.
|
||||
"""
|
||||
|
||||
def test(conf):
|
||||
assert conf.oldaskconfig() != 0
|
||||
assert conf.stderr_matches('expected_stderr')
|
|
@ -0,0 +1 @@
|
|||
Kconfig:5: Recursive variable 'X' references itself (eventually)
|
44
scripts/kconfig/tests/preprocess/escape/Kconfig
Normal file
44
scripts/kconfig/tests/preprocess/escape/Kconfig
Normal file
|
@ -0,0 +1,44 @@
|
|||
# SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
# Shorthand
|
||||
warning = $(warning-if,y,$(1))
|
||||
|
||||
# You can not pass commas directly to a function since they are treated as
|
||||
# delimiters. You can use the following trick to do so.
|
||||
comma := ,
|
||||
$(warning,hello$(comma) world)
|
||||
|
||||
# Like Make, single quotes, double quotes, spaces are treated verbatim.
|
||||
# The following prints the text as-is.
|
||||
$(warning, ' " '" ' ''' "'")
|
||||
|
||||
# Unlike Make, '$' has special meaning only when it is followed by '('.
|
||||
# No need to escape '$' itself.
|
||||
$(warning,$)
|
||||
$(warning,$$)
|
||||
$ := 1
|
||||
$(warning,$($))
|
||||
|
||||
# You need a trick to escape '$' followed by '('
|
||||
# The following should print "$(X)". It should not be expanded further.
|
||||
dollar := $
|
||||
$(warning,$(dollar)(X))
|
||||
|
||||
# You need a trick to treat unbalanced parentheses.
|
||||
# The following should print "(".
|
||||
left_paren := (
|
||||
$(warning,$(left_paren))
|
||||
|
||||
# A simple expanded should not be expanded multiple times.
|
||||
# The following should print "$(X)". It should not be expanded further.
|
||||
Y := $(dollar)(X)
|
||||
$(warning,$(Y))
|
||||
|
||||
# The following should print "$(X)" as well.
|
||||
Y = $(dollar)(X)
|
||||
$(warning,$(Y))
|
||||
|
||||
# The following should print "$(".
|
||||
# It should not be emit "unterminated reference" error.
|
||||
unterminated := $(dollar)(
|
||||
$(warning,$(unterminated))
|
8
scripts/kconfig/tests/preprocess/escape/__init__.py
Normal file
8
scripts/kconfig/tests/preprocess/escape/__init__.py
Normal file
|
@ -0,0 +1,8 @@
|
|||
# SPDX-License-Identifier: GPL-2.0
|
||||
"""
|
||||
Escape sequence tests.
|
||||
"""
|
||||
|
||||
def test(conf):
|
||||
assert conf.oldaskconfig() == 0
|
||||
assert conf.stderr_matches('expected_stderr')
|
10
scripts/kconfig/tests/preprocess/escape/expected_stderr
Normal file
10
scripts/kconfig/tests/preprocess/escape/expected_stderr
Normal file
|
@ -0,0 +1,10 @@
|
|||
Kconfig:9: hello, world
|
||||
Kconfig:13: ' " '" ' ''' "'"
|
||||
Kconfig:17: $
|
||||
Kconfig:18: $$
|
||||
Kconfig:20: 1
|
||||
Kconfig:25: $(X)
|
||||
Kconfig:30: (
|
||||
Kconfig:35: $(X)
|
||||
Kconfig:39: $(X)
|
||||
Kconfig:44: $(
|
53
scripts/kconfig/tests/preprocess/variable/Kconfig
Normal file
53
scripts/kconfig/tests/preprocess/variable/Kconfig
Normal file
|
@ -0,0 +1,53 @@
|
|||
# SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
# Shorthand
|
||||
warning = $(warning-if,y,$(1))
|
||||
|
||||
# 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))
|
||||
|
||||
# User-defined function.
|
||||
greeting = $(1), my name is $(2).
|
||||
$(warning,$(greeting,Hello,John))
|
||||
|
||||
# The number of arguments is not checked for user-defined functions.
|
||||
# If some arguments are optional, it is useful to pass fewer parameters.
|
||||
# $(2) will be blank in this case.
|
||||
$(warning,$(greeting,Hello))
|
||||
|
||||
# Unreferenced parameters are just ignored.
|
||||
$(warning,$(greeting,Hello,John,ignored,ignored))
|
8
scripts/kconfig/tests/preprocess/variable/__init__.py
Normal file
8
scripts/kconfig/tests/preprocess/variable/__init__.py
Normal file
|
@ -0,0 +1,8 @@
|
|||
# SPDX-License-Identifier: GPL-2.0
|
||||
"""
|
||||
Variable and user-defined function tests.
|
||||
"""
|
||||
|
||||
def test(conf):
|
||||
assert conf.oldaskconfig() == 0
|
||||
assert conf.stderr_matches('expected_stderr')
|
|
@ -0,0 +1,9 @@
|
|||
Kconfig:10: SIMPLE = 1
|
||||
Kconfig:16: RECURSIVE = 2
|
||||
Kconfig:22: SIMPLE = 1 3
|
||||
Kconfig:28: RECURSIVE = 2 4
|
||||
Kconfig:35: UNDEFINED_VARIABLE = 4
|
||||
Kconfig:41: AB = 5
|
||||
Kconfig:45: Hello, my name is John.
|
||||
Kconfig:50: Hello, my name is .
|
||||
Kconfig:53: Hello, my name is John.
|
Loading…
Reference in a new issue