Ejemplo n.º 1
0
        public void TestAddingAndUnifyingIpcPip()
        {
            var fragment = CreatePipGraphFragmentTest(nameof(TestAddingAndUnifyingIpcPip));

            (IIpcMoniker moniker, PipId servicePipId) = TestPipGraphFragmentUtils.CreateService(fragment);

            var          processBuilder          = fragment.GetProcessBuilder();
            var          argumentsBuilder        = new ArgumentsBuilder(processBuilder);
            FileArtifact outputFileToVerify      = fragment.CreateOutputFile("g");
            AbsolutePath outputDirectoryToVerify = fragment.CreateOutputDirectory("d").Path;

            argumentsBuilder
            .AddInputFileOption("/input:", fragment.CreateSourceFile("f"))
            .AddOutputFileOption("/output:", outputFileToVerify.Path)
            .AddOutputDirectoryOption("/outputDir:", outputDirectoryToVerify)
            .Finish();
            (Process process, ProcessOutputs processOutputs) = fragment.ScheduleProcessBuilder(processBuilder);

            XAssert.IsTrue(processOutputs.TryGetOutputDirectory(outputDirectoryToVerify, out var outputDirectory));

            var addFileProcessBuilder = fragment.GetIpcProcessBuilder();

            new ArgumentsBuilder(addFileProcessBuilder)
            .AddStringOption("--command ", "addFile")
            .AddIpcMonikerOption("--ipcMoniker ", moniker)
            .AddInputFileOption("--file ", outputFileToVerify)
            .AddInputDirectoryOption("--directory ", outputDirectory.Root)
            .AddFileIdOption("--fileId ", outputFileToVerify)
            .AddDirectoryIdOption("--directoryId ", outputDirectory.Root)
            .AddVsoHashOption("--vsoHash ", outputFileToVerify)
            .Finish();

            FileArtifact ipcOutputFileToVerify;

            IpcPip ipcPip = fragment.ScheduleIpcPip(
                moniker,
                servicePipId,
                addFileProcessBuilder,
                ipcOutputFileToVerify = fragment.CreateOutputFile("add"),
                false);

            var graph = SerializeAndDeserializeIndependentFragments(fragment, fragment);

            VerifyGraphSuccessfullyConstructed(graph);
            VerifyProducerExists(graph, fragment, outputFileToVerify.Path);
            VerifyProducerExists(graph, fragment, outputDirectoryToVerify);
            VerifyProducerExists(graph, fragment, ipcOutputFileToVerify);

            var remappedOutputFile      = FileArtifact.CreateOutputFile(RemapFragmentPath(fragment, outputFileToVerify.Path));
            var remappedOutputDirectory = DirectoryArtifact.CreateWithZeroPartialSealId(RemapFragmentPath(fragment, outputDirectory.Root));

            PipData expectedArguments = new ArgumentsDataBuilder(Context.StringTable)
                                        .AddStringOption("--command ", "addFile")
                                        .AddIpcMonikerOption("--ipcMoniker ", moniker)
                                        .AddPathOption("--file ", remappedOutputFile.Path)
                                        .AddPathOption("--directory ", remappedOutputDirectory.Path)
                                        .AddFileIdOption("--fileId ", remappedOutputFile)
                                        .AddDirectoryIdOption("--directoryId ", remappedOutputDirectory)
                                        .AddVsoHashOption("--vsoHash ", remappedOutputFile)
                                        .Finish();

            VerifyResultingArguments(graph, fragment, ipcOutputFileToVerify, expectedArguments);
        }
