Skip to content

Commit

Permalink
Add memory related logging to S.R.IS tests in Helix (dotnet#46517)
Browse files Browse the repository at this point in the history
* Log more info in Helix

* feedback:

* lambda
  • Loading branch information
danmoseley committed Jan 4, 2021
1 parent 5ac16c4 commit 32586d6
Showing 1 changed file with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using Xunit;

namespace System.Runtime.InteropServices.RuntimeInformationTests
{
public class DescriptionNameTests
{
// When running both inner and outer loop together, dump only once
private static bool s_dumpedRuntimeInfo = false;

private static readonly bool s_isInHelix = Environment.GetEnvironmentVariables().Keys.Cast<string>().Where(key => key.StartsWith("HELIX")).Any();

[Fact]
[PlatformSpecific(~TestPlatforms.Browser)] // throws PNSE when binariesLocation is not an empty string.
public void DumpRuntimeInformationToConsole()
{
if (s_dumpedRuntimeInfo || !s_isInHelix)
return;

s_dumpedRuntimeInfo = true;

// Not really a test, but useful to dump a variety of information to the test log to help
// debug environmental issues, in particular in CI

Expand Down Expand Up @@ -119,13 +131,26 @@ public void DumpRuntimeInformationToConsole()
if (osd.Contains("Linux"))
{
// Dump several procfs files and /etc/os-release
foreach (string path in new string[] { "/proc/self/mountinfo", "/proc/self/cgroup", "/proc/self/limits", "/etc/os-release" })
foreach (string path in new string[] { "/proc/self/mountinfo", "/proc/self/cgroup", "/proc/self/limits", "/etc/os-release", "/etc/sysctl.conf", "/proc/meminfo" })
{
Console.WriteLine($"### CONTENTS OF \"{path}\":");
try
{
using (Process cat = Process.Start("cat", path))
using (Process cat = new Process())
{
cat.StartInfo.FileName = "cat";
cat.StartInfo.Arguments = path;
cat.StartInfo.RedirectStandardOutput = true;
cat.OutputDataReceived += (sender, e) =>
{
string trimmed = e.Data?.Trim();
if (!string.IsNullOrEmpty(trimmed) && trimmed[0] != '#') // skip comments in files
{
Console.WriteLine(e.Data);
}
};
cat.Start();
cat.BeginOutputReadLine();
cat.WaitForExit();
}
}
Expand All @@ -137,6 +162,16 @@ public void DumpRuntimeInformationToConsole()
}
}

[Fact]
[OuterLoop]
[PlatformSpecific(~TestPlatforms.Browser)] // throws PNSE when binariesLocation is not an empty string.
public void DumpRuntimeInformationToConsoleOuter()
{
// Outer loop runs don't run inner loop tests.
// But we want to log this data for any Helix run.
DumpRuntimeInformationToConsole();
}

[Fact]
[SkipOnTargetFramework(~TargetFrameworkMonikers.Netcoreapp)]
public void VerifyRuntimeNameOnNetCoreApp()
Expand Down

0 comments on commit 32586d6

Please sign in to comment.