Esempio n. 1
0
        public void FailWhenTwoPipsHaveSameTempDirectory(bool allowDuplicateTemporaryDirectory, int tempArtifactType)
        {
            Configuration.Engine.AllowDuplicateTemporaryDirectory = allowDuplicateTemporaryDirectory;
            Exception caughtExpection = null;

            try
            {
                CreateAndSchedulePipWithTemp(tempArtifactType, out var tempOut1);
                CreateAndSchedulePipWithTemp(tempArtifactType, out var tempOut2);

                PipGraphBuilder.Build();
            }
            catch (Exception e)
            {
                caughtExpection = e;
            }

            if (!allowDuplicateTemporaryDirectory)
            {
                AssertTrue(caughtExpection != null, "Expected PipGraph Builder Exception, but Graph built successfully");
                AssertErrorEventLogged(LogEventId.MultiplePipsUsingSameTemporaryDirectory);
            }
            else
            {
                AssertTrue(caughtExpection == null, "Expected PipGraph Builder to pass, but Graph built failed with exception: " + caughtExpection?.Message);
            }
        }
        private void RunAndAssertDumpPip(Pip pip)
        {
            var graph   = PipGraphBuilder.Build();
            var success = CreateLogPathAndRun(pip, graph);

            AssertCommon(success, pip, graph);
        }
Esempio n. 3
0
        public void FailWhenCopyFileOutputsToTemp(int tempArtifactType)
        {
            CreateAndSchedulePipWithTemp(tempArtifactType, out var tempOut);

            var srcFile     = CreateSourceFile();
            var destFile    = CreateOutputFileArtifact(TempRoot);
            var copyFilePip = CreateAndScheduleCopyFile(srcFile, destFile);

            PipGraphBuilder.Build();
            AssertErrorEventLogged(EventId.InvalidGraphSinceArtifactPathOverlapsTempPath);
        }
Esempio n. 4
0
        /// <summary>
        /// Runs the scheduler using the instance member PipGraph and Configuration objects. This will also carry over
        /// any state from any previous run such as the cache
        /// </summary>
        public ScheduleRunResult RunScheduler(SchedulerTestHooks testHooks = null, SchedulerState schedulerState = null, RootFilter filter = null, TempCleaner tempCleaner = null)
        {
            if (m_graphWasModified || m_lastGraph == null)
            {
                m_lastGraph = PipGraphBuilder.Build();
                XAssert.IsNotNull(m_lastGraph, "Failed to build pip graph");
            }

            m_graphWasModified = false;
            return(RunSchedulerSpecific(m_lastGraph, testHooks, schedulerState, filter, tempCleaner));
        }
Esempio n. 5
0
        public void FailWhenTempDirectoryContainsTempDirectory(int tempArtifactType)
        {
            var parentTemp = CreateUniqueDirectory(TempRoot);

            CreateAndSchedulePipWithTemp(tempArtifactType, out var tempOut, parentTemp);

            var childTemp = CreateUniqueDirectory(parentTemp);

            CreateAndSchedulePipWithTemp(tempArtifactType, out var tempOut2, childTemp);

            PipGraphBuilder.Build();
        }
