Exemple #1
0
        public void SingleCounterWithContention()
        {
            var collection = new CounterCollection(1);

            XAssert.AreEqual(0, collection.GetCounterValueInternal(0));

            var  threads  = new Thread[Environment.ProcessorCount];
            long expected = 0;

            bool[] allStarted = new[] { false };
            for (int i = 0; i < threads.Length; i++)
            {
                threads[i] = new Thread(
                    () =>
                {
                    long thisThreadAdded = 0;
                    while (!Volatile.Read(ref allStarted[0]))
                    {
                        collection.AddToCounterInternal(0, 1);
                        thisThreadAdded++;
                    }

                    for (int j = 0; j < 30; j++)
                    {
                        collection.AddToCounterInternal(0, 1);
                        thisThreadAdded++;
                    }

                    Interlocked.Add(ref expected, thisThreadAdded);
                });
                threads[i].Start();
            }

            Volatile.Write(ref allStarted[0], true);

            for (int i = 0; i < threads.Length; i++)
            {
                threads[i].Join();
            }

            XAssert.AreEqual(expected, collection.GetCounterValueInternal(0));
        }
Exemple #2
0
        public void General()
        {
            var seg = new StringSegment(string.Empty);

            XAssert.AreEqual(0, seg.Length);
            XAssert.IsTrue(seg.IndexOf("AB") < 0);

            seg = new StringSegment("A");
            XAssert.AreEqual(1, seg.Length);
            XAssert.AreEqual('A', seg[0]);
            XAssert.IsTrue(seg.IndexOf("AB") < 0);

            var stable = new StringSegment("AB");

            seg = new StringSegment("AB");
            XAssert.AreEqual(2, seg.Length);
            XAssert.AreEqual('A', seg[0]);
            XAssert.AreEqual('B', seg[1]);
            XAssert.AreEqual(stable, seg);
            XAssert.IsTrue(seg.IndexOf("AB") == 0);

            seg = new StringSegment("XABY", 1, 2);
            XAssert.AreEqual(2, seg.Length);
            XAssert.AreEqual('A', seg[0]);
            XAssert.AreEqual('B', seg[1]);
            XAssert.AreEqual(stable, seg);
            XAssert.IsTrue(seg.IndexOf("AB") == 0);

            seg = new StringSegment("ABY", 0, 2);
            XAssert.AreEqual(2, seg.Length);
            XAssert.AreEqual('A', seg[0]);
            XAssert.AreEqual('B', seg[1]);
            XAssert.AreEqual(stable, seg);
            XAssert.IsTrue(seg.IndexOf("AB") == 0);

            seg = new StringSegment("XAB", 1, 2);
            XAssert.AreEqual(2, seg.Length);
            XAssert.AreEqual('A', seg[0]);
            XAssert.AreEqual('B', seg[1]);
            XAssert.AreEqual(stable, seg);
            XAssert.IsTrue(seg.IndexOf("AB") == 0);
        }
Exemple #3
0
        /// <summary>
        /// Helper method to run a set of pip definitions through the cache
        /// </summary>
        /// <param name="testName">Name of the test</param>
        /// <param name="pips">Pip definitions to run</param>
        /// <param name="accessMethod">Cas access method (stream or file)</param>
        /// <returns>async task only - no value</returns>
        protected async Task TestMultiplePipsAsync(string testName, PipDefinition[] pips, FakeBuild.CasAccessMethod accessMethod)
        {
            string testCacheId = MakeCacheId(testName + accessMethod);
            ICache cache       = await CreateCacheAsync(testCacheId);

            // Now for the session (which we base on the cache ID)
            string testSessionId = "Session1-" + cache.CacheId;

            ICacheSession session = await CreateSessionAsync(cache, testSessionId);

            HashSet <FullCacheRecord> records = await pips.BuildAsync(session);

            XAssert.AreEqual(pips.Length, records.Count, "Should have had {0} cache records generated!", pips.Length);
            foreach (var record in records)
            {
                XAssert.AreEqual(FakeBuild.NewRecordCacheId, record.CacheId);
            }

            // Now we see if we can get back the items we think we should
            await CloseSessionAsync(session, testSessionId);

            // Check that the content is fine
            await ValidateSessionAsync(records, cache, testSessionId, accessMethod);

            // Cache hits test...
            testSessionId = "Session2-" + cache.CacheId;

            session = await CreateSessionAsync(cache, testSessionId);

            foreach (var record in await pips.BuildAsync(session))
            {
                XAssert.AreNotEqual(FakeBuild.NewRecordCacheId, record.CacheId);
                XAssert.IsTrue(records.Contains(record));
            }

            await CloseSessionAsync(session, testSessionId);

            // Check that the content is fine
            await ValidateSessionAsync(records, cache, testSessionId, accessMethod);

            await ShutdownCacheAsync(cache, testCacheId);
        }
Exemple #4
0
        /// <summary>
        /// Checks that when the changes in change list are applied to
        /// old list, the resulting list has the same values as new list.
        /// </summary>
        private void AssertValidChange <T>(List <T> oldList, List <T> newList, ChangeList <T> changeList)
        {
            var transformedOld = ListToDictionary <T>(oldList);

            for (int i = 0; i < changeList.Count; ++i)
            {
                var change = changeList[i];
                switch (change.ChangeType)
                {
                case ChangeList <T> .ChangeType.Removed:
                    if (transformedOld[change.Value] == 1)
                    {
                        transformedOld.Remove(change.Value);
                    }
                    else
                    {
                        transformedOld[change.Value]--;
                    }
                    break;

                case ChangeList <T> .ChangeType.Added:
                    if (transformedOld.ContainsKey(change.Value))
                    {
                        transformedOld[change.Value]++;
                    }
                    else
                    {
                        transformedOld[change.Value] = 1;
                    }
                    break;
                }
            }

            var transformedNew = ListToDictionary(newList);

            XAssert.AreEqual(transformedOld.Count, transformedNew.Count);

            foreach (var valueCount in transformedNew)
            {
                XAssert.AreEqual(valueCount.Value, transformedOld[valueCount.Key]);
            }
        }
        public void TimeToLive()
        {
            int execTime = 1;
            var processPipExecutionPerformance = new ProcessPipExecutionPerformance(
                PipExecutionLevel.Executed,
                DateTime.UtcNow,
                DateTime.UtcNow.AddMilliseconds(execTime),
                FingerprintUtilities.ZeroFingerprint,
                TimeSpan.FromMilliseconds(execTime),
                default(FileMonitoringViolationCounters),
                default(IOCounters),
                TimeSpan.FromMilliseconds(execTime),
                TimeSpan.FromMilliseconds(execTime / 2),
                ProcessMemoryCounters.CreateFromMb(1024, 1024, 1024, 1024),
                1,
                workerId: 0,
                suspendedDurationMs: 0);

            ProcessPipHistoricPerfData runTimeData = new ProcessPipHistoricPerfData(processPipExecutionPerformance);
            HistoricPerfDataTable      table       = new HistoricPerfDataTable(LoggingContext);
            var semiStableHashToKeep = 0;

            table[semiStableHashToKeep] = runTimeData;
            var semiStableHashToDrop = 1;

            table[semiStableHashToDrop] = runTimeData;
            var stream = new MemoryStream();

            for (int i = 0; i < ProcessPipHistoricPerfData.DefaultTimeToLive; i++)
            {
                stream.Position = 0;
                table.Save(stream);
                stream.Position = 0;
                table           = HistoricPerfDataTable.Load(LoggingContext, stream);
                Analysis.IgnoreResult(table[semiStableHashToKeep]);
            }

            stream.Position = 0;
            table           = HistoricPerfDataTable.Load(LoggingContext, stream);
            XAssert.AreEqual(1u, table[semiStableHashToKeep].DurationInMs);
            XAssert.AreEqual(0u, table[semiStableHashToDrop].DurationInMs);
        }
        public void DirectorySymlinksUnderSharedOpaquesArePreservedIfNonEmpty()
        {
            string rootDir           = Path.Combine(TemporaryDirectory, nameof(DirectorySymlinksUnderSharedOpaquesArePreservedIfNonEmpty));
            string fullTargetDirPath = Path.Combine(rootDir, "target-dir");

            Directory.CreateDirectory(fullTargetDirPath);
            XAssert.IsTrue(Directory.Exists(fullTargetDirPath));

            var fileUnderTarget = Path.Combine(fullTargetDirPath, "file.txt");

            File.WriteAllText(fileUnderTarget, "content");

            string fullSymlinkPath = WriteSymlink(Path.Combine(rootDir, "directory symlink"), fullTargetDirPath, isTargetFile: false);

            XAssert.IsTrue(FileUtilities.FileExistsNoFollow(fullSymlinkPath));

            if (OperatingSystemHelper.IsMacOS)
            {
                SharedOpaqueOutputHelper.EnforceFileIsSharedOpaqueOutput(fullSymlinkPath);
                XAssert.IsTrue(SharedOpaqueOutputHelper.IsSharedOpaqueOutput(fullSymlinkPath));
            }

            // This is somewhat subtle. On Windows, IsSharedOpaqueOutput will say yes for any directory, including symlink directories. This means they won't be
            // considered part of the build and therefore should be traversed.
            // So if the symlink is traversed, fileUnderTarget will be found, which is not a shared opaque output. So the file won't be deleted. And
            // so nor the symlink directory. If the symlink directory wasn't traversed, then it would be deleted.
            Scrubber.RemoveExtraneousFilesAndDirectories(
                isPathInBuild: path => !SharedOpaqueOutputHelper.IsSharedOpaqueOutput(path),
                pathsToScrub: new[] { rootDir },
                blockedPaths: CollectionUtilities.EmptyArray <string>(),
                nonDeletableRootDirectories: CollectionUtilities.EmptyArray <string>());

            XAssert.FileExists(fileUnderTarget);

            // On Mac:
            //   - any symlink is a file, any file under shared opaque dir gets scrubber ==> fullSymlinkPath should be scrubbed
            //
            // On Windows:
            //   - directories under shared opaques are always removed unless they have files underneath that shouldn't be
            //     removed. This test verifies this behavior also applies to symlink directories
            XAssert.AreEqual(!OperatingSystemHelper.IsMacOS, Directory.Exists(fullSymlinkPath));
        }
        public void CanOpenFileByIdViaDirectoryHandle()
        {
            XAssert.IsTrue(Directory.Exists(TemporaryDirectory));

            SafeFileHandle directoryHandle = OpenTemporaryDirectory();

            string junkPath = GetFullPath("Junk");

            using (directoryHandle)
            {
                FileId fileId;
                using (FileStream fileStream = File.Create(junkPath))
                {
                    fileStream.WriteByte(0xFF);
                    fileId = FileUtilities.ReadFileUsnByHandle(fileStream.SafeFileHandle).Value.FileId;

                    XAssert.AreEqual(
                        FileUtilities.GetVolumeSerialNumberByHandle(directoryHandle),
                        FileUtilities.GetVolumeSerialNumberByHandle(fileStream.SafeFileHandle));
                }

                XAssert.IsTrue(File.Exists(junkPath));

                SafeFileHandle handleFromId;
                var            openByIdResult = FileUtilities.TryOpenFileById(
                    directoryHandle,
                    fileId,
                    FileDesiredAccess.GenericRead,
                    FileShare.Read | FileShare.Delete,
                    FileFlagsAndAttributes.None,
                    out handleFromId);
                using (handleFromId)
                {
                    XAssert.IsTrue(openByIdResult.Succeeded);

                    using (var fileStream = new FileStream(handleFromId, FileAccess.Read))
                    {
                        XAssert.AreEqual(0xFF, fileStream.ReadByte(), "Wrong contents for file opened by ID");
                    }
                }
            }
        }
