Log libc version in our "OS info logging test" (dotnet/corefx#27143)
authorDan Moseley <danmose@microsoft.com>
Fri, 16 Feb 2018 03:59:23 +0000 (19:59 -0800)
committerGitHub <noreply@github.com>
Fri, 16 Feb 2018 03:59:23 +0000 (19:59 -0800)
* Glibc logging

* Updates

Commit migrated from https://github.com/dotnet/corefx/commit/1840df10f8ea2d62ceb2b5ab2c367f4f9e54e6da

src/libraries/CoreFx.Private.TestUtilities/ref/CoreFx.Private.TestUtilities.cs
src/libraries/CoreFx.Private.TestUtilities/src/System/PlatformDetection.NetFx.cs
src/libraries/CoreFx.Private.TestUtilities/src/System/PlatformDetection.NonNetFx.cs
src/libraries/CoreFx.Private.TestUtilities/src/System/PlatformDetection.Windows.cs
src/libraries/System.Runtime.InteropServices.RuntimeInformation/tests/DescriptionNameTests.cs

index 59a8b12..cd4450a 100644 (file)
@@ -103,6 +103,8 @@ namespace System
         public static bool IsInAppContainer { get { throw null; } }
         public static bool IsWinRTSupported { get { throw null; } }
         public static bool IsXmlDsigXsltTransformSupported { get { throw null; } }
+        public static string LibcRelease { get { throw null; } }
+        public static string LibcVersion { get { throw null; } }
         public static System.Version OSXVersion { get { throw null; } }
         public static int WindowsVersion { get { throw null; } }
         public static string GetDistroVersionString() { throw null; }
index 6fb51b9..8074805 100644 (file)
@@ -24,6 +24,9 @@ namespace System
 
         public static bool IsNetfx471OrNewer => GetFrameworkVersion() >= new Version(4, 7, 1);
 
+        public static string LibcRelease => "";
+        public static string LibcVersion => "";
+
         // To get the framework version we can do it throught the registry key and getting the Release value under the .NET Framework key.
         // 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
         // everytime we ship a new version this method should be updated to include the new framework version.
index 087f2cf..8d5f5be 100644 (file)
@@ -2,6 +2,8 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 
+using System;
+using System.Runtime.InteropServices;
 using Xunit;
 
 namespace System
@@ -12,5 +14,50 @@ namespace System
         public static bool IsNetfx462OrNewer => false;
         public static bool IsNetfx470OrNewer => false;
         public static bool IsNetfx471OrNewer => false;
+
+
+        [DllImport("libc", ExactSpelling = true, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
+        private static extern IntPtr gnu_get_libc_release();
+
+        [DllImport("libc", ExactSpelling = true, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
+        private static extern IntPtr gnu_get_libc_version();
+
+        /// <summary>
+        /// If gnulibc is available, returns the release, such as "stable".
+        /// Otherwise (eg., Windows, musl) returns "glibc_not_found".
+        /// </summary>
+        public static string LibcRelease
+        {
+            get
+            {
+                try
+                {
+                    return Marshal.PtrToStringUTF8(gnu_get_libc_release());
+                }
+                catch (Exception e) when (e is DllNotFoundException || e is EntryPointNotFoundException)
+                {
+                    return "glibc_not_found";
+                }
+            }
+        }
+
+        /// <summary>
+        /// If gnulibc is available, returns the version, such as "2.22".
+        /// Otherwise (eg., Windows, musl) returns "glibc_not_found". (In future could run "ldd -version" for musl)
+        /// </summary>
+        public static string LibcVersion
+        {
+            get
+            {
+                try
+                {
+                    return Marshal.PtrToStringUTF8(gnu_get_libc_version());
+                }
+                catch (Exception e) when (e is DllNotFoundException || e is EntryPointNotFoundException)
+                {
+                    return "glibc_not_found";
+                }
+            }
+        }
     }
 }
index e92dfe9..cced49e 100644 (file)
@@ -71,7 +71,7 @@ namespace System
         public static bool IsWindows7 => GetWindowsVersion() == 6 && GetWindowsMinorVersion() == 1;
         public static bool IsWindows8x => GetWindowsVersion() == 6 && (GetWindowsMinorVersion() == 2 || GetWindowsMinorVersion() == 3);
 
-        public static string GetDistroVersionString() { return "ProductType=" + GetWindowsProductType() + "InstallationType=" + GetInstallationType(); }
+        public static string GetDistroVersionString() { return "WindowsProductType=" + GetWindowsProductType() + " WindowsInstallationType=" + GetInstallationType(); }
 
         private static int s_isInAppContainer = -1;
 
index 4432b68..f89b9bf 100644 (file)
@@ -21,8 +21,10 @@ namespace System.Runtime.InteropServices.RuntimeInformationTests
             string osa = RuntimeInformation.OSArchitecture.ToString();
             string pra = RuntimeInformation.ProcessArchitecture.ToString();
             string frd = RuntimeInformation.FrameworkDescription.Trim();
+            string lcr = PlatformDetection.LibcRelease;
+            string lcv = PlatformDetection.LibcVersion;
 
-            Console.WriteLine($@"{dvs} OS={osd} OSVer={osv} OSArch={osa} Arch={pra} Framework={frd}");
+            Console.WriteLine($@"{dvs} OS={osd} OSVer={osv} OSArch={osa} Arch={pra} Framework={frd} LibcRelease={lcr} LibcVersion={lcv}");
         }
 
         [Fact]