Skip to content

[DAM analyzer] Check for unexpected analyzer warnings in linker tests #2523

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

Merged
merged 23 commits into from
Feb 3, 2022

Conversation

sbomer
Copy link
Member

@sbomer sbomer commented Jan 19, 2022

This adds a source generator which generates analyzer xunit facts for the linker testcases. It discovers linker testcases by examining the referenced assembly, and avoids generating cases which already exist as analyzer facts (this requires tests to follow the existing convention for naming testcase files and facts). The generated sources are checked in to make changes easier to review.

The generated testcases only validate that the analyzer produces no unexpected warnings on the input (that is, these tests may pass even if the analyzer doesn't produce some of the expected warnings). Any tests which are currently skipped don't get this validation, so before closing out the feature branch we will want to replace skipped facts with facts that run in the allowMissingWarnings mode.

The failing tests have been disabled and are tracked in separate issues. This also contains a number of small infrastructure tweaks to match the linker's test infrastructure enough to run all of these tests.

@sbomer sbomer marked this pull request as ready for review January 19, 2022 20:42
@sbomer sbomer requested a review from marek-safar as a code owner January 19, 2022 20:42
@sbomer sbomer changed the title Add test run to check for unexpected analyzer warnings [WIP] [DAM analyzer] Add test run to check for unexpected analyzer warnings Jan 19, 2022
@sbomer sbomer closed this Jan 19, 2022
@sbomer sbomer reopened this Jan 19, 2022
@sbomer sbomer closed this Jan 27, 2022
@sbomer sbomer reopened this Jan 27, 2022
* Fix inconsistencies in Requires attribute checks

* Fix build and continue verifying attribute arguments

* PR feedback

- Remove unnecessary check for ITypeSymbol
- Clean up null check logic

* containingSymbol -> symbol

* Rename symbol -> member
@sbomer
Copy link
Member Author

sbomer commented Feb 1, 2022

/azp run

@azure-pipelines
Copy link

Azure Pipelines failed to run 1 pipeline(s).

@sbomer
Copy link
Member Author

sbomer commented Feb 1, 2022

/azp run

@azure-pipelines
Copy link

Azure Pipelines failed to run 1 pipeline(s).

- Support SandboxDependency with type argument
- Don't crash on SetupCompileResource with a text file
- Add analyzer ExpectedWarnings to work around lack of
  support for top-level ExpectedWarning with SourceLine/SourceColumn
@sbomer sbomer changed the title [WIP] [DAM analyzer] Add test run to check for unexpected analyzer warnings [DAM analyzer] Check for unexpected analyzer warnings in linker tests Feb 3, 2022
@sbomer sbomer requested review from jtschuster and LakshanF February 3, 2022 00:16
Copy link
Contributor

@LakshanF LakshanF left a comment

Choose a reason for hiding this comment

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

I didn't quite fully understand the part of the generated analyzer test passing even if it doesn't produce expected warnings. Does not having [ExpectedWarning] in the linker test ensure that at least the analyzer achieves parity with the linker via TestChecker?

Thanks for automating this process!

Copy link
Member

@vitek-karas vitek-karas left a comment

Choose a reason for hiding this comment

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

Looks good - only one question about the compiler/source control setup.

Comment on lines +7 to +12
<CompilerGeneratedFilesOutputPath>generated</CompilerGeneratedFilesOutputPath>
</PropertyGroup>

<ItemGroup>
<Compile Remove="$(CompilerGeneratedFilesOutputPath)" />
</ItemGroup>
Copy link
Member

Choose a reason for hiding this comment

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

I don't really understand this - we ask the compiler to write the generated code to disk (I get that, at least for validation purposes and such). But then remove it from the compilation... this is probably because the source generator already added it?

Also - why do we commit the generated files into the source control, if they are always regenerated?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, if we didn't remove them from the compilation they would be defined twice. I'm committing them to source control to make it easier to review changes, and because it sounds like the test UI may have trouble displaying generated tests otherwise. I don't have a strong opinion on it but this is per @agocke's suggestion - happy to remove them if we would rather not check in a bunch of generated sources.

Copy link
Member

Choose a reason for hiding this comment

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

For code that you're expected to interact w/ directly (e.g. tests), I'd prefer to have them checked in. VS Code can't run them individually otherwise

Copy link
Member

@agocke agocke Feb 3, 2022

Choose a reason for hiding this comment

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

Also, to properly enable these test cases, it will be easy to move the file into a non-generated directory. The generator will see that the test file is already present and will stop generating it, and git will understand and track the move operation.

@sbomer
Copy link
Member Author

sbomer commented Feb 3, 2022

Does not having [ExpectedWarning] in the linker test ensure that at least the analyzer achieves parity with the linker via TestChecker?

Generally yes, but in this change the generated tests (and any tests which pass allowMissingWarnings: true) specifically don't check that all of the ExpectedWarnings are covered. They only check that there aren't any extra warnings. We can remove the allowMissingWarnings from individual tests as they reach parity with the linker.

@sbomer sbomer merged commit 917830d into dotnet:feature/damAnalyzer Feb 3, 2022
@sbomer sbomer deleted the noExtraWarnings branch February 22, 2022 18:13
agocke pushed a commit to dotnet/runtime that referenced this pull request Nov 16, 2022
…dotnet/linker#2523)

This adds a source generator which generates analyzer xunit facts for the linker testcases. It discovers linker testcases by examining the referenced assembly, and avoids generating cases which already exist as analyzer facts (this requires tests to follow the existing convention for naming testcase files and facts). The generated sources are checked in to make changes easier to review.

The generated testcases only validate that the analyzer produces no unexpected warnings on the input (that is, these tests may pass even if the analyzer doesn't produce some of the expected warnings). Any tests which are currently skipped don't get this validation, so before closing out the feature branch we will want to replace skipped facts with facts that run in the allowMissingWarnings mode.

The failing tests have been disabled and are tracked in separate issues. This also contains a number of small infrastructure tweaks to match the linker's test infrastructure enough to run all of these tests.

* Add test run to check for unexpected analyzer warnings
* Allow more flexible test file organization
* Check expected warning locations
* Respect ExpectedNoWarningsAttribute
* Write generated code to disk
* Add generated sources
* Don't produce warnings for typeof(Foo<>)
* Don't crash on InvalidOperation
* Compare symbols correctly
* Don't run analyzer on .il test dependencies
* Make LinkAttributesTests partial
* Fix test infra bugs with LogContains attributes
  And check in correct suppression test generated sources
* Skip failing tests
- dotnet/linker#2578
- dotnet/linker#2415
- dotnet/linker#2579
* Fix remaining test infrastructure issues
- Support SandboxDependency with type argument
- Don't crash on SetupCompileResource with a text file
- Add analyzer ExpectedWarnings to work around lack of
  support for top-level ExpectedWarning with SourceLine/SourceColumn


Commit migrated from dotnet/linker@917830d
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.

4 participants