Merged PR 785975: Probing unset mount should not cause graph (engine) cache miss

Probing unset mount should not cause graph (engine) cache miss

Related work items: #2180048
This commit is contained in:
Iman Narasamdya 2024-05-20 22:23:30 +00:00
Родитель 376950b0f0
Коммит dffd38106e
3 изменённых файлов: 163 добавлений и 7 удалений

Просмотреть файл

@ -837,7 +837,7 @@ namespace BuildXL.Engine
}
[SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "ms")]
private static MatchResult? MatchesReader(
internal static MatchResult? MatchesReader(
LoggingContext loggingContext,
BinaryReader reader,
FileContentTable fileContentTable,
@ -921,7 +921,7 @@ namespace BuildXL.Engine
{
if (previousValue != UnsetVariableMarker)
{
// The previously consumed environment variable is not known and was not previously unset.
// The previously consumed environment variable is set with a value.
result.MissType = GraphCacheMissReason.EnvironmentVariableChanged;
result.FirstMissIdentifier = string.Format(CultureInfo.InvariantCulture, Strings.InputTracker_EnvironmentVariableRemoved, key);
Logger.Log.InputTrackerDetectedEnvironmentVariableChanged(loggingContext, key, previousValue, UnsetVariableMarker);
@ -958,11 +958,14 @@ namespace BuildXL.Engine
}
else
{
// The previously used mount is not known
result.MissType = GraphCacheMissReason.MountChanged;
result.FirstMissIdentifier = string.Format(CultureInfo.InvariantCulture, Strings.InputTracker_MountRemoved, mountName, previousPath);
Logger.Log.InputTrackerDetectedMountChanged(loggingContext, mountName, previousPath, string.Empty);
return result;
if (!string.IsNullOrEmpty(previousPath))
{
// The previously used mount is known to have a path.
result.MissType = GraphCacheMissReason.MountChanged;
result.FirstMissIdentifier = string.Format(CultureInfo.InvariantCulture, Strings.InputTracker_MountRemoved, mountName, previousPath);
Logger.Log.InputTrackerDetectedMountChanged(loggingContext, mountName, previousPath, string.Empty);
return result;
}
}
}

Просмотреть файл

@ -0,0 +1,150 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System.Collections.Generic;
using System.IO;
using System.Text;
using BuildXL.Engine;
using BuildXL.Storage;
using BuildXL.Utilities.Configuration;
using BuildXL.Utilities.Configuration.Mutable;
using BuildXL.Utilities.Core;
using BuildXL.Utilities.Instrumentation.Common;
using Test.BuildXL.TestUtilities.Xunit;
using Xunit;
using Xunit.Abstractions;
namespace Test.BuildXL.Engine
{
[TestClassIfSupported(requiresWindowsBasedOperatingSystem: true)]
public class InputTrackerTests : TemporaryStorageTestBase
{
public InputTrackerTests(ITestOutputHelper output)
: base(output)
{
}
[Fact]
public void TestProbeUnsetEnvVar()
{
var loggingContext = new LoggingContext("Test");
BuildXLContext buildXLContext = BuildXLContext.CreateInstanceForTesting();
string fileTrackerPath = GetFullPath("fileTracker");
FileContentTable fileContentTable = FileContentTable.CreateStub(loggingContext);
var graphFingerprint = new GraphFingerprint(CompositeGraphFingerprint.Zero, CompositeGraphFingerprint.Zero);
InputTracker inputTracker = InputTracker.Create(
loggingContext,
fileContentTable,
JournalState.DisabledJournal,
graphFingerprint.ExactFingerprint);
using var stream = new MemoryStream();
using (var writer = new BinaryWriter(stream, Encoding.UTF8, leaveOpen: true))
{
inputTracker.WriteToFile(
writer,
buildXLContext.PathTable,
new Dictionary<string, string>(1)
{
{ "UnsetEnvVar", null } // Unset environment variable that got probed.
},
new Dictionary<string, IMount>(0),
fileTrackerPath);
}
stream.Position = 0;
using (var reader = new BinaryReader(stream, Encoding.UTF8))
{
var configuration = new CommandLineConfiguration()
{
Startup = new StartupConfiguration()
{
ConfigFile = AbsolutePath.Create(buildXLContext.PathTable, Path.Combine(TemporaryDirectory, "config.dc"))
}
};
BuildXLEngine.PopulateLoggingAndLayoutConfiguration(configuration, buildXLContext.PathTable, bxlExeLocation: null, inTestMode: true);
MountsTable mountsTable = MountsTable.CreateAndRegister(loggingContext, buildXLContext, configuration, new Dictionary<string, string>(0));
mountsTable.CompleteInitialization();
InputTracker.MatchResult? matchResult = InputTracker.MatchesReader(
loggingContext,
reader,
fileContentTable,
JournalState.DisabledJournal,
default,
fileTrackerPath,
BuildParameters.GetFactory().PopulateFromDictionary([]),
mountsTable,
graphFingerprint,
1,
configuration,
true);
XAssert.IsTrue(matchResult.HasValue);
XAssert.IsTrue(matchResult.Value.Matches, $"Match result: {matchResult.Value.MissType}");
}
}
[Fact]
public void TestProbeUnknownMount()
{
var loggingContext = new LoggingContext("Test");
BuildXLContext buildXLContext = BuildXLContext.CreateInstanceForTesting();
string fileTrackerPath = GetFullPath("fileTracker");
FileContentTable fileContentTable = FileContentTable.CreateStub(loggingContext);
var graphFingerprint = new GraphFingerprint(CompositeGraphFingerprint.Zero, CompositeGraphFingerprint.Zero);
InputTracker inputTracker = InputTracker.Create(
loggingContext,
fileContentTable,
JournalState.DisabledJournal,
graphFingerprint.ExactFingerprint);
using var stream = new MemoryStream();
using (var writer = new BinaryWriter(stream, Encoding.UTF8, leaveOpen: true))
{
inputTracker.WriteToFile(
writer,
buildXLContext.PathTable,
new Dictionary<string, string>(0),
new Dictionary<string, IMount>(1)
{
{ "UnknownMount", null } // Unknown mount that got probed.
},
fileTrackerPath);
}
stream.Position = 0;
using (var reader = new BinaryReader(stream, Encoding.UTF8))
{
var configuration = new CommandLineConfiguration()
{
Startup = new StartupConfiguration()
{
ConfigFile = AbsolutePath.Create(buildXLContext.PathTable, Path.Combine(TemporaryDirectory, "config.dc"))
}
};
BuildXLEngine.PopulateLoggingAndLayoutConfiguration(configuration, buildXLContext.PathTable, bxlExeLocation: null, inTestMode: true);
MountsTable mountsTable = MountsTable.CreateAndRegister(loggingContext, buildXLContext, configuration, new Dictionary<string, string>(0));
mountsTable.CompleteInitialization();
InputTracker.MatchResult? matchResult = InputTracker.MatchesReader(
loggingContext,
reader,
fileContentTable,
JournalState.DisabledJournal,
default,
fileTrackerPath,
BuildParameters.GetFactory().PopulateFromDictionary([]),
mountsTable,
graphFingerprint,
1,
configuration,
true);
XAssert.IsTrue(matchResult.HasValue);
XAssert.IsTrue(matchResult.Value.Matches, $"Match result: {matchResult.Value.MissType}");
}
}
}
}

Просмотреть файл

@ -104,6 +104,9 @@ namespace Test.BuildXL.Utilities
XAssert.IsFalse(AbsolutePath.TryCreate(pt, @"C:\foo\bar\filename:stream", out AbsolutePath _));
XAssert.IsFalse(AbsolutePath.TryCreate(pt, @"C:\foo\bar\filename:stream:$DATA", out AbsolutePath _));
XAssert.IsFalse(AbsolutePath.TryCreate(pt, @"C:\foo\bar\filename::$DATA", out AbsolutePath _));
// Try create an empty path.
XAssert.IsFalse(AbsolutePath.TryCreate(pt, string.Empty, out AbsolutePath _));
}
[Fact]