From: Sangjung Woo Date: Wed, 25 Sep 2019 02:31:02 +0000 (+0900) Subject: [Tizen.MachineLearning.Inference][TCSACR-254][Add TCs for MachineLearning APIs] X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F99%2F214699%2F11;p=test%2Ftct%2Fcsharp%2Fapi.git [Tizen.MachineLearning.Inference][TCSACR-254][Add TCs for MachineLearning APIs] Change-Id: I02575f52d3b41520ee43916732786d8f6453ea6b Signed-off-by: Sangjung Woo --- diff --git a/tct-suite-vs/Tizen.MachineLearning.Inference.Tests/Program.cs b/tct-suite-vs/Tizen.MachineLearning.Inference.Tests/Program.cs new file mode 100755 index 000000000..e0f15ebe5 --- /dev/null +++ b/tct-suite-vs/Tizen.MachineLearning.Inference.Tests/Program.cs @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +using System; +using NUnitLite.TUnit; +using AutoTemplate; + +namespace XamarinForTizen.Tizen +{ + + class Program : global::Xamarin.Forms.Platform.Tizen.FormsApplication + { + private static App _app; + protected override void OnCreate() + { + base.OnCreate(); + + Console.WriteLine("TCT : OnCreate()"); + _app = new App(); + LoadApplication(_app); + + TRunner t = new TRunner(); + t.LoadTestsuite(); + t.Execute(); + } + + public static App getApp() + { + return _app; + } + static void Main(string[] args) + { + Console.WriteLine("TCT : Main()"); + var app = new Program(); + global::Xamarin.Forms.Platform.Tizen.Forms.Init(app); + app.Run(args); + } + } +} diff --git a/tct-suite-vs/Tizen.MachineLearning.Inference.Tests/Tizen.MachineLearning.Inference.Tests.csproj b/tct-suite-vs/Tizen.MachineLearning.Inference.Tests/Tizen.MachineLearning.Inference.Tests.csproj new file mode 100755 index 000000000..353af9b65 --- /dev/null +++ b/tct-suite-vs/Tizen.MachineLearning.Inference.Tests/Tizen.MachineLearning.Inference.Tests.csproj @@ -0,0 +1,40 @@ + + + + + Exe + tizen60 + + + + + true + + + + portable + + + None + + + + + + + + + + + + Runtime + + + + + + + + + + diff --git a/tct-suite-vs/Tizen.MachineLearning.Inference.Tests/Tizen.MachineLearning.Inference.Tests.sln b/tct-suite-vs/Tizen.MachineLearning.Inference.Tests/Tizen.MachineLearning.Inference.Tests.sln new file mode 100755 index 000000000..9675c0370 --- /dev/null +++ b/tct-suite-vs/Tizen.MachineLearning.Inference.Tests/Tizen.MachineLearning.Inference.Tests.sln @@ -0,0 +1,43 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26730.15 +MinimumVisualStudioVersion = 15.0.26124.0 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tizen.MachineLearning.Inference.Tests", "Tizen.MachineLearning.Inference.Tests.csproj", "{D92BEEAC-3B2A-45F8-8C53-53B92550404A}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "nunit.framework", "..\nunit.framework\nunit.framework.csproj", "{B9E7C1FD-CB38-42F7-AC43-7BD2E5B4D216}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "nunitlite", "..\nunitlite\nunitlite.csproj", "{FDB8025A-C029-461F-895E-287B4C65939B}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoTemplate", "..\Template\AutoTemplate\AutoTemplate.csproj", "{B11ABB0C-C3C1-4B5C-8251-A15628A775F3}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D92BEEAC-3B2A-45F8-8C53-53B92550404A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D92BEEAC-3B2A-45F8-8C53-53B92550404A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D92BEEAC-3B2A-45F8-8C53-53B92550404A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D92BEEAC-3B2A-45F8-8C53-53B92550404A}.Release|Any CPU.Build.0 = Release|Any CPU + {B9E7C1FD-CB38-42F7-AC43-7BD2E5B4D216}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B9E7C1FD-CB38-42F7-AC43-7BD2E5B4D216}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B9E7C1FD-CB38-42F7-AC43-7BD2E5B4D216}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B9E7C1FD-CB38-42F7-AC43-7BD2E5B4D216}.Release|Any CPU.Build.0 = Release|Any CPU + {FDB8025A-C029-461F-895E-287B4C65939B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FDB8025A-C029-461F-895E-287B4C65939B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FDB8025A-C029-461F-895E-287B4C65939B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FDB8025A-C029-461F-895E-287B4C65939B}.Release|Any CPU.Build.0 = Release|Any CPU + {B11ABB0C-C3C1-4B5C-8251-A15628A775F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B11ABB0C-C3C1-4B5C-8251-A15628A775F3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B11ABB0C-C3C1-4B5C-8251-A15628A775F3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B11ABB0C-C3C1-4B5C-8251-A15628A775F3}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {ED382B91-9930-40B6-B3D7-362304C78680} + SolutionGuid = {73AE7502-1CD2-4682-A131-8F10662865BC} + EndGlobalSection +EndGlobal diff --git a/tct-suite-vs/Tizen.MachineLearning.Inference.Tests/res/mobilenet_v1_1.0_224_quant.tflite b/tct-suite-vs/Tizen.MachineLearning.Inference.Tests/res/mobilenet_v1_1.0_224_quant.tflite new file mode 100755 index 000000000..9a81d7c81 Binary files /dev/null and b/tct-suite-vs/Tizen.MachineLearning.Inference.Tests/res/mobilenet_v1_1.0_224_quant.tflite differ diff --git a/tct-suite-vs/Tizen.MachineLearning.Inference.Tests/shared/res/Tizen.MachineLearning.Inference.Tests.png b/tct-suite-vs/Tizen.MachineLearning.Inference.Tests/shared/res/Tizen.MachineLearning.Inference.Tests.png new file mode 100755 index 000000000..9765b1bda Binary files /dev/null and b/tct-suite-vs/Tizen.MachineLearning.Inference.Tests/shared/res/Tizen.MachineLearning.Inference.Tests.png differ diff --git a/tct-suite-vs/Tizen.MachineLearning.Inference.Tests/testcase/TSSingleShot.cs b/tct-suite-vs/Tizen.MachineLearning.Inference.Tests/testcase/TSSingleShot.cs new file mode 100755 index 000000000..b732b1bdb --- /dev/null +++ b/tct-suite-vs/Tizen.MachineLearning.Inference.Tests/testcase/TSSingleShot.cs @@ -0,0 +1,192 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +using NUnit.Framework; +using NUnit.Framework.TUnit; +using System; +using System.IO; +using Tizen; +using Tizen.MachineLearning.Inference; + +namespace Tizen.MachineLearning.Inference.Tests { + + [TestFixture] + [Description("Tizen.MachineLearning.Inference.SingleShot Tests")] + public class TSSingleShot + { + private readonly string TAG = "Tizen.MachineLearning.Inference TCT"; + private readonly string _modelPath = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "mobilenet_v1_1.0_224_quant.tflite"; + + private TensorsInfo _in_info; + private TensorsInfo _out_info; + + [SetUp] + public void Init() + { + LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Preconditions for Tizen.MachineLearning.Inference TEST"); + + _in_info = new TensorsInfo(); + _in_info.AddTensorInfo(TensorType.UInt8, new int[4] { 3, 224, 224, 1 }); + + _out_info = new TensorsInfo(); + _out_info.AddTensorInfo(TensorType.UInt8, new int[4] { 1001, 1, 1, 1 }); + } + + [TearDown] + public void Destroy() + { + LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Postconditions for Tizen.MachineLearning.Inference TEST"); + + _in_info.Dispose(); + _out_info.Dispose(); + } + + [Test] + [Category("P1")] + [Description("Create SingleShot Instance")] + [Property("SPEC", "Tizen.MachineLearning.Inference.SingleShot.SingleShot C")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "CONSTR")] + [Property("AUTHOR", "Sangjung Woo, sangjung.woo@samsung.com")] + public void SingleShot_INIT() + { + /* TEST CODE */ + Assert.IsTrue(File.Exists(_modelPath), "Cannot find the mobilenet_v1_1.0_224_quant.tflite file"); + + try + { + var single = new SingleShot(_modelPath, _in_info, _out_info); + Assert.IsInstanceOf(single, "Should return SingleShot instance"); + Assert.IsNotNull(single, "Failed to create SingleShot instance"); + + single.Dispose(); + } + catch (Exception e) + { + Assert.True(false, e.Message); + } + } + + [Test] + [Category("P2")] + [Description("Check ArgumentException when creating SingleShot Instance")] + [Property("SPEC", "Tizen.MachineLearning.Inference.SingleShot.SingleShot C")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "CONSTX")] + [Property("AUTHOR", "Sangjung Woo, sangjung.woo@samsung.com")] + public void SingleShot_CHECK_ArgumentException() + { + try + { + var single = new SingleShot("Unknown_Path", _in_info, _out_info); + } + catch (ArgumentException) + { + Assert.Pass("ArgumentException: passed!"); + } + } + + [Test] + [Category("P1")] + [Description("Invokes the model with the given input data and check exceptions")] + [Property("SPEC", "Tizen.MachineLearning.Inference.SingleShot.Invoke M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MR")] + [Property("AUTHOR", "Sangjung Woo, sangjung.woo@samsung.com")] + public void Invoke_CHECK_NO_EXCEPTION() + { + Assert.IsTrue(File.Exists(_modelPath), "Cannot find the mobilenet_v1_1.0_224_quant.tflite file"); + + var in_buffer = new byte[3 * 224 * 224 * 1]; + Assert.IsInstanceOf(in_buffer, "in_buffer payload is not of the of the type byte[]"); + Assert.IsNotNull(in_buffer, "Fail to create the in_buffer the type byte[] "); + + var out_buffer_origin = new byte[1001 * 1 * 1 * 1]; + Assert.IsInstanceOf(out_buffer_origin, "out_buffer_origin payload is not of the of the type byte[]"); + Assert.IsNotNull(out_buffer_origin, "Fail to create the out_buffer_origin the type byte[] "); + + var single = new SingleShot(_modelPath, _in_info, _out_info); + Assert.IsInstanceOf(single, "Should return SingleShot instance"); + Assert.IsNotNull(single, "Failed to create SingleShot instance"); + + var in_data = _in_info.GetTensorsData(); + Assert.IsInstanceOf(in_data, "Should return TensorsData instance"); + Assert.IsNotNull(in_data, "Failed to create TensorsData instance"); + + in_data.SetTensorData(0, in_buffer); + + /* TEST CODE */ + try + { + var out_data = single.Invoke(in_data); + Assert.IsInstanceOf(out_data, "Should return TensorsData instance"); + Assert.IsNotNull(out_data, "Failed to create TensorsData instance"); + + var out_buffer = out_data.GetTensorData(0); + Assert.IsInstanceOf(out_buffer, "Should return byte[] instance"); + Assert.IsNotNull(out_buffer, "Failed to create byte[] instance"); + } + catch (Exception e) + { + Assert.True(false, e.Message); + } + + single.Dispose(); + } + + [Test] + [Category("P2")] + [Description("Check IOException when calling Invoke() of Single class")] + [Property("SPEC", "Tizen.MachineLearning.Inference.SingleShot.Invoke M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MEX")] + [Property("AUTHOR", "Sangjung Woo, sangjung.woo@samsung.com")] + public void Invoke_CHECK_IOException() + { + Assert.IsTrue(File.Exists(_modelPath), "Cannot find the mobilenet_v1_1.0_224_quant.tflite file"); + + var in_info = new TensorsInfo(); + Assert.IsInstanceOf(in_info, "Should return TensorsInfo instance"); + Assert.IsNotNull(in_info, "Failed to create TensorsInfo instance"); + + var in_buffer = new byte[10 * 1 * 1 * 1]; + Assert.IsInstanceOf(in_buffer, "in_buffer payload is not of the of the type byte[]"); + Assert.IsNotNull(in_buffer, "Fail to create the in_buffer the type byte[] "); + + in_info.AddTensorInfo(TensorType.UInt8, new int[4] { 10, 1, 1, 1 }); + + var in_data = _in_info.GetTensorsData(); + Assert.IsInstanceOf(in_data, "Should return TensorsData instance"); + Assert.IsNotNull(in_data, "Fail to create the TensorsData instance"); + + in_data.SetTensorData(0, in_buffer); + + var single = new SingleShot(_modelPath, _in_info, _out_info); + Assert.IsInstanceOf(single, "Should return SingleShot instance"); + Assert.IsNotNull(single, "Failed to create SingleShot instance"); + + /* TEST CODE */ + try + { + var out_data = single.Invoke(in_data); + } + catch (IOException) + { + Assert.Pass("IOException: passed!"); + } + } + } +} diff --git a/tct-suite-vs/Tizen.MachineLearning.Inference.Tests/testcase/TSTensorsData.cs b/tct-suite-vs/Tizen.MachineLearning.Inference.Tests/testcase/TSTensorsData.cs new file mode 100755 index 000000000..36edbafe9 --- /dev/null +++ b/tct-suite-vs/Tizen.MachineLearning.Inference.Tests/testcase/TSTensorsData.cs @@ -0,0 +1,194 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +using NUnit.Framework; +using NUnit.Framework.TUnit; +using System; +using Tizen; +using Tizen.MachineLearning.Inference; + +namespace Tizen.MachineLearning.Inference.Tests { + [TestFixture] + [Description("Tizen.MachineLearning.Inference.TensorsData Tests")] + public class TensorsDataTests + { + private readonly string TAG = "Tizen.MachineLearning.Inference TCT"; + private TensorsInfo _tensorsInfo; + private int[] _in_dim; + + [SetUp] + public void Init() + { + LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Preconditions for Tizen.MachineLearning.Inference TEST"); + + _tensorsInfo = new TensorsInfo(); + _in_dim = new int[4] { 10, 1, 1, 1 }; + + _tensorsInfo.AddTensorInfo(TensorType.UInt8, _in_dim); + } + + [TearDown] + public void Destroy() + { + LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Postconditions for Tizen.MachineLearning.Inference TEST"); + + _tensorsInfo.Dispose(); + } + + [Test] + [Category("P1")] + [Description("Set the TensorsData and check the exception")] + [Property("SPEC", "Tizen.MachineLearning.Inference.TensorsData.SetTensorData M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MR")] + [Property("AUTHOR", "Sangjung Woo, sangjung.woo@samsung.com")] + public void SetTensorData_CHECK_NO_EXCEPTION() + { + var buffer_in = new byte[] { 17, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + Assert.IsInstanceOf(buffer_in, "buffer_in payload is not of the of the type byte[]."); + Assert.IsNotNull(buffer_in, "Fail to create the buffer_in."); + + try + { + /* TEST CODE */ + var tensorsData = _tensorsInfo.GetTensorsData(); + Assert.IsInstanceOf(tensorsData, "tensorsData payload is not of the of the TensorsData."); + Assert.IsNotNull(tensorsData, "Fail to create the tensorsData."); + + tensorsData.SetTensorData(0, buffer_in); + tensorsData.Dispose(); + } + catch (Exception e) + { + Assert.True(false, e.Message); + } + } + + [Test] + [Category("P2")] + [Description("Check ArgumentException when calling SetTensorData() of TensorsData class")] + [Property("SPEC", "Tizen.MachineLearning.Inference.TensorsData.SetTensorData M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MEX")] + [Property("AUTHOR", "Sangjung Woo, sangjung.woo@samsung.com")] + public void SetTensorData_CHECK_ArgumentException() + { + var buffer_in = new byte[] { 17, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + Assert.IsInstanceOf(buffer_in, "buffer_in payload is not of the of the type byte[]."); + Assert.IsNotNull(buffer_in, "Fail to create the buffer_in."); + + try + { + var tensorsData = _tensorsInfo.GetTensorsData(); + Assert.IsInstanceOf(tensorsData, "tensorsData payload is not of the of the TensorsData."); + Assert.IsNotNull(tensorsData, "Fail to create the tensorsData."); + + tensorsData.SetTensorData(10, buffer_in); + } + catch (ArgumentException) + { + Assert.Pass("ArgumentException: passed!"); + } + } + + [Test] + [Category("P1")] + [Description("Get the TensorsData and compare it with its origin")] + [Property("SPEC", "Tizen.MachineLearning.Inference.TensorsData.GetTensorData M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MR")] + [Property("AUTHOR", "Sangjung Woo, sangjung.woo@samsung.com")] + public void GetTensorData_RETURN_VALUE() + { + var buffer_in = new byte[] { 17, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + Assert.IsInstanceOf(buffer_in, "buffer_in is not the type of byte[]."); + Assert.IsNotNull(buffer_in, "Fail to create buffer_in."); + + var tensorsData = _tensorsInfo.GetTensorsData(); + Assert.IsInstanceOf(tensorsData, "tensorsData is not the type of TensorsData."); + Assert.IsNotNull(tensorsData, "Fail to create tensorsData."); + + tensorsData.SetTensorData(0, buffer_in); + + /* TEST CODE */ + var buffer_out = tensorsData.GetTensorData(0); + Assert.IsInstanceOf(buffer_out, "buffer_out is not the type of byte[]."); + Assert.IsNotNull(buffer_out, "Fail to create buffer_out."); + + Assert.IsTrue(buffer_in.Length == buffer_out.Length, "The length of buffer_out payload is different from buffer_in."); + + for (int i = 0; i < buffer_out.Length; ++i) + { + Assert.IsTrue(buffer_in[i] == buffer_out[i], "The value of buffer_in is different from that of buffer_out"); + } + + tensorsData.Dispose(); + } + + [Test] + [Category("P2")] + [Description("Check ArgumentException when calling GetTensorData() of TensorsData class")] + [Property("SPEC", "Tizen.MachineLearning.Inference.TensorsData.GetTensorData M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MEX")] + [Property("AUTHOR", "Sangjung Woo, sangjung.woo@samsung.com")] + public void GetTensorData_CHECK_ArgumentException() + { + var buffer_in = new byte[] { 17, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + Assert.IsInstanceOf(buffer_in, "buffer_in is not the type of byte[]."); + Assert.IsNotNull(buffer_in, "Fail to create buffer_in."); + + var tensorsData = _tensorsInfo.GetTensorsData(); + Assert.IsInstanceOf(tensorsData, "tensorsData is not the type of TensorsData."); + Assert.IsNotNull(tensorsData, "Fail to create tensorsData."); + + tensorsData.SetTensorData(0, buffer_in); + + try + { + /* TEST CODE */ + var buffer_out = tensorsData.GetTensorData(100); + } + catch (ArgumentException) + { + Assert.Pass("ArgumentException: passed!"); + } + } + + [Test] + [Category("P1")] + [Description("Test property of TensorsData.")] + [Property("SPEC", "Tizen.MachineLearning.Inference.TensorsData.Count A")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "PRO")] + [Property("AUTHOR", "Sangjung Woo, sangjung.woo@samsung.com")] + public void Count_GET() + { + var buffer_in = new byte[] { 17, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + Assert.IsInstanceOf(buffer_in, "buffer_in is not the type of byte[]."); + Assert.IsNotNull(buffer_in, "Fail to create buffer_in."); + + var tensorsData = _tensorsInfo.GetTensorsData(); + Assert.IsInstanceOf(tensorsData, "tensorsData is not the type of TensorsData."); + Assert.IsNotNull(tensorsData, "Fail to create tensorsData."); + + tensorsData.SetTensorData(0, buffer_in); + + /* TEST CODE */ + Assert.IsTrue(1 == tensorsData.Count, "The number of Tensor in TensorsData is different from the origin."); + } + } +} diff --git a/tct-suite-vs/Tizen.MachineLearning.Inference.Tests/testcase/TSTensorsInfo.cs b/tct-suite-vs/Tizen.MachineLearning.Inference.Tests/testcase/TSTensorsInfo.cs new file mode 100755 index 000000000..3977307af --- /dev/null +++ b/tct-suite-vs/Tizen.MachineLearning.Inference.Tests/testcase/TSTensorsInfo.cs @@ -0,0 +1,707 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +using NUnit.Framework; +using NUnit.Framework.TUnit; +using System; +using Tizen; +using Tizen.MachineLearning.Inference; + +namespace Tizen.MachineLearning.Inference.Tests { + + [TestFixture] + [Description("Tizen.MachineLearning.Inference.TensorsInfo Tests")] + public class TensorsInfoTests + { + private readonly string TAG = "Tizen.MachineLearning.Inference TCT"; + + [SetUp] + public void Init() + { + LogUtils.Write(LogUtils.DEBUG , LogUtils.TAG , "Preconditions for Tizen.MachineLearning.Inference TEST"); + } + + [TearDown] + public void Destroy() + { + LogUtils.Write(LogUtils.DEBUG , LogUtils.TAG , "Postconditions for Tizen.MachineLearning.Inference TEST"); + } + + [Test] + [Category("P1")] + [Description("Create TensorsInfo Instance")] + [Property("SPEC", "Tizen.MachineLearning.Inference.TensorsInfo.TensorsInfo C")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "CONSTR")] + [Property("AUTHOR", "Sangjung Woo, sangjung.woo@samsung.com")] + public void TensorsInfo_INIT() + { + try + { + /* TEST CODE */ + var tensorsInfo = new TensorsInfo(); + Assert.IsInstanceOf(tensorsInfo, "Should return TensorsInfo instance"); + Assert.IsNotNull(tensorsInfo, "Failed to create TensorsInfo instance"); + + tensorsInfo.Dispose(); + } + catch (Exception e) + { + Assert.True(false, e.Message); + } + } + + [Test] + [Category("P1")] + [Description("Add TensorInfo into TensorsInfo with the input dimension information")] + [Property("SPEC", "Tizen.MachineLearning.Inference.TensorsInfo.AddTensorInfo M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MR")] + [Property("AUTHOR", "Sangjung Woo, sangjung.woo@samsung.com")] + [Property("COVPARAM", "Tizen.MachineLearning.Inference.TensorType, int[]")] + public void AddTensorInfo_CHECK_NO_EXCEPTION() + { + var in_dim = new int[4] { 3, 224, 224, 1 }; + Assert.IsInstanceOf(in_dim, "Should return int[] instance"); + Assert.IsNotNull(in_dim, "Failed to create in_dim instance"); + + var tensorsInfo = new TensorsInfo(); + Assert.IsInstanceOf(tensorsInfo, "Should return TensorsInfo instance"); + Assert.IsNotNull(tensorsInfo, "Failed to create tensorsInfo instance"); + + try + { + /* TEST CODE */ + tensorsInfo.AddTensorInfo(TensorType.UInt8, in_dim); + } + catch (Exception e) + { + Assert.True(false, e.Message); + } + + Assert.IsTrue(tensorsInfo.GetTensorType(0) == TensorType.UInt8, "The TensorType is not TensorType.UInt8."); + + var in_res = tensorsInfo.GetDimension(0); + Assert.IsInstanceOf(in_res, "Should return int[] instance"); + Assert.IsNotNull(in_res, "Failed to create in_res instance"); + + for (int i = 0; i < 4; ++i) + { + Assert.IsTrue(in_dim[i] == in_res[i], "The dimension of Input Tensor is different from the origin."); + } + } + + [Test] + [Category("P1")] + [Description("Add TensorInfo into TensorsInfo with the name and the input dimension information")] + [Property("SPEC", "Tizen.MachineLearning.Inference.TensorsInfo.AddTensorInfo M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MR")] + [Property("AUTHOR", "Sangjung Woo, sangjung.woo@samsung.com")] + [Property("COVPARAM", "string, Tizen.MachineLearning.Inference.TensorType, int[]")] + public void AddTensorInfo_CHECK_NO_EXCEPTION_WITH_NAME() + { + var in_dim = new int[4] { 3, 224, 224, 1 }; + Assert.IsInstanceOf(in_dim, "Should return int[] instance"); + Assert.IsNotNull(in_dim, "Failed to create in_dim instance"); + + var tensorsInfo = new TensorsInfo(); + Assert.IsInstanceOf(tensorsInfo, "Should return TensorsInfo instance"); + Assert.IsNotNull(tensorsInfo, "Failed to create tensorsInfo instance"); + + string TensorName = "InputTensorName"; + + try + { + /* TEST CODE */ + tensorsInfo.AddTensorInfo(TensorName, TensorType.UInt8, in_dim); + } + catch (Exception e) + { + Assert.True(false, e.Message); + } + + /* Type checking */ + Assert.IsTrue(tensorsInfo.GetTensorType(0) == TensorType.UInt8, "The TensorType is not TensorType.UInt8."); + + /* Dimension checking */ + var in_res = tensorsInfo.GetDimension(0); + Assert.IsInstanceOf(in_res, "Should return int[] instance"); + Assert.IsNotNull(in_res, "Failed to create in_res instance"); + + for (int i = 0; i < 4; ++i) + { + Assert.IsTrue(in_dim[i] == in_res[i], "The dimension of Input Tensor is different from the origin."); + } + + /* Name checking */ + Assert.IsTrue(tensorsInfo.GetTensorName(0) == TensorName, "The name of Input Tensor is different from the origin."); + } + + [Test] + [Category("P2")] + [Description("Check IndexOutOfRangeException when calling AddTensorInfo() of TensorsInfo class")] + [Property("SPEC", "Tizen.MachineLearning.Inference.TensorsInfo.AddTensorInfo M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MEX")] + [Property("AUTHOR", "Sangjung Woo, sangjung.woo@samsung.com")] + [Property("COVPARAM", "Tizen.MachineLearning.Inference.TensorType, int[]")] + public void AddTensorInfo_CHECK_IndexOutOfRangeException() + { + var in_dim = new int[4] { 3, 224, 224, 1 }; + Assert.IsInstanceOf(in_dim, "Should return int[] instance"); + Assert.IsNotNull(in_dim, "Failed to create in_dim instance"); + + var tensorsInfo = new TensorsInfo(); + Assert.IsInstanceOf(tensorsInfo, "Should return TensorsInfo instance"); + Assert.IsNotNull(tensorsInfo, "Failed to create tensorsInfo instance"); + + try + { + /* TEST CODE */ + for (int i = 0; i < 17; ++i) { + tensorsInfo.AddTensorInfo(TensorType.UInt8, in_dim); + } + Assert.True(false, "DO NOT COME HERE since the limit of tensor size is 16"); + } + catch (IndexOutOfRangeException) + { + Assert.Pass("IndexOutOfRangeException: passed!"); + } + } + + [Test] + [Category("P2")] + [Description("Check IndexOutOfRangeException when calling AddTensorInfo() of TensorsInfo class with name parameter")] + [Property("SPEC", "Tizen.MachineLearning.Inference.TensorsInfo.AddTensorInfo M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MEX")] + [Property("AUTHOR", "Sangjung Woo, sangjung.woo@samsung.com")] + [Property("COVPARAM", "string, Tizen.MachineLearning.Inference.TensorType, int[]")] + public void AddTensorInfo_CHECK_IndexOutOfRangeException_WITH_NAME() + { + var in_dim = new int[4] { 3, 224, 224, 1 }; + Assert.IsInstanceOf(in_dim, "Should return int[] instance"); + Assert.IsNotNull(in_dim, "Failed to create in_dim instance"); + + var tensorsInfo = new TensorsInfo(); + Assert.IsInstanceOf(tensorsInfo, "Should return TensorsInfo instance"); + Assert.IsNotNull(tensorsInfo, "Failed to create tensorsInfo instance"); + + string TensorName = "InputTensorName"; + + try + { + /* TEST CODE */ + for (int i = 0; i < 17; ++i) + { + tensorsInfo.AddTensorInfo(TensorName, TensorType.UInt8, in_dim); + } + Assert.True(false, "DO NOT COME HERE since the limit of tensor size is 16"); + } + catch (IndexOutOfRangeException) + { + Assert.Pass("IndexOutOfRangeException: passed!"); + } + } + + [Test] + [Category("P1")] + [Description("Get the name of TensorInfo and compare it with its origin")] + [Property("SPEC", "Tizen.MachineLearning.Inference.TensorsInfo.GetTensorName M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MR")] + [Property("AUTHOR", "Sangjung Woo, sangjung.woo@samsung.com")] + public void GetTensorName_RETURN_VALUE() + { + var in_dim = new int[4] { 3, 224, 224, 1 }; + Assert.IsInstanceOf(in_dim, "Should return int[] instance"); + Assert.IsNotNull(in_dim, "Failed to create in_dim instance"); + + var tensorsInfo = new TensorsInfo(); + Assert.IsInstanceOf(tensorsInfo, "Should return TensorsInfo instance"); + Assert.IsNotNull(tensorsInfo, "Failed to create tensorsInfo instance"); + + string inTensorName = "InputTensorName"; + tensorsInfo.AddTensorInfo(inTensorName, TensorType.UInt8, in_dim); + + /* TEST CODE */ + string outTensorName = tensorsInfo.GetTensorName(0); + Assert.IsTrue(inTensorName == outTensorName, "The TensorInfo name is different from the origin."); + } + + [Test] + [Category("P2")] + [Description("Check IndexOutOfRangeException when calling GetTensorName() of TensorsInfo class")] + [Property("SPEC", "Tizen.MachineLearning.Inference.TensorsInfo.GetTensorName M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MEX")] + [Property("AUTHOR", "Sangjung Woo, sangjung.woo@samsung.com")] + public void GetTensorName_CHECK_IndexOutOfRangeException() + { + var in_dim = new int[4] { 3, 224, 224, 1 }; + Assert.IsInstanceOf(in_dim, "Should return int[] instance"); + Assert.IsNotNull(in_dim, "Failed to create in_dim instance"); + + var tensorsInfo = new TensorsInfo(); + Assert.IsInstanceOf(tensorsInfo, "Should return TensorsInfo instance"); + Assert.IsNotNull(tensorsInfo, "Failed to create tensorsInfo instance"); + + string inTensorName = "InputTensorName"; + tensorsInfo.AddTensorInfo(inTensorName, TensorType.UInt8, in_dim); + + try + { + string outTensorName = tensorsInfo.GetTensorName(100); + } + catch (IndexOutOfRangeException) + { + Assert.Pass("IndexOutOfRangeException: passed!"); + } + } + + [Test] + [Category("P1")] + [Description("Set the name of TensorInfo and check the result")] + [Property("SPEC", "Tizen.MachineLearning.Inference.TensorsInfo.SetTensorName M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MR")] + [Property("AUTHOR", "Sangjung Woo, sangjung.woo@samsung.com")] + public void SetTensorName_RETURN_VALUE() + { + var in_dim = new int[4] { 3, 224, 224, 1 }; + Assert.IsInstanceOf(in_dim, "Should return int[] instance"); + Assert.IsNotNull(in_dim, "Failed to create in_dim instance"); + + var tensorsInfo = new TensorsInfo(); + Assert.IsInstanceOf(tensorsInfo, "Should return TensorsInfo instance"); + Assert.IsNotNull(tensorsInfo, "Failed to create tensorsInfo instance"); + + string inTensorName = "InputTensorName"; + tensorsInfo.AddTensorInfo(TensorType.UInt8, in_dim); + + /* TEST CODE */ + tensorsInfo.SetTensorName(0, inTensorName); + + string outTensorName = tensorsInfo.GetTensorName(0); + Assert.IsTrue(inTensorName == outTensorName, "The TensorInfo name is different from the origin."); + } + + [Test] + [Category("P2")] + [Description("Check IndexOutOfRangeException when calling SetTensorName() of TensorsInfo class")] + [Property("SPEC", "Tizen.MachineLearning.Inference.TensorsInfo.SetTensorName M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MEX")] + [Property("AUTHOR", "Sangjung Woo, sangjung.woo@samsung.com")] + public void SetTensorName_CHECK_IndexOutOfRangeException() + { + var in_dim = new int[4] { 3, 224, 224, 1 }; + Assert.IsInstanceOf(in_dim, "Should return int[] instance"); + Assert.IsNotNull(in_dim, "Failed to create in_dim instance"); + + var tensorsInfo = new TensorsInfo(); + Assert.IsInstanceOf(tensorsInfo, "Should return TensorsInfo instance"); + Assert.IsNotNull(tensorsInfo, "Failed to create tensorsInfo instance"); + + try + { + string inTensorName = "InputTensorName"; + tensorsInfo.AddTensorInfo(TensorType.UInt8, in_dim); + + /* TEST CODE */ + tensorsInfo.SetTensorName(100, inTensorName); + } + catch (IndexOutOfRangeException) + { + Assert.Pass("IndexOutOfRangeException: passed!"); + } + } + + [Test] + [Category("P2")] + [Description("Check ArgumentException when calling SetTensorName() of TensorsInfo class")] + [Property("SPEC", "Tizen.MachineLearning.Inference.TensorsInfo.SetTensorName M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MEX")] + [Property("AUTHOR", "Sangjung Woo, sangjung.woo@samsung.com")] + public void SetTensorName_CHECK_ArgumentException() + { + var in_dim = new int[4] { 3, 224, 224, 1 }; + Assert.IsInstanceOf(in_dim, "Should return int[] instance"); + Assert.IsNotNull(in_dim, "Failed to create in_dim instance"); + + var tensorsInfo = new TensorsInfo(); + Assert.IsInstanceOf(tensorsInfo, "Should return TensorsInfo instance"); + Assert.IsNotNull(tensorsInfo, "Failed to create tensorsInfo instance"); + + try + { + tensorsInfo.AddTensorInfo(TensorType.UInt8, in_dim); + + /* TEST CODE */ + tensorsInfo.SetTensorName(0, null); + } + catch (ArgumentException) + { + Assert.Pass("ArgumentException: passed!"); + } + } + + [Test] + [Category("P1")] + [Description("Set the type of TensorInfo and check the result")] + [Property("SPEC", "Tizen.MachineLearning.Inference.TensorsInfo.SetTensorType M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MR")] + [Property("AUTHOR", "Sangjung Woo, sangjung.woo@samsung.com")] + public void SetTensorType_RETURN_VALUE() + { + var in_dim = new int[4] { 10, 1, 1, 1 }; + Assert.IsInstanceOf(in_dim, "Should return int[] instance"); + Assert.IsNotNull(in_dim, "Failed to create in_dim instance"); + + var tensorsInfo = new TensorsInfo(); + Assert.IsInstanceOf(tensorsInfo, "Should return TensorsInfo instance"); + Assert.IsNotNull(tensorsInfo, "Failed to create tensorsInfo instance"); + + tensorsInfo.AddTensorInfo(TensorType.UInt8, in_dim); + + /* TEST CODE */ + tensorsInfo.SetTensorType(0, TensorType.Float32); + Assert.IsTrue(tensorsInfo.GetTensorType(0) == TensorType.Float32, "The TensorType is not TensorType.Float32."); + } + + [Test] + [Category("P2")] + [Description("Check IndexOutOfRangeException when calling SetTensorType() of TensorsInfo class")] + [Property("SPEC", "Tizen.MachineLearning.Inference.TensorsInfo.SetTensorType M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MEX")] + [Property("AUTHOR", "Sangjung Woo, sangjung.woo@samsung.com")] + public void SetTensorType_CHECK_IndexOutOfRangeException() + { + var in_dim = new int[4] { 10, 1, 1, 1 }; + Assert.IsInstanceOf(in_dim, "Should return int[] instance"); + Assert.IsNotNull(in_dim, "Failed to create in_dim instance"); + + var tensorsInfo = new TensorsInfo(); + Assert.IsInstanceOf(tensorsInfo, "Should return TensorsInfo instance"); + Assert.IsNotNull(tensorsInfo, "Failed to create tensorsInfo instance"); + + tensorsInfo.AddTensorInfo(TensorType.UInt8, in_dim); + + try + { + tensorsInfo.SetTensorType(100, TensorType.Float32); + } + catch (IndexOutOfRangeException) + { + Assert.Pass("IndexOutOfRangeException: passed!"); + } + } + + [Test] + [Category("P1")] + [Description("Get the type of TensorInfo and check the result")] + [Property("SPEC", "Tizen.MachineLearning.Inference.TensorsInfo.GetTensorType M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MR")] + [Property("AUTHOR", "Sangjung Woo, sangjung.woo@samsung.com")] + public void GetTensorType_RETURN_VALUE() + { + var in_dim = new int[4] { 10, 1, 1, 1 }; + Assert.IsInstanceOf(in_dim, "Should return int[] instance"); + Assert.IsNotNull(in_dim, "Failed to create in_dim instance"); + + var tensorsInfo = new TensorsInfo(); + Assert.IsInstanceOf(tensorsInfo, "Should return TensorsInfo instance"); + Assert.IsNotNull(tensorsInfo, "Failed to create tensorsInfo instance"); + + foreach (TensorType type in Enum.GetValues(typeof(TensorType))) + { + tensorsInfo.AddTensorInfo(type, in_dim); + } + + int i = 0; + foreach (TensorType type in Enum.GetValues(typeof(TensorType))) + { + /* TEST CODE */ + Assert.IsTrue(tensorsInfo.GetTensorType(i++) == type, "The TensorType is different from the origin."); + } + + /* + tensorsInfo.AddTensorInfo(TensorType.Int32, in_dim); + tensorsInfo.AddTensorInfo(TensorType.UInt32, in_dim); + tensorsInfo.AddTensorInfo(TensorType.Int16, in_dim); + tensorsInfo.AddTensorInfo(TensorType.UInt16, in_dim); + tensorsInfo.AddTensorInfo(TensorType.Int8, in_dim); + tensorsInfo.AddTensorInfo(TensorType.UInt8, in_dim); + tensorsInfo.AddTensorInfo(TensorType.Float64, in_dim); + tensorsInfo.AddTensorInfo(TensorType.Float32, in_dim); + tensorsInfo.AddTensorInfo(TensorType.Int64, in_dim); + tensorsInfo.AddTensorInfo(TensorType.UInt64, in_dim); + + Assert.IsTrue(tensorsInfo.GetTensorType(0) == TensorType.Int32, "The TensorType is not TensorType.UInt8."); + */ + } + + [Test] + [Category("P2")] + [Description("Check IndexOutOfRangeException when calling GetTensorType() of TensorsInfo class")] + [Property("SPEC", "Tizen.MachineLearning.Inference.TensorsInfo.GetTensorType M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MEX")] + [Property("AUTHOR", "Sangjung Woo, sangjung.woo@samsung.com")] + public void GetTensorType_CHECK_IndexOutOfRangeException() + { + var in_dim = new int[4] { 10, 1, 1, 1 }; + Assert.IsInstanceOf(in_dim, "Should return int[] instance"); + Assert.IsNotNull(in_dim, "Failed to create in_dim instance"); + + var tensorsInfo = new TensorsInfo(); + Assert.IsInstanceOf(tensorsInfo, "Should return TensorsInfo instance"); + Assert.IsNotNull(tensorsInfo, "Failed to create tensorsInfo instance"); + + tensorsInfo.AddTensorInfo(TensorType.UInt8, in_dim); + + try + { + TensorType type = tensorsInfo.GetTensorType(100); + } + catch (IndexOutOfRangeException) + { + Assert.Pass("IndexOutOfRangeException: passed!"); + } + } + + [Test] + [Category("P1")] + [Description("Set the dimension of TensorInfo and check the result")] + [Property("SPEC", "Tizen.MachineLearning.Inference.TensorsInfo.SetDimension M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MR")] + [Property("AUTHOR", "Sangjung Woo, sangjung.woo@samsung.com")] + public void SetDimension_RETURN_VALUE() + { + var in_dim = new int[4] { 10, 1, 1, 1 }; + Assert.IsInstanceOf(in_dim, "Should return int[] instance"); + Assert.IsNotNull(in_dim, "Failed to create in_dim instance"); + + var in_new_dim = new int[4] { 3, 224, 224, 1 }; + Assert.IsInstanceOf(in_new_dim, "Should return int[] instance"); + Assert.IsNotNull(in_new_dim, "Failed to create in_dim instance"); + + var tensorsInfo = new TensorsInfo(); + Assert.IsInstanceOf(tensorsInfo, "Should return TensorsInfo instance"); + Assert.IsNotNull(tensorsInfo, "Failed to create tensorsInfo instance"); + + tensorsInfo.AddTensorInfo(TensorType.UInt8, in_dim); + + /* TEST CODE */ + tensorsInfo.SetDimension(0, in_new_dim); + var in_res = tensorsInfo.GetDimension(0); + Assert.IsInstanceOf(in_res, "Should return int[] instance"); + Assert.IsNotNull(in_res, "Failed to create in_dim instance"); + + for (int i = 0; i < 4; ++i) + { + Assert.IsTrue(in_new_dim[i] == in_res[i], "The dimension of Input Tensor is different from the origin."); + } + } + + [Test] + [Category("P2")] + [Description("Check IndexOutOfRangeException when calling SetDimension() of TensorsInfo class")] + [Property("SPEC", "Tizen.MachineLearning.Inference.TensorsInfo.SetDimension M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MEX")] + [Property("AUTHOR", "Sangjung Woo, sangjung.woo@samsung.com")] + public void SetDimension_CHECK_IndexOutOfRangeException() + { + var in_dim = new int[4] { 10, 1, 1, 1 }; + Assert.IsInstanceOf(in_dim, "Should return int[] instance"); + Assert.IsNotNull(in_dim, "Failed to create in_dim instance"); + + var in_new_dim = new int[4] { 3, 224, 224, 1 }; + Assert.IsInstanceOf(in_new_dim, "Should return int[] instance"); + Assert.IsNotNull(in_new_dim, "Failed to create in_dim instance"); + + var tensorsInfo = new TensorsInfo(); + Assert.IsInstanceOf(tensorsInfo, "Should return TensorsInfo instance"); + Assert.IsNotNull(tensorsInfo, "Failed to create tensorsInfo instance"); + + tensorsInfo.AddTensorInfo(TensorType.UInt8, in_dim); + + try + { + tensorsInfo.SetDimension(100, in_new_dim); + } + catch (IndexOutOfRangeException) + { + Assert.Pass("IndexOutOfRangeException: passed!"); + } + } + + [Test] + [Category("P2")] + [Description("Check ArgumentException when calling SetDimension() of TensorsInfo class")] + [Property("SPEC", "Tizen.MachineLearning.Inference.TensorsInfo.SetDimension M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MEX")] + [Property("AUTHOR", "Sangjung Woo, sangjung.woo@samsung.com")] + public void SetDimension_CHECK_ArgumentException() + { + var in_dim = new int[4] { 10, 1, 1, 1 }; + Assert.IsInstanceOf(in_dim, "Should return int[] instance"); + Assert.IsNotNull(in_dim, "Failed to create in_dim instance"); + + var tensorsInfo = new TensorsInfo(); + Assert.IsInstanceOf(tensorsInfo, "Should return TensorsInfo instance"); + Assert.IsNotNull(tensorsInfo, "Failed to create tensorsInfo instance"); + + tensorsInfo.AddTensorInfo(TensorType.UInt8, in_dim); + + try + { + tensorsInfo.SetDimension(0, null); + } + catch (ArgumentException) + { + Assert.Pass("ArgumentException: passed!"); + } + } + + [Test] + [Category("P1")] + [Description("Get the dimension of TensorInfo and check the result")] + [Property("SPEC", "Tizen.MachineLearning.Inference.TensorsInfo.GetDimension M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MR")] + [Property("AUTHOR", "Sangjung Woo, sangjung.woo@samsung.com")] + public void GetDimension_RETURN_VALUE() + { + var in_dim = new int[4] { 10, 1, 1, 1 }; + Assert.IsInstanceOf(in_dim, "Should return int[] instance"); + Assert.IsNotNull(in_dim, "Failed to create in_dim instance"); + + var tensorsInfo = new TensorsInfo(); + Assert.IsInstanceOf(tensorsInfo, "Should return TensorsInfo instance"); + Assert.IsNotNull(tensorsInfo, "Failed to create tensorsInfo instance"); + + tensorsInfo.AddTensorInfo(TensorType.UInt8, in_dim); + + /* TEST CODE */ + int[] in_res = tensorsInfo.GetDimension(0); + for (int i = 0; i < 4; ++i) + { + Assert.IsTrue(in_dim[i] == in_res[i], "The dimension of Input Tensor is different from the origin."); + } + } + + [Test] + [Category("P2")] + [Description("Check IndexOutOfRangeException when calling GetDimension() of TensorsInfo class")] + [Property("SPEC", "Tizen.MachineLearning.Inference.TensorsInfo.GetDimension M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MEX")] + [Property("AUTHOR", "Sangjung Woo, sangjung.woo@samsung.com")] + public void GetDimension_CHECK_IndexOutOfRangeException() + { + var in_dim = new int[4] { 10, 1, 1, 1 }; + Assert.IsInstanceOf(in_dim, "Should return int[] instance"); + Assert.IsNotNull(in_dim, "Failed to create in_dim instance"); + + var tensorsInfo = new TensorsInfo(); + Assert.IsInstanceOf(tensorsInfo, "Should return TensorsInfo instance"); + Assert.IsNotNull(tensorsInfo, "Failed to create tensorsInfo instance"); + + tensorsInfo.AddTensorInfo(TensorType.UInt8, in_dim); + + try + { + var in_res = tensorsInfo.GetDimension(100); + } + catch (IndexOutOfRangeException) + { + Assert.Pass("IndexOutOfRangeException: passed!"); + } + } + + [Test] + [Category("P1")] + [Description("Create the TensorsData instance")] + [Property("SPEC", "Tizen.MachineLearning.Inference.TensorsInfo.GetTensorsData M")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "MR")] + [Property("AUTHOR", "Sangjung Woo, sangjung.woo@samsung.com")] + public void GetTensorsData_CHECK_NO_EXCEPTION() + { + var in_dim = new int[4] { 10, 1, 1, 1 }; + Assert.IsInstanceOf(in_dim, "Should return int[] instance"); + Assert.IsNotNull(in_dim, "Failed to create in_dim instance"); + + var buffer_in = new byte[] { 17, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + Assert.IsInstanceOf(buffer_in, "Should return byte[] instance"); + Assert.IsNotNull(buffer_in, "Failed to create in_dim instance"); + + var tensorsInfo = new TensorsInfo(); + Assert.IsInstanceOf(tensorsInfo, "Should return TensorsInfo instance"); + Assert.IsNotNull(tensorsInfo, "Failed to create tensorsInfo instance"); + + tensorsInfo.AddTensorInfo(TensorType.UInt8, in_dim); + + /* TEST CODE */ + var tensorsData = tensorsInfo.GetTensorsData(); + Assert.IsInstanceOf(tensorsData, "Should return TensorsData instance"); + Assert.IsNotNull(tensorsData, "Failed to create TensorsData instance"); + + tensorsData.SetTensorData(0, buffer_in); + + var buffer_out = tensorsData.GetTensorData(0); + Assert.IsInstanceOf(buffer_out, "buffer_out is not the type of byte[]."); + Assert.IsNotNull(buffer_out, "Fail to create buffer_out."); + + Assert.IsTrue(buffer_in.Length == buffer_out.Length, "The length of buffer_out payload is different from buffer_in."); + for (int i = 0; i < buffer_out.Length; ++i) + { + Assert.IsTrue(buffer_in[i] == buffer_out[i], "The value of buffer_in is different from that of buffer_out"); + } + } + + [Test] + [Category("P1")] + [Description("Check the Count property.")] + [Property("SPEC", "Tizen.MachineLearning.Inference.TensorsInfo.Count A")] + [Property("SPEC_URL", "-")] + [Property("CRITERIA", "PRO")] + [Property("AUTHOR", "Sangjung Woo, sangjung.woo@samsung.com")] + public void Count_Get() + { + var in_dim = new int[4] { 10, 1, 1, 1 }; + Assert.IsInstanceOf(in_dim, "Should return int[] instance"); + Assert.IsNotNull(in_dim, "Failed to create in_dim instance"); + + var tensorsInfo = new TensorsInfo(); + Assert.IsInstanceOf(tensorsInfo, "Should return TensorsInfo instance"); + Assert.IsNotNull(tensorsInfo, "Failed to create tensorsInfo instance"); + + tensorsInfo.AddTensorInfo(TensorType.UInt8, in_dim); + + Assert.IsTrue(1 == tensorsInfo.Count, "The count of TensorsInfo should be 1."); + } + } +} diff --git a/tct-suite-vs/Tizen.MachineLearning.Inference.Tests/tizen-manifest.xml b/tct-suite-vs/Tizen.MachineLearning.Inference.Tests/tizen-manifest.xml new file mode 100755 index 000000000..8b5158360 --- /dev/null +++ b/tct-suite-vs/Tizen.MachineLearning.Inference.Tests/tizen-manifest.xml @@ -0,0 +1,16 @@ + + + + + Tizen.MachineLearning.Inference.Tests.png + + + + http://tizen.org/privilege/appmanager.launch + +