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

C#: Dotnet test tracer improvements. #13387

Merged
merged 8 commits into from
Jun 8, 2023

Conversation

michaelnebel
Copy link
Contributor

@michaelnebel michaelnebel commented Jun 6, 2023

It turns out that the the tracer (unconditionally) injects the property -p:UseSharedCompilation=false when dotnet test is executed.
However, if the dotnet test is applied to a library or executable it results in a dotnet error, when the property is set is added as it is not valid in this context.

In this PR we update the LUA tracer code, such that -p:UseSharedCompilation=false is not injected when dotnet test is applied to a library or executable.

@github-actions github-actions bot added the C# label Jun 6, 2023
@michaelnebel michaelnebel marked this pull request as ready for review June 7, 2023 08:39
@michaelnebel michaelnebel requested a review from a team as a code owner June 7, 2023 08:39
@michaelnebel michaelnebel requested a review from hvitved June 7, 2023 08:40
csharp/ql/lib/change-notes/2023-06-06-dotnettest.md Outdated Show resolved Hide resolved
csharp/ql/integration-tests/posix-only/dotnet_test/test.py Outdated Show resolved Hide resolved
csharp/tools/tracing-config.lua Outdated Show resolved Hide resolved
csharp/tools/tracing-config.lua Outdated Show resolved Hide resolved
Co-authored-by: Michael B. Gale <[email protected]>
@michaelnebel michaelnebel requested review from mbg and hvitved June 7, 2023 10:49
@@ -48,6 +49,14 @@ function RegisterExtractorPack(id)
dotnetRunNeedsSeparator = true
dotnetRunInjectionIndex = i + 1
end
if arg == 'test' then
testMatch = true
Copy link
Contributor

Choose a reason for hiding this comment

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

How about

  • adding match = true here,
  • remove and not testMatch on line 38,
  • replace testMatch = false on line 58 with match = false; break, and
  • replace match or testMatch on line 74 with match?

Copy link
Contributor Author

@michaelnebel michaelnebel Jun 7, 2023

Choose a reason for hiding this comment

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

Yes, we can also do that if we accept that the change also applies to dotnet run. It appears that dotnet run can also be invoked with a dll or exe file, but in this case we don't get a failure if the -p:UseSharedCompilation=false is provided.

Copy link
Collaborator

Choose a reason for hiding this comment

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

So dotnet run when provided a dll or exe will not do any compilation?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I was maybe not clear: I intended to keep the testMatch variable, so specifically on this line it would say

testMatch = true
match = true

and then keep the check if testMatch and (arg:match('%.exe$') or arg:match('%.dll')) instead of just if arg:match('%.exe$') or arg:match('%.dll')

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So dotnet run when provided a dll or exe will not do any compilation?

By closer inspection, that part is actually unclear as it is not documented as a part of dotnet run.
We will make sure to narrow the fix such that it only applies to dotnet test (which was a misunderstanding between @hvitved and me)

Copy link
Collaborator

@adityasharad adityasharad left a comment

Choose a reason for hiding this comment

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

Some high-level suggestions.

match = true
end
-- for `dotnet test`, we should not append `-p:UseSharedCompilation=false` to the command line
-- if a library or executable is being provided as an argument.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Good comment. It would be useful to include why: the arguments get passed in this case to vstest rather than msbuild.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense - I will extended the description and state that when an exe or dll is provided the call is forwarded to vstest. Thank you!

check_diagnostics()

# Explicitly build and then run tests.
run_codeql_database_create(['dotnet clean', 'rm -rf test-db', 'dotnet build -o myout', 'dotnet test myout/dotnet_test.dll'], test_db="test2-db", lang="csharp")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it feasible to have a similar test with .exe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I will make another test.

@@ -48,6 +49,14 @@ function RegisterExtractorPack(id)
dotnetRunNeedsSeparator = true
dotnetRunInjectionIndex = i + 1
end
if arg == 'test' then
testMatch = true
Copy link
Collaborator

Choose a reason for hiding this comment

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

So dotnet run when provided a dll or exe will not do any compilation?

hvitved
hvitved previously approved these changes Jun 8, 2023
Copy link
Contributor

@hvitved hvitved left a comment

Choose a reason for hiding this comment

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

Let's do a DCA run before merging.

@michaelnebel
Copy link
Contributor Author

Let's do a DCA run before merging.

Yes. I also want to add another test - working on it right now.

… get the UseSharedCompilation=false flag forwarded.
@michaelnebel
Copy link
Contributor Author

Let's do a DCA run before merging.

Yes, I will start it now.

@hvitved hvitved merged commit a896be7 into github:main Jun 8, 2023
---
category: minorAnalysis
---
* C#: Analysis of the `dotnet test` command supplied with a `dll` or `exe` file as argument no longer fails due to the addition of an erroneous `-p:SharedCompilation=false` argument.

Choose a reason for hiding this comment

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

Should be -p:UseSharedCompilation not -p:SharedCompilation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, thank you!!!
Will be fixed here: #13440

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The release process has already been started, so we can't update the change note (since it is only a minor inaccuracy we don't want to stop the release to incorporate the change note modification).
Closing the related PR.

@michaelnebel michaelnebel deleted the csharp/dotnettest branch June 13, 2023 09:27
@smitpatel
Copy link

Which release this fix will be in? We are still seeing issue in our pipelines.

@michaelnebel
Copy link
Contributor Author

Which release this fix will be in? We are still seeing issue in our pipelines.

This should be in release 2.13.4. Is that the one you are using?

@smitpatel
Copy link

@michaelnebel - Thank you. I will check the version we are using and figure out upgrade path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants