コード例 #1
0
        public void UndeclaredReadCycleReportedForPathOrderedAfter()
        {
            BuildXLContext context  = BuildXLContext.CreateInstanceForTesting();
            var            graph    = new QueryablePipDependencyGraph(context);
            var            analyzer = new TestFileMonitoringViolationAnalyzer(LoggingContext, context, graph);

            AbsolutePath violatorOutput = CreateAbsolutePath(context, JunkPath);
            AbsolutePath producerOutput = CreateAbsolutePath(context, ProducedPath);

            Process violator = graph.AddProcess(violatorOutput);
            Process producer = graph.AddProcess(producerOutput);

            analyzer.AnalyzePipViolations(
                violator,
                new[] { CreateViolation(RequestedAccess.Read, producerOutput) },
                new ReportedFileAccess[0],
                exclusiveOpaqueDirectoryContent: null,
                sharedOpaqueDirectoryWriteAccesses: null,
                allowedUndeclaredReads: null,
                absentPathProbesUnderOutputDirectories: null);

            analyzer.AssertContainsViolation(
                new DependencyViolation(
                    FileMonitoringViolationAnalyzer.DependencyViolationType.UndeclaredReadCycle,
                    FileMonitoringViolationAnalyzer.AccessLevel.Read,
                    producerOutput,
                    violator,
                    producer),
                "An UndeclaredReadCycle should have been reported since an earlier pip has an undeclared read of a later pip's output.");

            analyzer.AssertNoExtraViolationsCollected();
            AssertErrorEventLogged(EventId.FileMonitoringError);
        }
コード例 #2
0
        public void DoubleWriteReportedForPathOrderedBefore()
        {
            BuildXLContext context  = BuildXLContext.CreateInstanceForTesting();
            var            graph    = new QueryablePipDependencyGraph(context);
            var            analyzer = new TestFileMonitoringViolationAnalyzer(LoggingContext, context, graph);

            AbsolutePath violatorOutput = CreateAbsolutePath(context, JunkPath);
            AbsolutePath producerOutput = CreateAbsolutePath(context, DoubleWritePath);

            Process producer = graph.AddProcess(producerOutput);
            Process violator = graph.AddProcess(violatorOutput);

            analyzer.AnalyzePipViolations(
                violator,
                new[] { CreateViolation(RequestedAccess.ReadWrite, producerOutput) },
                new ReportedFileAccess[0],
                exclusiveOpaqueDirectoryContent: null,
                sharedOpaqueDirectoryWriteAccesses: null,
                allowedUndeclaredReads: null,
                absentPathProbesUnderOutputDirectories: null);

            analyzer.AssertContainsViolation(
                new DependencyViolation(
                    FileMonitoringViolationAnalyzer.DependencyViolationType.DoubleWrite,
                    FileMonitoringViolationAnalyzer.AccessLevel.Write,
                    producerOutput,
                    violator,
                    producer),
                "The violator is after the producer, so this should be a double-write on the produced path.");
            analyzer.AssertNoExtraViolationsCollected();
            AssertErrorEventLogged(EventId.FileMonitoringError);
        }
コード例 #3
0
        public void ReadLevelViolationReportedForUnknownPath()
        {
            BuildXLContext context  = BuildXLContext.CreateInstanceForTesting();
            var            graph    = new QueryablePipDependencyGraph(context);
            var            analyzer = new TestFileMonitoringViolationAnalyzer(LoggingContext, context, graph);

            AbsolutePath unknown  = CreateAbsolutePath(context, X("/X/out/unknown"));
            AbsolutePath produced = CreateAbsolutePath(context, ProducedPath);

            Process process = graph.AddProcess(produced);

            analyzer.AnalyzePipViolations(
                process,
                new[] { CreateViolation(RequestedAccess.Read, unknown) },
                new ReportedFileAccess[0],
                exclusiveOpaqueDirectoryContent: null,
                sharedOpaqueDirectoryWriteAccesses: null,
                allowedUndeclaredReads: null,
                absentPathProbesUnderOutputDirectories: null);

            analyzer.AssertContainsViolation(
                new DependencyViolation(
                    FileMonitoringViolationAnalyzer.DependencyViolationType.MissingSourceDependency,
                    FileMonitoringViolationAnalyzer.AccessLevel.Read,
                    unknown,
                    process,
                    null),
                "A MissingSourceDependency should have been reported with no suggested value");

            analyzer.AssertNoExtraViolationsCollected();
            AssertErrorEventLogged(EventId.FileMonitoringError);
        }
