public void EnumCounters() { var collection = new CounterCollection <TestCounters>(); XAssert.IsTrue(CounterCollection <TestCounters> .IsStopwatch(TestCounters.SomeTime)); XAssert.IsFalse(CounterCollection <TestCounters> .IsStopwatch(TestCounters.SomeCount)); // Increase the time using (collection.StartStopwatch(TestCounters.SomeTime)) { Thread.Sleep(1); } TimeSpan elapsed = collection.GetElapsedTime(TestCounters.SomeTime); XAssert.IsTrue(elapsed.Ticks > 0); XAssert.AreEqual <long>(0, collection.GetCounterValue(TestCounters.SomeCount)); collection.AddToCounter(TestCounters.SomeCount, 2); XAssert.AreEqual(elapsed, collection.GetElapsedTime(TestCounters.SomeTime)); XAssert.AreEqual <long>(2, collection.GetCounterValue(TestCounters.SomeCount)); TimeSpan delta = new TimeSpan(100); collection.AddToCounter(TestCounters.SomeTime, delta); TimeSpan newElapsed = collection.GetElapsedTime(TestCounters.SomeTime); // note: must not check if `newElapsed == elapsed.Add(delta)` because // `AddToCounter(); GetElapsedTime()` is lossy due to float-point arithmetic XAssert.IsTrue(newElapsed > elapsed); }
internal void LogPipRetryInfo(LoggingContext loggingContext, CounterCollection <PipExecutorCounter> pipExecutionCounters) { if (pipExecutionCounters.GetCounterValue(PipExecutorCounter.ProcessUserRetries) > 0) { string pipsSucceedingAfterUserRetry = string.Join(",", m_pipsSucceedingAfterUserRetry.UnsafeGetList()); string pipsFailingAfterLastUserRetry = string.Join(",", m_pipsFailingAfterLastUserRetry.UnsafeGetList()); Logger.Log.ProcessRetries(loggingContext, pipsSucceedingAfterUserRetry, pipsFailingAfterLastUserRetry); } }
/// <summary> /// Appends <paramref name="other"/> into a current collection instance. /// </summary> public void Append(CounterCollection <TEnum> other) { foreach (var value in EnumTraits <TEnum> .EnumerateValues()) { if (IsStopwatch(value)) { AddToCounter(value, other.GetElapsedTime(value)); } AddToCounter(value, other.GetCounterValue(value)); } }
public void DetectNonDeterminism() { SetupTestState(); Configuration.Sandbox.UnsafeSandboxConfiguration = new UnsafeSandboxConfiguration(Configuration.Sandbox.UnsafeSandboxConfiguration) { UnexpectedFileAccessesAreErrors = false }; string undeclaredFilePath = Path.Combine(Configuration.Layout.SourceDirectory.ToString(PathTable), "undeclared.cpp"); var snapshot = EventListener.SnapshotEventCounts(); var paths = GetBuildPaths(Configuration, PathTable); File.Delete(paths.NonDeterministicTool_ReadAdditionalFileIndicator); EagerCleanBuild("Build #1"); // Ensure no determinism probe events for first build where determinism probe is not enabled XAssert.AreEqual(0, EventListener.GetEventCountSinceSnapshot(EventId.DeterminismProbeEncounteredNondeterministicOutput, snapshot)); XAssert.AreEqual(0, EventListener.GetEventCountSinceSnapshot(EventId.DeterminismProbeEncounteredProcessThatCannotRunFromCache, snapshot)); XAssert.AreEqual(0, EventListener.GetEventCountSinceSnapshot(EventId.DeterminismProbeEncounteredUnexpectedStrongFingerprintMismatch, snapshot)); XAssert.AreEqual(0, EventListener.GetEventCountSinceSnapshot(EventId.DeterminismProbeDetectedUnexpectedMismatch, snapshot)); // Write the indicator file so the second execution will probe an additional file path // thereby adding an absent path probe and changing the strong fingerprint File.WriteAllText(paths.NonDeterministicTool_ReadAdditionalFileIndicator, "Read additional file"); Configuration.Cache.DeterminismProbe = true; CounterCollection <PipExecutorCounter> counters = null; Build("Build #2", scheduler => { counters = scheduler.PipExecutionCounters; }); XAssert.AreEqual(1, counters.GetCounterValue(PipExecutorCounter.ProcessPipDeterminismProbeDifferentFiles)); XAssert.AreEqual(3, counters.GetCounterValue(PipExecutorCounter.ProcessPipDeterminismProbeSameFiles)); // Verify determinism events were logged XAssert.AreEqual(1, EventListener.GetEventCountSinceSnapshot(EventId.DeterminismProbeEncounteredNondeterministicOutput, snapshot)); XAssert.AreEqual(0, EventListener.GetEventCountSinceSnapshot(EventId.DeterminismProbeEncounteredProcessThatCannotRunFromCache, snapshot)); XAssert.AreEqual(1, EventListener.GetEventCountSinceSnapshot(EventId.DeterminismProbeEncounteredUnexpectedStrongFingerprintMismatch, snapshot)); XAssert.AreEqual(0, EventListener.GetEventCountSinceSnapshot(EventId.DeterminismProbeDetectedUnexpectedMismatch, snapshot)); // Now perform a build where the pip is uncacheable File.WriteAllText(undeclaredFilePath, "whatever"); Build("Build #3"); File.Delete(undeclaredFilePath); // Warnings for the file access violation, uncacheable pip, and dependency analyzer AssertWarningEventLogged(EventId.FileMonitoringWarning); AssertWarningEventLogged(EventId.ProcessNotStoredToCacheDueToFileMonitoringViolations, count: 2); // Determinism validation cannot be performed AssertInformationalEventLogged(EventId.DeterminismProbeEncounteredUncacheablePip); // Perform a build where the pip fails File.Delete(paths.NonDeterministicTool_ProbedFile); // The absence of the above file causes the pip to produce fewer files than expected. The // test executes with this condition in order to ensure that the determinism probe properly // handles pip failures. Configuration.Cache.DeterminismProbe = true; FailedBuild("Build #4"); AssertVerboseEventLogged(EventId.PipProcessMissingExpectedOutputOnCleanExit); AssertErrorEventLogged(EventId.PipProcessExpectedMissingOutputs); AssertErrorEventLogged(EventId.PipProcessError); // Verify DeterminismProbeEncounteredPipFailure was logged XAssert.AreEqual(1, EventListener.GetEventCountSinceSnapshot(EventId.DeterminismProbeEncounteredPipFailure, snapshot)); }