aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--scripts/kconfig/tests/preprocess/builtin_func/Kconfig27
-rw-r--r--scripts/kconfig/tests/preprocess/builtin_func/__init__.py9
-rw-r--r--scripts/kconfig/tests/preprocess/builtin_func/expected_stderr5
-rw-r--r--scripts/kconfig/tests/preprocess/builtin_func/expected_stdout1
-rw-r--r--scripts/kconfig/tests/preprocess/circular_expansion/Kconfig5
-rw-r--r--scripts/kconfig/tests/preprocess/circular_expansion/__init__.py11
-rw-r--r--scripts/kconfig/tests/preprocess/circular_expansion/expected_stderr1
-rw-r--r--scripts/kconfig/tests/preprocess/escape/Kconfig44
-rw-r--r--scripts/kconfig/tests/preprocess/escape/__init__.py8
-rw-r--r--scripts/kconfig/tests/preprocess/escape/expected_stderr10
-rw-r--r--scripts/kconfig/tests/preprocess/variable/Kconfig53
-rw-r--r--scripts/kconfig/tests/preprocess/variable/__init__.py8
-rw-r--r--scripts/kconfig/tests/preprocess/variable/expected_stderr9
13 files changed, 191 insertions, 0 deletions
diff --git a/scripts/kconfig/tests/preprocess/builtin_func/Kconfig b/scripts/kconfig/tests/preprocess/builtin_func/Kconfig
new file mode 100644
index 000000000000..baa328827911
--- /dev/null
+++ b/scripts/kconfig/tests/preprocess/builtin_func/Kconfig
@@ -0,0 +1,27 @@
1# SPDX-License-Identifier: GPL-2.0
2
3# 'info' prints the argument to stdout.
4$(info,hello world 0)
5
6# 'warning-if', if the first argument is y, sends the second argument to stderr,
7# and the message is prefixed with the current file name and line number.
8$(warning-if,y,hello world 1)
9
10# 'error-if' is similar, but it terminates the parsing immediately.
11# The following is just no-op since the first argument is not y.
12$(error-if,n,this should not be printed)
13
14# Shorthand
15warning = $(warning-if,y,$(1))
16
17# 'shell' executes a command, and returns its stdout.
18$(warning,$(shell,echo hello world 3))
19
20# Every newline in the output is replaced with a space,
21# but any trailing newlines are deleted.
22$(warning,$(shell,printf 'hello\nworld\n\n4\n\n\n'))
23
24# 'filename' is expanded to the currently parsed file name,
25# 'lineno' to the line number.
26$(warning,filename=$(filename))
27$(warning,lineno=$(lineno))
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 000000000000..2e53ba08fca1
--- /dev/null
+++ b/scripts/kconfig/tests/preprocess/builtin_func/__init__.py
@@ -0,0 +1,9 @@
1# SPDX-License-Identifier: GPL-2.0
2"""
3Built-in function tests.
4"""
5
6def test(conf):
7 assert conf.oldaskconfig() == 0
8 assert conf.stdout_contains('expected_stdout')
9 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 000000000000..33ea9ca38400
--- /dev/null
+++ b/scripts/kconfig/tests/preprocess/builtin_func/expected_stderr
@@ -0,0 +1,5 @@
1Kconfig:8: hello world 1
2Kconfig:18: hello world 3
3Kconfig:22: hello world 4
4Kconfig:26: filename=Kconfig
5Kconfig:27: lineno=27
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 000000000000..82de3a7e97de
--- /dev/null
+++ b/scripts/kconfig/tests/preprocess/builtin_func/expected_stdout
@@ -0,0 +1 @@
hello world 0
diff --git a/scripts/kconfig/tests/preprocess/circular_expansion/Kconfig b/scripts/kconfig/tests/preprocess/circular_expansion/Kconfig
new file mode 100644
index 000000000000..6838997c23ba
--- /dev/null
+++ b/scripts/kconfig/tests/preprocess/circular_expansion/Kconfig
@@ -0,0 +1,5 @@
1# SPDX-License-Identifier: GPL-2.0
2
3X = $(Y)
4Y = $(X)
5$(info $(X))
diff --git a/scripts/kconfig/tests/preprocess/circular_expansion/__init__.py b/scripts/kconfig/tests/preprocess/circular_expansion/__init__.py
new file mode 100644
index 000000000000..419bda3e075c
--- /dev/null
+++ b/scripts/kconfig/tests/preprocess/circular_expansion/__init__.py
@@ -0,0 +1,11 @@
1# SPDX-License-Identifier: GPL-2.0
2"""
3Detect circular variable expansion.
4
5If a recursively expanded variable references itself (eventually),
6it should fail with an error message.
7"""
8
9def test(conf):
10 assert conf.oldaskconfig() != 0
11 assert conf.stderr_matches('expected_stderr')
diff --git a/scripts/kconfig/tests/preprocess/circular_expansion/expected_stderr b/scripts/kconfig/tests/preprocess/circular_expansion/expected_stderr
new file mode 100644
index 000000000000..cde68fa989d0
--- /dev/null
+++ b/scripts/kconfig/tests/preprocess/circular_expansion/expected_stderr
@@ -0,0 +1 @@
Kconfig:5: Recursive variable 'X' references itself (eventually)
diff --git a/scripts/kconfig/tests/preprocess/escape/Kconfig b/scripts/kconfig/tests/preprocess/escape/Kconfig
new file mode 100644
index 000000000000..4e3f44445544
--- /dev/null
+++ b/scripts/kconfig/tests/preprocess/escape/Kconfig
@@ -0,0 +1,44 @@
1# SPDX-License-Identifier: GPL-2.0
2
3# Shorthand
4warning = $(warning-if,y,$(1))
5
6# You can not pass commas directly to a function since they are treated as
7# delimiters. You can use the following trick to do so.
8comma := ,
9$(warning,hello$(comma) world)
10
11# Like Make, single quotes, double quotes, spaces are treated verbatim.
12# The following prints the text as-is.
13$(warning, ' " '" ' ''' "'")
14
15# Unlike Make, '$' has special meaning only when it is followed by '('.
16# No need to escape '$' itself.
17$(warning,$)
18$(warning,$$)
19$ := 1
20$(warning,$($))
21
22# You need a trick to escape '$' followed by '('
23# The following should print "$(X)". It should not be expanded further.
24dollar := $
25$(warning,$(dollar)(X))
26
27# You need a trick to treat unbalanced parentheses.
28# The following should print "(".
29left_paren := (
30$(warning,$(left_paren))
31
32# A simple expanded should not be expanded multiple times.
33# The following should print "$(X)". It should not be expanded further.
34Y := $(dollar)(X)
35$(warning,$(Y))
36
37# The following should print "$(X)" as well.
38Y = $(dollar)(X)
39$(warning,$(Y))
40
41# The following should print "$(".
42# It should not be emit "unterminated reference" error.
43unterminated := $(dollar)(
44$(warning,$(unterminated))
diff --git a/scripts/kconfig/tests/preprocess/escape/__init__.py b/scripts/kconfig/tests/preprocess/escape/__init__.py
new file mode 100644
index 000000000000..7ee8e747f546
--- /dev/null
+++ b/scripts/kconfig/tests/preprocess/escape/__init__.py
@@ -0,0 +1,8 @@
1# SPDX-License-Identifier: GPL-2.0
2"""
3Escape sequence tests.
4"""
5
6def test(conf):
7 assert conf.oldaskconfig() == 0
8 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 000000000000..1c00957ddaa9
--- /dev/null
+++ b/scripts/kconfig/tests/preprocess/escape/expected_stderr
@@ -0,0 +1,10 @@
1Kconfig:9: hello, world
2Kconfig:13: ' " '" ' ''' "'"
3Kconfig:17: $
4Kconfig:18: $$
5Kconfig:20: 1
6Kconfig:25: $(X)
7Kconfig:30: (
8Kconfig:35: $(X)
9Kconfig:39: $(X)
10Kconfig:44: $(
diff --git a/scripts/kconfig/tests/preprocess/variable/Kconfig b/scripts/kconfig/tests/preprocess/variable/Kconfig
new file mode 100644
index 000000000000..9ce2f95cbd24
--- /dev/null
+++ b/scripts/kconfig/tests/preprocess/variable/Kconfig
@@ -0,0 +1,53 @@
1# SPDX-License-Identifier: GPL-2.0
2
3# Shorthand
4warning = $(warning-if,y,$(1))
5
6# Simply expanded variable.
7X := 1
8SIMPLE := $(X)
9X := 2
10$(warning,SIMPLE = $(SIMPLE))
11
12# Recursively expanded variable.
13X := 1
14RECURSIVE = $(X)
15X := 2
16$(warning,RECURSIVE = $(RECURSIVE))
17
18# Append something to a simply expanded variable.
19Y := 3
20SIMPLE += $(Y)
21Y := 4
22$(warning,SIMPLE = $(SIMPLE))
23
24# Append something to a recursively expanded variable.
25Y := 3
26RECURSIVE += $(Y)
27Y := 4
28$(warning,RECURSIVE = $(RECURSIVE))
29
30# Use += operator to an undefined variable.
31# This works as a recursively expanded variable.
32Y := 3
33UNDEFINED_VARIABLE += $(Y)
34Y := 4
35$(warning,UNDEFINED_VARIABLE = $(UNDEFINED_VARIABLE))
36
37# You can use variable references for the lefthand side of assignment statement.
38X := A
39Y := B
40$(X)$(Y) := 5
41$(warning,AB = $(AB))
42
43# User-defined function.
44greeting = $(1), my name is $(2).
45$(warning,$(greeting,Hello,John))
46
47# The number of arguments is not checked for user-defined functions.
48# If some arguments are optional, it is useful to pass fewer parameters.
49# $(2) will be blank in this case.
50$(warning,$(greeting,Hello))
51
52# Unreferenced parameters are just ignored.
53$(warning,$(greeting,Hello,John,ignored,ignored))
diff --git a/scripts/kconfig/tests/preprocess/variable/__init__.py b/scripts/kconfig/tests/preprocess/variable/__init__.py
new file mode 100644
index 000000000000..e88b1708d6d4
--- /dev/null
+++ b/scripts/kconfig/tests/preprocess/variable/__init__.py
@@ -0,0 +1,8 @@
1# SPDX-License-Identifier: GPL-2.0
2"""
3Variable and user-defined function tests.
4"""
5
6def test(conf):
7 assert conf.oldaskconfig() == 0
8 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 000000000000..a4841c3fdff5
--- /dev/null
+++ b/scripts/kconfig/tests/preprocess/variable/expected_stderr
@@ -0,0 +1,9 @@
1Kconfig:10: SIMPLE = 1
2Kconfig:16: RECURSIVE = 2
3Kconfig:22: SIMPLE = 1 3
4Kconfig:28: RECURSIVE = 2 4
5Kconfig:35: UNDEFINED_VARIABLE = 4
6Kconfig:41: AB = 5
7Kconfig:45: Hello, my name is John.
8Kconfig:50: Hello, my name is .
9Kconfig:53: Hello, my name is John.