summaryrefslogtreecommitdiff
path: root/testsuite.py
AgeCommit message (Collapse)Author
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-03Improve warning control API (with backwards compatibility)Ulf Magnusson
A wart of the warning control API (enable/disable_*_warnings()) is that the current warning settings can't be queried. Querying warning settings is useful in functions that want to temporarily enable/disable some warning and then put things back to how they were. kconfiglib.load_allconfig() ran into this, for example. Make the internal warning control variables public (improve the naming at the same time), and encourage just setting them directly. Keep the old API for backwards compatibility. Also remove _warn_redun_assign() and _warn_override(). They're trivial and were called in a single place.
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-29Convert docstrings to comments in testsuite.pyUlf Magnusson
Like was done a long time ago in kconfiglib.py. These functions are not part of a standalone API. Keep the docstrings for the compatibility tests, because those get printed as the tests run.
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-25Display n/m/y without quotesUlf Magnusson
These are constant symbols, which is why the quotes showed up. Special-case them to remove the quotes, to match what people expect. Internally, n/m/y without quotes is taken as a shorthand for "n"/"m"/"y".
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.
2019-05-24Touch up style a bit in test suiteUlf Magnusson
Ye olde code.
2019-03-06Give more helpful error messages when files are missingUlf Magnusson
The current error message talks a lot about $srctree, but $srctree is seldom the culprit in practice. More common is 'source "$(SOME_ENV_VAR)/foo"`, where SOME_ENV_VAR hasn't been set. Include the complete 'source ...' line for missing Kconfig files, and mention unset environment variables as a hint. Only mention $srctree briefly. Also shorten the message when a .config can't be a found a bit. This message would usually only be seen when working directly with the library.
2019-01-15Update copyright years for 2019Ulf Magnusson
2018-11-23Get rid of _next_token() and _peek_token()Ulf Magnusson
These are pretty hot. Inline them to save a few % of parsing time. They're pretty simple anyway. _tokens_i was initialized to -1 to simplify the _next_token() implementation. With _next_token() gone, initialize it to 0 instead, which simplifies some other code.
2018-11-21Disable test dependent on dict ordering on Python 3.5 and earlierUlf Magnusson
The KCONFIG_WARN_UNDEF test often fails on Python 3.4 (3.5 not tested), but the output is still correct. It just differs due to dict ordering randomness. Python 3.6 iterates over dicts in insertion order in practice, and Python 3.7 made it part of the spec, so enable the test for 3.6 and later. Python 2.7 seems fine as well.
2018-11-06Always strip trailing whitespace in 'MenuNode.help' and __str__()Ulf Magnusson
Previously, you could get either one or two newlines at the end of MenuNode.help and the various __str__() methods, though this wasn't documented. Always stripping trailing whitespace is cleaner e.g. when using print(), which automatically appends a trailing newline, and makes things consistent. Hopefully nothing relied on the old undocumented behavior. It's fine for genrest.py at least.
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-21Allow programmatically expanding preprocessor functions with argsUlf Magnusson
Add a Variable.expanded_value_w_args() function for expanding a preprocessor function with particular arguments. This is what expanded_value should have been, because expanded_value_w_args() is more general (expanded_value corresponds to zero arguments). Keep expanded_value for backwards compatibility though. Also add a simple __repr__() to Variable. It could show the expanded value, but that might mean calling shell functions or user-defined functions as a side effect (possibly with missing arguments). Not sure that's a good idea, so just show the unexpanded value.
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-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-08Fix a testsuite-related error for powerpcUlf Magnusson
The LD environment variable needs to be set now (in 4.19-rc2). It's referenced by LD_DEAD_CODE_DATA_ELIMINATION. The tests probably ought to run everything run via 'scriptconfig' in a clean environment, because 'scriptconfig' automatically picks up environment variables anyway. The current setup is nice in that it indirectly catches stuff that might affect the defconfig tests though, which don't use scriptconfig.
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-30Allow user values on 'option env' symbolsUlf Magnusson
Gets rid of a check, doesn't hurt. The check was added before 'option env' was changed to just add a 'default' under the hood. Note: New Kconfig code doesn't need 'option env'. Environment variables are now expanded directly, including in the C tools. 'option env' is only maintained for backwards compatibility.
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-25Add a Kconfig.kconfig_filenames attributeUlf Magnusson
Kconfig.kconfig_filenames is an ordered list of all Kconfig files included in the configuration, relative to $srctree. Can be used e.g. for custom incremental build implementations, though sync_deps() already indirectly catches any relevant changes to files. Piggyback some ' -> " quote style consistency cleanups.
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.