*/
@RunWith(AndroidJUnit4.class)
public class APITestSingleShot {
- private SingleShot mSingle;
-
@Rule
public GrantPermissionRule mPermissionRule = APITestCommon.grantPermissions();
@Before
public void setUp() {
APITestCommon.initNNStreamer();
-
- try {
- mSingle = new SingleShot(APITestCommon.getTFLiteImgModel());
- } catch (Exception e) {
- fail();
- }
- }
-
- @After
- public void tearDown() {
- mSingle.close();
}
@Test
public void testGetInputInfo() {
+ if (!NNStreamer.isAvailable(NNStreamer.NNFWType.TENSORFLOW_LITE)) {
+ /* cannot run the test */
+ return;
+ }
+
try {
- TensorsInfo info = mSingle.getInputInfo();
+ SingleShot single = new SingleShot(APITestCommon.getTFLiteImgModel());
+ TensorsInfo info = single.getInputInfo();
/* input: uint8 3:224:224:1 */
assertEquals(1, info.getTensorsCount());
assertEquals(NNStreamer.TensorType.UINT8, info.getTensorType(0));
assertArrayEquals(new int[]{3,224,224,1}, info.getTensorDimension(0));
+
+ single.close();
} catch (Exception e) {
fail();
}
@Test
public void testGetOutputInfo() {
+ if (!NNStreamer.isAvailable(NNStreamer.NNFWType.TENSORFLOW_LITE)) {
+ /* cannot run the test */
+ return;
+ }
+
try {
- TensorsInfo info = mSingle.getOutputInfo();
+ SingleShot single = new SingleShot(APITestCommon.getTFLiteImgModel());
+ TensorsInfo info = single.getOutputInfo();
/* output: uint8 1001:1 */
assertEquals(1, info.getTensorsCount());
assertEquals(NNStreamer.TensorType.UINT8, info.getTensorType(0));
assertArrayEquals(new int[]{1001,1,1,1}, info.getTensorDimension(0));
+
+ single.close();
} catch (Exception e) {
fail();
}
@Test
public void testSetNullInputInfo_n() {
+ if (!NNStreamer.isAvailable(NNStreamer.NNFWType.TENSORFLOW_LITE)) {
+ /* cannot run the test */
+ return;
+ }
+
try {
- mSingle.setInputInfo(null);
+ SingleShot single = new SingleShot(APITestCommon.getTFLiteImgModel());
+ single.setInputInfo(null);
fail();
} catch (Exception e) {
/* expected */
@Test
public void testSetInputInfo() {
+ if (!NNStreamer.isAvailable(NNStreamer.NNFWType.TENSORFLOW_LITE)) {
+ /* cannot run the test */
+ return;
+ }
+
try {
- SingleShot addSingle = new SingleShot(APITestCommon.getTFLiteAddModel());
- TensorsInfo info = addSingle.getInputInfo();
+ SingleShot single = new SingleShot(APITestCommon.getTFLiteAddModel());
+ TensorsInfo info = single.getInputInfo();
/* input: float32 with dimension 1 */
assertEquals(1, info.getTensorsCount());
TensorsInfo newInfo = new TensorsInfo();
newInfo.addTensorInfo(NNStreamer.TensorType.FLOAT32, new int[]{10});
- addSingle.setInputInfo(newInfo);
+ single.setInputInfo(newInfo);
- info = addSingle.getInputInfo();
+ info = single.getInputInfo();
/* input: float32 with dimension 10 */
assertEquals(1, info.getTensorsCount());
assertEquals(NNStreamer.TensorType.FLOAT32, info.getTensorType(0));
assertArrayEquals(new int[]{10,1,1,1}, info.getTensorDimension(0));
- info = addSingle.getOutputInfo();
+ info = single.getOutputInfo();
/* output: float32 with dimension 10 */
assertEquals(1, info.getTensorsCount());
assertEquals(NNStreamer.TensorType.FLOAT32, info.getTensorType(0));
assertArrayEquals(new int[]{10,1,1,1}, info.getTensorDimension(0));
+
+ single.close();
} catch (Exception e) {
fail();
}
@Test
public void testInvoke() {
+ if (!NNStreamer.isAvailable(NNStreamer.NNFWType.TENSORFLOW_LITE)) {
+ /* cannot run the test */
+ return;
+ }
+
try {
- TensorsInfo info = mSingle.getInputInfo();
+ SingleShot single = new SingleShot(APITestCommon.getTFLiteImgModel());
+ TensorsInfo info = single.getInputInfo();
/* let's ignore timeout (set 10 sec) */
- mSingle.setTimeout(10000);
+ single.setTimeout(10000);
/* single-shot invoke */
for (int i = 0; i < 600; i++) {
/* dummy input */
- TensorsData out = mSingle.invoke(info.allocate());
+ TensorsData out = single.invoke(info.allocate());
/* output: uint8 1001:1 */
assertEquals(1, out.getTensorsCount());
Thread.sleep(30);
}
+
+ single.close();
} catch (Exception e) {
fail();
}
@Test
public void testInvokeDynamicVary() {
+ if (!NNStreamer.isAvailable(NNStreamer.NNFWType.TENSORFLOW_LITE)) {
+ /* cannot run the test */
+ return;
+ }
+
try {
- SingleShot addSingle = new SingleShot(APITestCommon.getTFLiteAddModel());
+ SingleShot single = new SingleShot(APITestCommon.getTFLiteAddModel());
/* single-shot invoke */
for (int i = 1; i < 2; i++) {
info.addTensorInfo(NNStreamer.TensorType.FLOAT32, new int[]{1,1,1,i});
/* dummy input */
- TensorsData out = addSingle.invoke(TensorsData.allocate(info));
+ TensorsData out = single.invoke(TensorsData.allocate(info));
/* output: float32 1:1:1:i */
assertEquals(1, out.getTensorsCount());
Thread.sleep(30);
}
+
+ single.close();
} catch (Exception e) {
fail();
}
@Test
public void testInvokeTimeout_n() {
- TensorsInfo info = mSingle.getInputInfo();
-
- /* timeout 5ms */
- mSingle.setTimeout(5);
+ if (!NNStreamer.isAvailable(NNStreamer.NNFWType.TENSORFLOW_LITE)) {
+ /* cannot run the test */
+ return;
+ }
try {
+ SingleShot single = new SingleShot(APITestCommon.getTFLiteImgModel());
+ TensorsInfo info = single.getInputInfo();
+
+ /* timeout 5ms (not enough time to invoke the model */
+ single.setTimeout(5);
+
/* dummy input */
- mSingle.invoke(TensorsData.allocate(info));
+ single.invoke(TensorsData.allocate(info));
fail();
} catch (Exception e) {
/* expected */
@Test
public void testInvalidInputType_n() {
+ if (!NNStreamer.isAvailable(NNStreamer.NNFWType.TENSORFLOW_LITE)) {
+ /* cannot run the test */
+ return;
+ }
+
/* input: uint8 3:224:224:1 */
TensorsInfo info = new TensorsInfo();
info.addTensorInfo(NNStreamer.TensorType.UINT16, new int[]{3,224,224,1});
@Test
public void testInvalidInputDimension_n() {
+ if (!NNStreamer.isAvailable(NNStreamer.NNFWType.TENSORFLOW_LITE)) {
+ /* cannot run the test */
+ return;
+ }
+
/* input: uint8 3:224:224:1 */
TensorsInfo info = new TensorsInfo();
info.addTensorInfo(NNStreamer.TensorType.UINT8, new int[]{2,224,224});
@Test
public void testInvalidOutputType_n() {
+ if (!NNStreamer.isAvailable(NNStreamer.NNFWType.TENSORFLOW_LITE)) {
+ /* cannot run the test */
+ return;
+ }
+
/* output: uint8 1001:1 */
TensorsInfo info = new TensorsInfo();
info.addTensorInfo(NNStreamer.TensorType.INT16, new int[]{1001,1});
@Test
public void testInvalidOutputDimension_n() {
+ if (!NNStreamer.isAvailable(NNStreamer.NNFWType.TENSORFLOW_LITE)) {
+ /* cannot run the test */
+ return;
+ }
+
/* output: uint8 1001:1 */
TensorsInfo info = new TensorsInfo();
info.addTensorInfo(NNStreamer.TensorType.UINT8, new int[]{1001,2,1,1});
@Test
public void testInvokeNullData_n() {
+ if (!NNStreamer.isAvailable(NNStreamer.NNFWType.TENSORFLOW_LITE)) {
+ /* cannot run the test */
+ return;
+ }
+
try {
- mSingle.invoke(null);
+ SingleShot single = new SingleShot(APITestCommon.getTFLiteImgModel());
+
+ single.invoke(null);
fail();
} catch (Exception e) {
/* expected */
@Test
public void testInvokeInvalidData_n() {
+ if (!NNStreamer.isAvailable(NNStreamer.NNFWType.TENSORFLOW_LITE)) {
+ /* cannot run the test */
+ return;
+ }
+
/* input data size: 3 * 224 * 224 */
TensorsInfo info = new TensorsInfo();
info.addTensorInfo(NNStreamer.TensorType.UINT8, new int[]{100});
try {
- mSingle.invoke(TensorsData.allocate(info));
+ SingleShot single = new SingleShot(APITestCommon.getTFLiteImgModel());
+
+ single.invoke(TensorsData.allocate(info));
fail();
} catch (Exception e) {
/* expected */
@Test
public void testSetZeroTimeout_n() {
+ if (!NNStreamer.isAvailable(NNStreamer.NNFWType.TENSORFLOW_LITE)) {
+ /* cannot run the test */
+ return;
+ }
+
try {
- mSingle.setTimeout(0);
+ SingleShot single = new SingleShot(APITestCommon.getTFLiteImgModel());
+
+ single.setTimeout(0);
fail();
} catch (Exception e) {
/* expected */
@Test
public void testSetInvalidTimeout_n() {
+ if (!NNStreamer.isAvailable(NNStreamer.NNFWType.TENSORFLOW_LITE)) {
+ /* cannot run the test */
+ return;
+ }
+
try {
- mSingle.setTimeout(-1);
+ SingleShot single = new SingleShot(APITestCommon.getTFLiteImgModel());
+
+ single.setTimeout(-1);
fail();
} catch (Exception e) {
/* expected */
@Test
public void testGetInvalidPropertyName_n() {
+ if (!NNStreamer.isAvailable(NNStreamer.NNFWType.TENSORFLOW_LITE)) {
+ /* cannot run the test */
+ return;
+ }
+
try {
- mSingle.getValue("");
+ SingleShot single = new SingleShot(APITestCommon.getTFLiteImgModel());
+
+ single.getValue("");
fail();
} catch (Exception e) {
/* expected */
@Test
public void testGetUnknownPropertyName_n() {
+ if (!NNStreamer.isAvailable(NNStreamer.NNFWType.TENSORFLOW_LITE)) {
+ /* cannot run the test */
+ return;
+ }
+
try {
- mSingle.getValue("unknown_prop");
+ SingleShot single = new SingleShot(APITestCommon.getTFLiteImgModel());
+
+ single.getValue("unknown_prop");
fail();
} catch (Exception e) {
/* expected */
@Test
public void testGetNullPropertyName_n() {
+ if (!NNStreamer.isAvailable(NNStreamer.NNFWType.TENSORFLOW_LITE)) {
+ /* cannot run the test */
+ return;
+ }
+
try {
- mSingle.getValue(null);
+ SingleShot single = new SingleShot(APITestCommon.getTFLiteImgModel());
+
+ single.getValue(null);
fail();
} catch (Exception e) {
/* expected */
@Test
public void testUnknownPropertyName_n() {
+ if (!NNStreamer.isAvailable(NNStreamer.NNFWType.TENSORFLOW_LITE)) {
+ /* cannot run the test */
+ return;
+ }
+
try {
- mSingle.setValue("unknown_prop", "unknown");
+ SingleShot single = new SingleShot(APITestCommon.getTFLiteImgModel());
+
+ single.setValue("unknown_prop", "unknown");
fail();
} catch (Exception e) {
/* expected */
@Test
public void testSetNullPropertyName_n() {
+ if (!NNStreamer.isAvailable(NNStreamer.NNFWType.TENSORFLOW_LITE)) {
+ /* cannot run the test */
+ return;
+ }
+
try {
- mSingle.setValue(null, "ANY");
+ SingleShot single = new SingleShot(APITestCommon.getTFLiteImgModel());
+
+ single.setValue(null, "ANY");
fail();
} catch (Exception e) {
/* expected */
@Test
public void testSetNullPropertyValue_n() {
+ if (!NNStreamer.isAvailable(NNStreamer.NNFWType.TENSORFLOW_LITE)) {
+ /* cannot run the test */
+ return;
+ }
+
try {
- mSingle.setValue("inputlayout", null);
+ SingleShot single = new SingleShot(APITestCommon.getTFLiteImgModel());
+
+ single.setValue("inputlayout", null);
fail();
} catch (Exception e) {
/* expected */
@Test
public void testGetPropertyDimension() {
+ if (!NNStreamer.isAvailable(NNStreamer.NNFWType.TENSORFLOW_LITE)) {
+ /* cannot run the test */
+ return;
+ }
+
try {
- assertEquals("3:224:224:1", mSingle.getValue("input"));
- assertEquals("1001:1:1:1", mSingle.getValue("output"));
+ SingleShot single = new SingleShot(APITestCommon.getTFLiteImgModel());
+
+ assertEquals("3:224:224:1", single.getValue("input"));
+ assertEquals("1001:1:1:1", single.getValue("output"));
+
+ single.close();
} catch (Exception e) {
fail();
}
/* let's ignore timeout (set 60 sec) */
single.setTimeout(60000);
- /* set layout */
- single.setValue("inputlayout", "NHWC");
- single.setValue("outputlayout", "NCHW");
-
/* single-shot invoke */
for (int i = 0; i < 10; i++) {
/* dummy input */