|
| 1 | +// <copyright file="ProcessBasicCheckTests.cs" company="Datadog"> |
| 2 | +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. |
| 3 | +// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. |
| 4 | +// </copyright> |
| 5 | + |
| 6 | +using System.Collections.Generic; |
| 7 | +using Datadog.Trace.TestHelpers; |
| 8 | +using Datadog.Trace.Tools.dd_dotnet.Checks; |
| 9 | +using Datadog.Trace.Tools.Shared; |
| 10 | +using FluentAssertions; |
| 11 | +using Xunit; |
| 12 | + |
| 13 | +namespace Datadog.Trace.Tools.dd_dotnet.Tests |
| 14 | +{ |
| 15 | + public class ProcessBasicCheckTests |
| 16 | + { |
| 17 | + [Theory] |
| 18 | + [InlineData("/app/datadog/linux-x64/Datadog.Trace.ClrProfiler.Native.so")] |
| 19 | + [InlineData("/app/datadog/linux-musl-x64/Datadog.Trace.ClrProfiler.Native.so")] |
| 20 | + [InlineData("/app/datadog/linux-arm64/Datadog.Trace.ClrProfiler.Native.so")] |
| 21 | + [InlineData("/app/datadog/linux-musl-arm64/Datadog.Trace.ClrProfiler.Native.so")] |
| 22 | + public void DetectsBundleWhenMainModuleDirectoryMatchesAppDirectory(string profilerPath) |
| 23 | + { |
| 24 | + var process = CreateProcessInfo(mainModuleDirectory: "/app"); |
| 25 | + |
| 26 | + var result = ProcessBasicCheck.TracingWithBundle(new[] { profilerPath }, process); |
| 27 | + |
| 28 | + result.Should().BeTrue(); |
| 29 | + } |
| 30 | + |
| 31 | + [SkippableTheory] |
| 32 | + [InlineData(@"\datadog\win-x64\Datadog.Trace.ClrProfiler.Native.dll")] |
| 33 | + [InlineData(@"\datadog\win-x86\Datadog.Trace.ClrProfiler.Native.dll")] |
| 34 | + public void DetectsBundleWhenMainModuleDirectoryMatchesAppDirectoryOnWindows(string bundleSuffix) |
| 35 | + { |
| 36 | + SkipOn.Platform(SkipOn.PlatformValue.Linux); |
| 37 | + SkipOn.Platform(SkipOn.PlatformValue.MacOs); |
| 38 | + |
| 39 | + var process = CreateProcessInfo(mainModuleDirectory: @"C:\app"); |
| 40 | + |
| 41 | + var result = ProcessBasicCheck.TracingWithBundle(new[] { @"C:\app" + bundleSuffix }, process); |
| 42 | + |
| 43 | + result.Should().BeTrue(); |
| 44 | + } |
| 45 | + |
| 46 | + [Fact] |
| 47 | + public void DetectsBundleWhenLaunchedAsDotnetDll() |
| 48 | + { |
| 49 | + // GH-7214: `dotnet app.dll` launches (e.g. Azure App Service Linux) report the |
| 50 | + // dotnet host as MainModule, not the app's own directory. |
| 51 | + var process = CreateProcessInfo(mainModuleDirectory: "/usr/share/dotnet"); |
| 52 | + var profilerPath = "/app/datadog/linux-x64/Datadog.Trace.ClrProfiler.Native.so"; |
| 53 | + |
| 54 | + var result = ProcessBasicCheck.TracingWithBundle(new[] { profilerPath }, process); |
| 55 | + |
| 56 | + result.Should().BeTrue(); |
| 57 | + } |
| 58 | + |
| 59 | + [Theory] |
| 60 | + [InlineData(null)] |
| 61 | + [InlineData("/opt/datadog/Datadog.Trace.ClrProfiler.Native.so")] |
| 62 | + [InlineData("/app/datadog/linux-x64/Datadog.Tracer.Native.so")] |
| 63 | + public void DoesNotDetectBundleForNonBundlePaths(string profilerPath) |
| 64 | + { |
| 65 | + var process = CreateProcessInfo(mainModuleDirectory: "/app"); |
| 66 | + |
| 67 | + var result = ProcessBasicCheck.TracingWithBundle(new[] { profilerPath }, process); |
| 68 | + |
| 69 | + result.Should().BeFalse(); |
| 70 | + } |
| 71 | + |
| 72 | + [Fact] |
| 73 | + public void DetectsBundleWhenAnyProfilerPathValueMatches() |
| 74 | + { |
| 75 | + var process = CreateProcessInfo(mainModuleDirectory: "/app"); |
| 76 | + string[] profilerPathValues = |
| 77 | + { |
| 78 | + null, |
| 79 | + "/opt/datadog/linux-x64/Datadog.Trace.ClrProfiler.Native.so", |
| 80 | + "/app/datadog/linux-x64/Datadog.Trace.ClrProfiler.Native.so" |
| 81 | + }; |
| 82 | + |
| 83 | + var result = ProcessBasicCheck.TracingWithBundle(profilerPathValues, process); |
| 84 | + |
| 85 | + result.Should().BeTrue(); |
| 86 | + } |
| 87 | + |
| 88 | + private static ProcessInfo CreateProcessInfo(string mainModuleDirectory) |
| 89 | + { |
| 90 | + return new ProcessInfo( |
| 91 | + "app", |
| 92 | + 1, |
| 93 | + new Dictionary<string, string>(), |
| 94 | + mainModule: $"{mainModuleDirectory}/app", |
| 95 | + modules: System.Array.Empty<string>()); |
| 96 | + } |
| 97 | + } |
| 98 | +} |
0 commit comments