forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]>
- Loading branch information
Showing
13 changed files
with
191 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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') |
5 changes: 5 additions & 0 deletions
5
scripts/kconfig/tests/preprocess/builtin_func/expected_stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
hello world 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# SPDX-License-Identifier: GPL-2.0 | ||
|
||
X = $(Y) | ||
Y = $(X) | ||
$(info $(X)) |
11 changes: 11 additions & 0 deletions
11
scripts/kconfig/tests/preprocess/circular_expansion/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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') |
1 change: 1 addition & 0 deletions
1
scripts/kconfig/tests/preprocess/circular_expansion/expected_stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Kconfig:5: Recursive variable 'X' references itself (eventually) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: $( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |