summaryrefslogtreecommitdiff
path: root/tests
AgeCommit message (Collapse)Author
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.
2018-02-27Implement 'rsource' statement ('source' with relative path)Roman
The 'rsource' statement works like 'source', but looks relative to the Kconfig file that has the 'rsource' rather than relative to the base Kconfig file. Using 'rsource' makes it possible to move subtrees with Kconfig files around without breaking references to other Kconfig files. So far, this is a Kconfiglib-exclusive feature.
2018-02-16Include direct deps. in Symbol/Choice.__str__()Ulf Magnusson
Direct dependencies are significant for 'imply' even if the symbol has no properties, so they need to be included to get semantically equivalent output. Making the direct dependencies clear is helpful in general too, even if you can usually infer them from the properties they get propagated to.
2018-01-30Fix warnings printed for test suiteUlf Magnusson
Just to have clean output. The warnings themselves are accurate.
2018-01-28Add some post-parsing warningsUlf Magnusson
These are easiest to check after parsing, since a symbol/choice can be defined in multiple locations: - Warn if a symbol or choice defined without a type. Also warn for choice value symbols defined without a type, even if they automatically get their type from the choice. This feature isn't well-known and probably not used deliberately. - Warn if a choice is defined without a prompt - Warn of a choice default symbol is not contained in the choice Also move _name_and_loc_str() from the symbol class to the global scope and generalize it to be able to handle choices.
2018-01-28Flag constant symbols where they're not allowedUlf Magnusson
Might break U-Boot if they ever upgrade Kconfiglib, because they have a 'select y' in there (which the C tools don't flag since they only look for quotes), but it's a one-line fix.
2018-01-20Get rid of _next_help_line()Ulf Magnusson
Speeds things up a bit further. Rework the unget handling to save the ungotten line directly instead of using a flag. Add some help texts to tests/Klocation to make sure the line number is updated properly for those.
2018-01-17Detect recursive 'source' and print backtraceUlf Magnusson
Easier to debug than a RecursionError. Point out in the exception message that a common cause is environment variables not being set correctly.
2018-01-05Don't write out 'option env' symbols to C headerUlf Magnusson
Oversight. SYMBOL_AUTO (env_var) being set indirectly clears SYMBOL_WRITE (_write_to_conf) in sym_calc_value(). The .config case was already fine due to an explicit env_var check. Even non-visible env. symbols ended up in the header, due to 'option env' internally adding a default. Disallow user values altogether on 'option env' symbols, even if specified manually. This matches the C implementation. Add a warning too.
2017-11-12Remove unused test filesUlf Magnusson
Some were for now-removed APIs, others tested things that are tested differently now.
2017-11-08Spacing nitUlf Magnusson
2017-11-08Add a release test scriptUlf Magnusson
Confirms that all the examples that aren't tested in the test suite at least run. Easy to miss brokenness there. Output can be inspected manually (it'll vary depending on the kernel version). Fix defconfig_oldconfig.py, which hadn't been properly updated for the new API.
2017-11-03Test Choice.assignable, fix for optional choicesUlf Magnusson
Could never return 0 as a valid assignable value previously.
2017-11-03Add .assignable selftests for choice symbolsUlf Magnusson
2017-11-03Test .assignable for imply, find C menuconfig bugUlf Magnusson
A tristate implied to y can't be set to m. Other than that, imply doesn't affect assignable values. Fix some copy-paste type errors too. In the C menuconfig, a tristate with m visibility implied to y gets stuck if you change it with space. Look into that later. Test case: config MODULES def_bool y option modules config Y_IMPLIER def_tristate y imply Y_IMP_M_VIS_TRI config Y_IMP_M_VIS_TRI tristate "y-imp m-vis tri" if m
2017-11-03Add initial selftests for .assignableUlf Magnusson
Comprehensive selftests are important here, because the allno/yesconfig.py scripts only check the upper and lower bound, and allnoconfig disables modules. Found a bug for non-selected m-visible tristates, where n didn't show up in sym.assignable. Everything matches menuconfig after fixing that. Still need to test symbols in choices with different modes, imply, and .assignable for choices.
2017-11-02Clean up choice semantics testsUlf Magnusson
Can finally get rid of get_choices() and get_items() now. Piggyback some more Kwtf tests, and remove some outdated comments. There's already plenty of select/imply testing.
2017-11-02Clean up .kconfig testsUlf Magnusson
Kinda silly to test if they're separate since a long time, but can do that easily too with some reorganization.
2017-11-02Clean up relation testUlf Magnusson
Think those variables got used in other places before... Fetch the choices by name. Also dedotdotdot all messages for consistency.
2017-11-02Get rid of separate is_optional testUlf Magnusson
The choice semantics tests already verify the behavior of optional choices. Just print an optional choice instead to get some coverage for querying it. Do minor cleanup elsewhere.
2017-11-02Always save user values if they're validUlf Magnusson
Can just skip the invalidation for promptless symbols. Makes things less magic and more intuitive while still being fast. Means no docs need to be rewritten too. Now the warning gets printed for unset_value() as well.
2017-11-02Do not invalidate everything when loading .configsUlf Magnusson
In replace mode, only unset symbols that didn't get set. Get rid of _set_value_no_invalidate() and just do a normal set_value() with invalidation. It's speedy with the new invalidation algorithm, and simpler. Not a big performance boost (but a small one), but means that invalidation must be even more rock solid for the test suite to pass (no global invalidations to hide behind), which is nice. Also make y assignments to choice symbol update just the choice user value. Gives nicer behavior when the choice mode is changed.
2017-10-28Add uncommitted test filesUlf Magnusson
2017-10-24Kconfiglib 2 backupUlf Magnusson
WIP
2017-10-02Make 'imply' consider direct dependenciesUlf Magnusson
Bad oversight. Weak reverse dependencies (from imply) are not considered if the direct dependencies of a symbol are not met (the 'if'/'depends on' dependencies from the symbol and its parents, taking location into account if the symbol is defined in multiple places). Caused a wrong value for the symbol FS_FAT in the U-Boot Kconfigs, where 'imply' is more heavily used compared to the kernel. Add a new variable _direct_deps that corresponds to dir_dep from the C implementation. Before 'imply', dir_dep was only used for a 'select'-related warning in the C implementation. Add a bunch of tests to cover 'imply' semantics. Should be solid now.
2017-10-01Propagate dependencies to range conditionsUlf Magnusson
Just like for other properties, conditions on ranges get local 'depends on' and parent dependencies propagated to them. Oversight. Did not trigger any deviations for the kernel defconfigs. Pretty specific circumstances were required for breakage, like a symbol depending on the particular value of a symbol with a 'range' and parent deps 'n', or a symbol with ranges being defined in multiple locations with different parent deps. (There is one symbol that both has ranges and is defined in multiple locations: BCH_CONST_M. The second definition adds a default rather than a range though.)
2017-09-29Only invalidate defined symbolsUlf Magnusson
Think I had it in the back of my head somewhere that not invalidating undefined symbols could break some obscure cases, but turns out it's perfectly safe: Nothing can change the value of an undefined symbol. They always get their name as their value. There's no need to unset user values on them either, because set_user_value() already refuses to to set one on them. Lets us get rid of the Python 2/3 compatibility hack and instead iterate over a plain list of defined symbols.
2017-09-25Fix 'default' on non-visible choice symbolsUlf Magnusson
Previously, 'default CHOICE_SYM [if <cond>]' in a choice would skip any following 'default' properties if <cond> was non-'n'. However, those other defaults should still be considered if CHOICE_SYM has visibility 'n'. Previously, we'd immediately fall back to selecting the first visible symbol in the choice in that case. get_selection_from_defaults() now exactly mirrors sym_choice_default() from the C implementation, and got less convoluted too. Nothing in the kernel defconfigs triggered this. Add a new test case too.
2017-09-25Don't set defaults that will always be overwrittenUlf Magnusson
The constructors previously defaulted all properties. This is dead code for properties that are always set on items from outside during parsing, and obfuscates the code flow and wastes time. Instead, just mention other properties that exist in comments in the constructors. Also add test cases for missing and empty 'choice' help texts. Removing the default 'self._help = None' assignment in Choice.__init__() wasn't caught by the selftests.
2017-09-24Fix defconfig srctree absolute/relative mixup bugUlf Magnusson
This code in zconf.l says !=, not ==. Thought the behavior seemed weird. if (!f && name != NULL && name[0] != '/') { env = getenv(SRCTREE); if (env) { sprintf(fullname, "%s/%s", env, name); f = fopen(fullname, "r"); } } return f; Thankfully only broken for a short while. Also gives much simpler code.