summaryrefslogtreecommitdiff
path: root/testsuite.py
AgeCommit message (Collapse)Author
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-23Exclude User-mode Linux from testingUlf Magnusson
This "architecture" has an unorthodox Kconfig setup that would require a different testing setup.
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-23Flag extra tokens after 'if'/'depends on'/'visible if' expressionsUlf Magnusson
Extra trailing tokens after 'if <expr>', 'depends on <expr>', and 'visible if <expr>' now trigger syntax errors instead of being ignored. Oversight. This indirectly makes Kconfig.eval_expr() detect extra trailing tokens as well.
2018-08-22Add a generic node iteratorUlf Magnusson
Suggested by Mitja Horvat (pinkfluid) in https://github.com/ulfalizer/Kconfiglib/pull/50. Kconfig.node_iter() iterates through all menu nodes in the menu tree in Kconfig order. This saves scripts the trouble of implementing their own tree walking code. Have node_iter() take a 'unique_syms' flag that can be enabled to only include symbols defined in multiple locations once. This is often what you want when generating output (and is used by write_config()). Order is still preserved. Piggyback a fix to a syntax error test comment. Parsing has been tightened up now.
2018-08-21Merge Symbol._checked and Symbol._writtenUlf Magnusson
These are never used at the same time, and Symbol._visited is a good name for both. Gets rid of an internal attribute.
2018-08-21Handle multiple definition locations in a nicer wayUlf Magnusson
Instead of precalculating a set() to get unique symbols, precalculate a list with any duplicates from multiple definition locations removed, and preserve the order of the symbols within it. This makes it possible to get rid of the Symbol._written shenanigans in functions that only need to iterate through unique symbols in sorted order, which is all of them except write_config() (because it needs to walk the entire menu tree).
2018-08-21Fix header/minimal configuration ordering testUlf Magnusson
Should test write_autoconf(), not write_config().
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-08-18Look up the top-level Kconfig file relative to $srctreeUlf Magnusson
Due to an old design braino, the top-level Kconfig filename passed to Kconfig.__init__() wasn't looked up relative to $srctree, breaking out-of-tree usage for e.g. menuconfig. Fixing it required ugliness like srctree = os.environ.get("srctree", "") kconfiglib.Kconfig(os.path.join(srctree, "Kconfig")) Change the behavior of Kconfig.__init__() to look up the top-level Kconfig file relative to $srctree. This means that all Kconfig files (both the top-level file and any source'd files) now use $srctree, which makes the vast majority of scripts just work when running out-of-tree. Also remove the note re. loading a subset of Kconfig files. Saying that the top-level file and all source'd Kconfig files are looked up relative to $srctree should make the behavior clear enough. Print a note about the new behavior whenever the top-level Kconfig file can't be opened, as this change could be breaking for some scripts. This is a slight backwards-compatiblity break, so the major version will be bumped.
2018-08-18Revert "Fix $srctree logic for the top-level Kconfig file"Ulf Magnusson
This reverts commit 8a3999bc708e8468ff79665e3cbdfccd603160e1. I realized that this should go in a major release at least, because it has the potential to break scripts that rely on the old behavior of ignoring $srctree for the filename passed to Kconfig.__init__(). A dummy release will bump the version to 9.4.2. Any future release with the change will be 10.0.0.
2018-08-17Fix $srctree logic for the top-level Kconfig fileUlf Magnusson
Due to a major design braino, the top-level Kconfig file passed to Kconfig.__init__() wasn't looked up relative to $srctree, breaking out-of-tree usage for e.g. menuconfig. With this change, Kconfig files are consistently looked up relative to $srctree, which makes a lot more sense. Also remove note re. loading a subset of Kconfig files. Saying that the top-level file and all source'd Kconfig files are looked up relative to $srctree should make the behavior clear enough.
2018-08-10Support custom printing of symbols/choices in expressionsUlf Magnusson
Allow custom output formats for symbols/choices when turning expressions into strings, via a user-supplied callback function (sc_str_fn). This makes things like turning symbols into links in generated documentation and displaying symbol values in the menuconfig interface less hacky to implement. Two new Symbol/Choice.custom_str() functions were added, as passing extra arguments to __str__() is awkward.
2018-08-10Fix minimal configuration testUlf Magnusson
Needs an initial rm_config() after earlier reorganization.
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-13Fix absolute $srctree prefixes showing up on gsource'd filesUlf Magnusson
When using gsource with $srctree set to an absolute path, the $srctree prefix would show up in MenuNode.filename, trickling its way into e.g. generated documentation. This was due to a broken test: os.path.isabs() was checked after joining the pattern with $srctree, making it mistake an absolute $srctree for an absolute path in the Kconfig file. Fix the test.
2018-07-10Warn if int/hex 'default' is outside active 'range'Ulf Magnusson
Only out-of-range user values generated warnings before. The C tools warn for neither of them.
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-02Refactor tokenization a bitUlf Magnusson
Have _tokenize() take the string to tokenize and return a list of tokens, and handle all the token list management outside. Simplifies the internal logic a bit. Likely faster too.
2018-06-22Turn MenuNode/Symbol/Choice.referenced() into a @propertyUlf Magnusson
Having it as a function is inconsistent, since all other read-only fields use properties. Oversight. Major version will be bumped to 7, though the function version wasn't in for long.
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-20Rename KconfigSyntaxError to KconfigErrorUlf Magnusson
This exception is generated for semantic errors and e.g. when dependency loops are detected as well, so the name is bad. Keep the old name as an alias for now for backwards compatibility.
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 MenuNode.referenced() on Kconfig.top_nodeUlf Magnusson
The property lists weren't created for Kconfig.top_node, making referenced() crash. Add a MenuNode constructor and create the property lists there instead of in _parse_properties().
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-31Reorder compatibility testsUlf Magnusson
The defconfig tests tend to find any issue quickly, so keep those first. Go alldefconfig -> allnoconfig -> allmodconfig -> allyesconfig after that, and do the sanity checks at the end.
2018-05-30Add an allmodconfig implementationUlf Magnusson
Verified to produce identical output to 'make allmodconfig', for all arches. Will be packaged.
2018-05-30Add an alldefconfig.py scriptUlf Magnusson
Will be packaged. Piggyback test suite cleanups to make test names match the name of the script being tested.
2018-05-30Add tool helper for selecting the top-level KconfigUlf Magnusson
standard_kconfig() gets the top-level Kconfig file from the first command-line argument, defaulting to "Kconfig". This removes some boilerplate from tools.
2018-05-30allyesconfig: Prepare for packagingUlf Magnusson
Move to the root, simplify a bit, provide an entry point function (for setuptools's entry_points).
2018-05-27Provide lists with all menus and commentsUlf Magnusson
Handy e.g. when implementing advanced search features.
2018-05-27Make Kconfig._choices publicUlf Magnusson
Useful in various places outside the library, e.g. in the upcoming packaged allyesconfig implementation, and when generating documentation.
2018-05-27allnoconfig: Move from examples/ to rootUlf Magnusson
Put to-be-packaged stuff in the root. Use allnoconfig_simpler.py, and rename allnoconfig.py to allnoconfig_walk.py and keep it as an example.
2018-05-27Simplify error exitsUlf Magnusson
Had missed sys.exit(msg).
2018-05-27Get rid of the predefined UNAME_RELEASE symbolUlf Magnusson
Commit cbf32e2 ("Expand environment variables in strings directly") added direct expansion of environment variables is strings, with commit b9384a1 ("Restore compatibility with $UNAME_RELEASE") adding a hack to restore compatibility with the predefined $UNAME_RELEASE symbol, used by DEFCONFIG_LIST in the Linux kernel. With the compatibility hack in place, there's no longer any need to define UNAME_RELEASE as a proper symbol. Remove it.
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-01Make warnings available in a listUlf Magnusson
Also make printing of warnings to stderr optional. It's on by default, since it's almost always what you want. This makes printing and processing of warnings more flexible, compared to always printing warnings to stderr as soon as they're generated. It was inspired by wanting to promote certain warnings to errors in Zephyr, which previously required capturing stderr.
2018-04-11Add helper for splitting expressionsUlf Magnusson
I've had to implement the logic for walking reverse dependencies (from select) a couple of times now, and it's always a bit tricky to get right. Reduce code duplication and simplify things by adding a helper function split_expr() that splits an expression into a list of either its AND or OR operands. A nice side effect is that e.g. the warning generated for selecting a symbol with unsatisfied direct dependencies now lists the selecting symbols in the order that they appear in the Kconfig files. split_expr() might be helpful for splitting other types of expressions as well, e.g. to put operands on separate lines when generating documentation.
2018-04-05Set is_menuconfig True on the top menuUlf Magnusson
Oversight
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