Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 1840df1

Browse files
authored
Log libc version in our "OS info logging test" (#27143)
* Glibc logging * Updates
1 parent 7eb6dba commit 1840df1

File tree

5 files changed

+56
-2
lines changed

5 files changed

+56
-2
lines changed

src/CoreFx.Private.TestUtilities/ref/CoreFx.Private.TestUtilities.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ public static partial class PlatformDetection
103103
public static bool IsInAppContainer { get { throw null; } }
104104
public static bool IsWinRTSupported { get { throw null; } }
105105
public static bool IsXmlDsigXsltTransformSupported { get { throw null; } }
106+
public static string LibcRelease { get { throw null; } }
107+
public static string LibcVersion { get { throw null; } }
106108
public static System.Version OSXVersion { get { throw null; } }
107109
public static int WindowsVersion { get { throw null; } }
108110
public static string GetDistroVersionString() { throw null; }

src/CoreFx.Private.TestUtilities/src/System/PlatformDetection.NetFx.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ public static partial class PlatformDetection
2424

2525
public static bool IsNetfx471OrNewer => GetFrameworkVersion() >= new Version(4, 7, 1);
2626

27+
public static string LibcRelease => "";
28+
public static string LibcVersion => "";
29+
2730
// To get the framework version we can do it throught the registry key and getting the Release value under the .NET Framework key.
2831
// the mapping to each version can be found in: https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/how-to-determine-which-versions-are-installed
2932
// everytime we ship a new version this method should be updated to include the new framework version.

src/CoreFx.Private.TestUtilities/src/System/PlatformDetection.NonNetFx.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
using System;
6+
using System.Runtime.InteropServices;
57
using Xunit;
68

79
namespace System
@@ -12,5 +14,50 @@ public static partial class PlatformDetection
1214
public static bool IsNetfx462OrNewer => false;
1315
public static bool IsNetfx470OrNewer => false;
1416
public static bool IsNetfx471OrNewer => false;
17+
18+
19+
[DllImport("libc", ExactSpelling = true, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
20+
private static extern IntPtr gnu_get_libc_release();
21+
22+
[DllImport("libc", ExactSpelling = true, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
23+
private static extern IntPtr gnu_get_libc_version();
24+
25+
/// <summary>
26+
/// If gnulibc is available, returns the release, such as "stable".
27+
/// Otherwise (eg., Windows, musl) returns "glibc_not_found".
28+
/// </summary>
29+
public static string LibcRelease
30+
{
31+
get
32+
{
33+
try
34+
{
35+
return Marshal.PtrToStringUTF8(gnu_get_libc_release());
36+
}
37+
catch (Exception e) when (e is DllNotFoundException || e is EntryPointNotFoundException)
38+
{
39+
return "glibc_not_found";
40+
}
41+
}
42+
}
43+
44+
/// <summary>
45+
/// If gnulibc is available, returns the version, such as "2.22".
46+
/// Otherwise (eg., Windows, musl) returns "glibc_not_found". (In future could run "ldd -version" for musl)
47+
/// </summary>
48+
public static string LibcVersion
49+
{
50+
get
51+
{
52+
try
53+
{
54+
return Marshal.PtrToStringUTF8(gnu_get_libc_version());
55+
}
56+
catch (Exception e) when (e is DllNotFoundException || e is EntryPointNotFoundException)
57+
{
58+
return "glibc_not_found";
59+
}
60+
}
61+
}
1562
}
1663
}

src/CoreFx.Private.TestUtilities/src/System/PlatformDetection.Windows.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public static bool IsWindowsIoTCore
7171
public static bool IsWindows7 => GetWindowsVersion() == 6 && GetWindowsMinorVersion() == 1;
7272
public static bool IsWindows8x => GetWindowsVersion() == 6 && (GetWindowsMinorVersion() == 2 || GetWindowsMinorVersion() == 3);
7373

74-
public static string GetDistroVersionString() { return "ProductType=" + GetWindowsProductType() + "InstallationType=" + GetInstallationType(); }
74+
public static string GetDistroVersionString() { return "WindowsProductType=" + GetWindowsProductType() + " WindowsInstallationType=" + GetInstallationType(); }
7575

7676
private static int s_isInAppContainer = -1;
7777

src/System.Runtime.InteropServices.RuntimeInformation/tests/DescriptionNameTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ public void DumpRuntimeInformationToConsole()
2121
string osa = RuntimeInformation.OSArchitecture.ToString();
2222
string pra = RuntimeInformation.ProcessArchitecture.ToString();
2323
string frd = RuntimeInformation.FrameworkDescription.Trim();
24+
string lcr = PlatformDetection.LibcRelease;
25+
string lcv = PlatformDetection.LibcVersion;
2426

25-
Console.WriteLine($@"{dvs} OS={osd} OSVer={osv} OSArch={osa} Arch={pra} Framework={frd}");
27+
Console.WriteLine($@"{dvs} OS={osd} OSVer={osv} OSArch={osa} Arch={pra} Framework={frd} LibcRelease={lcr} LibcVersion={lcv}");
2628
}
2729

2830
[Fact]

0 commit comments

Comments
 (0)