コード例 #4
0
        public void DoubleWriteNotReportedForPathOrderedAfter()
        {
            BuildXLContext context  = BuildXLContext.CreateInstanceForTesting();
            var            graph    = new QueryablePipDependencyGraph(context);
            var            analyzer = new TestFileMonitoringViolationAnalyzer(LoggingContext, context, graph);

            AbsolutePath violatorOutput = CreateAbsolutePath(context, JunkPath);
            AbsolutePath producerOutput = CreateAbsolutePath(context, DoubleWritePath);

            Process violator = graph.AddProcess(violatorOutput);
            Process producer = graph.AddProcess(producerOutput);

            analyzer.AnalyzePipViolations(
                violator,
                new[] { CreateViolation(RequestedAccess.ReadWrite, producerOutput) },
                new ReportedFileAccess[0],
                exclusiveOpaqueDirectoryContent: null,
                sharedOpaqueDirectoryWriteAccesses: null,
                allowedUndeclaredReads: null,
                absentPathProbesUnderOutputDirectories: null,
                ReadOnlyArray <(FileArtifact, FileMaterializationInfo, PipOutputOrigin)> .Empty,
                out _);

            analyzer.AssertContainsViolation(
                new DependencyViolation(
                    FileMonitoringViolationAnalyzer.DependencyViolationType.UndeclaredOutput,
                    FileMonitoringViolationAnalyzer.AccessLevel.Write,
                    producerOutput,
                    violator,
                    null),
                "The violator has an undeclared output but it wasn't reported.");

            analyzer.AssertNoExtraViolationsCollected();
            AssertErrorEventLogged(EventId.FileMonitoringError);
        }
コード例 #5
0
        public void DoubleWritePolicyDeterminesViolationSeverity(DoubleWritePolicy doubleWritePolicy)
        {
            BuildXLContext context  = BuildXLContext.CreateInstanceForTesting();
            var            graph    = new QueryablePipDependencyGraph(context);
            var            analyzer = new TestFileMonitoringViolationAnalyzer(
                LoggingContext,
                context,
                graph,
                // Set this to test the logic of base.HandleDependencyViolation(...) instead of the overriding fake
                doLogging: true,
                collectNonErrorViolations: true);

            AbsolutePath violatorOutput = CreateAbsolutePath(context, JunkPath);
            AbsolutePath producerOutput = CreateAbsolutePath(context, DoubleWritePath);

            Process producer = graph.AddProcess(producerOutput, doubleWritePolicy);
            Process violator = graph.AddProcess(violatorOutput, doubleWritePolicy);

            analyzer.AnalyzePipViolations(
                violator,
                new[] { CreateViolation(RequestedAccess.ReadWrite, producerOutput) },
                new ReportedFileAccess[0],
                exclusiveOpaqueDirectoryContent: null,
                sharedOpaqueDirectoryWriteAccesses: null,
                allowedUndeclaredReads: null,
                absentPathProbesUnderOutputDirectories: null,
                ReadOnlyArray <(FileArtifact, FileMaterializationInfo, PipOutputOrigin)> .Empty,
                out _);

            analyzer.AssertContainsViolation(
                new DependencyViolation(
                    FileMonitoringViolationAnalyzer.DependencyViolationType.DoubleWrite,
                    FileMonitoringViolationAnalyzer.AccessLevel.Write,
                    producerOutput,
                    violator,
                    producer),
                "The violator is after the producer, so this should be a double-write on the produced path.");

            analyzer.AssertNoExtraViolationsCollected();
            AssertVerboseEventLogged(LogEventId.DependencyViolationDoubleWrite);

            // Based on the double write policy, the violation is an error or a warning
            if (doubleWritePolicy == DoubleWritePolicy.DoubleWritesAreErrors)
            {
                AssertErrorEventLogged(EventId.FileMonitoringError);
            }
            else
            {
                AssertWarningEventLogged(EventId.FileMonitoringWarning);
            }
        }
