This is an archive of the discontinued LLVM Phabricator instance.

Make run-clang-tidy.py print the configured checks correctly
ClosedPublic

Authored by JesApp on Jan 24 2022, 11:52 PM.

Details

Summary

The test invocation at the start of run-clang-tidy.py (line 257) prints all enabled checks - meaning either the default set or anything configured via the -checks option. If any checks were (un-)configured via the -config option, these are not printed. This is confusing to the user, since the list of checks that are printed may be different from the list of checks that are used by the non-testing calls to clang-tidy, where the -config option is passed correctly.

This patch adds the -config option to the test invocation of clang-tidy at the start of the script. This means that checks (un-)configured via the -config option (rather than the -checks option) are applied correctly, when printing the list of enabled checks.

Diff Detail

Event Timeline

JesApp created this revision.Jan 24 2022, 11:52 PM
JesApp requested review of this revision.Jan 24 2022, 11:52 PM

See this github issue for the bug this fixes.

carlosgalvezp added inline comments.Jan 25 2022, 8:11 AM
clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
256–263

Would it make sense to re-use get_tidy_invocation with the proper arguments here?

JesApp updated this revision to Diff 403244.Jan 26 2022, 6:38 AM

As requested by @carlosgalvezp, this update uses the get_tidy_invocation function, rather than building it's own test invocation.

I chose to pass all arguments of the script, in case any of them ever have an impact on what is being printed. The exception is the tmpdir argument, since this directory would get created even if the test invocation then failed.

carlosgalvezp added a comment.EditedJan 26 2022, 7:08 AM

Looks good to me! A general comment not related to this patch is that the get_tidy_invocation is very error prone when called like that, since all arguments are strings. It would be better to specify the arguments:

get_tidy_invocation(name="", clang_tidy_binary=args.clang_tidy_binary,...)

But as said no need to fix here.

I haven't reviewed this file much and I'm quite new as reviewer so perhaps it's good that someone else takes another look and agrees with the change.

JesApp added a comment.EditedJan 26 2022, 7:13 AM

Thanks, @carlosgalvezp!

I'm new to phabricator, buildkite, your whole setup. Any idea why the patch fails?

Perhaps the patch was applied on a too old baseline, could you try rebasing on top of latest main?

clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
163

Am I missing something, or is this function now unused?

carlosgalvezp added inline comments.Jan 26 2022, 3:20 PM
clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
163

Nope, still used in line 301.

JesApp updated this revision to Diff 403541.Jan 27 2022, 1:06 AM
JesApp marked 2 inline comments as done.

Resubmitting the same changes after rebasing onto current main.

Anyone have an idea why it's still building?

Anyone have an idea why it's still building?

Very strange, I have no clue :/

Anyone have an idea why it's still building?

Hmmm, it looks like an infrastructure issue with the CI builder. https://buildkite.com/organizations/llvm-project/pipelines/diff-checks/builds/85880/jobs/928e70c7-6afc-4585-9e42-00b1644d0bf1/raw_log suggests that the issue comes from GitHub closing the connection forcefully (so it could be an issue with whatever login credentials are being used by the bot perhaps).

Rebasing onto current main may be insufficient to trigger the bot to rebuild. I'd recommend making a change to the patch (add some whitespace changes or something) and resubmit that. That should trigger a new build and we can pull the changes back out before landing. If the issue still reproduces, we can get the CI folks involved in investigating further.

I can (re)start a build manually. Let's see how that goes, before we start doing workarounds like that.

I can (re)start a build manually. Let's see how that goes, before we start doing workarounds like that.

I think there's just some serious latency problems with the pre merge checks atm

I can (re)start a build manually. Let's see how that goes, before we start doing workarounds like that.

I think there's just some serious latency problems with the pre merge checks atm

I guess you are right, since the build has now passed.

Any other changes I should include before this can be merged?

