예제 #1
0
        /// <inheritdoc />
        public override void Dispose()
        {
            m_perfCollector?.Cancel();
            m_perfCollector?.Join();
            m_perfCollector?.Dispose();

            m_timeoutTaskCancelationSource.Cancel();

            ulong reportCount = (ulong)Counters.GetCounterValue(SandboxedProcessCounters.AccessReportCount);

            if (reportCount > 0)
            {
                Counters.AddToCounter(SandboxedProcessCounters.SumOfAccessReportAvgQueueTimeUs, (long)(m_sumOfReportQueueTimesUs / reportCount));
                Counters.AddToCounter(SandboxedProcessCounters.SumOfAccessReportAvgCreationTimeUs, (long)(m_sumOfReportCreationTimesUs / reportCount));
            }

            if (!Killed)
            {
                // Try to kill all processes once the parent gets disposed, so we clean up all used
                // system resources appropriately
                KillAllChildProcesses();
            }

            if (m_pipKextStats != null)
            {
                var statsJson = Newtonsoft.Json.JsonConvert.SerializeObject(m_pipKextStats.Value);
                LogProcessState($"Process Kext Stats: {statsJson}");
            }

            base.Dispose();
        }
예제 #2
0
 /// <nodoc />
 public void Dispose()
 {
     RequestStop();
     m_workerThread.Join();
     m_activeProcessesChecker.Join();
     m_pathCache.Clear();
     m_activeProcesses.Clear();
     Analysis.IgnoreResult(FileUtilities.TryDeleteFile(ReportsFifoPath, waitUntilDeletionFinished: false));
     Analysis.IgnoreResult(FileUtilities.TryDeleteFile(FamPath, waitUntilDeletionFinished: false));
 }
예제 #3
0
        public void CancellingNotStartedActionTest()
        {
            int counter = 0;

            using (var timedAction = new CancellableTimedAction(() => ++ counter, 10, nameof(CancellingNotStartedActionTest)))
            {
                Thread.Sleep(500);
                timedAction.Cancel();
                timedAction.Join();
                XAssert.AreEqual(0, counter);
            }
        }
예제 #4
0
        public void LongIntervalTest()
        {
            int counter = 0;

            using (var timedAction = new CancellableTimedAction(() => Interlocked.Increment(ref counter), 1000, nameof(LongIntervalTest)))
            {
                var sw = System.Diagnostics.Stopwatch.StartNew();
                XAssert.IsTrue(timedAction.Start());
                Thread.Sleep(100);
                timedAction.Cancel();
                timedAction.Join();
                sw.Stop();
                XAssert.AreEqual(1, counter);
                XAssert.IsTrue(sw.ElapsedMilliseconds < 1000);
            }
        }
예제 #5
0
        public void MultipleActionStartsTest()
        {
            var mre     = new ManualResetEvent(false);
            int counter = 0;

            using (var timedAction = new CancellableTimedAction(() =>
            {
                // Signal that thread is started
                mre.Set();
                ++counter;
            }, 10, nameof(MultipleActionStartsTest)))
            {
                XAssert.IsTrue(timedAction.Start());
                XAssert.IsFalse(timedAction.Start());
                Thread.Sleep(500);
                XAssert.IsFalse(timedAction.Start());
                timedAction.Cancel();
                timedAction.Join();
                XAssert.IsTrue(counter > 2, "Value of counter is " + counter);
            }
        }
예제 #6
0
        public void BasicFunctionalityTest()
        {
            var mre     = new ManualResetEvent(false);
            int counter = 0;

            using (var timedAction = new CancellableTimedAction(() =>
            {
                // Signal that thread is started
                mre.Set();
                ++counter;
            }, 10, nameof(BasicFunctionalityTest)))
            {
                XAssert.IsTrue(timedAction.Start());

                // Wait for thread to start
                mre.WaitOne();

                Thread.Sleep(500);
                timedAction.Cancel();
                timedAction.Join();
                XAssert.IsTrue(counter > 2, "Value of counter is " + counter);
            }
        }