コード例 #6
0
        public void ReadRaceReportedForConcurrentPath()
        {
            BuildXLContext context  = BuildXLContext.CreateInstanceForTesting();
            var            graph    = new QueryablePipDependencyGraph(context);
            var            analyzer = new TestFileMonitoringViolationAnalyzer(LoggingContext, context, graph);

            AbsolutePath violatorOutput = CreateAbsolutePath(context, JunkPath);
            AbsolutePath producerOutput = CreateAbsolutePath(context, ProducedPath);

            Process producer = graph.AddProcess(producerOutput);
            Process violator = graph.AddProcess(violatorOutput);

            graph.SetConcurrentRange(producer, violator);

            analyzer.AnalyzePipViolations(
                violator,
                new[] { CreateViolation(RequestedAccess.Read, producerOutput) },
                new ReportedFileAccess[0],
                exclusiveOpaqueDirectoryContent: null,
                sharedOpaqueDirectoryWriteAccesses: null,
                allowedUndeclaredReads: null,
                absentPathProbesUnderOutputDirectories: null,
                ReadOnlyArray <(FileArtifact, FileMaterializationInfo, PipOutputOrigin)> .Empty,
                out _);

            analyzer.AssertContainsViolation(
                new DependencyViolation(
                    FileMonitoringViolationAnalyzer.DependencyViolationType.ReadRace,
                    FileMonitoringViolationAnalyzer.AccessLevel.Read,
                    producerOutput,
                    violator,
                    producer),
                "The violator is concurrent with the producer, so this should be a read-race on the produced path.");
            analyzer.AssertNoExtraViolationsCollected();
            AssertErrorEventLogged(EventId.FileMonitoringError);
        }
コード例 #7
0
        public void MultipleViolationsReportedForSinglePip()
        {
            BuildXLContext context  = BuildXLContext.CreateInstanceForTesting();
            var            graph    = new QueryablePipDependencyGraph(context);
            var            analyzer = new TestFileMonitoringViolationAnalyzer(LoggingContext, context, graph);

            AbsolutePath produced1 = CreateAbsolutePath(context, X("/X/out/produced1"));
            AbsolutePath produced2 = CreateAbsolutePath(context, X("/X/out/produced2"));
            AbsolutePath produced3 = CreateAbsolutePath(context, X("/X/out/produced3"));

            Process producer1 = graph.AddProcess(produced1);
            Process producer2 = graph.AddProcess(produced2);
            Process producer3 = graph.AddProcess(produced3);
            Process violator  = graph.AddProcess(CreateAbsolutePath(context, X("/X/out/violator")));

            graph.SetConcurrentRange(producer3, violator);

            analyzer.AnalyzePipViolations(
                violator,
                new[]
            {
                CreateViolation(RequestedAccess.Read, produced3),
                CreateViolation(RequestedAccess.Read, produced2),
                CreateViolation(RequestedAccess.Write, produced1),
            },
                new ReportedFileAccess[0],
                exclusiveOpaqueDirectoryContent: null,
                sharedOpaqueDirectoryWriteAccesses: null,
                allowedUndeclaredReads: null,
                absentPathProbesUnderOutputDirectories: null);

            analyzer.AssertContainsViolation(
                new DependencyViolation(
                    FileMonitoringViolationAnalyzer.DependencyViolationType.ReadRace,
                    FileMonitoringViolationAnalyzer.AccessLevel.Read,
                    produced3,
                    violator,
                    producer3),
                "The violator is concurrent with the producer, so this should be a read-race on the produced path.");

            analyzer.AssertContainsViolation(
                new DependencyViolation(
                    FileMonitoringViolationAnalyzer.DependencyViolationType.UndeclaredOrderedRead,
                    FileMonitoringViolationAnalyzer.AccessLevel.Read,
                    produced2,
                    violator,
                    producer2),
                "The violator has an undeclared read on the producer but it wasn't reported.");

            analyzer.AssertContainsViolation(
                new DependencyViolation(
                    FileMonitoringViolationAnalyzer.DependencyViolationType.DoubleWrite,
                    FileMonitoringViolationAnalyzer.AccessLevel.Write,
                    produced1,
                    violator,
                    producer1),
                "The violator is after the producer, so this should be a double-write on the produced path.");

            analyzer.AssertNoExtraViolationsCollected();
            AssertErrorEventLogged(EventId.FileMonitoringError);
        }