Do you reckon it's worth expanding the test: https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/test/clang-tidy/infrastructure/run-clang-tidy.cpp to look at this issue?
There isn't much testing of the run-clang-tidy.py at the moment, but it doesn't have to always remain that way.

Well, since this was more of source of confusion than actual incorrect behaviour, I don't think there should be a test for it.

In general though, I think the script is complex enough to warrant some testing. That being said: I don't think they should be part of this patch. Also, I'm doing this on company time and I don't think my boss would be to happy if I wrote a testsuite from scratch when I just wanted to fix one bug. :D

In general though, I think the script is complex enough to warrant some testing.

What is the feasibility of Python unit tests Instead of a heavy-weight lit oriented test?

What is the feasibility of Python unit tests Instead of a heavy-weight lit oriented test?

I don't know the code-base well enough to answer that. Is python used for testing purposes anywhere else? I'm pretty sure the actual effort of writing the tests would be roughly the same, regardless.

Anyway, I'm new here, so I don't want to tell you guys how to run things, but: In the projects I usually work on, a fix would get merged quickly and things like "let's write a test suite for this script" would go in the backlog. What's your opinion on that?

salman-javed-nz added a comment.EditedFeb 4 2022, 3:48 AM

Well, since this was more of source of confusion than actual incorrect behaviour, I don't think there should be a test for it.

In general though, I think the script is complex enough to warrant some testing. That being said: I don't think they should be part of this patch. Also, I'm doing this on company time and I don't think my boss would be to happy if I wrote a testsuite from scratch when I just wanted to fix one bug. :D

The idea I had was a file in clang-tools-extra\test\clang-tidy\infrastructure with something like this:

// RUN: %run_clang_tidy -checks="-*,google-explicit-constructor,modernize-use-auto" %s | FileCheck -check-prefix=CHECK-ENABLED-CHECKS-1 %s
// CHECK-ENABLED-CHECKS-1: Enabled checks:
// CHECK-ENABLED-CHECKS-1-NEXT: google-explicit-constructor
// CHECK-ENABLED-CHECKS-1-NEXT: modernize-use-auto

// RUN: %run_clang_tidy -checks="-*,google-explicit-constructor,modernize-use-auto" -config "Checks: -modernize-use-auto" %s | FileCheck -check-prefix=CHECK-ENABLED-CHECKS-2 %s
// CHECK-ENABLED-CHECKS-2: Enabled checks:
// CHECK-ENABLED-CHECKS-2-NEXT: google-explicit-constructor
// CHECK-ENABLED-CHECKS-2-NOT: modernize-use-auto

Note: I haven't tested this. If it doesn't work, then it's probably a minor tweak away from working.

This would confirm that the "Enabled checks:" message reflects the combined results of -checks and -config arguments.
I was wondering whether a test like the one above was an easy enough win to consider bundling in with the fix. In my initial comment I just wanted to bring up the topic, not to make a call on whether it should be done or not.

Well, since this was more of source of confusion than actual incorrect behaviour, I don't think there should be a test for it.

In general though, I think the script is complex enough to warrant some testing. That being said: I don't think they should be part of this patch. Also, I'm doing this on company time and I don't think my boss would be to happy if I wrote a testsuite from scratch when I just wanted to fix one bug. :D

The idea I had was a file in clang-tools-extra\test\clang-tidy\infrastructure with something like this:

// RUN: %run_clang_tidy -checks="-*,google-explicit-constructor,modernize-use-auto" %s | FileCheck -check-prefix=CHECK-ENABLED-CHECKS-1 %s
// CHECK-ENABLED-CHECKS-1: Enabled checks:
// CHECK-ENABLED-CHECKS-1-NEXT: google-explicit-constructor
// CHECK-ENABLED-CHECKS-1-NEXT: modernize-use-auto

