Skip to content

Try to find memory usage in LibraryImportTests #114707

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eng/testing/xunit/xunit.console.targets
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<ItemGroup>
<!-- Configures xunit to not print out passing tests with output when diagnostic messages are enabled. -->
<SetScriptCommands Condition="'$(TargetOS)' == 'windows'" Include="set XUNIT_HIDE_PASSING_OUTPUT_DIAGNOSTICS=1" />
<SetScriptCommands Condition="'$(TargetOS)' != 'windows'" Include="export XUNIT_HIDE_PASSING_OUTPUT_DIAGNOSTICS=1" />
<!-- <SetScriptCommands Condition="'$(TargetOS)' != 'windows'" Include="export XUNIT_HIDE_PASSING_OUTPUT_DIAGNOSTICS=1" /> -->
</ItemGroup>

<PropertyGroup Condition="'$(BundleXunitRunner)' == 'true'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Runtime.InteropServices.Marshalling;
using SharedTypes;
using Xunit;
using Xunit.Abstractions;

namespace LibraryImportGenerator.IntegrationTests
{
Expand Down Expand Up @@ -184,6 +185,11 @@ public static partial BoolStruct[] NegateBools(

public class ArrayTests
{
public ArrayTests(ITestOutputHelper output)
{
PrintTopHelper.PrintOutputOfTopCommand(output);
}

private int[] GetIntArray() => new[] { 1, 5, 79, 165, 32, 3 };

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using SharedTypes;

using Xunit;
using Xunit.Abstractions;

namespace LibraryImportGenerator.IntegrationTests
{
Expand Down Expand Up @@ -45,7 +46,7 @@ public static partial class IntStructExtensions
{
[LibraryImport(NativeExportsNE.NativeExportsNE_Binary, EntryPoint = "blittablestructs_return_instance")]
public static partial IntFields DoubleIntFields(this IntFields result);

[LibraryImport(NativeExportsNE.NativeExportsNE_Binary, EntryPoint = "blittablestructs_double_intfields_refreturn")]
public static partial void DoubleIntFieldsOutReturn(
this IntFields input,
Expand All @@ -54,6 +55,11 @@ public static partial void DoubleIntFieldsOutReturn(

public class BlittableStructTests
{
public BlittableStructTests(ITestOutputHelper output)
{
PrintTopHelper.PrintOutputOfTopCommand(output);
}

[Fact]
public void ValidateIntFields()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Runtime.InteropServices;

using Xunit;
using Xunit.Abstractions;

namespace LibraryImportGenerator.IntegrationTests
{
Expand Down Expand Up @@ -71,6 +72,11 @@ partial class NativeExportsNE

public class BooleanTests
{
public BooleanTests(ITestOutputHelper output)
{
PrintTopHelper.PrintOutputOfTopCommand(output);
}

// See definition of Windows' VARIANT_BOOL
const ushort VARIANT_TRUE = unchecked((ushort)-1);
const ushort VARIANT_FALSE = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Runtime.InteropServices.Marshalling;
using SharedTypes;
using Xunit;
using Xunit.Abstractions;

namespace LibraryImportGenerator.IntegrationTests
{
Expand Down Expand Up @@ -109,6 +110,11 @@ public static partial void NegateBoolsRef2D_ClearMarshalling(

public class CollectionMarshallingFails
{
public CollectionMarshallingFails(ITestOutputHelper output)
{
PrintTopHelper.PrintOutputOfTopCommand(output);
}

[Fact]
public void UTFStringConversionFailures()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Text;

using Xunit;
using Xunit.Abstractions;

namespace LibraryImportGenerator.IntegrationTests
{
Expand Down Expand Up @@ -192,6 +193,11 @@ public void Free() { }

public class CollectionTests
{
public CollectionTests(ITestOutputHelper output)
{
PrintTopHelper.PrintOutputOfTopCommand(output);
}

[Fact]
public void BlittableElementColllection_ByValue()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using SharedTypes;

using Xunit;
using Xunit.Abstractions;

namespace LibraryImportGenerator.IntegrationTests
{
Expand Down Expand Up @@ -119,6 +120,11 @@ public void Free() {}

public class CustomMarshallingTests
{
public CustomMarshallingTests(ITestOutputHelper output)
{
PrintTopHelper.PrintOutputOfTopCommand(output);
}

[Fact]
public void NonBlittableStructWithFree()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Runtime.InteropServices;

using Xunit;
using Xunit.Abstractions;

namespace LibraryImportGenerator.IntegrationTests
{
Expand All @@ -22,6 +23,11 @@ partial class NativeExportsNE

public class DelegateTests
{
public DelegateTests(ITestOutputHelper output)
{
PrintTopHelper.PrintOutputOfTopCommand(output);
}

[Fact]
public void DelegateIsKeptAliveDuringCall()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Runtime.InteropServices;

using Xunit;
using Xunit.Abstractions;

namespace LibraryImportGenerator.IntegrationTests
{
Expand Down Expand Up @@ -35,6 +36,11 @@ public partial class FunctionPointer

public class FunctionPointerTests
{
public FunctionPointerTests(ITestOutputHelper output)
{
PrintTopHelper.PrintOutputOfTopCommand(output);
}

private static bool wasCalled;

[Fact]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

using System;
using Xunit.Abstractions;

internal class PrintTopHelper
{
public static void PrintOutputOfTopCommand(ITestOutputHelper output)
{
if (Environment.OSVersion.Platform == PlatformID.Unix)
{
// grab the output of the `top` command to get the memory usage
// and CPU usage of the process
var process = new System.Diagnostics.Process
{
StartInfo = new System.Diagnostics.ProcessStartInfo
{
FileName = "top",
Arguments = "-b -n 1",
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true
}
};

process.Start();
string outputText = process.StandardOutput.ReadToEnd();
process.WaitForExit();

output.WriteLine(outputText);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

using Microsoft.Win32.SafeHandles;
using Xunit;
using Xunit.Abstractions;

namespace LibraryImportGenerator.IntegrationTests
{
Expand Down Expand Up @@ -49,6 +50,11 @@ protected override bool ReleaseHandle()

public class SafeHandleTests
{
public SafeHandleTests(ITestOutputHelper output)
{
PrintTopHelper.PrintOutputOfTopCommand(output);
}

[Fact]
public void ReturnValue_CreatesSafeHandle()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Text;

using Xunit;
using Xunit.Abstractions;

namespace LibraryImportGenerator.IntegrationTests
{
Expand Down Expand Up @@ -48,6 +49,11 @@ public partial class Span

public class SpanTests
{
public SpanTests(ITestOutputHelper output)
{
PrintTopHelper.PrintOutputOfTopCommand(output);
}

[Fact]
public void BlittableElementSpanMarshalledToNativeAsExpected()
{
Expand Down
Loading