Ejemplo n.º 2
0
        public void TestIpcPipConsumptionFromOtherFragment()
        {
            // Create fragment 1:
            //
            // h -> R -> g -> Q -> f -> P -> e

            var fragment1         = CreatePipGraphFragmentTest(nameof(TestIpcPipConsumptionFromOtherFragment) + "1");
            var processBuilderP   = fragment1.GetProcessBuilder();
            var argumentsBuilderP = new ArgumentsBuilder(processBuilderP);
            var f = fragment1.CreateOutputFile("f");

            argumentsBuilderP
            .AddInputFileOption("/input:", fragment1.CreateSourceFile("e"))
            .AddOutputFileOption("/output:", f.Path)
            .Finish();
            (Process processP, ProcessOutputs outputsP) = fragment1.ScheduleProcessBuilder(processBuilderP);

            var processBuilderQ   = fragment1.GetProcessBuilder();
            var argumentsBuilderQ = new ArgumentsBuilder(processBuilderQ);
            var g = fragment1.CreateOutputFile("g");

            argumentsBuilderQ
            .AddInputFileOption("/input:", outputsP.TryGetOutputFile(f.Path, out var fAsOutput) ? fAsOutput : FileArtifact.Invalid)
            .AddOutputFileOption("/output:", g.Path)
            .Finish();
            (Process processQ, ProcessOutputs outputsQ) = fragment1.ScheduleProcessBuilder(processBuilderQ);

            var processBuilderR   = fragment1.GetProcessBuilder();
            var argumentsBuilderR = new ArgumentsBuilder(processBuilderR);
            var h = fragment1.CreateOutputFile("h");

            argumentsBuilderR
            .AddInputFileOption("/input:", outputsQ.TryGetOutputFile(g.Path, out var gAsOutput) ? gAsOutput : FileArtifact.Invalid)
            .AddOutputFileOption("/output:", h.Path)
            .Finish();
            (Process processR, ProcessOutputs outputsR) = fragment1.ScheduleProcessBuilder(processBuilderR);

            // Create fragment 2:
            //
            // z -> C -> x -> A -> w
            //      |
            //      + -> y -> B -> v

            var fragment2         = CreatePipGraphFragmentTest(nameof(TestIpcPipConsumptionFromOtherFragment) + "2");
            var processBuilderA   = fragment2.GetProcessBuilder();
            var argumentsBuilderA = new ArgumentsBuilder(processBuilderA);
            var x = fragment2.CreateOutputFile("x");

            argumentsBuilderA
            .AddInputFileOption("/input:", fragment2.CreateSourceFile("w"))
            .AddOutputFileOption("/output:", x.Path)
            .Finish();
            (Process processA, ProcessOutputs outputsA) = fragment2.ScheduleProcessBuilder(processBuilderA);

            var processBuilderB   = fragment2.GetProcessBuilder();
            var argumentsBuilderB = new ArgumentsBuilder(processBuilderB);
            var y = fragment2.CreateOutputFile("y");

            argumentsBuilderB
            .AddInputFileOption("/input:", fragment2.CreateSourceFile("v"))
            .AddOutputFileOption("/output:", y.Path)
            .Finish();
            (Process processB, ProcessOutputs outputsB) = fragment2.ScheduleProcessBuilder(processBuilderB);

            var processBuilderC   = fragment2.GetProcessBuilder();
            var argumentsBuilderC = new ArgumentsBuilder(processBuilderC);
            var z = fragment2.CreateOutputFile("z");

            argumentsBuilderC
            .AddInputFileOption("/input:", outputsB.TryGetOutputFile(y.Path, out var yAsOutput) ? yAsOutput : FileArtifact.Invalid)
            .AddInputFileOption("/input:", outputsA.TryGetOutputFile(x.Path, out var xAsOutput) ? xAsOutput : FileArtifact.Invalid)
            .AddOutputFileOption("/output:", z.Path)
            .Finish();
            (Process processC, ProcessOutputs outputsC) = fragment2.ScheduleProcessBuilder(processBuilderC);

            // Drop z and h in fragment 2.
            (IIpcMoniker moniker, PipId servicePipId) = TestPipGraphFragmentUtils.CreateService(fragment2);

            var addZBuilder = fragment2.GetIpcProcessBuilder();

            new ArgumentsBuilder(addZBuilder)
            .AddStringOption("--command ", "addFile")
            .AddIpcMonikerOption("--ipcMoniker ", moniker)
            .AddInputFileOption("--file ", z)
            .Finish();

            IpcPip ipcPipZ = fragment2.ScheduleIpcPip(
                moniker,
                servicePipId,
                addZBuilder,
                fragment2.CreateOutputFile("addZ"),
                false);

            var addHBuilder = fragment2.GetIpcProcessBuilder();

            new ArgumentsBuilder(addHBuilder)
            .AddStringOption("--command ", "addFile")
            .AddIpcMonikerOption("--ipcMoniker ", moniker)
            .AddInputFileOption("--file ", fragment2.CreateOutputFile("h"))     // h is created by fragment 1.
            .Finish();

            IpcPip ipcPipH = fragment2.ScheduleIpcPip(
                moniker,
                servicePipId,
                addHBuilder,
                fragment2.CreateOutputFile("addH"),
                false);

            var graph = SerializeAndDeserializeFragments(fragment1, fragment2);

            VerifyGraphSuccessfullyConstructed(graph);
        }
