summaryrefslogtreecommitdiff
path: root/tests
AgeCommit message (Collapse)Author
2026-02-02drop support for Python 2.x as it is very much EOLBenjamin Cabé
A follow-up to b96a5ad562deffa697d966c29546650aae645f48 where we stopped having CI run tests on Python 2.x. This actually drops the few remaining Python 2.x compatibility bits as Python 2.x has EOL'd a long time ago. Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org> Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2025-10-20kconfiglib: add origin testLuca Burelli
This patch adds a test for the origin feature added in the series. Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2024-10-04reltest: Support custom Python executablesStephanos Ioannidis
The reltest script previously hard-coded the Python executable names, which may vary across different host systems. This commit updates the reltest script to accept custom Python executable name(s) as arguments; if no argument is specified, 'python2' and 'python3' are used by default. Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2019-11-17Make header strings customizable via the environmentUlf Magnusson
If no header string is specified in write_(min_)config() or write_autoconf(), use the values of the environment variables KCONFIG_CONFIG_HEADER and KCONFIG_AUTOHEADER_HEADER, respectively, if set. KCONFIG_AUTOHEADER_HEADER is consistent with KCONFIG_AUTOHEADER (the header path), which will be added soon. Using environment variables avoids having to add separate flags to each tool that writes configuration files or headers. Like for $prefix and $CONFIG_, store the values of the environment variables when the Kconfig instance is created, and expose them via Kconfig.config_header and Kconfig.header_header. This if flexible and avoids gotchas when working with multiple Kconfig instances. Also remove the old default header and make the default no header. Less advertising, but it felt a bit silly to add workarounds to keep it. Came up in https://github.com/ulfalizer/Kconfiglib/pull/80.
2019-10-29Add public helpers for generating "<name> (defined at ...)" stringsUlf Magnusson
Have Symbol/Choice.name_and_loc return strings like "MY_SYM (defined at foo:1, bar:2)" "<choice> (defined at foo:4)" I've added a function like that in at least four different scripts now, so that's probably a sign that it's a worthwhile helper. Clean up the tests/Klocation tests a bit while adding tests.
2019-09-26Make preprocessor nested parens test slightly trickierUlf Magnusson
Macros should still be expanded within nested parentheses. Test it.
2019-09-26Fix handling of parentheses in macro argument valuesUlf Magnusson
As an oversight, there was no check for nested parentheses in macro arguments, making the preprocessor think the call ended after 'void)' in def_bool $(success,echo 'void foo(void) { asm inline (""); }' | $(CC) -x c - -c -o /dev/null) This broke the latest linux-next kernels, starting with commit eb111869301e1 ("compiler-types.h: add asm_inline definition"). I remember seeing this when going through the C code, but somehow forgot to put it in. Fix it, and clean up _expand_macro() a bit at the same time. Fixes: #76
2019-09-04Allow preprocessor user functions to access the parsing locationUlf Magnusson
Just requires making Kconfig.filename/linenr public. 'lineno' would be a more standard name, but be consistent with MenuNode.linenr.
2019-06-24Add {Symbol,Choice}.orig_*, corresponding to the MenuNode fieldsUlf Magnusson
Getting defaults, select, implies, and ranges without dependencies propagated to conditions can be useful for symbols and choices as well, e.g. when generating standalone documentation for properties.
2019-06-23Shorten __repr__() functions a bitUlf Magnusson
Do 'add = fields.append'. Pointless as an optimization, but shaves some lines, and obvious in context. Also add test coverage for __repr__() for string symbols with user values.
2019-06-09Get test coverage for --help---- and the likeUlf Magnusson
Weirdly formatted _T_HELP tokens are supported for compatibility with old versions of the C tools. Also add a lone '#' after the tricky help text. Some reconsidered refactoring choked on that.
2019-06-04Remove reference to Kconfiglib 1 APIUlf Magnusson
2019-06-01Fix obscure crash with rsource and $srctree pointing to a symlinkUlf Magnusson
Sourcing a file with an absolute path and using rsource in it triggered a relpath() between the absolute path and $srctree. Since e.g. symlink/../bar/ = bar/ is not guaranteed for symlinks, this could lead to the rsource'd file not being found if $srctree pointed to a symlink. Switch to a simpler, more textual method for stripping $srctree from glob results, which should be robust against symlink shenanigans. This also makes the code a bit easier to follow. Discovered by Marc Herbert. Piggyback some minor cleanup.
2019-05-25Use the '<type> "prompt"' shorthand in __str__()Ulf Magnusson
Pro: Looks cleaner and matches how definitions are usually written. Con: Makes it harder to discover that 'bool "foo"' is just shorthand for 'bool' + 'prompt "foo"' (though it's documented). The pros probably win.
2019-05-25Strip direct deps. from property conditions in Symbol/Choice/MenuNode.__str__()Ulf Magnusson
Commit e81a77b ("Consistently put direct deps. last when propagating") makes the position of the direct deps. in property conditions predictable after dependency propagation, making it easy to strip them as needed. Use this to implement MenuNode.orig_{prompt,defaults,selects,implies,ranges}, which work like the non-orig_* versions but omit the direct deps. Use those in turn to omit the direct deps in Symbol/Choice.__str__(). The direct deps. (with propagated parent deps.) can still be seen after 'depends on ...', so there is no loss of information. This unclutters Kconfig definitions shown in menuconfig/guiconfig and in any generated documentation. The old output also had duplicated dependencies, though it doesn't matter for evaluation. Before: config A bool prompt "A" if DEP default y if FOO && DEP depends on DEP After: config A bool prompt "A" default y if FOO depends on DEP
2019-05-24Consistently put direct deps. last when propagatingUlf Magnusson
Preparation for some later additions. Previously, the 'visible if' deps appeared to the right of the 'depends on' deps. Now, the direct deps always appear last. With this change, the prompt tuple is only updated once for any given menu node too, which should be a tiny bit faster.
2018-12-08Make {load,write}_config(filename=None) implement the standard behaviorUlf Magnusson
Make the previously obligatory 'filename' argument to load_config() and write_config() default to None, and have that implement the behavior you'd usually want: read/write either KCONFIG_CONFIG or ".config" if unset, and read the 'option defconfig_list' configuration file if KCONFIG_CONFIG/".config" doesn't exist. For load_config(), filename=None also allows the configuration file to be missing without raising an error. load_config() returns True if a local configuration file was loaded, which is useful to check in the menuconfig (if no local configuration file exists, we always want to prompt for saving the configuration when exiting). Also add a 'verbose' argument (default True) to load_config() and read_config() that makes them print which files were read/written in filename=None mode. Also generalize olddefconfig.py and oldconfig.py to not require there to already be a local configuration file. This was a bit silly for olddefconfig.py in particular. Remove the examples/defconfig.py script. It's a duplicate of olddefconfig.py.
2018-11-02Fix removal of multiple consecutive 'if' nodesUlf Magnusson
Despite 'if' nodes being flattened before 'if' removal, consecutive 'if' nodes can still show up for code like the following: ... if X endif if X endif ... _remove_ifs() failed to remove the second 'if' node, leading to a crash e.g. when turning on show-all mode in the menuconfig in a menu with such code (due to the unexpected 'if' node). Stuff like the above could potentially result from 'osource's with no matches, though I just spotted the error while looking over the code. Fix the 'if' removal logic to properly handle consecutive 'if' nodes.
2018-10-26Support enabling the assignment-to-undef. symbol warning via the environmentUlf Magnusson
This makes it possible to enable it for the bundled tools, by setting KCONFIG_WARN_UNDEF_ASSIGN=y. Previously, the code had to be modified to call Kconfig.enable_undef_warnings(). Also rename KCONFIG_STRICT to KCONFIG_WARN_UNDEF, for consistency. Keep supporting KCONFIG_STRICT as an alias for backwards compatibility.
2018-10-16Make Kconfig.choices match its descriptionUlf Magnusson
Kconfig.choices has accidentally been identical to Kconfig.unique_choices all along, because named choices defined in multiple locations (which are pretty obscure) were only added once. Fix Kconfig.choices to match its description. This simplifies the code a bit too. Kconfig.unique_choices is usually what you want.
2018-09-29Refactor parsing to get rid of _saved_lineUlf Magnusson
Handle the line-after-help-text case specially, which allows _has_tokens (renamed to _reuse_tokens) to be used as the unget mechanism for help texts as well, leaving _saved_line unused. Move the _reuse_tokens check into _next_line(). This makes _parse_block() as straightforward as _parse_properties(), and simplifies _parse_properties() a tiny bit too by getting rid of the '_tokens_i = -1' assignment.
2018-09-23Fix formatting nit in user-defined Python function testsUlf Magnusson
2018-09-23Add support for user-defined Python preprocessor functionsUlf Magnusson
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.
2018-09-04Allow macro expansion within symbol namesUlf Magnusson
The C implementation supports this (though it's undocumented, and unused to far). This can be used e.g. to dynamically instatiate symbols from template files: Kconfig.template: config $(subsys)_LOG bool "Enable logging for $(subsys)" depends on $(subsys)_HAS_LOG ... other stuff dependent on $(subsys) Elsewhere: subsys = FOO source "Kconfig.template" subsys = BAR source "Kconfig.template" Pretty sure this can easily be abused, but it should be supported at least.
2018-08-25Add a Kconfig.env_vars attribute that lists env. variablesUlf Magnusson
Kconfig.env_vars is a set() with the names of all environment variables referenced in the configuration. Can be used e.g. for custom incremental build implementations, though sync_deps() already indirectly catches any relevant changes to environment variables.
2018-08-24Show include paths in menuconfig symbol informationUlf Magnusson
Add a MenuNode.include_path attribute that holds a tuple of (filename, linenr) tuples, giving the locations of the 'source' statements via which the node's Kconfig file was included, starting from the top-level Kconfig file. Use MenuNode.include_path to give the include path for symbols and other items in the help display in the menuconfig interface. This is useful for figuring out how Kconfig files are organized, and when reorganizing things.
2018-08-23Fix recursive 'source' error reportingUlf Magnusson
The recursive 'source' detection was still fine, but the error reporting had broken due a missed variable renaming. The test suite didn't catch it, because a different type of KconfigError was raised instead, due to a separate error in the test suite (need to include tests/Krecursive{1,2}, since paths are relative to $srctree). Fix the variable name and tighten up the tests to check that the KconfigError message is the one we except. Tighten up the dependency loop detection tests in the same way too.
2018-08-21Make header symbol order match .config symbol order againUlf Magnusson
I accidentally broke this when I added the _defined_syms_set optimization. No semantic difference, but having the order match is more readable.
2018-07-20Fix detection of hex literalsUlf Magnusson
Missing 'not'. Add some literals to the Kstrict testcase.
2018-07-20Add KCONFIG_STRICT flag for flagging refs. to undefined symsUlf Magnusson
Settings KCONFIG_STRICT to y in the environment turns on warnings for all references to undefined symbols within Kconfig files (with the only gotcha that hex literals must be prefixed by 0x or 0X, to make it possible to distinguish them from undefined references). Always flagging undefined references gets awkward, as some projects (e.g. the Linux kernel) use multiple Kconfig trees with shared files, leading to some safe undefined references. It's helpful for other projects though. Having KCONFIG_STRICT as an environment variable is handy when multiple tools are involved. Piggyback a small README change re. warnings. Kconfiglib now has many more warnings than the C tools.
2018-07-18Add def_int, def_hex, and def_string keywordsUlf Magnusson
Analogous to def_bool and def_tristate, setting the type and adding a default at the same time. This is a Kconfiglib extension. These keywords can be useful in projects that make use of symbols defined in multiple locations, and remove some Kconfig inconsistency.
2018-07-15Switch to more sensible globbing statements (w/ backwards compatibility)Ulf Magnusson
Instead of having 'source' and 'gsource', have 'source' always glob, but require the pattern to match at least one file, throwing KconfigError otherwise. Have separate 'osource' and 'orsource' statements (the o is for "optional") for cases where it's okay for the pattern to not match any files. This is analogous to 'include' and '-include' in Make. The biggest flaw with 'gsource' was that there was no way to do a globbing match while requiring something to match, possibly leading to subtle failures. Preserve backwards compatibility by having "gsource" and "grsource" be aliases for "osource" and "orsource", respectively. Also include some related changes: - Kconfig.srctree is now set to the empty string if $srctree is unset, rather than to None. This gives nice behavior with os.path.join() and os.path.relpath(), which treat the empty string as the current directory (without adding './', for os.path.join()). - When $srctree is set, Kconfig files in the current directory will no longer override Kconfig files in $srctree when the relative paths match. This was likely a bug all along in the C tools, and probably only makes sense for .config files. I've seen it cause breakage in Zephyr. - Clarify the behavior of $srctree in the Kconfig.__init__() docstring. - Make MenuNode.filename be relative to $srctree for the Kconfig file passed to Kconfig.__init__(). This makes it consistent. The major version will be bumped later due to the small Kconfig.srctree API change.
2018-07-10Add Kconfig preprocessorUlf Magnusson
Implement the Kconfig preprocessor described in https://github.com/torvalds/linux/blob/master/Documentation/kbuild/kconfig-macro-language.txt (which is now in linux-next and will appear in Linux 4.18). A new Kconfig.variables property holds all the preprocessor variables so that they can be inspected programmatically. Preprocessor variables are represented by a new Variable class. With the preprocessor, environment variables are referenced with $(FOO) instead of $FOO. For backwards compatibility, $FOO is accepted as well for now (and leaves "$FOO" as-is if FOO doesn't exist). The $FOO syntax might be dropped at some point in the future (together with a major version increase). It should be supported for a few months at least. Some internals were cleaned up too, mostly related to parsing. Some outdated documentation was fixed as well.
2018-07-01Drop some compatibility and tighten up lexingUlf Magnusson
Old versions of the C tools used to ignore unhandled characters in some contexts due to sloppy lexing, which Kconfiglib emulated for compatibility (things like "---help---" used to depend on it). This was improved in the C tools by commit c2264564 ("kconfig: warn of unhandled characters in Kconfig commands"), committed in July 2015. Remove the compatibility hack and tighten up the lexing in Kconfiglib as well. It will make implementing the new preprocessor stuff smoother. The major version will be bumped.
2018-06-22Add Symbol/Choice.referenced() convenience methodsUlf Magnusson
Returns the union of the MenuNode.referenced() sets for all the menu nodes of the symbol/choice.
2018-06-19Add dependency loop detectionUlf Magnusson
Pretty long overdue. Until now, dependency loops have raised a hard-to-debug Python RecursionError during evaluation. A Kconfiglib exception is raised now instead, with a message that lists all the items in the loop. See the comment at the start of _check_dep_loop_sym() for an overview of the algorithm. At a high level, it's loop detection in a directed graph by keeping track of unvisited/visited nodes during depth-first search. (A third "visited, known to not be in a dependency loop" state is used as well.) Choices complicate things, as they're inherently loopy: The choice depends on the choice symbols and vice versa, and the choice symbols in a sense all depend on each other. Add the choice-to-choice-symbol dependencies separately after dependency loop detection, so that there's just the choice-symbol-to-choice dependencies to deal with. It simplifies things, as it makes it possible to tell dependencies from 'prompt' and 'default' conditions on the choice from choice symbol dependencies. Do some flag shenanigans to prevent the choice from being "re-entered" while looping through the choice symbols. Maybe this could be cleaned up a bit somehow... Example exception message: Dependency loop =============== A (defined at tests/Kdeploop10:1), with definition... config A bool depends on B ...depends on B (defined at tests/Kdeploop10:5), with definition... config B bool depends on C = 7 ...depends on C (defined at tests/Kdeploop10:9), with definition... config C int range D 8 ...depends on D (defined at tests/Kdeploop10:13), with definition... config D int default 3 if E default 8 ...depends on E (defined at tests/Kdeploop10:18), with definition... config E bool (select-related dependencies: F && G) ...depends on G (defined at tests/Kdeploop10:25), with definition... config G bool depends on H ...depends on the choice symbol H (defined at tests/Kdeploop10:32), with definition... config H bool prompt "H" if I && <choice> depends on I && <choice> ...depends on the choice symbol I (defined at tests/Kdeploop10:41), with definition... config I bool prompt "I" if <choice> depends on <choice> ...depends on <choice> (defined at tests/Kdeploop10:38), with definition... choice bool prompt "choice" if J ...depends on J (defined at tests/Kdeploop10:46), with definition... config J bool depends on A ...depends again on A (defined at tests/Kdeploop10:1)
2018-06-14Test property ordering on nested multi.def. choicesUlf Magnusson
This case wasn't covered.
2018-06-14Fix incorrectly ordered properties for some nested multi.def. symbolsUlf Magnusson
_propagate_deps() visits menu nodes roughly breadth-first, meaning properties on symbols and choices defined in multiple locations could end up in the wrong order when copied from the menu node for some unlucky if/menu nestings. Fix it by moving the menu-node-to-symbol/choice property copying in _finalize_tree() so that it's guaranteed to happen in definition order. This bug was introduced by commit 63a4418 ("Record which MenuNode has each property").
2018-06-13Add MenuNode function that returns referenced itemsUlf Magnusson
MenuNode.referenced() returns all symbols (and choices, for choice symbols) referenced in the properties (prompt, defaults, selects, ranges, etc.) and property conditions of the menu node. Handy e.g. when generating cross-references.
2018-06-11Add a function for getting all items in an expressionUlf Magnusson
Handy e.g. when searching.
2018-05-27Provide lists with all menus and commentsUlf Magnusson
Handy e.g. when implementing advanced search features.
2018-05-26Micro-optimize _parse_help() loopUlf Magnusson
Shaves ~6% off the _parse_help() runtime for the x86 Kconfigs in cProfile.
2018-05-16Record which MenuNode has each propertyUlf Magnusson
This allows accurate documentation to be generated for symbols and choices defined in multiple locations. There are now MenuNode.defaults, MenuNode.selects, etc., lists that mirror the corresponding Symbol/Choice lists. Symbol/Choice.__str__() now correctly show property locations as well, by simply concatenating the strings returned by MenuNode.__str__() for each node. _parse_properties() was modified to add all properties directly to the menu node instead of adding them to the contained symbol or choice. The properties are then copied up to symbols and choices in _finalize_tree(). Dependency propagation is handled at the same time. As a side effect, this cleans up the code a bit and de-bloats _parse_properties(). Update the menuconfig implementation to use the new functionality. It now lists the menu nodes for symbols and choices with the correct properties for each node (previously, all defaults, selects, implies, and ranges appeared on the first definition).
2018-05-16Expand environment variables in strings directlyUlf Magnusson
Make "$FOO" directly reference the environment variable $FOO in e.g. 'source' statements, instead of the symbol FOO. Use os.path.expandvars() to expand strings (which preserves "$FOO" as-is if no environment variable FOO exists). This gets rid of the 'option env' "bounce" symbols, which are mostly just spam and are buggy in the C tools (dependencies aren't always respected, due to parsing and evaluation getting mixed up). The same change will probably appear soon in the C tools as well. Keep accepting 'option env' to preserve some backwards compatibility, but ignore it when expanding strings. For compatibility with the C tools, bounce symbols will need to be named the same as the environment variables they reference (which is the case for the Linux kernel). This is a compatibility break, so the major version will be bumped to 6 at the next release. The main motivation for adding this now is to allow recording properties on each MenuNode in a clean way. 'option env' symbols interact badly with delayed dependency propagation. Side note: I have a feeling that recording environment variable values might be redundant to trigger rebuilds if sync_deps() is run at each compile. It should detect all changes to symbol values due to environment variables changing value.
2018-05-01Rename examples/menuconfig.py to menuconfig_example.pyUlf Magnusson
To avoid confusing it with the new terminal menuconfig implementation. Clean up the README a bit at the same time, removing some stuff that's less essential now (e.g. the menuconfig_example.py "screenshot").
2018-04-04Generalize is_menuconfig to non-symbol itemsUlf Magnusson
Extending the scope of is_menuconfig so that it's True for all items whose children should be displayed in a separate menu turns out to be handy when implementing menuconfig-like functionality. Keep the old name for backwards compatibility. It's good enough.
2018-03-28Parenthesize && expressions within || expressionsUlf Magnusson
This is redundant from an evaluation perspective, as && has higher precedence than ||, but is easier to read. A && B || C && D is now rendered as "(A && B) || (C && D)".
2018-03-26Refactor expr_str() casesUlf Magnusson
- Detect Symbol directly instead of as (not tuple) + (not choice) - Test explicitly for a tuple (non-Symbol) in NOT - Add some tests to get better coverage for NOT and parentheses
2018-03-13Test grsource with nonexistent fileUlf Magnusson
Just for completeness.
2018-03-13Add a globbing source statementUlf Magnusson
'gsource' works like 'source', but takes a glob pattern and sources all matching files. Works as a no-op if no files match, and hence doubles as an include-if-exists function, similar to '-include' in 'make'. Add a 'grsource' statement as well, mirroring 'rsource'. Came up in https://github.com/ulfalizer/Kconfiglib/pull/40.