-
-
Notifications
You must be signed in to change notification settings - Fork 110
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
configuration: fix incorrect handling of out-dir argument #415
Conversation
Currently the argument parsing code expands all the arguments. This means that an out-dir parameter having the same name of an executable is fully expanded, thus becoming an executable instead of a directory. Examples: > kcov python echo kcov: error: Can't find or open echo > kcov python /bin/echo kcov: error: Can't open directory /usr/bin/python3.11/ Remove checking if the first argument is an elf file, since the executable must be after the out-dir argument. Skip options and don't expand arguments, unless lstat fails. Issue SimonKagstrom#414: kcov: error when out-dir is an executable
1b25092
to
6148d2e
Compare
The code in this PR does not fully solve the problem. When the |
Thanks for your PR! One of the tests fail though: https://github.com/SimonKagstrom/kcov/actions/runs/8175261352/job/22356631660?pr=415, which was related to this issue: #368 |
Yes, it was my fault sorry. I tried to skip all options, but that was clearly incorrect. Still, as I wrote the previous comment, the current change does not fully solve the bug. I would like to run tests locally, but how do you run tests? Thanks. UPDATEThe problem does not seem to be related to my code to skip all the option when searching for an elf executable. Not sure what's causing the bug. |
Unfortunately, it's somewhat convoluted. Perhaps the easiest is to look at how the ci does it, which is in You need to build some test binaries (i.e., cmake against the tests/ directory) and then run |
... and also look in |
@SimonKagstrom what do you think about following the standard way to mark extra arguments? kcov --clean coverage tests/python/link_main -- 5 --foo instead of: kcov --clean coverage tests/python/link_main 5 --foo I also tried to remove completely the code scanning for an elf executable, and it seems to still work, but I need to run the tests. |
Well, I kind of like the current method, since it allows this pattern:
anyway, isn't the problem really that all paths are expanded with $PATH? Only the binary should be processed that way, and perhaps that can be done after the loop? |
This comment was marked as outdated.
This comment was marked as outdated.
The purpose of the scan is to find the argv index of the executable, so that Unfortunately I think this is an impossible task, since you can never tell what parameter is an executable, when they are relative names instead of full paths. |
Yeah, sorry, I haven't touched that code in a long time, so I had forgotten quite how it worked... Anyway, shouldn't it work to do:
The path in 3 should be looked up in $PATH, if not found. Your patch seems to pretty much do this, but maybe I'm missing something. |
Coincidentally I also found a possible solution:
Unfortunately there is still a small window for a bug: kcov --include-path python This is possible because GNU Additionally I would like to improve the current code, by adding two additional functions in
These change should make the code more readable. I will try to implement this, testing the code locally before push the code. Let me know if you don't like adding the two new functions. |
Sounds very good, thanks! The only comment I have is that |
@SimonKagstrom I compared how The example is: build/bin/kcov --python-parser=python2 cover tests/python/main 5 --foo With this change I get: NOT FOUND: 6, (null)
build/bin/kcov: unrecognized option '--foo'
kcov: error: Unrecognized option: - With the old master: NOT FOUND: 1, --python-parser=python2
NOT FOUND: 2, cover
hello!
... So the old code inner for loop (over This can be probably fixed in two way:
|
It should already match python and bash scripts. It calls matchParser in e.g., python-engine.cc, which looks for python in the shebang at the start of the file, so I don't quite understand why it doesn't work |
I wonder if it's just something like this that's needed:
I.e., accept the file if it's either already given in a relative or absolute path? |
Yes, I have reached the same conclusion. The problem was that As an example, Go Currently I'm trying to split |
The code seems to work but I got two errors: ======================================================================
FAIL: runTest (bash_linux_only.bash_sh_shebang.runTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/manlio/src/contrib/kcov/github/perillo/kcov/tests/tools/bash_linux_only.py", line 12, in runTest
assert parse_cobertura.hitsPerLine(dom, "sh-shebang.sh", 4) == 1
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError
======================================================================
FAIL: runTest (python.python_issue_368_can_handle_symlink_target.runTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/manlio/src/contrib/kcov/github/perillo/kcov/tests/tools/python.py", line 39, in runTest
assert b"unrecognized option '--foo'" not in o
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError |
Funnily enough, the python test works fine here (MacOS, but the python stuff should be exactly the same):
So since it's an improvement, I'd suggest to add that to the PR. Edit: The bash failure is Linux-specific, so wasn't run on my machine (so all tests ran fine here). |
My |
@perillo is this PR still relevant, or was it solved by the other? |
On Tue, Mar 12, 2024, 07:31 Simon Kagstrom ***@***.***> wrote:
@perillo <https://github.com/perillo> is this PR still relevant, or was
it solved by the other?
—
Reply to this email directly, view it on GitHub
<#415 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABPN3AEPW2QU2BSGU6GLXITYX2ONRAVCNFSM6AAAAABEJLJ4HWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOJQHA2DGNZUHE>
.
You are receiving this because you were mentioned.
It is still relevant.
… Message ID: ***@***.***>
|
I have a change that should finally fix the problem, but I think that reusing this PR is not a good idea. |
OK, so feel free to close this and open a new one when you feel ready! Thanks! |
Replaced by #426. |
Currently the argument parsing code expands all the arguments.
This means that an
out-dir
argument having the same name of an executable is fully expanded, thus becoming an executable instead of a directory.Examples:
Remove checking if the first argument is an elf file, since the executable must be after the
out-dir
argument.Skip options and don't expand arguments, unless
lstat
fails.Issue #414: kcov: error when out-dir is an executable
TODO
Add tests