diff --git a/csharp/test/Microsoft.ML.OnnxRuntime.Tests.Common/InferenceTest.cs b/csharp/test/Microsoft.ML.OnnxRuntime.Tests.Common/InferenceTest.cs index e853fa0c86..1cb8d1a870 100644 --- a/csharp/test/Microsoft.ML.OnnxRuntime.Tests.Common/InferenceTest.cs +++ b/csharp/test/Microsoft.ML.OnnxRuntime.Tests.Common/InferenceTest.cs @@ -2098,46 +2098,4 @@ namespace Microsoft.ML.OnnxRuntime.Tests } } - // Copy of the class that is internal in the main package - internal class DisposableListTest : List, IDisposableReadOnlyCollection - where T : IDisposable - { - public DisposableListTest() { } - public DisposableListTest(int count) : base(count) { } - - #region IDisposable Support - private bool disposedValue = false; // To detect redundant calls - - protected virtual void Dispose(bool disposing) - { - if (!disposedValue) - { - if (disposing) - { - // Dispose in the reverse order. - // Objects should typically be destroyed/disposed - // in the reverse order of its creation - // especially if the objects created later refer to the - // objects created earlier. For homogeneous collections of objects - // it would not matter. - for (int i = this.Count - 1; i >= 0; --i) - { - this[i]?.Dispose(); - } - this.Clear(); - } - - disposedValue = true; - } - } - - // This code added to correctly implement the disposable pattern. - public void Dispose() - { - // Do not change this code. Put cleanup code in Dispose(bool disposing) above. - Dispose(true); - GC.SuppressFinalize(this); - } - #endregion - } } diff --git a/csharp/test/Microsoft.ML.OnnxRuntime.Tests.Common/TestDataLoader.cs b/csharp/test/Microsoft.ML.OnnxRuntime.Tests.Common/TestDataLoader.cs index 3d09af304c..9992b5a8e5 100644 --- a/csharp/test/Microsoft.ML.OnnxRuntime.Tests.Common/TestDataLoader.cs +++ b/csharp/test/Microsoft.ML.OnnxRuntime.Tests.Common/TestDataLoader.cs @@ -11,6 +11,49 @@ using Xunit; namespace Microsoft.ML.OnnxRuntime.Tests { + // Copy of the class that is internal in the main package + public class DisposableListTest : List, IDisposableReadOnlyCollection + where T : IDisposable + { + public DisposableListTest() { } + public DisposableListTest(int count) : base(count) { } + + #region IDisposable Support + private bool disposedValue = false; // To detect redundant calls + + protected virtual void Dispose(bool disposing) + { + if (!disposedValue) + { + if (disposing) + { + // Dispose in the reverse order. + // Objects should typically be destroyed/disposed + // in the reverse order of its creation + // especially if the objects created later refer to the + // objects created earlier. For homogeneous collections of objects + // it would not matter. + for (int i = this.Count - 1; i >= 0; --i) + { + this[i]?.Dispose(); + } + this.Clear(); + } + + disposedValue = true; + } + } + + // This code added to correctly implement the disposable pattern. + public void Dispose() + { + // Do not change this code. Put cleanup code in Dispose(bool disposing) above. + Dispose(true); + GC.SuppressFinalize(this); + } + #endregion + } + internal struct DisposableTestPair : IDisposable where TValue : IDisposable { @@ -184,7 +227,7 @@ namespace Microsoft.ML.OnnxRuntime.Tests } case OnnxValueType.ONNX_TYPE_MAP: { - throw new OnnxRuntimeException(ErrorCode.NotImplemented, + throw new NotImplementedException( "Map test data format requires clarification: https://github.com/onnx/onnx/issues/5072"); } @@ -220,7 +263,7 @@ namespace Microsoft.ML.OnnxRuntime.Tests } case OnnxValueType.ONNX_TYPE_MAP: { - throw new OnnxRuntimeException(ErrorCode.NotImplemented, + throw new NotImplementedException( "Map test data format requires clarification: https://github.com/onnx/onnx/issues/5072"); } @@ -411,7 +454,7 @@ namespace Microsoft.ML.OnnxRuntime.Tests case Onnx.SequenceProto.Types.DataType.Tensor: { SequenceCheckMatchOnnxType(nodeName, sequenceMeta, OnnxValueType.ONNX_TYPE_TENSOR); - using (var sequenceOfTensors = new DisposableList(sequence.TensorValues.Count)) + using (var sequenceOfTensors = new DisposableListTest(sequence.TensorValues.Count)) { foreach (var tensor in sequence.TensorValues) { @@ -424,7 +467,7 @@ namespace Microsoft.ML.OnnxRuntime.Tests case Onnx.SequenceProto.Types.DataType.Sequence: // Sequence of sequences { SequenceCheckMatchOnnxType(nodeName, sequenceMeta, OnnxValueType.ONNX_TYPE_SEQUENCE); - using (var seqOfSequences = new DisposableList(sequence.TensorValues.Count)) + using (var seqOfSequences = new DisposableListTest(sequence.TensorValues.Count)) { foreach (var s in sequence.SequenceValues) { @@ -437,13 +480,13 @@ namespace Microsoft.ML.OnnxRuntime.Tests } case Onnx.SequenceProto.Types.DataType.Map: { - throw new OnnxRuntimeException(ErrorCode.NotImplemented, + throw new NotImplementedException( "Test data format for maps is under investigation"); } case Onnx.SequenceProto.Types.DataType.Optional: { SequenceCheckMatchOnnxType(nodeName, sequenceMeta, OnnxValueType.ONNX_TYPE_OPTIONAL); - using (var seqOfSequences = new DisposableList(sequence.TensorValues.Count)) + using (var seqOfSequences = new DisposableListTest(sequence.TensorValues.Count)) { foreach (var opt in sequence.OptionalValues) { @@ -478,7 +521,7 @@ namespace Microsoft.ML.OnnxRuntime.Tests } case Onnx.OptionalProto.Types.DataType.Map: { - throw new OnnxRuntimeException(ErrorCode.NotImplemented, + throw new NotImplementedException( "Test data format for maps is under investigation"); } @@ -499,7 +542,8 @@ namespace Microsoft.ML.OnnxRuntime.Tests var typeInfo = TensorBase.GetElementTypeInfo(elementType); Assert.NotNull(typeInfo); - var shapeSize = ArrayUtilities.GetSizeForShape(shape); + // ArrayUtilities not accessible in all builds + var shapeSize = shape.Aggregate(1L, (a, v) => a * v); var inferredSize = rawData.Length / typeInfo.TypeSize; Assert.Equal(shapeSize, inferredSize); Assert.Equal(0, rawData.Length % typeInfo.TypeSize);