Esempio n. 6
0
        public void FailWhenTempDirectoryContainsAnotherPipsOutputFile(int tempArtifactType)
        {
            CreateAndSchedulePipWithTemp(tempArtifactType, out var tempOut);

            // Pip attempts to declare an output in a temp directory (that was declared by a different pip)
            var pipInvalidOutInTempOps = CreateAndSchedulePipBuilder(new Operation[]
            {
                Operation.WriteFile(CreateOutputFileArtifact(TempRoot))
            }).Process;

            PipGraphBuilder.Build();
            AssertErrorEventLogged(EventId.InvalidGraphSinceArtifactPathOverlapsTempPath);
        }
        public void TestBadPath()
        {
            FileArtifact outputFile = CreateOutputFileArtifact();
            WriteFile    pip        = CreateWriteFile(outputFile, string.Empty, new[] { "some content" });

            PipGraphBuilder.AddWriteFile(pip);
            var graph = PipGraphBuilder.Build();

            var success = DumpPipLiteAnalysisUtilities.DumpPip(pip, @"X:\not\a\real\path\", Context.PathTable, Context.StringTable, Context.SymbolTable, graph, LoggingContext);

            Assert.False(success);
            AssertWarningEventLogged(LogEventId.DumpPipLiteUnableToSerializePipDueToBadPath);
        }
        /// <summary>
        /// Serializes and deserializes graph fragments synchronously according to its dependency relation specified by their order in the array.
        /// </summary>
        /// <param name="fragments">Graph fragments with total order on their dependency relation.</param>
        /// <returns>Resulting pip graph.</returns>
        private PipGraph SerializeDeserializeFragmentsSynchronously(params TestPipGraphFragment[] fragments)
        {
            var streams = SerializeFragmentsSynchronously(fragments);

            var fragmentManager = new PipGraphFragmentManager(LoggingContext, Context, PipGraphBuilder);

            for (int i = 0; i < streams.Length; ++i)
            {
                XAssert.IsTrue(fragmentManager.AddFragmentFileToGraph(streams[i], fragments[i].ModuleName));
            }

            DisposeStreams(streams);

            return(PipGraphBuilder.Build());
        }
Esempio n. 9
0
        public void FailWhenTempDirectoryContainsSourceFile(int tempArtifactType)
        {
            CreateAndSchedulePipWithTemp(tempArtifactType, out var tempOut);

            // Declare a dependency on a source file within a different pip's temp directory
            var src = CreateSourceFile(TempRootPath);

            CreateAndSchedulePipBuilder(new Operation[]
            {
                Operation.ReadFile(src),
                Operation.WriteFile(CreateOutputFileArtifact())
            });

            PipGraphBuilder.Build();
            AssertErrorEventLogged(EventId.InvalidGraphSinceArtifactPathOverlapsTempPath);
        }
Esempio n. 10
0
        public void FailWhenTempDirectoryContainsAnotherPipsOutputDirectory(int tempArtifactType)
        {
            CreateAndSchedulePipWithTemp(tempArtifactType, out var tempOut);

            // Pip attempts to declare an output directory in a temp directory (that was declared by a different pip)
            var builder = CreatePipBuilder(new Operation[] { });

            var opaqueDir     = Path.Combine(TempRoot, "opaquedir");
            var opaqueDirPath = AbsolutePath.Create(Context.PathTable, opaqueDir);

            builder.AddOutputDirectory(opaqueDirPath, SealDirectoryKind.Opaque);
            SchedulePipBuilder(builder);

            PipGraphBuilder.Build();
            AssertErrorEventLogged(EventId.InvalidGraphSinceArtifactPathOverlapsTempPath);
        }
Esempio n. 11
0
        public void FailWhenSealedSourceDirectoryIsTempArtifact(int tempArtifactType)
        {
            var sealDir = SealDirectory(SourceRootPath, SealDirectoryKind.SourceAllDirectories);

            var builder = CreatePipBuilder(new Operation[]
            {
                Operation.WriteFile(CreateOutputFileArtifact())
            });

            builder.AddInputDirectory(sealDir);
            SchedulePipBuilder(builder);

            CreateAndSchedulePipWithTemp(tempArtifactType, out var tempOut, tempRoot: sealDir.Path);

            PipGraphBuilder.Build();
            AssertErrorEventLogged(EventId.InvalidGraphSinceArtifactPathOverlapsTempPath);
        }
Esempio n. 12
0
        public void FailWhenTempDirectoryContainsPipsOutputFile(int tempArtifactType)
        {
            var tempOut = CreateOutputFileArtifact(TempRoot);

            // Pip attempts to declare an output in its own temp
            CreateAndScheduleTempDirProcess(new Operation[]
            {
                Operation.WriteFile(tempOut),
                Operation.WriteFile(CreateOutputFileArtifact())
            },
                                            tempArtifactType,
                                            TempRootPath,
                                            tempOut.Path);

            PipGraphBuilder.Build();
            AssertErrorEventLogged(EventId.InvalidGraphSinceArtifactPathOverlapsTempPath);
        }
Esempio n. 13
0
        public void FailWhenTwoPipsHaveSameTempDirectory(int tempArtifactType)
        {
            Exception exception = null;

            try
            {
                CreateAndSchedulePipWithTemp(tempArtifactType, out var tempOut1);
                CreateAndSchedulePipWithTemp(tempArtifactType, out var tempOut2);

                PipGraphBuilder.Build();
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            XAssert.AreNotEqual(null, exception);
        }
        /// <summary>
        /// Serializes and deserializes graph fragments in parallel.
        /// </summary>
        /// <param name="fragments">Graph fragments.</param>
        /// <returns>Resulting pip graph.</returns>
        /// <remarks>
        /// The graph fragments, <paramref name="fragments"/>, are serialized synchronously, but are deserialized in parallel.
        /// For correctness, the graph fragments in <paramref name="fragments"/> are assumed to be independent of each other.
        /// </remarks>
        private PipGraph SerializeDeserializeFragmentsInParallel(params TestPipGraphFragment[] fragments)
        {
            var streams = SerializeFragmentsSynchronously(fragments);

            var fragmentManager = new PipGraphFragmentManager(LoggingContext, Context, PipGraphBuilder);

            Parallel.For(
                0,
                fragments.Length,
                i =>
            {
                XAssert.IsTrue(fragmentManager.AddFragmentFileToGraph(streams[i], fragments[i].ModuleName));
            });

            DisposeStreams(streams);

            return(PipGraphBuilder.Build());
        }
Esempio n. 15
0
        public void FailWhenTempDirectoryContainsSharedOpaque(int tempArtifactType, SealDirectoryKind sealDirectoryKind)
        {
            // Place a temp underneath previous pip's output directory
            CreateAndSchedulePipWithTemp(tempArtifactType, out var tempOut);

            var outputDir     = Path.Combine(TempRoot, "opaquedir");
            var outputDirPath = AbsolutePath.Create(Context.PathTable, outputDir);

            var builderWithOutputDirectory = CreatePipBuilder(
                new Operation[]
            {
                Operation.WriteFile(CreateOutputFileArtifact(outputDirPath), doNotInfer: true),
            });

            builderWithOutputDirectory.AddOutputDirectory(outputDirPath, sealDirectoryKind);
            SchedulePipBuilder(builderWithOutputDirectory);

            PipGraphBuilder.Build();
            AssertErrorEventLogged(EventId.InvalidGraphSinceArtifactPathOverlapsTempPath);
        }
Esempio n. 16
0
        public void FailWhenTempDirectoryIsAlsoAnotherPipsOutputDirectory(int tempArtifactType)
        {
            var tempDir     = Path.Combine(TempRoot, "opaquedir");
            var tempDirPath = AbsolutePath.Create(Context.PathTable, tempDir);

            CreateAndSchedulePipWithTemp(tempArtifactType, out var tempOut, tempRoot: tempDirPath);

            // Pip tries to declare a temp directory or temp output as a directory output
            var builderWithOutputDirectory = CreatePipBuilder(
                new Operation[]
            {
                Operation.WriteFile(CreateOutputFileArtifact())
            });

            builderWithOutputDirectory.AddOutputDirectory(tempDirPath, SealDirectoryKind.Opaque);
            SchedulePipBuilder(builderWithOutputDirectory);

            PipGraphBuilder.Build();
            AssertErrorEventLogged(EventId.InvalidGraphSinceArtifactPathOverlapsTempPath);
        }
Esempio n. 17
0
        public void FailWhenTempDirectoryIsAlsoPipsOutputDirectory(int tempArtifactType)
        {
            var tempDir     = Path.Combine(TempRoot, "opaquedir");
            var tempDirPath = AbsolutePath.Create(Context.PathTable, tempDir);
            var tempOut     = CreateOutputFileArtifact(tempDirPath);

            var builder = CreateTempDirProcessBuilder(
                new Operation[]
            {
                Operation.WriteFile(CreateOutputFileArtifact())
            },
                tempArtifactType,
                tempRootPath: tempDirPath,
                tempOut: tempOut);

            // Pip tries to declare a temp directory or temp output as a directory output
            builder.AddOutputDirectory(tempDirPath, SealDirectoryKind.Opaque);
            var pip = SchedulePipBuilder(builder).Process;

            PipGraphBuilder.Build();
            AssertErrorEventLogged(EventId.InvalidGraphSinceArtifactPathOverlapsTempPath);
        }
Esempio n. 18
0
        public void FailWhenTempDirectoryContainsPipsOutputDirectory(int tempArtifactType)
        {
            var tempOut = CreateOutputFileArtifact(TempRoot);

            // Pip attempts to declare an output in its own temp
            var builder = CreateTempDirProcessBuilder(new Operation[]
            {
                Operation.WriteFile(tempOut, doNotInfer: true),
                Operation.WriteFile(CreateOutputFileArtifact())
            },
                                                      tempArtifactType,
                                                      TempRootPath,
                                                      tempOut.Path);

            var opaqueDir     = Path.Combine(TempRoot, "opaquedir");
            var opaqueDirPath = AbsolutePath.Create(Context.PathTable, opaqueDir);

            builder.AddOutputDirectory(opaqueDirPath, SealDirectoryKind.Opaque);
            SchedulePipBuilder(builder);

            PipGraphBuilder.Build();
            AssertErrorEventLogged(EventId.InvalidGraphSinceArtifactPathOverlapsTempPath);
        }
Esempio n. 19
0
        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());
        }