-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Replace config.pl by config.py #2765
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
a3a4467 to
9620857
Compare
k-stachowiak
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I raised some minor questions regarding the code, which I consider more of a design discussion than review issues.
Unfortunately I found some minor errors as well:
- Incorrect formatting of the "templates",
- The
--forceoption not working properly.
OTOH, I compared the config.pl and config.py outputs for the config presets and found them to be identical, so I can confirm the main functionality being fine.
|
I've ported and improved There's a CI failure on Windows which I haven't investigated yet. |
bdcfc94 to
216fe59
Compare
CMakeLists.txt
Outdated
| "${WARNING_BORDER}") | ||
|
|
||
| find_package(PythonInterp) | ||
| find_package(Perl) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume this needs to be
| find_package(Perl) | |
| find_package(Python) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well-spotted. Perl is no longer needed. But PythonInterp is already present. There's also a FindPython but only on recent CMake versions. And PYTHON_FOUND below should actually be PYTHONINTERP_FOUND.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And on my machine FindPython actually finds python which is Python 2 but we need Python 3!
|
I fixed some issues, but this now needs rebasing 😭 |
|
The CI failure is one Windows job which calls |
c60850a to
812fd0f
Compare
|
I rebased on top of The previous history is in https://github.com/gilles-peskine-arm/mbedtls/tree/config_py-2. It started at ff645d9. The new history starts at 4197f0e, To verify that The only differences are the return status on error (before it was a happenstance value of |
812fd0f to
9a7368e
Compare
|
This will need another rebase once #2469 is merged :( |
This is meant to be a drop-in replacement for config.pl which can additionally be used as a library in a Python script. So far this script supports the commands 'get', 'set' and 'realfull' but not the other built-in configurations.
Also fix 'realfull' to only affect the appropriate sections. Tested to produce the same results as config.pl on the default configuration. This commit deliberately contains a direct copy the lists of symbol names from config.pl.
These options haven't existed for a long time.
They're easier to maintain that way. The old lists were partly alphabetized, partly based on config.h order, and partly in the order in which symbols had been added to config.pl.
git grep -Fl /config.pl | xargs sed -i -e 's!/config\.pl!/config.py!g' Also: * Change one comment in include/mbedtls/check_config.h. * Change PERL to PYTHON in CMakeLists.txt.
Keep config.pl in Perl in case people are running "perl config.pl".
Also make that error message end with a newline.
Run config.py with various options and store the results in files. This script also supports the now-removed config.pl. This is a framework to run non-regression tests on config.py: run it with the old version, run it with the new version, and compare the output. This is deliberately not a functional test suite so that we don't need to maintain a set of known outputs. When something changes in config.py (or config.h), run the script before, run it after, and check manually whether any differences in the output are acceptable.
Perl is no longer needed. Python must be version 3. Version 2 is not suitable. The variable is PYTHONINTERP_FOUND, not PYTHON_FOUND.
The test suite generator has been a Python script for a long time, but tests/CMakeLists.txt still looked for Perl. The reference to PYTHON_INTERP only worked due to a call to find_package(PythonInterp) in the toplevel CMakeLists.txt, and cmake would not have printed the expected error message if python was not available.
Normally a valueless symbol remains valueless and a symbol with a value keeps having one. But just in case a symbol does get changed from valueless to having a value, make sure there's a space between the symbol and the value. And if a symbol gets changed from having a value to valueless, strip trailing whitespace. Add corresponding tests. Also fix the case of a valueless symbol added with the set method, which would have resulted in attempting to use None as a string. This only happened with the Python API, not with the command line API.
9a7368e to
a103c18
Compare
|
Rebased again. Previous version in https://github.com/gilles-peskine-arm/mbedtls/tree/config_py-3. |
Patater
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty close to good to me.
tests/scripts/test_config_script.py
Outdated
| run_one(options, ['--force', 'set', symbol]) | ||
| run_one(options, ['unset', symbol]) | ||
| for symbol in TEST_SYMBOLS_WITH_VALUE: | ||
| run_one(options, ['get', symbol]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This exercises get, but doesn't check you get a sane value back from it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This script doesn't check anything for sanity. It's purely a non-regression test: record the outcome, and then you can compare it with the previous version. See the comment at the top of the script and the PR description.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do you know that get works as well as it worked with config.pl?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I run
./tests/scripts/test_config_script.py -d old -s ./config.pl
./tests/scripts/test_config_script.py -d new
diff -ruw old new
and it doesn't find any difference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I run ./tests/scripts/test_config_script.py -d old -s ./config.pl, I get an error about ./config.pl not found. When I run ./tests/scripts/test_config_script.py -d old -s ./scripts/config.pl, I see no output at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ran again with newest config.pl (I had been using an older one).
diff -ruw old/config-set-CUSTOM_SYMBOL-value.status new/config-set-CUSTOM_SYMBOL-value.status
--- old/config-set-CUSTOM_SYMBOL-value.status 2019-09-19 13:52:16.000000000 +0100
+++ new/config-set-CUSTOM_SYMBOL-value.status 2019-09-19 13:52:28.000000000 +0100
@@ -1 +1 @@
-25
+1
diff -ruw old/config-set-CUSTOM_SYMBOL.status new/config-set-CUSTOM_SYMBOL.status
--- old/config-set-CUSTOM_SYMBOL.status 2019-09-19 13:52:16.000000000 +0100
+++ new/config-set-CUSTOM_SYMBOL.status 2019-09-19 13:52:28.000000000 +0100
@@ -1 +1 @@
-25
+1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still see this diff, even on Linux.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$ ./scripts/config.pl set CUSTOM_SYMBOL value
A #define for the symbol CUSTOM_SYMBOL was not found in include/mbedtls/config.h
$ echo $status
1
$ ./config.pl set CUSTOM_SYMBOL value
A #define for the symbol CUSTOM_SYMBOL was not found in include/mbedtls/config.h
$ echo $status
25
Error code returned is different. Not sure we care, but is this different from what you see? You said you see no difference in behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's expected. See the description:
This should only report a differing nonzero error code in some error cases.
The old code was returning 25 on some errors because die returns errno and the value of errno just happens to be ENOTTY at that point for whatever reason. I mostly kept the new script bug-compatible but not that bug-compatible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. I had trouble reconciling what I saw with your comment in "#2765 (comment)" and wanted to confirm.
We currently test setting a symbol with a value even if it didn't originally had one and vice versa. So there's no need to have separate lists of symbols to test with. Just test everything we want to test with each symbol.
The tests were not covering get for a symbol with a value. No symbol has an uncommented value in the default config.h. (Actually there's _CRT_SECURE_NO_DEPRECATE, but that's a bit of a hack that this script is not expected to handle, so don't use it). Add tests of "get FOO" after "set FOO" and "set FOO value", so that we have coverage for "get FOO" when "FOO" has a value.
k-stachowiak
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for addressing my comments. Looks good to me.
Patater
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One question about error code returned, but otherwise OK.
Patater
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Replace
config.plbyconfig.py. I went for feature parity:config.pyshould be a drop-in replacement forconfig.pl, and has no new command line feature. The two scripts may behave differently in edge cases, but they support the same commands (get,set,unset,full,realfull,baremetal) and give identical results for each configuration.To verify that
config.pyis compatible with the formerconfig.pl:This should only report a differing nonzero error code in some error cases.
Reasons to switch to Python:
config.pycan be used as a library in other Python scripts to read and modify the configuration simply and efficiently.config.plhad relatively convoluted logic and was in need a major dust-up anyway.I think this should be backported to ease maintenance, but it does add a new build-time requirement. Python is a requirement for testing in all maintained branches, but not for building. — For the time being, we've decided to keep
config.plin the LTS branches. We might backport it later when we start adding new features toconfig.pyand we want to backport test scripts that use those new features.