Esempio n. 1
0
        public void EmptyArray()
        {
            var array1 = CollectionUtilities.EmptyArray <string>();
            var array2 = CollectionUtilities.EmptyArray <string>();

            XAssert.AreEqual(0, array1.Length);
            XAssert.AreSame(array1, array2);
        }
Esempio n. 2
0
        public async Task FromException()
        {
            var toThrow = new BuildXLException("Got exception?");

            try
            {
                await TaskUtilities.FromException <int>(toThrow);
            }
            catch (BuildXLException ex)
            {
                XAssert.AreSame(toThrow, ex);
                return;
            }

            XAssert.Fail("Expected an exception");
        }
Esempio n. 3
0
        public void AsArray()
        {
            var list       = new List <int>();
            var emptyArray = CollectionUtilities.EmptyArray <int>();

            var listArray = CollectionUtilities.AsArray(list);

            XAssert.AreSame(emptyArray, listArray);

            list.Add(1);
            list.Add(2);
            list.Add(3);

            listArray = CollectionUtilities.AsArray(list);
            XAssert.IsTrue(Enumerable.SequenceEqual(list, listArray));
        }
Esempio n. 4
0
        public void ObjectPoolWillReturnNewInstanceIfCleanupMethodCreatesNewInstance()
        {
            ObjectPool <StringBuilder> disabledPool = new ObjectPool <StringBuilder>(
                creator: () => new StringBuilder(),
                cleanup: sb => new StringBuilder());

            StringBuilder firstInstanceFromDisabledPool;

            using (var wrap = disabledPool.GetInstance())
            {
                firstInstanceFromDisabledPool = wrap.Instance;
            }

            StringBuilder secondInstanceFromDisabledPool;

            using (var wrap = disabledPool.GetInstance())
            {
                secondInstanceFromDisabledPool = wrap.Instance;
            }

            XAssert.AreNotSame(firstInstanceFromDisabledPool, secondInstanceFromDisabledPool, "Disabled pool should return new instance each time.");

            ObjectPool <StringBuilder> regularPool = new ObjectPool <StringBuilder>(
                creator: () => new StringBuilder(),
                cleanup: sb => sb.Clear());

            StringBuilder firstInstanceFromRegularPool;

            using (var wrap = regularPool.GetInstance())
            {
                firstInstanceFromRegularPool = wrap.Instance;
            }

            StringBuilder secondInstanceFromRegularPool;

            using (var wrap = regularPool.GetInstance())
            {
                secondInstanceFromRegularPool = wrap.Instance;
            }

            XAssert.AreSame(firstInstanceFromRegularPool, secondInstanceFromRegularPool, "Regular pool should return each object every time.");
        }
Esempio n. 5
0
        public void TestProcessExecutionResultSerialization()
        {
            var reportedAccess = CreateRandomReportedFileAccess();

            Fingerprint fingerprint = FingerprintUtilities.CreateRandom();

            var processExecutionResult = ExecutionResult.CreateSealed(
                result: PipResultStatus.Succeeded,
                numberOfWarnings: 12,
                outputContent: ReadOnlyArray <(FileArtifact, FileMaterializationInfo, PipOutputOrigin)> .FromWithoutCopy(CreateRandomOutputContent(), CreateRandomOutputContent()),
                directoryOutputs: ReadOnlyArray <(DirectoryArtifact, ReadOnlyArray <FileArtifact>)> .FromWithoutCopy(CreateRandomOutputDirectory(), CreateRandomOutputDirectory()),
                performanceInformation: new ProcessPipExecutionPerformance(
                    PipExecutionLevel.Executed,
                    DateTime.UtcNow,
                    DateTime.UtcNow + TimeSpan.FromMinutes(2),
                    FingerprintUtilities.ZeroFingerprint,
                    TimeSpan.FromMinutes(2),
                    new FileMonitoringViolationCounters(2, 3, 4),
                    default(IOCounters),
                    TimeSpan.FromMinutes(3),
                    TimeSpan.FromMinutes(3),
                    ProcessMemoryCounters.CreateFromBytes(12324, 12325, 12326, 12326),
                    33,
                    7,
                    0),
                fingerprint: new WeakContentFingerprint(fingerprint),
                fileAccessViolationsNotAllowlisted: new[]
            {
                reportedAccess,
                CreateRandomReportedFileAccess(),

                // Create reported file access that uses the same process to test deduplication during deserialization
                CreateRandomReportedFileAccess(reportedAccess.Process),
            },
                allowlistedFileAccessViolations: new ReportedFileAccess[0],
                mustBeConsideredPerpetuallyDirty: true,
                dynamicallyObservedFiles: ReadOnlyArray <AbsolutePath> .FromWithoutCopy(
                    CreateSourceFile().Path,
                    CreateSourceFile().Path
                    ),
                dynamicallyProbedFiles: ReadOnlyArray <AbsolutePath> .FromWithoutCopy(
                    CreateSourceFile().Path,
                    CreateSourceFile().Path,
                    CreateSourceFile().Path
                    ),
                dynamicallyObservedEnumerations: ReadOnlyArray <AbsolutePath> .FromWithoutCopy(
                    CreateSourceFile().Path
                    ),
                allowedUndeclaredSourceReads: new ReadOnlyHashSet <AbsolutePath> {
                CreateSourceFile().Path,
                CreateSourceFile().Path
            },
                absentPathProbesUnderOutputDirectories: new ReadOnlyHashSet <AbsolutePath> {
                CreateSourceFile().Path,
                CreateSourceFile().Path
            },
                twoPhaseCachingInfo: new TwoPhaseCachingInfo(
                    new WeakContentFingerprint(Fingerprint.Random(FingerprintUtilities.FingerprintLength)),
                    ContentHashingUtilities.CreateRandom(),
                    new StrongContentFingerprint(Fingerprint.Random(FingerprintUtilities.FingerprintLength)),
                    new CacheEntry(ContentHashingUtilities.CreateRandom(), null, CreateRandomContentHashArray())),
                pipCacheDescriptorV2Metadata: null,
                converged: true,
                pathSet: null,
                cacheLookupStepDurations: null,
                pipProperties: new Dictionary <string, int> {
                { "Foo", 1 }, { "Bar", 9 }
            },
                hasUserRetries: true);

            ExecutionResultSerializer serializer = new ExecutionResultSerializer(0, Context);

            ExecutionResult deserializedProcessExecutionResult;

            using (var stream = new MemoryStream())
                using (var writer = new BuildXLWriter(false, stream, true, false))
                    using (var reader = new BuildXLReader(false, stream, true))
                    {
                        serializer.Serialize(writer, processExecutionResult, preservePathCasing: false);

                        stream.Position = 0;

                        deserializedProcessExecutionResult = serializer.Deserialize(reader,
                                                                                    processExecutionResult.PerformanceInformation.WorkerId);
                    }

            // Ensure successful pip result is changed to not materialized.
            XAssert.AreEqual(PipResultStatus.NotMaterialized, deserializedProcessExecutionResult.Result);

            AssertEqual(processExecutionResult, deserializedProcessExecutionResult,
                        r => r.NumberOfWarnings,
                        r => r.Converged,

                        r => r.OutputContent.Length,
                        r => r.DirectoryOutputs.Length,

                        r => r.PerformanceInformation.ExecutionLevel,
                        r => r.PerformanceInformation.ExecutionStop,
                        r => r.PerformanceInformation.ExecutionStart,
                        r => r.PerformanceInformation.ProcessExecutionTime,
                        r => r.PerformanceInformation.FileMonitoringViolations.NumFileAccessViolationsNotAllowlisted,
                        r => r.PerformanceInformation.FileMonitoringViolations.NumFileAccessesAllowlistedAndCacheable,
                        r => r.PerformanceInformation.FileMonitoringViolations.NumFileAccessesAllowlistedButNotCacheable,
                        r => r.PerformanceInformation.UserTime,
                        r => r.PerformanceInformation.KernelTime,
                        r => r.PerformanceInformation.MemoryCounters.PeakWorkingSetMb,
                        r => r.PerformanceInformation.MemoryCounters.AverageWorkingSetMb,
                        r => r.PerformanceInformation.MemoryCounters.PeakCommitSizeMb,
                        r => r.PerformanceInformation.MemoryCounters.AverageCommitSizeMb,

                        r => r.PerformanceInformation.NumberOfProcesses,

                        r => r.FileAccessViolationsNotAllowlisted.Count,
                        r => r.MustBeConsideredPerpetuallyDirty,
                        r => r.DynamicallyObservedFiles.Length,
                        r => r.DynamicallyProbedFiles.Length,
                        r => r.DynamicallyObservedEnumerations.Length,
                        r => r.AllowedUndeclaredReads.Count,

                        r => r.TwoPhaseCachingInfo.WeakFingerprint,
                        r => r.TwoPhaseCachingInfo.StrongFingerprint,
                        r => r.TwoPhaseCachingInfo.PathSetHash,
                        r => r.TwoPhaseCachingInfo.CacheEntry.MetadataHash,
                        r => r.TwoPhaseCachingInfo.CacheEntry.OriginatingCache,
                        r => r.TwoPhaseCachingInfo.CacheEntry.ReferencedContent.Length,

                        r => r.PipProperties.Count,
                        r => r.HasUserRetries,
                        r => r.RetryInfo
                        );

            for (int i = 0; i < processExecutionResult.OutputContent.Length; i++)
            {
                int j = i;
                AssertEqual(processExecutionResult, deserializedProcessExecutionResult,
                            r => r.OutputContent[j].Item1,
                            r => r.OutputContent[j].Item2
                            );

                // Ensure that output origin from deserialzed output content is changed to not materialized.
                XAssert.AreEqual(PipOutputOrigin.NotMaterialized, deserializedProcessExecutionResult.OutputContent[i].Item3);
            }

            for (int i = 0; i < processExecutionResult.DirectoryOutputs.Length; i++)
            {
                var expected = processExecutionResult.DirectoryOutputs[i];
                var result   = deserializedProcessExecutionResult.DirectoryOutputs[i];
                XAssert.AreEqual(expected.Item1, result.Item1);
                XAssert.AreEqual(expected.Item2.Length, result.Item2.Length);

                for (int j = 0; j < expected.Item2.Length; j++)
                {
                    XAssert.AreEqual(expected.Item2[j], result.Item2[j]);
                }
            }

            for (int i = 0; i < processExecutionResult.FileAccessViolationsNotAllowlisted.Count; i++)
            {
                // Compare individual fields for ReportedFileAccess since it uses reference
                // equality for reported process which would not work for serialization/deserialization
                AssertEqual(processExecutionResult.FileAccessViolationsNotAllowlisted[i], deserializedProcessExecutionResult.FileAccessViolationsNotAllowlisted[i]);
            }

            // Ensure that reported process instances are deduplicated.
            XAssert.AreSame(deserializedProcessExecutionResult.FileAccessViolationsNotAllowlisted[0].Process,
                            deserializedProcessExecutionResult.FileAccessViolationsNotAllowlisted[2].Process);

            for (int i = 0; i < processExecutionResult.DynamicallyObservedFiles.Length; i++)
            {
                AssertEqual(processExecutionResult.DynamicallyObservedFiles[i], deserializedProcessExecutionResult.DynamicallyObservedFiles[i]);
            }

            for (int i = 0; i < processExecutionResult.DynamicallyProbedFiles.Length; i++)
            {
                AssertEqual(processExecutionResult.DynamicallyProbedFiles[i], deserializedProcessExecutionResult.DynamicallyProbedFiles[i]);
            }

            for (int i = 0; i < processExecutionResult.DynamicallyObservedEnumerations.Length; i++)
            {
                AssertEqual(processExecutionResult.DynamicallyObservedEnumerations[i], deserializedProcessExecutionResult.DynamicallyObservedEnumerations[i]);
            }

            XAssert.AreSetsEqual(processExecutionResult.AllowedUndeclaredReads, deserializedProcessExecutionResult.AllowedUndeclaredReads, expectedResult: true);

            var referencedContentLength = processExecutionResult.TwoPhaseCachingInfo.CacheEntry.ReferencedContent.Length;

            for (int i = 0; i < referencedContentLength; i++)
            {
                XAssert.AreEqual(
                    processExecutionResult.TwoPhaseCachingInfo.CacheEntry.ReferencedContent[i],
                    deserializedProcessExecutionResult.TwoPhaseCachingInfo.CacheEntry.ReferencedContent[i]);
            }

            XAssert.AreEqual(9, deserializedProcessExecutionResult.PipProperties["Bar"]);
        }