[Android/Test] Add Test cases for SNPE Singleshot api
authorYongjoo Ahn <yongjoo1.ahn@samsung.com>
Mon, 24 Aug 2020 07:37:23 +0000 (16:37 +0900)
committerjaeyun-jung <39614140+jaeyun-jung@users.noreply.github.com>
Tue, 25 Aug 2020 02:41:42 +0000 (11:41 +0900)
- Add two negative TCs for invalid custom properties
- Add a TC to test utilizing DSP runtime

Signed-off-by: Yongjoo Ahn <yongjoo1.ahn@samsung.com>
api/android/api/src/androidTest/java/org/nnsuite/nnstreamer/APITestSingleShot.java

index d5e4d57..1f163a2 100644 (file)
@@ -845,4 +845,68 @@ public class APITestSingleShot {
             fail();
         }
     }
+
+    @Test
+    public void testInvalidSNPEOptionRuntime_n() {
+        if (!NNStreamer.isAvailable(NNStreamer.NNFWType.SNPE)) {
+            /* cannot run the test */
+            return;
+        }
+
+        String invalid_option = "Runtime:invalid_runtime";
+        try {
+            File model = APITestCommon.getSNPEModel();
+            new SingleShot(new File[] {model}, null, null, NNStreamer.NNFWType.SNPE, invalid_option);
+            fail();
+        } catch (Exception e) {
+            /* expected */
+        }
+    }
+
+    @Test
+    public void testInvalidSNPEOptionCPUFallback_n() {
+        if (!NNStreamer.isAvailable(NNStreamer.NNFWType.SNPE)) {
+            /* cannot run the test */
+            return;
+        }
+
+        String invalid_option = "CPUFallback:invalid_value";
+        try {
+            File model = APITestCommon.getSNPEModel();
+            new SingleShot(new File[] {model}, null, null, NNStreamer.NNFWType.SNPE, invalid_option);
+            fail();
+        } catch (Exception e) {
+            /* expected */
+        }
+    }
+
+    @Test
+    public void testSNPEClassificationResultWithRuntimeDSP() {
+        if (!NNStreamer.isAvailable(NNStreamer.NNFWType.SNPE)) {
+            /* cannot run the test */
+            return;
+        }
+
+        /* expected label is measuring_cup (648) */
+        final int expected_label = 648;
+        String option_string = "Runtime:DSP";
+        try {
+            File model = APITestCommon.getSNPEModel();
+            SingleShot single = new SingleShot(new File[] {model}, null, null, NNStreamer.NNFWType.SNPE, option_string);
+
+            /* single-shot invoke */
+            TensorsData in = APITestCommon.readRawImageDataSNPE();
+            TensorsData out = single.invoke(in);
+            int labelIndex = APITestCommon.getMaxScoreSNPE(out.getTensorData(0));
+
+            /* check label index (measuring cup) */
+            if (labelIndex != expected_label) {
+                fail();
+            }
+
+            single.close();
+        } catch (Exception e) {
+            fail();
+        }
+    }
 }