Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Diagnostics;

namespace Microsoft.ML.TorchSharp.Tests.QATests
{
public class ResourceLeakDetector
{
public bool CheckForResourceLeaks()
{
// Check for resource leaks
if (GC.GetTotalMemory(true) > 100 * 1024 * 1024)
{
return true;
}
return false;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Microsoft.ML;
using Microsoft.ML.TorchSharp;
using System;
using System.Threading;

namespace Microsoft.ML.TorchSharp.Tests.QATests
{
public class TestSimpleQA
{
[Fact]
public void TestSimpleQA_Succeeds()
{
// Create a new MLContext
var mlContext = new MLContext();

// Create a new TorchSharp model
var model = new TorchSharpModel(mlContext);

// Set a timeout for the test
var timeout = TimeSpan.FromSeconds(30);

try
{
// Run the test with a timeout
model.RunTest(timeout);
}
catch (OperationCanceledException ex)
{
// Handle the timeout exception
Console.WriteLine($"Test timed out: {ex.Message}");
}
catch (Exception ex)
{
// Handle any other exceptions
Console.WriteLine($"Test failed: {ex.Message}");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Microsoft.ML;
using Microsoft.ML.TorchSharp;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Threading;

namespace Microsoft.ML.TorchSharp.Tests.QATests
{
[TestClass]
public class TestSimpleQATests
{
[TestMethod]
public void TestSimpleQA_Succeeds()
{
// Create a new MLContext
var mlContext = new MLContext();

// Create a new TorchSharp model
var model = new TorchSharpModel(mlContext);

// Set a timeout for the test
var timeout = TimeSpan.FromSeconds(30);

try
{
// Run the test with a timeout
model.RunTest(timeout);
}
catch (OperationCanceledException ex)
{
// Handle the timeout exception
Assert.Fail($"Test timed out: {ex.Message}");
}
catch (Exception ex)
{
// Handle any other exceptions
Assert.Fail($"Test failed: {ex.Message}");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using Microsoft.ML;
using Microsoft.ML.TorchSharp;
using System;
using System.Diagnostics;

namespace Microsoft.ML.TorchSharp.Tests.QATests
{
public class TorchSharpModel
{
private readonly MLContext _mlContext;

public TorchSharpModel(MLContext mlContext)
{
_mlContext = mlContext;
}

public void RunTest(TimeSpan timeout)
{
// Create a new TorchSharp model
var model = new TorchSharpModel(_mlContext);

// Run the model with a timeout
var stopwatch = Stopwatch.StartNew();
while (stopwatch.Elapsed < timeout)
{
// Run the model
model.Run();

// Check for resource leaks
if (GC.GetTotalMemory(true) > 100 * 1024 * 1024)
{
// Handle the resource leak
Console.WriteLine("Resource leak detected!");
break;
}
}

// Check if the test timed out
if (stopwatch.Elapsed >= timeout)
{
throw new OperationCanceledException("Test timed out");
}
}

public void Run()
{
// Run the TorchSharp model
// (Implementation omitted for brevity)
}
}
}
Loading