Exemple #8
0
        public void ChangeFileNoMaterialization(RepoConfig repoCfg)
        {
            using var helper = Clone(repoCfg);

            // track an existing file
            var file   = helper.GetPath(@"src\files\changingFile.txt");
            var result = helper.TrackPath(file);

            XAssert.AreEqual(PathExistence.ExistsAsFile, result.Existence);

            // switch to a new branch where that file is modified
            using var reseter = helper.GitCheckout("changingFile1");

            // immediately snap changes
            helper.SnapCheckPoint();

            // assert that the journal recorded a change
            // (it doesn't matter to us whether that change is 'Delete' or 'Change')
            helper.AssertDeleteOrChangeFile(file);
        }
Exemple #9
0
        public void Empty()
        {
            CommandLineUtilities.Option option = default(CommandLineUtilities.Option);
            option.Name  = "translateDirectory";
            option.Value = string.Empty;

            try
            {
                Args.ParseTranslatePathOption(m_pathTable, option);
            }
            catch (Exception e)
            {
                XAssert.AreEqual(
                    "The value provided for the /translateDirectory argument is invalid.",
                    e.GetLogEventMessage());
                return;
            }

            XAssert.Fail("Should have gotten an exception.");
        }
        public static void AssertPathSetsEquivalent(ObservedPathSet a, ObservedPathSet b)
        {
            List <AbsolutePath> aPaths = RemoveDuplicates(a.Paths);
            List <AbsolutePath> bPaths = RemoveDuplicates(b.Paths);

            XAssert.AreEqual(aPaths.Count, bPaths.Count);
            for (int i = 0; i < aPaths.Count; i++)
            {
                XAssert.AreEqual(aPaths[i], bPaths[i]);
            }

            List <StringId> aFileNames = RemoveDuplicates(a.ObservedAccessedFileNames);
            List <StringId> bFileNames = RemoveDuplicates(b.ObservedAccessedFileNames);

            XAssert.AreEqual(aFileNames.Count, bFileNames.Count);
            for (int i = 0; i < aFileNames.Count; i++)
            {
                XAssert.IsTrue(a.ObservedAccessedFileNames.Comparer.Compare(aFileNames[i], bFileNames[i]) == 0);
            }
        }
        public void IsInitialized()
        {
            RelativePath p = default(RelativePath);

            XAssert.IsFalse(p.IsValid);

            var st = new StringTable(0);

            p = RelativePath.Create(st, @"usr/src");
            XAssert.AreEqual(@"usr/src", p.ToString(st));
            XAssert.IsTrue(p.IsValid);
            XAssert.IsFalse(p.IsEmpty);

            p = RelativePath.Create(st, string.Empty);
            XAssert.IsTrue(p.IsValid);
            XAssert.IsTrue(p.IsEmpty);

            p = RelativePath.Create(st, "path1:/path2/");
            XAssert.IsTrue(p.IsValid);
        }
        public void TestInvalidDirectoryTranslatorDueToCycle()
        {
            var context   = BuildXLContext.CreateInstanceForTesting();
            var pathTable = context.PathTable;

            DirectoryTranslator.RawInputTranslation[] translations = new[]
            {
                CreateInputTranslation(pathTable, getAtoms(new string[] { "d", "foo", "bar" }), getAtoms(new string[] { "E" })),
                CreateInputTranslation(pathTable, getAtoms(new string[] { "A" }), getAtoms(new string[] { "B" })),
                CreateInputTranslation(pathTable, getAtoms(new string[] { "C" }), getAtoms(new string[] { "A" })),
                CreateInputTranslation(pathTable, getAtoms(new string[] { "B" }), getAtoms(new string[] { "C" }))
            };
            string error;

            XAssert.IsFalse(DirectoryTranslator.ValidateDirectoryTranslation(pathTable, translations, out error));
            XAssert.AreEqual(@"cycle in directory translations '" + A(getAtoms(new string[] { "A" })) +
                             "' < '" + A(getAtoms(new string[] { "B" })) +
                             "' < '" + A(getAtoms(new string[] { "C" })) +
                             "' < '" + A(getAtoms(new string[] { "A" })) + "'", error);
        }
        public void NameFilter_filters_starts_and_ends_correctly()
        {
            PackedExecution.Builder builder = ConstructExecution();

            NameIndex nameIndex = new NameIndex(builder.PackedExecution.PipTable.PipNameTable);

            // should match "alpha.bravo" pip substrings
            NameFilter <PipId> nameFilter = new NameFilter <PipId>(
                builder.PackedExecution.PipTable,
                nameIndex,
                pid => builder.PackedExecution.PipTable[pid].Name,
                '.',
                "a.b");

            PipId[] results = nameFilter.Filter().OrderBy(pid => pid).ToArray();

            XAssert.AreEqual(2, results.Count());
            XAssert.AreEqual(new PipId(1), results.First());
            XAssert.AreEqual(new PipId(2), results.Last());
        }
        public async Task ObservedOutputWithNullStorage()
        {
            var    content        = new string('S', 100);
            string observedOutput = string.Empty;
            var    outputBuilder  =
                new SandboxedProcessOutputBuilder(
                    Encoding.UTF8,
                    0,
                    null,
                    SandboxedProcessFile.StandardOutput,
                    writtenOutput => observedOutput += writtenOutput);

            XAssert.IsTrue(outputBuilder.HookOutputStream);
            outputBuilder.AppendLine(content);
            SandboxedProcessOutput output = outputBuilder.Freeze();

            XAssert.IsFalse(output.IsSaved);
            XAssert.AreEqual(string.Empty, await output.ReadValueAsync());
            XAssert.AreEqual(content, observedOutput);
        }
