public void ReadRaceEventLoggedOnViolationDistributed() { BuildXLContext context = BuildXLContext.CreateInstanceForTesting(); var graph = new QueryablePipDependencyGraph(context); var analyzer = new FileMonitoringViolationAnalyzer(LoggingContext, context, graph, new QueryableEmptyFileContentManager(), validateDistribution: true, ignoreDynamicWritesOnAbsentProbes: false, unexpectedFileAccessesAsErrors: true); AbsolutePath violatorOutput = CreateAbsolutePath(context, JunkPath); AbsolutePath producerOutput = CreateAbsolutePath(context, ProducedPath); Process producer = graph.AddProcess(producerOutput); Process violator = graph.AddProcess(violatorOutput); graph.SetConcurrentRange(producer, violator); AnalyzePipViolationsResult analyzePipViolationsResult = analyzer.AnalyzePipViolations( violator, new[] { CreateViolation(RequestedAccess.Read, producerOutput) }, null, // whitelisted accesses exclusiveOpaqueDirectoryContent: null, sharedOpaqueDirectoryWriteAccesses: null, allowedUndeclaredReads: null, absentPathProbesUnderOutputDirectories: null); AssertTrue(!analyzePipViolationsResult.IsViolationClean); AssertErrorEventLogged(EventId.FileMonitoringError); AssertVerboseEventLogged(LogEventId.DependencyViolationReadRace); }
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); 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); }
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); }