[Tizen.MachineLearning.Inference][TCSACR-365] Add TCs for custom filter 30/241930/13
authorgichan-jang <gichan2.jang@samsung.com>
Fri, 21 Aug 2020 02:19:28 +0000 (11:19 +0900)
committergichan-jang <gichan2.jang@samsung.com>
Tue, 8 Sep 2020 01:30:31 +0000 (10:30 +0900)
Add TCs for custom filter

Change-Id: I924390a5c42b7e96b961f52a9943e7acc46ab19f
Signed-off-by: gichan-jang <gichan2.jang@samsung.com>
tct-suite-vs/Tizen.MachineLearning.Inference.Tests/testcase/TSCustomFilter.cs [new file with mode: 0644]

diff --git a/tct-suite-vs/Tizen.MachineLearning.Inference.Tests/testcase/TSCustomFilter.cs b/tct-suite-vs/Tizen.MachineLearning.Inference.Tests/testcase/TSCustomFilter.cs
new file mode 100644 (file)
index 0000000..37b7cbd
--- /dev/null
@@ -0,0 +1,370 @@
+using NUnit.Framework;
+using NUnit.Framework.TUnit;
+using System;
+using System.IO;
+using Tizen;
+using Tizen.System;
+using Tizen.MachineLearning.Inference;
+using System.Threading.Tasks;
+
+namespace Tizen.MachineLearning.Inference.Tests
+{
+    [TestFixture]
+    [Description("Tizen.MachineLearning.Inference.CustomFilter Tests")]
+    public class CustomFilterTests
+    {
+        private const string TAG = "Tizen.MachineLearning.Inference.Tests";
+        private const string FeatureKey = "http://tizen.org/feature/machine_learning.inference";
+        private bool _isMachineLeanringInferenceSupported = false;
+
+        [SetUp]
+        public void Init()
+        {
+            LogUtils.Write(LogUtils.DEBUG, TAG, "Preconditions for Tizen.MachineLearning.Inference TEST");
+
+            Information.TryGetValue(FeatureKey, out _isMachineLeanringInferenceSupported);
+
+            if (!_isMachineLeanringInferenceSupported)
+            {
+                LogUtils.Write(LogUtils.DEBUG, TAG, "ML feature is not supported.");
+            }
+        }
+
+        [TearDown]
+        public void Destroy()
+        {
+            LogUtils.Write(LogUtils.DEBUG, TAG, "Postconditions for Tizen.MachineLearning.Inference TEST");
+
+            if (_isMachineLeanringInferenceSupported)
+            {
+                /* release if any res initialized */
+            }
+        }
+
+        private TensorsData InvokePassThrough(TensorsData inData)
+        {
+            /* Just Pass through without modification */
+            return inData;
+        }
+
+        [Test]
+        [Category("P1")]
+        [Description("Get custom filter name and check exception")]
+        [Property("SPEC", "Tizen.MachineLearning.Inference.CustomFilter.Name A")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "PRO")]
+        [Property("AUTHOR", "Gichan Jang, gichan2.jang@samsung.com")]
+        public void Name_NO_Exception()
+        {
+            try
+            {
+                var buffer_in = new byte[] { 1, 2, 3, 4 };
+
+                TensorsInfo in_info = new TensorsInfo();
+                in_info.AddTensorInfo(TensorType.UInt8, new int[4] { 4, 1, 1, 1 });
+
+                TensorsInfo out_info = new TensorsInfo();
+                out_info.AddTensorInfo(TensorType.UInt8, new int[4] { 4, 1, 1, 1 });
+
+                CustomFilter customFilter = CustomFilter.Create("custom-passthrough", in_info, out_info, InvokePassThrough);
+
+                /* Test Code */
+                var name = customFilter.Name;
+                Assert.IsInstanceOf<string>(name, "Should return string");
+                Assert.AreEqual(name, "custom-passthrough", "Failed to get custrom filter name");
+
+                customFilter.Dispose();
+                out_info.Dispose();
+                in_info.Dispose();
+            }
+            catch (Exception e)
+            {
+                if (e is NotSupportedException)
+                {
+                    LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "NotSupportedException occurs");
+                    Assert.IsTrue(_isMachineLeanringInferenceSupported == false, "Invalid NotSupportedException");
+                }
+                else
+                {
+                    LogUtils.Write(LogUtils.ERROR, LogUtils.TAG, e.Message);
+                    Assert.IsTrue(false, e.Message);
+                }
+            }
+        }
+
+        [Test]
+        [Category("P1")]
+        [Description("Create custom filter and check exception")]
+        [Property("SPEC", "Tizen.MachineLearning.Inference.CustomFilter.Create M")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "MR")]
+        [Property("AUTHOR", "Gichan Jang, gichan2.jang@samsung.com")]
+        public void Create_NO_Exception()
+        {
+            try
+            {
+                var buffer_in = new byte[] { 1, 2, 3, 4 };
+
+                TensorsInfo in_info = new TensorsInfo();
+                in_info.AddTensorInfo(TensorType.UInt8, new int[4] { 4, 1, 1, 1 });
+
+                TensorsInfo out_info = new TensorsInfo();
+                out_info.AddTensorInfo(TensorType.UInt8, new int[4] { 4, 1, 1, 1 });
+
+                /* Test Code */
+                var customFilter = CustomFilter.Create("custom-passthrough", in_info, out_info, InvokePassThrough);
+                Assert.IsInstanceOf<CustomFilter>(customFilter, "Should return CustomFilter instance");
+                Assert.AreEqual(customFilter.Name, "custom-passthrough", "Failed to get custrom filter name");
+
+                customFilter.Dispose();
+                out_info.Dispose();
+                in_info.Dispose();
+            }
+            catch (Exception e)
+            {
+                if (e is NotSupportedException)
+                {
+                    LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "NotSupportedException occurs");
+                    Assert.IsTrue(_isMachineLeanringInferenceSupported == false, "Invalid NotSupportedException");
+                }
+                else
+                {
+                    LogUtils.Write(LogUtils.ERROR, LogUtils.TAG, e.Message);
+                    Assert.IsTrue(false, e.Message);
+                }
+            }
+        }
+
+        [Test]
+        [Category("P2")]
+        [Description("Check ArgumentException when Creating cutom filter with null name")]
+        [Property("SPEC", "Tizen.MachineLearning.Inference.CustomFilter.Create M")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "MEX")]
+        [Property("AUTHOR", "Gichan Jang, gichan2.jang@samsung.com")]
+        public void Create_ArgumentException_null_name()
+        {
+            try
+            {
+                TensorsInfo in_info = new TensorsInfo();
+                in_info.AddTensorInfo(TensorType.UInt8, new int[4] { 10, 1, 1, 1 });
+
+                TensorsInfo out_info = new TensorsInfo();
+                out_info.AddTensorInfo(TensorType.UInt8, new int[4] { 10, 1, 1, 1 });
+
+                /* Test Code */
+                CustomFilter customFilter = CustomFilter.Create(null, in_info, out_info, InvokePassThrough);
+
+                Assert.True(false, "DO NOT COME HERE!");
+            }
+            catch (Exception e)
+            {
+                if (e is NotSupportedException)
+                {
+                    LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "NotSupportedException occurs");
+                    Assert.IsTrue(_isMachineLeanringInferenceSupported == false, "Invalid NotSupportedException");
+                }
+                else if (e is ArgumentException)
+                {
+                    Assert.Pass("ArgumentException: passed!");
+                }
+                else
+                {
+                    Assert.Fail(e.Message);
+                }
+            }
+        }
+
+        [Test]
+        [Category("P2")]
+        [Description("Check ArgumentException when Creating cutom filter with null input info")]
+        [Property("SPEC", "Tizen.MachineLearning.Inference.CustomFilter.Create M")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "MEX")]
+        [Property("AUTHOR", "Gichan Jang, gichan2.jang@samsung.com")]
+        public void Create_ArgumentException_null_in_info()
+        {
+            try
+            {
+                TensorsInfo out_info = new TensorsInfo();
+                out_info.AddTensorInfo(TensorType.UInt8, new int[4] { 10, 1, 1, 1 });
+
+                /* Test Code */
+                CustomFilter customFilter = CustomFilter.Create("custom-passthrough", null, out_info, InvokePassThrough);
+
+                Assert.True(false, "DO NOT COME HERE!");
+            }
+            catch (Exception e)
+            {
+                if (e is NotSupportedException)
+                {
+                    LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "NotSupportedException occurs");
+                    Assert.IsTrue(_isMachineLeanringInferenceSupported == false, "Invalid NotSupportedException");
+                }
+                else if (e is ArgumentException)
+                {
+                    Assert.Pass("ArgumentException: passed!");
+                }
+                else
+                {
+                    Assert.Fail(e.Message);
+                }
+            }
+        }
+
+        [Test]
+        [Category("P2")]
+        [Description("Check ArgumentException when Creating cutom filter with invalid input info")]
+        [Property("SPEC", "Tizen.MachineLearning.Inference.CustomFilter.Create M")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "MEX")]
+        [Property("AUTHOR", "Gichan Jang, gichan2.jang@samsung.com")]
+        public void Create_ArgumentException_invalid_in_info()
+        {
+            try
+            {
+                TensorsInfo in_info = new TensorsInfo();
+
+                TensorsInfo out_info = new TensorsInfo();
+                out_info.AddTensorInfo(TensorType.UInt8, new int[4] { 10, 1, 1, 1 });
+
+                /* Test Code */
+                CustomFilter customFilter = CustomFilter.Create("custom-passthrough", in_info, out_info, InvokePassThrough);
+
+                Assert.True(false, "DO NOT COME HERE!");
+            }
+            catch (Exception e)
+            {
+                if (e is NotSupportedException)
+                {
+                    LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "NotSupportedException occurs");
+                    Assert.IsTrue(_isMachineLeanringInferenceSupported == false, "Invalid NotSupportedException");
+                }
+                else if (e is ArgumentException)
+                {
+                    Assert.Pass("ArgumentException: passed!");
+                }
+                else
+                {
+                    Assert.Fail(e.Message);
+                }
+            }
+        }
+
+        [Test]
+        [Category("P2")]
+        [Description("Check ArgumentException when Createing cutom filter with null output info")]
+        [Property("SPEC", "Tizen.MachineLearning.Inference.CustomFilter.Create M")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "MEX")]
+        [Property("AUTHOR", "Gichan Jang, gichan2.jang@samsung.com")]
+        public void Create_ArgumentException_null_out_info()
+        {
+            try
+            {
+                TensorsInfo in_info = new TensorsInfo();
+                in_info.AddTensorInfo(TensorType.UInt8, new int[4] { 10, 1, 1, 1 });
+
+                /* Test Code */
+                CustomFilter customFilter = CustomFilter.Create("custom-passthrough", in_info, null, InvokePassThrough);
+
+                Assert.True(false, "DO NOT COME HERE!");
+            }
+            catch (Exception e)
+            {
+                if (e is NotSupportedException)
+                {
+                    LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "NotSupportedException occurs");
+                    Assert.IsTrue(_isMachineLeanringInferenceSupported == false, "Invalid NotSupportedException");
+                }
+                else if (e is ArgumentException)
+                {
+                    Assert.Pass("ArgumentException: passed!");
+                }
+                else
+                {
+                    Assert.Fail(e.Message);
+                }
+            }
+        }
+
+        [Test]
+        [Category("P2")]
+        [Description("Check ArgumentException when Creating cutom filter with invalid output info")]
+        [Property("SPEC", "Tizen.MachineLearning.Inference.CustomFilter.Create M")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "MEX")]
+        [Property("AUTHOR", "Gichan Jang, gichan2.jang@samsung.com")]
+        public void Create_ArgumentException_invalid_out_info()
+        {
+            try
+            {
+                TensorsInfo in_info = new TensorsInfo();
+                in_info.AddTensorInfo(TensorType.UInt8, new int[4] { 10, 1, 1, 1 });
+
+                TensorsInfo out_info = new TensorsInfo();
+
+                /* Test Code */
+                CustomFilter customFilter = CustomFilter.Create("custom-passthrough", in_info, out_info, InvokePassThrough);
+
+                Assert.True(false, "DO NOT COME HERE!");
+            }
+            catch (Exception e)
+            {
+                if (e is NotSupportedException)
+                {
+                    LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "NotSupportedException occurs");
+                    Assert.IsTrue(_isMachineLeanringInferenceSupported == false, "Invalid NotSupportedException");
+                }
+                else if (e is ArgumentException)
+                {
+                    Assert.Pass("ArgumentException: passed!");
+                }
+                else
+                {
+                    Assert.Fail(e.Message);
+                }
+            }
+        }
+
+        [Test]
+        [Category("P2")]
+        [Description("Check ArgumentException when Creating cutom filter without callback")]
+        [Property("SPEC", "Tizen.MachineLearning.Inference.CustomFilter.Create M")]
+        [Property("SPEC_URL", "-")]
+        [Property("CRITERIA", "MEX")]
+        [Property("AUTHOR", "Gichan Jang, gichan2.jang@samsung.com")]
+        public void Create_ArgumentException_null_callback()
+        {
+            try
+            {
+                TensorsInfo in_info = new TensorsInfo();
+                in_info.AddTensorInfo(TensorType.UInt8, new int[4] { 10, 1, 1, 1 });
+
+                TensorsInfo out_info = new TensorsInfo();
+                out_info.AddTensorInfo(TensorType.UInt8, new int[4] { 10, 1, 1, 1 });
+
+                /* Test Code */
+                CustomFilter customFilter = CustomFilter.Create("custom-passthrough", in_info, out_info, null);
+
+                Assert.True(false, "DO NOT COME HERE!");
+            }
+            catch (Exception e)
+            {
+                if (e is NotSupportedException)
+                {
+                    LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "NotSupportedException occurs");
+                    Assert.IsTrue(_isMachineLeanringInferenceSupported == false, "Invalid NotSupportedException");
+                }
+                else if (e is ArgumentException)
+                {
+                    Assert.Pass("ArgumentException: passed!");
+                }
+                else
+                {
+                    Assert.Fail(e.Message);
+                }
+            }
+        }
+    }
+}