Exemple #15
0
        public void TestGraphConstructionWithLightEdges()
        {
            MutableDirectedGraph graph;

            NodeId[] nodes;

            CreateGraphWithLightEdges(out graph, out nodes);

            XAssert.AreEqual(graph.NodeCount, nodes.Length);
            XAssert.AreEqual(graph.EdgeCount, 5);

            XAssert.IsTrue(graph.ContainsEdge(nodes[0], nodes[1], isLight: true));
            XAssert.IsTrue(graph.ContainsEdge(nodes[0], nodes[1], isLight: false));
            XAssert.IsFalse(graph.ContainsEdge(nodes[1], nodes[0], isLight: true));
            XAssert.IsFalse(graph.ContainsEdge(nodes[1], nodes[0], isLight: false));
            XAssert.IsFalse(graph.ContainsEdge(nodes[1], nodes[3], isLight: true));

            XAssert.IsTrue(graph.IsSinkNode(nodes[3]));
            XAssert.IsFalse(graph.IsSourceNode(nodes[3]), "Has an incoming light edge");
        }
Exemple #16
0
        public void BaseEventListenerDiagnosticFiltering()
        {
            using (var listener = new TestEventListener(Events.Log, "Test.BuildXL.Utilities.EventListenerTests.BaseEventListenerDiagnosticFiltering", captureAllDiagnosticMessages: false))
            {
                listener.RegisterEventSource(TestEvents.Log);
                // Initially, diagnostic events are disabled.
                TestEvents.Log.DiagnosticEvent("Super low level");
                TestEvents.Log.DiagnosticEventInOtherTask("Also super low level");
                XAssert.AreEqual(0, listener.GetEventCount((int)EventId.DiagnosticEvent));
                XAssert.AreEqual(0, listener.GetEventCount((int)EventId.DiagnosticEventInOtherTask));

                // We can enable messages from one task, but leave those in another disabled.
                listener.EnableTaskDiagnostics(Tasks.UnitTest);

                TestEvents.Log.DiagnosticEvent("Super low level");
                TestEvents.Log.DiagnosticEventInOtherTask("Also super low level");
                XAssert.AreEqual(1, listener.GetEventCount((int)EventId.DiagnosticEvent));
                XAssert.AreEqual(0, listener.GetEventCount((int)EventId.DiagnosticEventInOtherTask));
            }
        }
