Update of /cvsroot/adapdev/Adapdev/src/Adapdev.Tests/Diagnostics
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv909/src/Adapdev.Tests/Diagnostics
Added Files:
CPUMeterTest.cs PerfTimerFactoryTest.cs
Log Message:
--- NEW FILE: CPUMeterTest.cs ---
using System;
namespace Adapdev.Diagnostics.Tests
{
using System.Threading;
using NUnit.Framework;
/// <summary>
/// Summary description for CPUMeterTest.
/// </summary>
///
[TestFixture]
public class CPUMeterTest
{
[Test]
public void GetCpuUtilizationForCurrentProcess()
{
CPUMeter mtr = new CPUMeter();
this.Process(mtr);
}
[Test]
public void GetCpuUtilizationForSystemProcess()
{
// System PID is 4
CPUMeter mtr = new CPUMeter(4);
this.Process(mtr);
}
[Test]
public void GetCpuUtilizationForCurrentProcessOverTime()
{
CPUMeter mtr = new CPUMeter();
this.Process(mtr);
mtr.ResetCounter();
Thread.Sleep(1000);
this.Process(mtr);
}
private double Process(CPUMeter cpuMeter)
{
double result = 0;
for (int i = 0;i<100000000; i++)
{
result = result+Math.Sin(i);
}
double usage = cpuMeter.GetCpuUtilization();
Console.WriteLine("Done. CPU Usage {0:#00.00} %", usage);
return usage;
}
}
}
--- NEW FILE: PerfTimerFactoryTest.cs ---
using System;
using Adapdev.Diagnostics;
namespace Adapdev.Diagnostics.Tests
{
using System.Threading;
using NUnit.Framework;
/// <summary>
/// Summary description for PerfTimerFactoryTest.
/// </summary>
///
[TestFixture]
public class PerfTimerFactoryTest
{
[Test]
public void HiResSeconds()
{
double result = this.GetOutput(PerfTimerType.HIRESSECONDS);
Assert.IsTrue(result != 1000);
Assert.IsTrue(result < 1.0 && result > 0.1);
}
[Test]
public void Millisecond()
{
double result = this.GetOutput(PerfTimerType.MILLISECONDS);
Assert.AreEqual(1000, result);
}
[Test]
public void Minutes()
{
double result = this.GetOutput(PerfTimerType.MINUTES);
Assert.AreEqual(0.0166666666666667, result);
}
[Test]
public void Seconds()
{
double result = this.GetOutput(PerfTimerType.SECONDS);
Assert.AreEqual(1, result);
}
[Test]
public void Ticks()
{
double result = this.GetOutput(PerfTimerType.TICKS);
Assert.AreEqual(1000, result);
}
private double GetOutput(PerfTimerType timer)
{
IPerfTimer t = PerfTimerFactory.GetPerfTimer(timer);
t.Start();
Thread.Sleep(1000);
t.Stop();
Console.WriteLine(timer.ToString() + ": " + t.Duration);
return t.Duration;
}
}
}
|