[Test/Flatbuf] Add Pipeline API test for Flatbuf
authorYongjoo Ahn <yongjoo1.ahn@samsung.com>
Thu, 6 May 2021 04:20:29 +0000 (13:20 +0900)
committerjaeyun-jung <39614140+jaeyun-jung@users.noreply.github.com>
Thu, 6 May 2021 09:48:50 +0000 (18:48 +0900)
- Add a test for Flatbuf which check eqaulity of input buffer with output of flatbuf decoder and converter
- input -> decoder -> other/flatbuf-tensor -> converter -> output)

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

index 8cc15ea..f27c41d 100644 (file)
@@ -2133,4 +2133,59 @@ public class APITestPipeline {
             fail();
         }
     }
+
+    @Test
+    public void testFlatbuf() {
+        /* This test assume that the NNStreamer library is built with Flatbuf (default option) */
+        String desc = "appsrc name=srcx ! " +
+                "other/tensor,dimension=(string)3:224:224:1,type=(string)uint8,framerate=(fraction)0/1 ! " +
+                "tensor_decoder mode=flatbuf ! other/flatbuf-tensor,framerate=(fraction)0/1 ! " +
+                "tensor_converter ! tensor_sink name=sinkx";
+
+        try (Pipeline pipe = new Pipeline(desc)) {
+            TensorsInfo info = new TensorsInfo();
+            info.addTensorInfo(NNStreamer.TensorType.UINT8, new int[]{3, 224, 224, 1});
+
+            /* register sink callback */
+            pipe.registerSinkCallback("sinkx", new Pipeline.NewDataCallback() {
+                @Override
+                public void onNewDataReceived(TensorsData data) {
+                    if (data == null || data.getTensorsCount() != 1) {
+                        mInvalidState = true;
+                        return;
+                    }
+                    ByteBuffer buffer = data.getTensorData(0);
+                    ByteBuffer bufferOri = APITestCommon.readRawImageData().getTensorData(0);
+                    bufferOri.rewind();
+
+                    /* check with original input data */
+                    if (!buffer.equals(bufferOri)) {
+                        mInvalidState = true;
+                    }
+
+                    mReceived++;
+                }
+            });
+
+            /* start pipeline */
+            pipe.start();
+
+            /* push input buffer */
+            TensorsData in = APITestCommon.readRawImageData();
+            pipe.inputData("srcx", in);
+
+            /* sleep 100 to invoke */
+            Thread.sleep(100);
+
+            /* stop pipeline */
+            pipe.stop();
+
+            /* check received data from sink */
+            assertFalse(mInvalidState);
+            assertEquals(1, mReceived);
+        } catch (Exception e) {
+            fail();
+        }
+    }
+
 }