Ejemplo n.º 3
0
        public void TestTopSort()
        {
            // Create fragment :
            //
            // z -> C --------+----> x -> A -> w
            //      |         |
            //      |         |
            //      + -> y -> B -> v

            var fragment          = CreatePipGraphFragment(nameof(TestTopSort), useTopSort: true);
            var processBuilderA   = fragment.GetProcessBuilder();
            var argumentsBuilderA = new ArgumentsBuilder(processBuilderA);
            var x = fragment.CreateOutputFile("x");

            argumentsBuilderA
            .AddInputFileOption("/input:", fragment.CreateSourceFile("w"))
            .AddOutputFileOption("/output:", x.Path)
            .Finish();
            (Process processA, ProcessOutputs outputsA) = fragment.ScheduleProcessBuilder(processBuilderA);

            var processBuilderB   = fragment.GetProcessBuilder();
            var argumentsBuilderB = new ArgumentsBuilder(processBuilderB);
            var y = fragment.CreateOutputFile("y");

            argumentsBuilderB
            .AddInputFileOption("/input:", fragment.CreateSourceFile("v"))
            .AddInputFileOption("/input:", outputsA.TryGetOutputFile(x.Path, out var xAsOutput) ? xAsOutput : FileArtifact.Invalid)
            .AddOutputFileOption("/output:", y.Path)
            .Finish();
            (Process processB, ProcessOutputs outputsB) = fragment.ScheduleProcessBuilder(processBuilderB);

            var processBuilderC   = fragment.GetProcessBuilder();
            var argumentsBuilderC = new ArgumentsBuilder(processBuilderC);
            var z = fragment.CreateOutputFile("z");

            argumentsBuilderC
            .AddInputFileOption("/input:", outputsB.TryGetOutputFile(y.Path, out var yAsOutput) ? yAsOutput : FileArtifact.Invalid)
            .AddInputFileOption("/input:", outputsA.TryGetOutputFile(x.Path, out var xAsOutput2) ? xAsOutput2 : FileArtifact.Invalid)
            .AddOutputFileOption("/output:", z.Path)
            .Finish();
            (Process processC, ProcessOutputs outputsC) = fragment.ScheduleProcessBuilder(processBuilderC);

            // Drop z and y.
            var serviceRelatedPips = new TestPipGraphFragmentUtils.ServiceRelatedPips();

            (IIpcMoniker moniker, PipId servicePipId) = TestPipGraphFragmentUtils.CreateService(fragment, serviceRelatedPips);

            var addZBuilder = fragment.GetIpcProcessBuilder();

            new ArgumentsBuilder(addZBuilder)
            .AddStringOption("--command ", "addFile")
            .AddIpcMonikerOption("--ipcMoniker ", moniker)
            .AddInputFileOption("--file ", z)
            .Finish();

            IpcPip ipcPipZ = fragment.ScheduleIpcPip(
                moniker,
                servicePipId,
                addZBuilder,
                fragment.CreateOutputFile("addZ"),
                false);

            var addYBuilder = fragment.GetIpcProcessBuilder();

            new ArgumentsBuilder(addYBuilder)
            .AddStringOption("--command ", "addFile")
            .AddIpcMonikerOption("--ipcMoniker ", moniker)
            .AddInputFileOption("--file ", y)
            .Finish();

            IpcPip ipcPipY = fragment.ScheduleIpcPip(
                moniker,
                servicePipId,
                addYBuilder,
                fragment.CreateOutputFile("addY"),
                false);

            var sortedPips = new PipGraphFragmentTopSort(fragment.PipGraph).Sort();

            XAssert.AreEqual(10, sortedPips.Count);                   // There are ten layers.
            XAssert.IsTrue(sortedPips[0].All(p => p is ModulePip));   // 0th layer is module pips.
            XAssert.IsTrue(sortedPips[1].All(p => p is SpecFilePip)); // 1st layer is spec pips.
            XAssert.IsTrue(sortedPips[2].All(p => p is ValuePip));    // 2nd layer is value pips.

            for (int i = 3; i <= 5; ++i)
            {
                // 3rd, 4th, and 5th layer are service related pips.
                XAssert.AreEqual(1, sortedPips[i].Count);
                XAssert.IsTrue(ServicePipKindUtil.IsServiceStartShutdownOrFinalizationPip(sortedPips[i][0]));
            }

            // 6th layer contains pip A and create drop pip.
            XAssert.AreEqual(2, sortedPips[6].Count);
            XAssert.Contains(sortedPips[6], serviceRelatedPips.Create, processA);

            // 7th layer contains pip B.
            XAssert.AreEqual(1, sortedPips[7].Count);
            XAssert.Contains(sortedPips[7], processB);

            // 8th layer contains pip C and create drop pip y.
            XAssert.AreEqual(2, sortedPips[8].Count);
            XAssert.Contains(sortedPips[8], ipcPipY, processC);

            // 9th layer contains drop pip z.
            XAssert.AreEqual(1, sortedPips[9].Count);
            XAssert.Contains(sortedPips[9], ipcPipZ);
        }