public void DBCreatedAndPopulated() { Configuration.Logging.LogExecution = true; var file = FileArtifact.CreateOutputFile(Combine(TestDirPath, "blah.txt")); var pipA = CreateAndSchedulePipBuilder(new [] { Operation.WriteFile(file), }).Process; var pipB = CreateAndSchedulePipBuilder(new [] { Operation.ReadFile(file), Operation.WriteFile(CreateOutputFileArtifact()) }).Process; var buildA = RunScheduler().AssertSuccess(); var analyzerRes = RunAnalyzer(buildA).AssertSuccess(); XAssert.AreNotEqual(Directory.GetFiles(OutputDirPath.ToString(Context.PathTable), "*.sst").Length, 0); }
public void InvalidTranslateFrom() { CommandLineUtilities.Option option = default(CommandLineUtilities.Option); option.Name = "translateDirectory"; option.Value = m_helloTestPath + "::" + m_worldTestPath + "<" + m_bigTestPath; try { Args.ParseTranslatePathOption(m_pathTable, option); } catch (Exception e) { XAssert.AreEqual( "The value '" + m_helloTestPath + "::" + m_worldTestPath + "' provided for the /translateDirectory argument is invalid. It should have a valid translateFrom path", e.GetLogEventMessage()); return; } if (!OperatingSystemHelper.IsUnixOS) { XAssert.Fail("Should have gotten an exception."); } }
public async Task TestRegisterFileForBuildManifestAsync() { string dropName = "DropName"; string relativePath = "/a/b"; var path = X("/x/y/z"); var fileArtifact = OutputFile(path); var hash = ContentHash.Random(); using var apiClient = CreateApiClient(ipcOperation => { var cmd = (RegisterFileForBuildManifestCommand)Command.Deserialize(ipcOperation.Payload); XAssert.AreEqual(dropName, cmd.DropName); XAssert.AreEqual(relativePath, cmd.RelativePath); XAssert.AreEqual(hash, cmd.Hash); XAssert.AreEqual(fileArtifact, cmd.File); XAssert.AreEqual(path, cmd.FullFilePath); return(IpcResult.Success(cmd.RenderResult(true))); }); var maybeResult = await apiClient.RegisterFileForBuildManifest(dropName, relativePath, hash, fileArtifact, path); XAssert.PossiblySucceeded(maybeResult); XAssert.AreEqual(true, maybeResult.Result); }
public void RewrittenPreservedOutputsAreStoredInCache() { Configuration.Sandbox.UnsafeSandboxConfigurationMutable.PreserveOutputs = PreserveOutputsMode.Enabled; FileArtifact rewrittenOutput; Process preservingProcessA; Process preservingProcessB; ScheduleRewriteProcess(out rewrittenOutput, out preservingProcessA, out preservingProcessB); // No cache hit RunScheduler().AssertCacheMiss(preservingProcessA.PipId, preservingProcessB.PipId); string outputContents = File.ReadAllText(ArtifactToString(rewrittenOutput)); XAssert.AreEqual(CONTENT_TWICE, outputContents); File.Delete(ArtifactToString(rewrittenOutput)); // Cache hit RunScheduler().AssertCacheHit(preservingProcessA.PipId, preservingProcessB.PipId); outputContents = File.ReadAllText(ArtifactToString(rewrittenOutput)); XAssert.AreEqual(CONTENT_TWICE, outputContents); }
public void VolumeEnumerationFindsKnownVolumeSerial() { XAssert.IsTrue(Directory.Exists(TemporaryDirectory)); List <Tuple <VolumeGuidPath, ulong> > volumeInfo = FileUtilities.ListVolumeGuidPathsAndSerials(); XAssert.IsTrue(volumeInfo.Count > 0); SafeFileHandle directoryHandle = OpenTemporaryDirectory(); ulong serial; using (directoryHandle) { serial = FileUtilities.GetVolumeSerialNumberByHandle(directoryHandle); XAssert.AreNotEqual(0, serial, "A volume serial of zero is very unlikely"); } List <VolumeGuidPath> matchingVolumePaths = volumeInfo.Where(t => t.Item2 == serial).Select(t => t.Item1).ToList(); XAssert.AreNotEqual(0, matchingVolumePaths.Count, "No volumes were found matching the serial {0:X}", serial); XAssert.AreEqual(1, matchingVolumePaths.Count, "Serial collision for {0:X}", serial); }
public void GetReparsePointTarget() { string symlinkPath = GetFullPath("symlink"); // the length of the target path must be at least 128 chars, so we could properly test the parsing // of the struct returned from DeviceIoControl. string symlinkTarget = PathGeneratorUtilities.GetAbsolutePath("Z", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), $"{Guid.NewGuid().ToString()}.txt"); XAssert.IsTrue(symlinkTarget.Length >= 128); XAssert.IsTrue(FileUtilities.TryCreateSymbolicLink(symlinkPath, symlinkTarget, isTargetFile: true)); Possible <ReparsePointType> reparsePointType = FileUtilities.TryGetReparsePointType(symlinkPath); XAssert.IsTrue(reparsePointType.Succeeded); XAssert.IsTrue(reparsePointType.Result == ReparsePointType.SymLink); using (var symlinkHandle = OpenHandleForReparsePoint(symlinkPath)) { var possibleSymlinkTargetToCheck = FileUtilities.TryGetReparsePointTarget(symlinkHandle, symlinkPath); XAssert.IsTrue(possibleSymlinkTargetToCheck.Succeeded, I($"Failed to get the reparse point target for '{symlinkPath}'")); XAssert.AreEqual(symlinkTarget, possibleSymlinkTargetToCheck.Result); } }
public void TestEstablishAndQueryIdentity() { string fullPath = WriteFile(TestFileAName, TestFileAName); VersionedFileIdentity id1; using (var stream = File.Open(fullPath, FileMode.Open)) { var mayBeId = VersionedFileIdentity.TryEstablishStrong(stream.SafeFileHandle, true); XAssert.IsTrue(mayBeId.Succeeded); id1 = mayBeId.Result; } VersionedFileIdentity id2; using (var stream = File.Open(fullPath, FileMode.Open)) { var mayBeId = VersionedFileIdentity.TryQuery(stream.SafeFileHandle); XAssert.IsTrue(mayBeId.Succeeded); id2 = mayBeId.Result; } XAssert.AreEqual(id1.Usn, id2.Usn); }
private static ObservedPathSet SerializeRoundTripAndAssertEquivalent(PathTable pathTable, ObservedPathSet original, PathExpander pathExpander = null) { using (var mem = new MemoryStream()) { using (var writer = new BuildXLWriter(stream: mem, debug: true, leaveOpen: true, logStats: true)) { original.Serialize(pathTable, writer, preserveCasing: false, pathExpander); } mem.Position = 0; ObservedPathSet roundtrip; using (var reader = new BuildXLReader(stream: mem, debug: true, leaveOpen: true)) { var maybeRoundtrip = ObservedPathSet.TryDeserialize(pathTable, reader, pathExpander); XAssert.IsTrue(maybeRoundtrip.Succeeded, "Failed to deserialize a path set unexpectedly"); roundtrip = maybeRoundtrip.Result; } ObservedPathSetTestUtilities.AssertPathSetsEquivalent(original, roundtrip); return(roundtrip); } }
public void FailWhenOnlyOutputIsTemporary(int tempArtifactType) { var tempOut = CreateOutputFileArtifact(TempRoot); Exception exception = null; try { CreateAndScheduleTempDirProcess( new Operation[] { }, tempArtifactType, TempRootPath, tempOut.Path); } catch (Exception ex) { exception = ex; } XAssert.IsTrue(exception != null); XAssert.IsTrue(exception.Message.Contains("Failed to add process pip")); AssertErrorEventLogged(global::BuildXL.Pips.Tracing.LogEventId.InvalidProcessPipDueToNoOutputArtifacts); }
public virtual async Task ReadOnlyRemoteIsNotUpdatedWhenDisconnected() { string testCacheId = "Disconnected"; ICache testCache = await InitializeCacheAsync(NewCache(testCacheId, false)).SuccessAsync(); VerticalCacheAggregator vertCache = testCache as VerticalCacheAggregator; XAssert.IsNotNull(vertCache); PoisonAllRemoteSessions(testCache); DisconnectRemoteCache(testCache); ICacheSession session = (await testCache.CreateSessionAsync()).Success(); FullCacheRecord cacheRecord = await FakeBuild.DoPipAsync(session, "TestPip"); await VerticalAggregatorBaseTests.ValidateItemsInCacheAsync( vertCache.LocalCache, cacheRecord.StrongFingerprint.WeakFingerprint, new List <CasHash>(cacheRecord.CasEntries), CacheDeterminism.None, cacheRecord.StrongFingerprint.CasElement, vertCache.LocalCache.CacheId, 1); var remoteSession = await vertCache.RemoteCache.CreateReadOnlySessionAsync().SuccessAsync(); int fingerprintsReturned = 0; foreach (var fingerprint in remoteSession.EnumerateStrongFingerprints(cacheRecord.StrongFingerprint.WeakFingerprint)) { fingerprintsReturned++; } XAssert.AreEqual(0, fingerprintsReturned, "No fingerprints should have been found in the remote cache."); AssertSuccess(await testCache.ShutdownAsync()); }
public void TestFileUtilitiesTempDirectoryNotScrubbed() { // Do a run of some valid modules // The engine will set and create the path for the FileUtilities temp directory // This will also register the directory to be cleaned by TempCleaner SetupTestData(); Configuration.Engine.Scrub = true; RunEngine(); // Expect empty object root to be scrubbed always AssertVerboseEventLogged(EventId.ScrubbingFinished); var objectDirectoryPath = Configuration.Layout.ObjectDirectory.ToString(Context.PathTable); // Put a file underneath the object root, which is always scrubbed string scrubbedFile = Path.Combine(objectDirectoryPath, "scrubbed"); File.WriteAllText(scrubbedFile, "asdf"); // Put a file underneath the FileUtilities temp directory, which is underneath the object root but is not scrubbed string unscrubbedFile = Path.Combine(TestHooks.TempCleanerTempDirectory, "unscrubbed"); File.WriteAllText(unscrubbedFile, "hjkl"); RunEngine(); string eventLog = EventListener.GetLog(); // File underneath object root should be scrubbed AssertVerboseEventLogged(EventId.ScrubbingFile); XAssert.IsTrue(eventLog.Contains($"Scrubber deletes file '{ scrubbedFile }")); XAssert.IsFalse(File.Exists(scrubbedFile)); // Check that no file that starts with FileUtilities temp directory was scrubbed // Checking directly for /unscrubbedFile existence is invalid since TempCleaner will have cleaned the directory instead XAssert.IsFalse(eventLog.Contains($"Scrubber deletes file '{ TestHooks.TempCleanerTempDirectory }")); }
public void ValidateCachingDirectoryEnumerationReadWriteMount(string enumeratePattern) { var outDir = CreateOutputDirectoryArtifact(); var outDirStr = ArtifactToString(outDir); Directory.CreateDirectory(outDirStr); // PipA enumerates directory \outDir, creates file \outDir\outA var outA = CreateOutputFileArtifact(outDirStr); Process pipA = CreateAndSchedulePipBuilder(new Operation[] { // Enumerate pattern does not matter in the ReadWrite mount because we use the graph based enumeration. Operation.EnumerateDir(outDir, enumeratePattern: enumeratePattern), Operation.WriteFile(outA) }).Process; // PipB consumes directory \outA, creates file \outDir\outB var outB = CreateOutputFileArtifact(outDirStr); Process pipB = CreateAndSchedulePipBuilder(new Operation[] { Operation.ReadFile(outA), Operation.WriteFile(outB) }).Process; RunScheduler().AssertCacheMiss(pipA.PipId, pipB.PipId); RunScheduler().AssertCacheHit(pipA.PipId, pipB.PipId); // Delete files in enumerated directory File.Delete(ArtifactToString(outA)); File.Delete(ArtifactToString(outB)); RunScheduler().AssertCacheHit(pipA.PipId, pipB.PipId); // Double check that cache replay worked XAssert.IsTrue(File.Exists(ArtifactToString(outA))); XAssert.IsTrue(File.Exists(ArtifactToString(outB))); }
public async Task TestGcPrefix() { string cacheConfig = TestType.NewCache(nameof(TestGcPrefix), true); BasicFilesystemCache cache = (await InitializeCacheAsync(cacheConfig).SuccessAsync()) as BasicFilesystemCache; XAssert.IsNotNull(cache, "Failed to create cache for GC tests!"); PipDefinition[] pips = { new PipDefinition("Pip1", pipSize: 3), new PipDefinition("Pip2", pipSize: 4), new PipDefinition("Pip3", pipSize: 5) }; // First, lets filter the GC to only do one of the files. CacheEntries files = await BuildPipsAndGetCacheEntries(cache, "Build", pips); cache.DeleteSession("Build"); for (int i = 1; i < 4; i++) { files.AgeAll(); string targetFile = files.FingerprintFiles.Keys.First(); // Get the shard directory of the weak fingerprint string prefix = Path.GetFileName(Path.GetDirectoryName(Path.GetDirectoryName(targetFile))); XAssert.AreEqual(3, prefix.Length); m_output.WriteLine("GC Prefix: [{0}]", prefix); var stats = cache.CollectUnreferencedFingerprints(m_output, prefixFilter: prefix.Substring(0, i)); XAssert.IsFalse(File.Exists(targetFile), "Should have moved this one to pending"); BasicFilesystemCache.UndoPendingDelete(targetFile); files.AssertExists(); } AssertSuccess(await cache.ShutdownAsync()); }
public void CompositeSharedOpaquesCanBeComposed() { var sodDir1 = @"\\dummyPath\SharedOpaqueDir1"; var root = @"\\dummyPath"; using (TestEnv env = TestEnv.CreateTestEnvWithPausedScheduler()) { AbsolutePath sodPath1 = env.Paths.CreateAbsolutePath(sodDir1); var pip1 = CreatePipBuilderWithTag(env, "test"); pip1.AddOutputDirectory(sodPath1, SealDirectoryKind.SharedOpaque); var outputs1 = env.PipConstructionHelper.AddProcess(pip1); outputs1.TryGetOutputDirectory(sodPath1, out var sharedOpaqueDirectory1); // This composite shared opaque contains a regular shared opaque var result = env.PipConstructionHelper.TryComposeSharedOpaqueDirectory( env.Paths.CreateAbsolutePath(root), new[] { sharedOpaqueDirectory1.Root }, description: null, tags: new string[] { }, out var composedSharedOpaque); XAssert.IsTrue(result); // This composite shared opaque contains another composite shared opaque result = env.PipConstructionHelper.TryComposeSharedOpaqueDirectory( env.Paths.CreateAbsolutePath(root), new[] { composedSharedOpaque }, description: null, tags: new string[] { }, out var nestedComposedSharedOpaque); XAssert.IsTrue(result); AssertSuccessGraphBuilding(env); } }
public void TryCreateWithDeviceOrNtPrefix() { var pt = new PathTable(); AbsolutePath p; XAssert.IsTrue(AbsolutePath.TryCreate(pt, @"\\?\C:\AAA\CCC", out p)); XAssert.AreEqual(@"C:\AAA\CCC", p.ToString(pt)); XAssert.IsTrue(AbsolutePath.TryCreate(pt, @"\\.\C:\AAA\CCC", out p)); XAssert.AreEqual(@"C:\AAA\CCC", p.ToString(pt)); // TODO: This is not faithful to Wndows behavior. Win32NT paths do not canonicalize .. or slashes. XAssert.IsTrue(AbsolutePath.TryCreate(pt, @"\\?\C:\AAA\..\CCC", out p)); XAssert.AreEqual(@"C:\CCC", p.ToString(pt)); XAssert.IsTrue(AbsolutePath.TryCreate(pt, @"\\.\C:\AAA\..\CCC", out p)); XAssert.AreEqual(@"C:\CCC", p.ToString(pt)); XAssert.IsTrue(AbsolutePath.TryCreate(pt, @"\\.\C:\A/B", out p)); XAssert.AreEqual(@"C:\A\B", p.ToString(pt)); int errorPosition; AbsolutePath.ParseResult parseResult = AbsolutePath.TryCreate(pt, @"\\?\C:", out p, out errorPosition); XAssert.AreEqual(AbsolutePath.ParseResult.DevicePathsNotSupported, parseResult); XAssert.AreEqual(0, errorPosition); parseResult = AbsolutePath.TryCreate(pt, @"\\.\nul", out p, out errorPosition); XAssert.AreEqual(AbsolutePath.ParseResult.DevicePathsNotSupported, parseResult); XAssert.AreEqual(0, errorPosition); parseResult = AbsolutePath.TryCreate(pt, @"\\.\pipe\abc", out p, out errorPosition); XAssert.AreEqual(AbsolutePath.ParseResult.DevicePathsNotSupported, parseResult); XAssert.AreEqual(0, errorPosition); parseResult = AbsolutePath.TryCreate(pt, @"\\?\C:\foo\:", out p, out errorPosition); XAssert.AreEqual(AbsolutePath.ParseResult.FailureDueToInvalidCharacter, parseResult); XAssert.AreEqual(11, errorPosition); }
public void RetryOnFailureAsyncTest() { int attemptCount = 0; var possibleResult = Helpers.RetryOnFailureAsync( lastAttempt => { attemptCount++; return(Task.FromResult(new Possible <string, Failure>(string.Empty))); }, numberOfAttempts: MaxAttempts, initialTimeoutMs: InitialTimeoutMs, postTimeoutMultiplier: PostTimeoutMultiplier).GetAwaiter().GetResult(); XAssert.IsTrue(possibleResult.Succeeded && attemptCount == 1); attemptCount = 0; possibleResult = Helpers.RetryOnFailureAsync( lastAttempt => { attemptCount++; return(Task.FromResult(new Possible <string, Failure>(new Failure <string>(string.Empty)))); }, numberOfAttempts: MaxAttempts, initialTimeoutMs: InitialTimeoutMs, postTimeoutMultiplier: PostTimeoutMultiplier).GetAwaiter().GetResult(); XAssert.IsTrue(!possibleResult.Succeeded && attemptCount == MaxAttempts); }
private PipGraph DeserializeFragments(bool dependent, params TestPipGraphFragment[] fragments) { var fragmentManager = new PipGraphFragmentManager(LoggingContext, Context, PipGraphBuilder, default); for (int i = 0; i < fragments.Length; ++i) { TestPipGraphFragment fragment = fragments[i]; bool success = fragmentManager.AddFragmentFileToGraph( AbsolutePath.Create(Context.PathTable, GetIndexedFragmentPath(fragment, i)), fragment.ModuleName, i > 0 && dependent ? new[] { AbsolutePath.Create(Context.PathTable, GetIndexedFragmentPath(fragments[i - 1], i - 1)) } : new AbsolutePath[0]); XAssert.IsTrue(success, $"Adding fragment {fragment.ModuleName} from file '{GetFragmentPath(fragment)}' to graph is unsuccessful"); } Task.WaitAll(fragmentManager.GetAllFragmentTasks().Select(t => t.Item2).ToArray()); XAssert.IsTrue(fragmentManager.GetAllFragmentTasks().All(t => t.Item2.Result), "Adding all fragments to graph is unsuccessful"); return(PipGraphBuilder.Build()); }
public void AllowedDoubleWriteCachesTheRightContent() { string sharedOpaqueDir = Path.Combine(ObjectRoot, "sharedopaquedir"); AbsolutePath sharedOpaqueDirPath = AbsolutePath.Create(Context.PathTable, sharedOpaqueDir); FileArtifact doubleWriteArtifact = CreateOutputFileArtifact(sharedOpaqueDir); var firstProducerBuilder = CreateFileInSharedOpaqueBuilder(ContainerIsolationLevel.IsolateAllOutputs, DoubleWritePolicy.UnsafeFirstDoubleWriteWins, doubleWriteArtifact, "first", sharedOpaqueDirPath); var secondProducerBuilder = CreateFileInSharedOpaqueBuilder(ContainerIsolationLevel.IsolateAllOutputs, DoubleWritePolicy.UnsafeFirstDoubleWriteWins, doubleWriteArtifact, "second", sharedOpaqueDirPath); var firstProducer = SchedulePipBuilder(firstProducerBuilder); var secondProducer = SchedulePipBuilder(secondProducerBuilder); // Given the policy and isolation level, both producers should get cached RunScheduler().AssertSuccess(); AssertWarningEventLogged(EventId.FileMonitoringWarning); string doubleWritePath = doubleWriteArtifact.Path.ToString(Context.PathTable); // Run the first producer alone. It should be a cache hit, and the content of the produced // file should correspond to the first producer RootFilter filter = new RootFilter(new PipIdFilter(firstProducer.Process.SemiStableHash)); var result = RunScheduler(filter: filter).AssertSuccess(); result.AssertCacheHit(firstProducer.Process.PipId); XAssert.IsTrue(File.Exists(doubleWritePath)); XAssert.Equals("first", File.ReadAllText(doubleWritePath)); // Same procedure with the second producer filter = new RootFilter(new PipIdFilter(secondProducer.Process.SemiStableHash)); result = RunScheduler(filter: filter).AssertSuccess(); result.AssertCacheHit(secondProducer.Process.PipId); XAssert.IsTrue(File.Exists(doubleWritePath)); XAssert.Equals("second", File.ReadAllText(doubleWritePath)); }
public void TryCreate() { var st = new StringTable(0); RelativePath p; XAssert.IsTrue(RelativePath.TryCreate(st, @"AAA\CCC", out p)); XAssert.AreEqual(@"AAA\CCC", p.ToString(st)); XAssert.IsFalse(RelativePath.TryCreate(st, @"C\:AAA", out p)); XAssert.IsFalse(RelativePath.TryCreate(st, @"AAA:", out p)); XAssert.IsFalse(RelativePath.TryCreate(st, @":AAA", out p)); XAssert.IsFalse(RelativePath.TryCreate(st, @"..", out p)); p = RelativePath.Create(st, "."); XAssert.AreEqual(string.Empty, p.ToString(st)); p = RelativePath.Create(st, "BBB"); XAssert.AreEqual("BBB", p.ToString(st)); p = RelativePath.Create(st, @"BBB\."); XAssert.AreEqual("BBB", p.ToString(st)); p = RelativePath.Create(st, @"BBB\.."); XAssert.AreEqual(string.Empty, p.ToString(st)); p = RelativePath.Create(st, @"BBB\CCC\.."); XAssert.AreEqual("BBB", p.ToString(st)); PathAtom a1 = PathAtom.Create(st, "AAA"); PathAtom a2 = PathAtom.Create(st, "BBB"); PathAtom a3 = PathAtom.Create(st, "CCC"); p = RelativePath.Create(a1, a2, a3); XAssert.AreEqual(@"AAA\BBB\CCC", p.ToString(st)); }
/// <summary> /// Validates that a pip was a cache miss without asserting all pips being successful. /// </summary> public ScheduleRunResult AssertCacheMissWithoutAssertingSuccess(params PipId[] pipIds) { XAssert.IsTrue(pipIds.Length > 0, "Cache hit assertions should specify the pip ids in question"); PipResultStatus status; for (int i = 0; i < pipIds.Length; i++) { PipId pipId = pipIds[i]; if (PipResults.TryGetValue(pipId, out status)) { XAssert.IsTrue(IsExecutedPipResult(status), "A pip was a cache hit, but it should have been a cache miss. Pip at 0-based parameter index: " + i); } else { XAssert.Fail("A pip did not run, but it should have been a cache miss. Pip at 0-based parameter index: " + i); } } // Check that our counters for cache misses are working ValidateCacheMissTypesSumToTotal(); return(this); }
public async Task CacheAutoReadOnly() { string testName = "CacheAutoReadOnly"; ICache firstInvocation = await CreateCacheAsync(testName, true); Guid originalGuid = firstInvocation.CacheGuid; await ShutdownCacheAsync(firstInvocation, testName); // Now, we need to get the path such that we can read-only the read-write marker string path = Path.Combine(CacheId2cacheDir[testName], "ReadWrite-Marker"); File.SetAttributes(path, FileAttributes.ReadOnly); ICache secondInvocation = await GetExistingCacheAsync(testName, true); bool failureSeen = false; secondInvocation.SuscribeForCacheStateDegredationFailures((failure) => { XAssert.IsFalse(failureSeen); failureSeen = true; XAssert.IsTrue(failure is BuildXL.Cache.BasicFilesystem.CacheFallbackToReadonlyFailure, "Failure was of the wrong type, it was {0}", failure.GetType()); }); XAssert.AreEqual(originalGuid, secondInvocation.CacheGuid, "Persistent caches: GUID should not change"); XAssert.IsTrue(secondInvocation.IsReadOnly, "This should have been a read-only cache"); XAssert.IsTrue(failureSeen, "The cache did not call the failure callback"); await ShutdownCacheAsync(secondInvocation, testName); // Undo the read-only file File.SetAttributes(path, FileAttributes.Normal); }
private ContentFingerprint CreateFingerprintForCompositeSharedOpaque(string composedSharedOpaqueRoot, params string[] sharedOpaqueMembers) { using (TestEnv env = TestEnv.CreateTestEnvWithPausedScheduler()) { var sharedOpaqueDirectoryArtifactMembers = new DirectoryArtifact[sharedOpaqueMembers.Length]; for (int i = 0; i < sharedOpaqueMembers.Length; i++) { sharedOpaqueDirectoryArtifactMembers[i] = CreateSharedOpaque(env, env.Paths.CreateAbsolutePath(sharedOpaqueMembers[i])); } var success = env.PipConstructionHelper.TryComposeSharedOpaqueDirectory( env.Paths.CreateAbsolutePath(composedSharedOpaqueRoot), sharedOpaqueDirectoryArtifactMembers, description: null, tags: new string[0], out var sharedOpaqueDirectory); XAssert.IsTrue(success); var graph = AssertSuccessGraphBuilding(env); var fingerprint = CreateFingerprintForSharedOpaque(sharedOpaqueDirectory, graph); return(fingerprint); } }
public async Task TestJsonStringWithIncorrectParameterValueType() { // we will specify and string value to an int parameter string jsonString = GetJsonStringFromDictionary(new Dictionary <string, object>() { { "StringWithDefaultValue", "Value_of_StringWithDefaultValue" }, { "StringWithNoDefaultValue", "Value_of_StringWithNoDefaultValue" }, { "IntValue", "Invalid int value" }, { "BoolValue", false }, { "FloatValue", 245.45 } }); // this Json string will produce a failure and there will be no results to validate. We will set the result validation to null here resultValidationLambda = null; // call InitializeCache, there should be no exception Possible <ICache, Failure> cache = await InitializeCacheAsync(jsonString); // make sure that we do not get a cache XAssert.IsFalse(cache.Succeeded); // validate the returned error message XAssert.AreEqual("BuildXL.Cache.Tests.TestCacheFactory Json configuration field 'IntValue' can not be set to 'Invalid int value'\nInput string was not in a correct format.", cache.Failure.Describe()); }
public void Subsegment() { RunForEncoding(isAscii => { var seg = CreateSegment(string.Empty, isAscii); var sub = seg.Subsegment(0, 0); XAssert.AreEqual(0, sub.Length); seg = CreateSegment("ABCDEF", isAscii); sub = seg.Subsegment(0, 1); XAssert.AreEqual(1, sub.Length); XAssert.AreEqual('A', sub[0]); sub = seg.Subsegment(5, 1); XAssert.AreEqual(1, sub.Length); XAssert.AreEqual('F', sub[0]); sub = seg.Subsegment(2, 3); XAssert.AreEqual(3, sub.Length); XAssert.AreEqual('C', sub[0]); XAssert.AreEqual('D', sub[1]); XAssert.AreEqual('E', sub[2]); }); }
public void SpannableList_can_be_inserted() { SpannableList <int> list = new SpannableList <int>(1); list.Insert(0, 1); XAssert.AreEqual(1, list.Count); XAssert.AreEqual(1, list.Count()); XAssert.IsTrue(list.Contains(1)); XAssert.AreEqual(0, list.IndexOf(1)); XAssert.AreEqual(1, list.AsSpan().Length); XAssert.AreEqual("SpannableList<Int32>[1]{ 1 }", list.ToFullString()); list.Insert(0, 2); XAssert.AreEqual(2, list.Count); XAssert.AreEqual(2, list.Count()); XAssert.IsTrue(list.Contains(1)); XAssert.IsTrue(list.Contains(2)); XAssert.IsFalse(list.Contains(3)); XAssert.AreEqual(1, list.IndexOf(1)); XAssert.AreEqual(0, list.IndexOf(2)); XAssert.AreEqual(2, list.AsSpan().Length); XAssert.AreEqual(2, list.AsSpan()[0]); XAssert.AreEqual(1, list.AsSpan()[1]); list.Insert(2, 3); XAssert.AreEqual(3, list.Count); XAssert.AreEqual(3, list.Count()); XAssert.IsTrue(list.Contains(1)); XAssert.IsTrue(list.Contains(2)); XAssert.IsTrue(list.Contains(3)); XAssert.AreEqual(1, list.IndexOf(1)); XAssert.AreEqual(0, list.IndexOf(2)); XAssert.AreEqual(2, list.IndexOf(3)); XAssert.AreEqual(3, list.AsSpan().Length); XAssert.AreArraysEqual(new[] { 2, 1, 3 }, list.ToArray(), true); }
public void CheckForFalsePositives() { var pt = GetPathTranslator(); // Don't match the patterns. Validate for off by one errors & false positives if (OperatingSystemHelper.IsUnixOS) { XAssert.AreEqual( PathGeneratorUtilities.GetAbsolutePath(null, @"\\?x", "foo", "bar"), pt.Translate(PathGeneratorUtilities.GetAbsolutePath(null, @"\\?x", "foo", "bar"))); XAssert.AreEqual( PathGeneratorUtilities.GetAbsolutePath(null, @"comb", "foo", "bar"), pt.Translate(PathGeneratorUtilities.GetAbsolutePath(null, @"comb", "foo", "bar"))); } else { XAssert.AreEqual( PathGeneratorUtilities.GetAbsolutePath(@"\\?x", "foo", "bar"), pt.Translate(PathGeneratorUtilities.GetAbsolutePath(@"\\?x", "foo", "bar"))); XAssert.AreEqual( PathGeneratorUtilities.GetAbsolutePath(@"comb", "foo", "bar"), pt.Translate(PathGeneratorUtilities.GetAbsolutePath(@"comb", "foo", "bar"))); } }
public void SpannableList_can_be_removed() { SpannableList <int> list = new SpannableList <int>(1); list.Add(1); list.Add(2); list.Add(3); XAssert.AreArraysEqual(new[] { 1, 2, 3 }, list.ToArray(), true); list.RemoveAt(0); XAssert.AreEqual(2, list.Count); XAssert.AreArraysEqual(new[] { 2, 3 }, list.ToArray(), true); list.RemoveAt(1); XAssert.AreEqual(1, list.Count); XAssert.AreArraysEqual(new[] { 2 }, list.ToArray(), true); XAssert.IsFalse(list.Remove(1)); XAssert.IsTrue(list.Remove(2)); XAssert.AreEqual(0, list.Count); }
public void IsEqual() { var s1 = new StringSegment("ABCDEF"); var s2 = new StringSegment("ABCDEF", 0, 6); XAssert.IsTrue(s1.Equals(s2)); XAssert.IsTrue(s1 == s2); XAssert.IsFalse(s1 != s2); s2 = new StringSegment("XABCDEF", 1, 6); XAssert.IsTrue(s1.Equals(s2)); XAssert.IsTrue(s1 == s2); XAssert.IsFalse(s1 != s2); s2 = new StringSegment("ABCDEF", 0, 5); XAssert.IsFalse(s1.Equals(s2)); XAssert.IsFalse(s1 == s2); XAssert.IsTrue(s1 != s2); s2 = new StringSegment("GHIJKL", 0, 6); XAssert.IsFalse(s1.Equals(s2)); XAssert.IsFalse(s1 == s2); XAssert.IsTrue(s1 != s2); }
private GraphReloadResult ReloadGraph(Pip[] procs, params int[] affectedIndexes) { XAssert.All(affectedIndexes, i => Assert.True(i >= 0 && i < procs.Length)); // add meta pips only for non-affected processes, because they should be present in the reloaded graph var nonAffectedIndexes = Enumerable.Range(0, procs.Length).Except(affectedIndexes); var nonAffectedProcs = nonAffectedIndexes.Select(i => procs[i]).ToArray(); // partially reload graph into the newly created PipGraph.Builder var builder = new PatchablePipGraph( oldPipGraph: PipGraphBuilder.DirectedGraph, oldPipTable: PipTable, graphBuilder: CreatePipGraphBuilder(), maxDegreeOfParallelism: Environment.ProcessorCount); var affectedSpecs = affectedIndexes.Select(i => procs[i].Provenance.Token.Path); var reloadingStats = builder.PartiallyReloadGraph(new HashSet <AbsolutePath>(affectedSpecs)); // build and return the new PipGraph together with the statistics of graph reloading return(new GraphReloadResult() { PipGraph = builder.Build(), Stats = reloadingStats }); }
public void StrongFingerprintMissWithMatchedPathSetIsPerformedPostCacheLookUp() { var directory = CreateUniqueDirectoryArtifact(); var sourceFile = CreateSourceFile(directory.Path); var sealedDirectory = CreateAndScheduleSealDirectoryArtifact( directory.Path, global::BuildXL.Pips.Operations.SealDirectoryKind.SourceAllDirectories); var builder = CreatePipBuilder(new[] { Operation.ReadFile(sourceFile, doNotInfer: true), Operation.WriteFile(CreateOutputFileArtifact()) }); builder.AddInputDirectory(sealedDirectory); var process = SchedulePipBuilder(builder).Process; RunScheduler().AssertCacheMiss(process.PipId); File.WriteAllText(ArtifactToString(sourceFile), "modified"); RunScheduler(m_testHooks).AssertCacheMiss(process.PipId); XAssert.IsTrue(m_testHooks.FingerprintStoreTestHooks.TryGetCacheMiss(process.PipId, out var cacheMiss)); XAssert.AreEqual(CacheMissAnalysisResult.StrongFingerprintMismatch, cacheMiss.DetailAndResult.Result); XAssert.IsTrue(cacheMiss.IsFromCacheLookUp); }