diff options
| author | Ulf Magnusson <ulfalizer@gmail.com> | 2018-09-20 13:33:59 +0200 |
|---|---|---|
| committer | Ulf Magnusson <ulfalizer@gmail.com> | 2018-09-23 17:31:20 +0200 |
| commit | 6156041560c75831e003202b790ab3f435bbb388 (patch) | |
| tree | 8bb3de3561d87e4faeb73dfef098d8e3726db363 /testsuite.py | |
| parent | 3df532b8d4cdf6915eaf079ee8082f792ab9b0cb (diff) | |
Add support for user-defined Python preprocessor functions
Allow preprocessor functions to be defined in Python by putting a module
called 'kconfigfunctions' into sys.path. Internally, this simply adds
the functions to the predefined functions in Kconfig._functions.
User-defined Python functions make it simple to integrate information
from existing Python tools into Kconfig, e.g. to have Kconfig symbols
depend on hardware information stored in some other format. This might
be used to get device tree information into Kconfig in Zephyr.
Piggyback module docstring documentation for some extensions that were
previously only mentioned in the README.
Diffstat (limited to 'testsuite.py')
| -rw-r--r-- | testsuite.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/testsuite.py b/testsuite.py index b5f0388..802234e 100644 --- a/testsuite.py +++ b/testsuite.py @@ -2459,6 +2459,39 @@ config PRINT_ME_TOO ]) + print("Testing user-defined preprocessor functions") + + # Make Kconfiglib/tests/kconfigfunctions.py importable + sys.path.insert(0, "Kconfiglib/tests") + + c = Kconfig("Kconfiglib/tests/Kuserfunctions") + + verify_variable("add-zero", "$(add)", "0", True) + verify_variable("add-one", "$(add,1)", "1", True) + verify_variable("add-three", "$(add,1,-1,2,1)", "3", True) + + verify_variable("one-one", "$(one,foo bar)", "onefoo barfoo bar", True) + + verify_variable("one-or-more-one", "$(one-or-more,foo)", "foo + ", True) + verify_variable("one-or-more-three", "$(one-or-more,foo,bar,baz)", + "foo + bar,baz", True) + + def verify_bad_argno(name): + try: + c.variables[name].expanded_value + except KconfigError: + pass + else: + fail("Expected '{}' expansion to flag wrong number of arguments, " + "didn't".format(name)) + + verify_bad_argno("one-zero") + verify_bad_argno("one-two") + verify_bad_argno("one-or-more-zero") + + sys.path.pop(0) + + print("Testing KCONFIG_STRICT") os.environ["KCONFIG_STRICT"] = "y" |