// RUN: %run_clang_tidy -checks="-*,google-explicit-constructor,modernize-use-auto" -config "Checks: -modernize-use-auto" %s | FileCheck -check-prefix=CHECK-ENABLED-CHECKS-2 %s
// CHECK-ENABLED-CHECKS-2: Enabled checks:
// CHECK-ENABLED-CHECKS-2-NEXT: google-explicit-constructor
// CHECK-ENABLED-CHECKS-2-NOT: modernize-use-auto

Note: I haven't tested this. If it doesn't work, then it's probably a minor tweak away from working.

This would confirm that the "Enabled checks:" message reflects the combined results of -checks and -config arguments.
I was wondering whether a test like the one above was an easy enough win to consider bundling in with the fix. In my initial comment I just wanted to bring up the topic, not to make a call on whether it should be done or not.

FWIW the --checks option takes priority over the --config option.
If a check is enabled via --checks, but disabled via --config, the check will be enabled.
If a check is disabled via --checks, but enabled via --config, the check will be disabled.

salman-javed-nz added a comment.EditedFeb 4 2022, 5:17 AM

My bad. Test should have called run-clang-tidy with -checks=-some-check in the first test case, and with -config "Checks: -some-check" in the second. In both cases, the disabled check should not appear in the Enabled checks: printout.

There could be third test case where neither -checks nor -config are provided - this should display the default checks.

Anyway, I don't want what was a drive-by comment by me baloon into a lot of extra work for the author, so I will not push for it, unless others really want it.

Anyway, I don't want what was a drive-by comment by me baloon into a lot of extra work for the author, so I will not push for it, unless others really want it.

I think it's reasonable to accept this change and have the tests added as a follow-up change.

What is the feasibility of Python unit tests Instead of a heavy-weight lit oriented test?

I don't know the code-base well enough to answer that. Is python used for testing purposes anywhere else?

I'm not sure; this is a little bit unusual because there is not much production
python code in llvm/clang. I'm actually bumping into some grief in check_clang_tidy.py
that might go easier if I were to unit test some of the python itself.

Anyway, I'm new here, so I don't want to tell you guys how to run things,
but: In the projects I usually work on, a fix would get merged quickly and things
like "let's write a test suite for this script" would go in the backlog. What's your
opinion on that?

In this case, I think it's fine. Generally speaking though, the coding guidelines for llvm/clang
require that tests be added alongside the new features or bug fixes. This is certainly the case
when we add new checks, for instance.

See https://llvm.org/docs/DeveloperPolicy.html#test-cases

I'm not so much opposed to writing a test case for the one change I made (especially after @salman-javed-nz suggestion) as I am opposed to learning the build system. I've tried to set for a few minutes and oh man, that's a lot of targets...

So yeah, If someone could merge it like this, I'd be grateful.

aaron.ballman accepted this revision.Feb 7 2022, 6:48 AM

Anyway, I don't want what was a drive-by comment by me baloon into a lot of extra work for the author, so I will not push for it, unless others really want it.

I think it's reasonable to accept this change and have the tests added as a follow-up change.

Normally I'd be opposed to this, but given the testing difficulties with this tool are not new and this patch doesn't make them substantially worse, I think it's fine to land as-is and address testing in a follow-up.

This revision is now accepted and ready to land.Feb 7 2022, 6:48 AM

Thanks for accepting. Do I need to do anything to get this merged or is this basically done?

Thanks for accepting. Do I need to do anything to get this merged or is this basically done?

Oops, sorry for failing to ask if you needed this committed on your behalf. :-) What name and email address would you like me to use for patch attribution?

JesApp added a comment.Feb 8 2022, 4:55 AM

No problem. :)

Jesko Appelfeller, jesko@appelfeller.eu please.

aaron.ballman closed this revision.Feb 8 2022, 5:32 AM

I've commit on your behalf in 0851970af5771f6721c29d066c88a72db823ba83, thank you!

JesApp added a comment.Feb 8 2022, 5:34 AM

Thank you! :)