< Summary

Information
Class: InferenceEngine.Core.Diagnostics.HostPlatformDetector
Assembly: InferenceEngine.Core
File(s): /home/runner/work/inference-engine-lib/inference-engine-lib/InferenceEngine.Core/Diagnostics/HostPlatform.cs
Line coverage
100%
Covered lines: 26
Uncovered lines: 0
Coverable lines: 26
Total lines: 65
Line coverage: 100%
Branch coverage
100%
Covered branches: 18
Total branches: 18
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_IsOSPlatformProbe()100%11100%
.cctor()100%11100%
get_ProcessArchitectureProbe()100%11100%
Current()100%1818100%

File(s)

/home/runner/work/inference-engine-lib/inference-engine-lib/InferenceEngine.Core/Diagnostics/HostPlatform.cs

#LineLine coverage
 1using System.Runtime.InteropServices;
 2
 3namespace InferenceEngine.Core.Diagnostics;
 4
 5/// <summary>Identifies the host platform and architecture.</summary>
 6public enum HostPlatform
 7{
 8    Unknown = 0,
 9    LinuxX64,
 10    LinuxArm64,
 11    WinX64,
 12    WinArm64,
 13    OSX64,
 14    OSXArm64,
 15}
 16
 17/// <summary>
 18/// Detects the host platform at runtime. Provided for convenience; the primary
 19/// API for platform information is <see cref="InferenceEngineInfo.Platform"/>.
 20/// </summary>
 21public static class HostPlatformDetector
 22{
 23    // Test seam: the OS/architecture probes are injectable so tests can drive every
 24    // branch of Current() hermetically on any host (the real RuntimeInformation calls
 25    // answer for the host OS only, leaving the other branches permanently uncovered).
 26    // Internal and nullable-probe-free: production callers always go through Current(),
 27    // whose public surface is unchanged. Tests must restore the defaults afterwards.
 22228    internal static Func<string, bool> IsOSPlatformProbe { get; set; } =
 17029        static name => RuntimeInformation.IsOSPlatform(OSPlatform.Create(name));
 20730    internal static Func<Architecture> ProcessArchitectureProbe { get; set; } =
 17031        static () => RuntimeInformation.ProcessArchitecture;
 32
 33    /// <summary>Detects the current host platform. See <see cref="HostPlatform"/>.</summary>
 34    public static HostPlatform Current()
 35    {
 18336        if (IsOSPlatformProbe("Linux"))
 37        {
 17538            return ProcessArchitectureProbe() switch
 17539            {
 17240                Architecture.X64 => HostPlatform.LinuxX64,
 141                Architecture.Arm64 => HostPlatform.LinuxArm64,
 242                _ => HostPlatform.Unknown,
 17543            };
 44        }
 845        if (IsOSPlatformProbe("OSX"))
 46        {
 347            return ProcessArchitectureProbe() switch
 348            {
 149                Architecture.X64 => HostPlatform.OSX64,
 150                Architecture.Arm64 => HostPlatform.OSXArm64,
 151                _ => HostPlatform.Unknown,
 352            };
 53        }
 554        if (IsOSPlatformProbe("Windows"))
 55        {
 356            return ProcessArchitectureProbe() switch
 357            {
 158                Architecture.X64 => HostPlatform.WinX64,
 159                Architecture.Arm64 => HostPlatform.WinArm64,
 160                _ => HostPlatform.Unknown,
 361            };
 62        }
 263        return HostPlatform.Unknown;
 64    }
 65}