Exemple #17
0
        public void CreateReplacementFileCanReplaceMemoryMappedFile()
        {
            string file = GetFullPath("File");
            string link = GetFullPath("link");

            WithNewFileMemoryMapped(
                file,
                () =>
            {
                if (!CreateHardLinkIfSupported(link: link, linkTarget: file))
                {
                    return;
                }

                using (FileStream fs = FileUtilities.CreateReplacementFile(link, FileShare.Delete))
                {
                    XAssert.AreEqual(0, fs.Length);
                }
            });
        }
Exemple #18
0
        public async Task GetAndRecordContentHashAsyncWithMatch()
        {
            ContentHash fakeHash = ContentHashingUtilities.CreateRandom();

            var fileContentTable = FileContentTable.CreateNew(LoggingContext);

            WriteFile(FileA, "Some string");

            using (FileStream fs = File.OpenRead(GetFullPath(FileA)))
            {
                // Note that this content hash is clearly wrong, but also not all zeroes.
                fileContentTable.RecordContentHash(fs, fakeHash);
            }

            FileContentTableExtensions.VersionedFileIdentityAndContentInfoWithOrigin result =
                await fileContentTable.GetAndRecordContentHashAsync(GetFullPath(FileA));

            XAssert.AreEqual(FileContentTableExtensions.ContentHashOrigin.Cached, result.Origin);
            XAssert.AreEqual(fakeHash, result.VersionedFileIdentityAndContentInfo.FileContentInfo.Hash);
        }
Exemple #19
0
        public void CaseFolding()
        {
            var hnt = new HierarchicalNameTable(new StringTable(), true, Path.DirectorySeparatorChar);

            // shouldn't be interference between different hierarchies and case should be preserved
            HierarchicalNameId id1 = hnt.AddName(A("c","a","b","c"));
            HierarchicalNameId id3 = hnt.AddName(A("c","A","B","C"));

            HierarchicalNameId id2 = hnt.AddName(A("c","X","A","B","C"));
            XAssert.AreEqual(A("c","a","b","c"), hnt.ExpandName(id1));
            XAssert.AreEqual(A("c","X","A","B","C"), hnt.ExpandName(id2));

            // we expect to find an existing path when using different casing
            // HierarchicalNameId id3 = hnt.AddName((A("c","\A\B\C");
            XAssert.AreEqual(id1, id3);

            // and we expect for common paths to have "first one in wins" casing
            HierarchicalNameId id4 = hnt.AddName(A("c","A","B","C","D"));
            XAssert.AreEqual(A("c","a","b","c","D"), hnt.ExpandName(id4));
        }
