示例#1
0
        public void RelationTable_can_be_built()
        {
            PackedExecution packedExecution = new PackedExecution();

            PackedExecution.Builder packedExecutionBuilder = new PackedExecution.Builder(packedExecution);
            long   hash   = 1;
            string name   = "ShellCommon.Shell.ShellCommon.Shell.Merged.Winmetadata";
            PipId  pipId  = packedExecutionBuilder.PipTableBuilder.Add(hash, name, PipType.Process);
            PipId  pipId2 = packedExecutionBuilder.PipTableBuilder.Add(hash + 1, $"{name}2", PipType.Process);
            PipId  pipId3 = packedExecutionBuilder.PipTableBuilder.Add(hash + 2, $"{name}3", PipType.Process);

            packedExecution.ConstructRelationTables();

            RelationTable <PipId, PipId> relationTable = packedExecution.PipDependencies;

            RelationTable <PipId, PipId> .Builder builder = new RelationTable <PipId, PipId> .Builder(relationTable);

            // add relations in any order
            builder.Add(pipId3, pipId2);
            builder.Add(pipId3, pipId);
            builder.Add(pipId, pipId3);
            builder.Add(pipId, pipId2);

            // done adding relations; flush to table
            builder.Complete();

            XAssert.AreArraysEqual(new[] { pipId2, pipId3 }, relationTable[pipId].ToArray(), true);
            XAssert.AreArraysEqual(new PipId[0], relationTable[pipId2].ToArray(), true);
            XAssert.AreArraysEqual(new[] { pipId, pipId2 }, relationTable[pipId3].ToArray(), true);

            XAssert.AreArraysEqual(new[] { pipId2, pipId3 }, relationTable.Enumerate(pipId).ToArray(), true);
            XAssert.AreArraysEqual(new PipId[0], relationTable.Enumerate(pipId2).ToArray(), true);
            XAssert.AreArraysEqual(new[] { pipId, pipId2 }, relationTable.Enumerate(pipId3).ToArray(), true);
        }
示例#2
0
        private static void CheckRelation(PackedExecution packedExecution, PipId pipId1, PipId pipId2, PipId pipId3, PipId pipId4, RelationTable <PipId, PipId> relationTable)
        {
            XAssert.AreArraysEqual(new PipId[0], relationTable[pipId1].ToArray(), true);
            XAssert.AreArraysEqual(new[] { pipId1 }, relationTable[pipId2].ToArray(), true);
            XAssert.AreArraysEqual(new[] { pipId1 }, relationTable[pipId3].ToArray(), true);
            XAssert.AreArraysEqual(new[] { pipId2, pipId3 }, relationTable[pipId4].ToArray(), true);

            XAssert.AreArraysEqual(new PipId[0], relationTable.Enumerate(pipId1).ToArray(), true);
            XAssert.AreArraysEqual(new[] { pipId1 }, relationTable.Enumerate(pipId2).ToArray(), true);
            XAssert.AreArraysEqual(new[] { pipId2, pipId3 }, relationTable.Enumerate(pipId4).ToArray(), true);

            // try traversing from pipId4; should traverse over pipId3 and reach pipId (as well as pipId2)
            IEnumerable <PipId> reachable = relationTable.Traverse(
                pipId4,
                p => packedExecution.PipTable[p].PipType == PipType.Process
                    ? TraversalFilterResult.AcceptAndHalt
                    : TraversalFilterResult.RejectAndContinue);

            XAssert.AreArraysEqual(new[] { pipId1, pipId2 }, reachable.OrderBy(p => p.Value).ToArray(), true);
        }