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

Console Output in Unit Tests #27561

Closed
nbaztec opened this issue Oct 7, 2018 · 8 comments
Closed

Console Output in Unit Tests #27561

nbaztec opened this issue Oct 7, 2018 · 8 comments
Labels
area-Meta question Answer questions and provide assistance, not an issue with source code or documentation.
Milestone

Comments

@nbaztec
Copy link
Contributor

nbaztec commented Oct 7, 2018

I'm facing a issue where a particular test fails for exactly a single target, however there's no way that I can debug the actual code to fix it. I've tried with Console.WriteLine but of course the assembly isn't included within System.Net.Sockets. System.Diagnostics.Debug doesn't show up on the test log either.

Any ideas?

@stephentoub
Copy link
Member

stephentoub commented Oct 7, 2018

From within a corefx unit test you should definitely be able to use Console.WriteLine. If you mean using it within the product code in System.Net.Sockets, you could do something like:

#pragma warning disable BCL0015
[DllImport("msvcrt")]
private static extern int printf(string format, string arg);
private static void WriteLine(string s) => printf("%s\r\n", s);

on Windows, or:

#pragma warning disable BCL0015
[DllImport("libc")]
private static extern int printf(string format, string arg);
private static void WriteLine(string s) => printf("%s\n", s);

on Unix.

Or you could locally/temporarily modify https://github.com/dotnet/corefx/blob/d6646295b889daf9cf46caae1f9097b719873439/src/System.Net.Sockets/src/System.Net.Sockets.csproj#L382-L402 to include System.Console and then just use Console.WriteLine.

@stephentoub
Copy link
Member

What's the test btw? Is it some existing test that's failing for you without any changes to System.Net.Sockets?

@nbaztec
Copy link
Contributor Author

nbaztec commented Oct 7, 2018

Thanks I'll try that, it's this test: https://mc.dot.net/#/user/nbaztec/pr~2Fjenkins~2Fdotnet~2Fcorefx~2Fmaster~2F/test~2Ffunctional~2Fcli~2F/da29f1b45f466d29d0049f0c02535bb1a668fbde/workItem/System.Net.Sockets.Tests

basically I need to see the output of DNS resolution since all the other assertions are passing.

@nbaztec nbaztec closed this as completed Oct 7, 2018
@nbaztec
Copy link
Contributor Author

nbaztec commented Oct 7, 2018

@nbaztec nbaztec reopened this Oct 7, 2018
@stephentoub
Copy link
Member

stephentoub commented Oct 7, 2018

Sadly I still couldn't get the console output after adding System.Console

I see output like:

2018-10-07 16:01:42,330: INFO: proc(55): run_and_log_output: Output: �[mlen: 1
2018-10-07 16:01:42,330: INFO: proc(55): run_and_log_output: Output: 127.0.0.1 InterNetwork InterNetworkV6

in those logs... what's not working?

@nbaztec
Copy link
Contributor Author

nbaztec commented Oct 7, 2018

I see, interestingly all the log outputs are missing from Windows.10.Amd64.ClientRS4.Open-x86:Release as if it uses an entirely different codebase.

@ViktorHofer
Copy link
Member

ViktorHofer commented Oct 7, 2018

That's .NET Framework. If your project doesn't have a netfx configuration it will just run the official assembly from the GAC. Therefore your changes and outputs are not run.

@nbaztec
Copy link
Contributor Author

nbaztec commented Oct 7, 2018

Interesting, I guessed so but wasn't sure. I don't think I will be able to patch this bug it the original GAC, as such what might be the potential solutions - we can take this discussion to dotnet/corefx#32504 since the originnal answer is sufficient, just my code is never executed.

This bug is single handedly bothering me since a week now and I'm unable to come to a solution.
Thanks for the help.

@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 3.0 milestone Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Meta question Answer questions and provide assistance, not an issue with source code or documentation.
Projects
None yet
Development

No branches or pull requests

4 participants