Exemple #20
0
        public void GetRoot()
        {
            var          pt   = new PathTable();
            AbsolutePath da   = AbsolutePath.Create(pt, @"c:\a");
            AbsolutePath root = da.GetRoot(pt);

            XAssert.AreEqual(@"c:\", root.ToString(pt));

            da   = AbsolutePath.Create(pt, @"c:\");
            root = da.GetRoot(pt);
            XAssert.AreEqual(@"c:\", root.ToString(pt));

            da   = AbsolutePath.Create(pt, @"c:\a\b");
            root = da.GetRoot(pt);
            XAssert.AreEqual(@"c:\", root.ToString(pt));

            da   = AbsolutePath.Create(pt, @"\\server\foo");
            root = da.GetRoot(pt);
            XAssert.AreEqual(@"\\server", root.ToString(pt));
        }
Exemple #21
0
        public void LargeNestedObjectTest()
        {
            string jsonA = "{\"Object\":[\"10?B:\\\\out\\\\objects\\\\d\\\\z\\\\bqkrr8zzp30wta21jx01qhl915zwxn\\\\xunit-out\\\\FingerprintS1F4BDE58\\\\2\\\\obj\\\\readonly\\\\obj_0???None?\"," +
                           "\"5?B:\\\\out\\\\objects\\\\d\\\\z\\\\bqkrr8zzp30wta21jx01qhl915zwxn\\\\xunit-out\\\\FingerprintS1F4BDE58\\\\2\\\\obj\\\\obj_1???None?\",{\"ExecutionAndFingerprintOptionsHash\":\"224F5F8E17D4590F2CD7AFAB82AA672D2E0C86E8\"}," +
                           "{\"ContentHashAlgorithmName\":\"Vso0\"},{\"PipType\":\"80\"}," +
                           "{\"Executable\":{\"B:/out/objects/d/z/bqkrr8zzp30wta21jx01qhl915zwxn/Test.BuildXL.FingerprintStore-test-deployment/TestProcess/Test.BuildXL.Executables.TestProcess.exe\":\"VSO0:17426AF3467E448CD8E1146EEE9CFC27107690D39B8091E2882AB164B57ED90400\"}}," +
                           "{\"WorkingDirectory\":\"B:/out/objects/d/z/bqkrr8zzp30wta21jx01qhl915zwxn/xunit-out/FingerprintS1F4BDE58/2/obj/z/7/69c8nz08y0ehxg5vn8ex8g7g59at90/Test.BuildXL.Executables.TestProcess\"}," +
                           "{\"StandardError\":\"{Invalid}\"},{\"StandardOutput\":\"{Invalid}\"}," +
                           "{\"Dependencies\":{\"B:/out/objects/d/z/bqkrr8zzp30wta21jx01qhl915zwxn/Test.BuildXL.FingerprintStore-test-deployment/TestProcess/Test.BuildXL.Executables.TestProcess.exe\":\"VSO0:17426AF3467E448CD8E1146EEE9CFC27107690D39B8091E2882AB164B57ED90400\"}}," +
                           "{\"DirectoryDependencies\":[]},{\"Outputs\":[{\"Path\":\"B:/out/objects/d/z/bqkrr8zzp30wta21jx01qhl915zwxn/xunit-out/ FingerprintS1F4BDE58 / 2 / obj / obj_1\"},{\"Attributes\":\"0\"}]},{\"DirectoryOutputs\":[]}," +
                           "{\"UntrackedPaths\":[]},{\"UntrackedScopes\":[\"C:/WINDOWS\",\"C:/Users/userName/AppData/Local/Microsoft/Windows/INetCache\",\"C:/Users/userName/AppData/Local/Microsoft/Windows/History\"]}," +
                           "{\"HasUntrackedChildProcesses\":\"0\"},{\"PipData\":\"Arguments\"},{\"Escaping\":\"2\"},{\"Separator\":\" \"},{\"Fragments\":\"1\"},{\"PipData\":\"NestedFragment\"},{\"Escaping\":\"2\"},{\"Separator\":\" \"},{\"Fragments\":\"2\"}," +
                           "{\"Environment\":[]},{\"WarningTimeout\":\"-1\"},{\"WarningRegex.Pattern\":\"^\\\\s*((((((\\\\d+>)?[a-zA-Z]?:[^:]*)|([^:]*))):)|())(()|([^:]*? ))warning( \\\\s*([^: ]*))?\\\\s*:.*$\"},{\"WarningRegex.Options\":\"1\"}," +
                           "{\"ErrorRegex.Pattern\":\".*\"},{\"ErrorRegex.Options\":\"1\"},{\"SuccessExitCodes\":[]}]}";

            var    treeA        = JsonTree.Deserialize(jsonA);
            string deserialized = JsonTree.Serialize(treeA);

            XAssert.AreEqual(JsonTree.PrettyPrintJson(jsonA), deserialized);
        }
        public async Task CacheMissTest()
        {
            const string TestName    = nameof(CacheMissTest);
            string       testCacheId = MakeCacheId(TestName);
            ICache       cache       = await CreateCacheAsync(testCacheId);

            ICacheSession session = await cache.CreateSessionAsync().SuccessAsync();

            FakeBuild fb = new FakeBuild("test", 3);

            StrongFingerprint fakeFingerprint = new StrongFingerprint(WeakFingerprintHash.Random(), new CasHash(fb.OutputHashes[0]), fb.OutputHashes[0], "fake");

            var response = await session.GetCacheEntryAsync(fakeFingerprint);

            XAssert.IsFalse(response.Succeeded);
            XAssert.AreEqual(typeof(NoMatchingFingerprintFailure), response.Failure.GetType(), response.Failure.Describe());

            await CloseSessionAsync(session, null);
            await ShutdownCacheAsync(cache, testCacheId);
        }
Exemple #23
0
        public void NoLessThanNoDblCol()
        {
            CommandLineUtilities.Option option = default(CommandLineUtilities.Option);
            option.Name  = "translateDirectory";
            option.Value = "Hello";

            try
            {
                Args.ParseTranslatePathOption(m_pathTable, option);
            }
            catch (Exception e)
            {
                XAssert.AreEqual(
                    "The value 'Hello' provided for the /translateDirectory argument is invalid. It should contain a '::' or '<' separator",
                    e.GetLogEventMessage());
                return;
            }

            XAssert.Fail("Should have gotten an exception.");
        }
        public void PathsInMarkers()
        {
            var pt = GetPathTranslator();

            XAssert.AreEqual(
                PathGeneratorUtilities.GetAbsolutePath(@"logging a path: [d", "src", "123", "bar]"),
                pt.Translate(PathGeneratorUtilities.GetAbsolutePath(@"logging a path: [x", "foo", "bar]")));
            XAssert.AreEqual(
                PathGeneratorUtilities.GetAbsolutePath(@"##vso[task.uploadsummary]d", "src", "123", "bar"),
                pt.Translate(PathGeneratorUtilities.GetAbsolutePath(@"##vso[task.uploadsummary]x", "foo", "bar")));
            XAssert.AreEqual(
                PathGeneratorUtilities.GetAbsolutePath(@" \\?\d", "src", "123", "bar"),
                pt.Translate(PathGeneratorUtilities.GetAbsolutePath(@" \\?\x", "foo", "bar")));
            XAssert.AreEqual(
                PathGeneratorUtilities.GetAbsolutePath(@"\\?\d", "src", "123", "bar"),
                pt.Translate(PathGeneratorUtilities.GetAbsolutePath(@"\\?\x", "foo", "bar")));
            XAssert.AreEqual(
                PathGeneratorUtilities.GetAbsolutePath(@"\??\d", "src", "123", "bar"),
                pt.Translate(PathGeneratorUtilities.GetAbsolutePath(@"\??\x", "foo", "bar")));
        }
Exemple #25
0
        public void NewFileWhenParentFolderIsNotMaterialzedBeforeOperation(RepoConfig repoCfg)
        {
            using var helper = Clone(repoCfg);

            // track a file that doesn't exist
            var file   = helper.GetPath(@"src\files\subfolder\newfile2.txt");
            var result = helper.TrackPath(file);

            XAssert.AreEqual(PathExistence.Nonexistent, result.Existence);

            // switch to a new branch where that file does exist
            using var reseter = helper.GitCheckout("newFileInSubfolder");

            // immediately snap changes
            helper.SnapCheckPoint();

            // assert that 'CreateFile' USN entry was recorded
            helper.AssertCreateFile(file);
            XAssert.FileExists(file);
        }
        public void TestValidBuildManifestData()
        {
            List <BuildManifestFile> outputs = new List <BuildManifestFile>();
            BuildManifestData        data0   = new BuildManifestData("Version", 1598291222, "cbId", "Repo", "branch", "commitId", outputs);

            XAssert.IsTrue(BuildManifestData.TryParse(data0.ToString(), out var parsedData0));
            XAssert.AreEqual(data0, parsedData0);

            outputs.Add(new BuildManifestFile("relativePath1", "vsohash", "sha256Hash"));
            BuildManifestData data1 = new BuildManifestData("Version", 1598291222, "cbId", "Repo", "branch", "commitId", outputs);

            XAssert.IsTrue(BuildManifestData.TryParse(data1.ToString(), out var parsedData1));
            XAssert.AreEqual(data1, parsedData1);

            outputs.Add(new BuildManifestFile("relativePath2", "vsohash", "sha256Hash"));
            BuildManifestData data2 = new BuildManifestData("Version", 1598291222, "cbId", "Repo", "branch", "commitId", outputs);

            XAssert.IsTrue(BuildManifestData.TryParse(data2.ToString(), out var parsedData2));
            XAssert.AreEqual(data2, parsedData2);
        }
Exemple #27
0
 private static void AssertEqualFileArtifacts(
     BuildXLContext context,
     string objPath,
     Remapper remapper,
     FileArtifact expectedFile,
     FileArtifact actualFile)
 {
     if (remapper != null)
     {
         AssertEqualAbsolutePaths(context, objPath, remapper, expectedFile.Path, actualFile.Path);
         XAssert.AreEqual(
             expectedFile.RewriteCount,
             actualFile.RewriteCount,
             $"{nameof(FileArtifact)} values don't match for objPath: {objPath}");
     }
     else
     {
         XAssert.AreEqual(expectedFile, actualFile, $"{nameof(FileArtifact)} values don't match for objPath: {objPath}");
     }
 }
        public void PreserveOutputsOnlyAppliesToSpecificPips()
        {
            Configuration.Sandbox.UnsafeSandboxConfigurationMutable.PreserveOutputs = PreserveOutputsMode.Enabled;

            var pipA = ScheduleAndGetPip(out var input, out var output, opaque: false, pipPreserveOutputsFlag: false);

            // No cache hit.
            string outputContents = RunSchedulerAndGetOutputContents(output, cacheHitAssert: false, id: pipA.Process.PipId);

            XAssert.AreEqual(CONTENT, outputContents);

            // Cache hit.
            outputContents = RunSchedulerAndGetOutputContents(output, cacheHitAssert: true, id: pipA.Process.PipId);
            XAssert.AreEqual(CONTENT, outputContents);

            // Disabling preserve outputs should have no impact because it was not enabled for this pip in the first run
            Configuration.Sandbox.UnsafeSandboxConfigurationMutable.PreserveOutputs = PreserveOutputsMode.Disabled;
            outputContents = RunSchedulerAndGetOutputContents(output, cacheHitAssert: true, id: pipA.Process.PipId);
            XAssert.AreEqual(CONTENT, outputContents);
        }
        public void PreserveOutputsOffThenOn()
        {
            // Turn off.
            Configuration.Sandbox.UnsafeSandboxConfigurationMutable.PreserveOutputs = PreserveOutputsMode.Disabled;

            var pipA = ScheduleAndGetPip(out var input, out var output, false, true);

            // No cache hit.
            string outputContents = RunSchedulerAndGetOutputContents(output, cacheHitAssert: false, id: pipA.Process.PipId);

            XAssert.AreEqual(CONTENT, outputContents);

            // Cache hit.
            outputContents = RunSchedulerAndGetOutputContents(output, cacheHitAssert: true, id: pipA.Process.PipId);
            XAssert.AreEqual(CONTENT, outputContents);

            // Turn on.
            Configuration.Sandbox.UnsafeSandboxConfigurationMutable.PreserveOutputs = PreserveOutputsMode.Enabled;

            // Cache hit.
            outputContents = RunSchedulerAndGetOutputContents(output, cacheHitAssert: true, id: pipA.Process.PipId);
            XAssert.AreEqual(CONTENT, outputContents);

            // Change the input.
            ModifyFile(input);

            // This should be the only cache miss.
            outputContents = RunSchedulerAndGetOutputContents(output, cacheHitAssert: false, id: pipA.Process.PipId);
            XAssert.AreEqual(CONTENT_TWICE, outputContents);

            // Turn off again.
            Configuration.Sandbox.UnsafeSandboxConfigurationMutable.PreserveOutputs = PreserveOutputsMode.Disabled;

            // This hould result in cache miss.
            outputContents = RunSchedulerAndGetOutputContents(output, cacheHitAssert: false, id: pipA.Process.PipId);
            XAssert.AreEqual(CONTENT, outputContents);

            // Cache hit.
            outputContents = RunSchedulerAndGetOutputContents(output, cacheHitAssert: true, id: pipA.Process.PipId);
            XAssert.AreEqual(CONTENT, outputContents);
        }
        public void PreservingProcessConsumingDynamicOutputTest()
        {
            Configuration.Sandbox.UnsafeSandboxConfigurationMutable.PreserveOutputs = PreserveOutputsMode.Enabled;

            FileArtifact      input;
            FileArtifact      preservedOutput;
            DirectoryArtifact outputDirectory;
            Process           dynamicOutputProducer;
            Process           preservingProcess;

            ScheduleProcessConsumingDynamicOutput(
                out input,
                out outputDirectory,
                out preservedOutput,
                out dynamicOutputProducer,
                out preservingProcess);

            RunScheduler().AssertCacheMiss(preservingProcess.PipId, dynamicOutputProducer.PipId);

            // Delete dynamic output.
            FileUtilities.DeleteDirectoryContents(ArtifactToString(outputDirectory), deleteRootDirectory: true);

            // Cache miss as the output is gone.
            RunScheduler().AssertCacheMiss(dynamicOutputProducer.PipId);

            // Dynamic output producer should result in cache hit.
            RunScheduler().AssertCacheHit(dynamicOutputProducer.PipId);
            var preservedOutputContent = File.ReadAllText(ArtifactToString(preservedOutput));

            XAssert.AreEqual(CONTENT, preservedOutputContent);

            // Modify input to preserving process.
            ModifyFile(input);

            var schedulerResult = RunScheduler();

            schedulerResult.AssertCacheHit(dynamicOutputProducer.PipId);
            schedulerResult.AssertCacheMiss(preservingProcess.PipId);
            preservedOutputContent = File.ReadAllText(ArtifactToString(preservedOutput));
            XAssert.AreEqual(CONTENT_TWICE, preservedOutputContent);
        }