Skip to content
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

Fix #13523 CTU: Mention including cpp file for error in header #7174

Merged
merged 27 commits into from
Jan 8, 2025

Conversation

chrchr-github
Copy link
Collaborator

No description provided.

@chrchr-github chrchr-github marked this pull request as ready for review January 4, 2025 10:13
file0 = ''
for e in results.findall('errors/error'):
if e.attrib['id'] == 'ctunullpointer':
if 'file0' in e.attrib:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why this is necessary, but there was a KeyError without it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That means that it doesn't contain that key. [] acts like at()in C++.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but there should only be one ctunullpointer error, which has the file0 attribute.
XML shown here: https://github.com/danmar/cppcheck/actions/runs/12605458944/job/35134122531
KeyError: https://github.com/danmar/cppcheck/actions/runs/12605258027/job/35133607619

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably add a few more asserts on the results. Like the amount of returned nodes and such.

You could also limit the XPath to only return the node in question by adding [@id='ctunullpointer'].

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably add a few more asserts on the results. Like the amount of returned nodes and such.

Not so easy, since getting both nullpointer and ctunullpointer seems wrong already. With -j2, we get an additional ctunullpointer (https://trac.cppcheck.net/ticket/11883)

You could also limit the XPath to only return the node in question by adding [@id='ctunullpointer'].

Done.

lib/checkclass.cpp Outdated Show resolved Hide resolved
@chrchr-github chrchr-github changed the title Fix #13523 Mention including cpp file for error in header Fix #13523 CTU: Mention including cpp file for error in header Jan 4, 2025
@firewave
Copy link
Collaborator

firewave commented Jan 4, 2025

FYI running the tests locally on Windows is actually quite easy. You can install the official Python distribution from the Microsoft Store (https://apps.microsoft.com/detail/9pnrbtzxmb4z) which will place python in the PATH and then you can just run them from any command-line.

@chrchr-github
Copy link
Collaborator Author

FYI running the tests locally on Windows is actually quite easy. You can install the official Python distribution from the Microsoft Store (https://apps.microsoft.com/detail/9pnrbtzxmb4z) which will place python in the PATH and then you can just run them from any command-line.

Hadn't even tried that, fearing another rabbit hole. But it works:

python -m pytest .\whole-program_test.py
================================================= test session starts =================================================
platform win32 -- Python 3.10.2, pytest-8.3.4, pluggy-1.5.0
rootdir: source\repos\cppcheck\test\cli
collected 31 items

whole-program_test.py .x.x.x.x.x.x.x.x......x...x...x                                                            [100%]

=========================================== 20 passed, 11 xfailed in 43.52s ===========================================

Copy link
Owner

@danmar danmar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not strongly against that we test it in test/cli but I wonder why it wasn't tested in testrunner instead.
A pytest that executes cppcheck is slower than a testrunner test as far as I understand?

@firewave
Copy link
Collaborator

firewave commented Jan 5, 2025

A pytest that executes cppcheck is slower than a testrunner test as far as I understand?

Obviously by design but all the Python tests together take less than 40 seconds. So even if we add several dozens more that will hardly make a dent in the CI runtime.

@firewave
Copy link
Collaborator

firewave commented Jan 5, 2025

I am not strongly against that we test it in test/cli but I wonder why it wasn't tested in testrunner instead.

We also get all the injection matrix in the CI with those tests which is actually important as these behave different with threads and/or builddir. And that is annoying or really hard to test in the unit tests and here we get it for "free".

@chrchr-github chrchr-github reopened this Jan 7, 2025
@chrchr-github
Copy link
Collaborator Author

Not sure why test_nullpointer_file0_j suddenly passed and then failed again (it always fails locally).

___________________________ test_nullpointer_file0_j ___________________________
[gw0] linux -- Python 3.11.11 /opt/hostedtoolcache/Python/3.11.11/x64/bin/python3
[XPASS(strict)] 

https://github.com/danmar/cppcheck/actions/runs/12654460990/job/35262407668
https://github.com/danmar/cppcheck/actions/runs/12654913760/job/35263940012

Comment on lines 378 to 386
assert file0 == 'whole-program/nullpointer1.cpp'
assert stdout == ''
assert ret == 1, stdout


def test_nullpointer_file0():
__test_nullpointer_file0(['-j1'])

@pytest.mark.skip(reason="flaky!?")
Copy link
Collaborator

@firewave firewave Jan 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert file0 == 'whole-program/nullpointer1.cpp'
assert stdout == ''
assert ret == 1, stdout
def test_nullpointer_file0():
__test_nullpointer_file0(['-j1'])
@pytest.mark.skip(reason="flaky!?")
assert ret == 1, stdout if stdout else stderr
assert stdout == ''
assert file0 == 'whole-program/nullpointer1.cpp', stderr
def test_nullpointer_file0():
__test_nullpointer_file0(['-j1'])

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually I would assume it is an issue with running the test in parallel but there is nothing in this test which could cause that.

But this test is build with UBSAN so it might indicate such an issue. The asserts are in a bad order so that would be obfuscated. I adjusted them so we should get more details (that needs to be applied across all the tests - there are already some initial helpers but something for later).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The xfail is still in, so it might pass now but we might not see the error reported by the sanitizer.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With xfail in, Run test/cli (--cppcheck-build-dir) fails (test succeeds). Without xfail, Run test/cli fails as expected.
How is this injection stuff supposed to work? I also see extraargs being used in the test.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The injection stuff checks if any of the parameters in question already exists and only injects those is necessary. The -j2 injection will not be done if -j1 already exists. Same with --cppcheck-build-dir and --executor. So if you have to specify them explicitly they will not return the same no matter how it is called (e.g. Windows does not support --executor=process) and you need to provide an override.

This looks weird though. Will take a look later.

@chrchr-github chrchr-github merged commit 77a6705 into danmar:main Jan 8, 2025
60 checks passed
@chrchr-github chrchr-github deleted the chr_13523 branch January 8, 2025 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants