|
8 | 8 | */
|
9 | 9 |
|
10 | 10 | #include <nnstreamer.h>
|
| 11 | +#include <nnstreamer-single.h> |
11 | 12 | #include <gtest/gtest.h>
|
12 | 13 | #include <glib.h>
|
13 | 14 | #include <glib/gstdio.h> /* GStatBuf */
|
@@ -982,6 +983,228 @@ TEST (nnstreamer_capi_switch, failure_01)
|
982 | 983 | g_free (pipeline);
|
983 | 984 | }
|
984 | 985 |
|
| 986 | +/** |
| 987 | + * @brief Test NNStreamer single shot |
| 988 | + */ |
| 989 | +TEST (nnstreamer_capi_singleshot, invoke_01) |
| 990 | +{ |
| 991 | + ml_simpleshot_model_h model; |
| 992 | + nns_tensors_info_s in_info, out_info; |
| 993 | + nns_tensors_info_s in_res, out_res; |
| 994 | + tensor_data *input, *output1, *output2; |
| 995 | + int status; |
| 996 | + |
| 997 | + const gchar *root_path = g_getenv ("NNSTREAMER_BUILD_ROOT_PATH"); |
| 998 | + gchar *test_model; |
| 999 | + |
| 1000 | + memset (&in_info, 0, sizeof (nns_tensors_info_s)); |
| 1001 | + memset (&out_info, 0, sizeof (nns_tensors_info_s)); |
| 1002 | + memset (&in_res, 0, sizeof (nns_tensors_info_s)); |
| 1003 | + memset (&out_res, 0, sizeof (nns_tensors_info_s)); |
| 1004 | + |
| 1005 | + ASSERT_TRUE (root_path != NULL); |
| 1006 | + test_model = g_build_filename (root_path, "tests", "test_models", "models", |
| 1007 | + "mobilenet_v1_1.0_224_quant.tflite", NULL); |
| 1008 | + |
| 1009 | + in_info.num_tensors = 1; |
| 1010 | + in_info.info[0].type = NNS_TENSOR_TYPE_UINT8; |
| 1011 | + in_info.info[0].dimension[0] = 3; |
| 1012 | + in_info.info[0].dimension[1] = 224; |
| 1013 | + in_info.info[0].dimension[2] = 224; |
| 1014 | + in_info.info[0].dimension[3] = 1; |
| 1015 | + |
| 1016 | + out_info.num_tensors = 1; |
| 1017 | + out_info.info[0].type = NNS_TENSOR_TYPE_UINT8; |
| 1018 | + out_info.info[0].dimension[0] = 1001; |
| 1019 | + out_info.info[0].dimension[1] = 1; |
| 1020 | + out_info.info[0].dimension[2] = 1; |
| 1021 | + out_info.info[0].dimension[3] = 1; |
| 1022 | + |
| 1023 | + status = ml_model_open (test_model, &model, &in_info, &out_info, |
| 1024 | + ML_NNFW_TENSORFLOW_LITE, ML_NNFW_HW_DO_NOT_CARE); |
| 1025 | + EXPECT_EQ (status, NNS_ERROR_NONE); |
| 1026 | + |
| 1027 | + /* input tensor in filter */ |
| 1028 | + status = ml_model_get_input_type (model, &in_res); |
| 1029 | + EXPECT_EQ (status, NNS_ERROR_NONE); |
| 1030 | + |
| 1031 | + EXPECT_TRUE (in_info.num_tensors == in_res.num_tensors); |
| 1032 | + for (guint idx = 0; idx < in_res.num_tensors; idx++) { |
| 1033 | + EXPECT_TRUE (in_info.info[idx].type == in_res.info[idx].type); |
| 1034 | + EXPECT_TRUE (in_info.info[idx].dimension[0] == in_res.info[idx].dimension[0]); |
| 1035 | + EXPECT_TRUE (in_info.info[idx].dimension[1] == in_res.info[idx].dimension[1]); |
| 1036 | + EXPECT_TRUE (in_info.info[idx].dimension[2] == in_res.info[idx].dimension[2]); |
| 1037 | + EXPECT_TRUE (in_info.info[idx].dimension[3] == in_res.info[idx].dimension[3]); |
| 1038 | + } |
| 1039 | + |
| 1040 | + /* output tensor in filter */ |
| 1041 | + status = ml_model_get_output_type (model, &out_res); |
| 1042 | + EXPECT_EQ (status, NNS_ERROR_NONE); |
| 1043 | + |
| 1044 | + EXPECT_TRUE (out_info.num_tensors == out_res.num_tensors); |
| 1045 | + for (guint idx = 0; idx < out_res.num_tensors; idx++) { |
| 1046 | + EXPECT_TRUE (out_info.info[idx].type == out_res.info[idx].type); |
| 1047 | + EXPECT_TRUE (out_info.info[idx].dimension[0] == out_res.info[idx].dimension[0]); |
| 1048 | + EXPECT_TRUE (out_info.info[idx].dimension[1] == out_res.info[idx].dimension[1]); |
| 1049 | + EXPECT_TRUE (out_info.info[idx].dimension[2] == out_res.info[idx].dimension[2]); |
| 1050 | + EXPECT_TRUE (out_info.info[idx].dimension[3] == out_res.info[idx].dimension[3]); |
| 1051 | + } |
| 1052 | + |
| 1053 | + /* generate dummy data */ |
| 1054 | + input = ml_model_allocate_tensor_data (&in_info); |
| 1055 | + EXPECT_TRUE (input != NULL); |
| 1056 | + |
| 1057 | + output1 = ml_model_inference (model, input, NULL); |
| 1058 | + EXPECT_TRUE (output1 != NULL); |
| 1059 | + ml_model_free_tensor_data (output1); |
| 1060 | + |
| 1061 | + output2 = ml_model_allocate_tensor_data (&out_info); |
| 1062 | + EXPECT_TRUE (output2 != NULL); |
| 1063 | + |
| 1064 | + output1 = ml_model_inference (model, input, output2); |
| 1065 | + EXPECT_TRUE (output1 != NULL); |
| 1066 | + EXPECT_TRUE (output1 == output2); |
| 1067 | + ml_model_free_tensor_data (output2); |
| 1068 | + |
| 1069 | + ml_model_free_tensor_data (input); |
| 1070 | + |
| 1071 | + status = ml_model_close (model); |
| 1072 | + EXPECT_EQ (status, NNS_ERROR_NONE); |
| 1073 | + |
| 1074 | + g_free (test_model); |
| 1075 | +} |
| 1076 | + |
| 1077 | +/** |
| 1078 | + * @brief Test NNStreamer single shot |
| 1079 | + * @detail Start pipeline without tensor info |
| 1080 | + */ |
| 1081 | +TEST (nnstreamer_capi_singleshot, invoke_02) |
| 1082 | +{ |
| 1083 | + ml_simpleshot_model_h model; |
| 1084 | + nns_tensors_info_s in_info, out_info; |
| 1085 | + tensor_data *input, *output1, *output2; |
| 1086 | + int status; |
| 1087 | + |
| 1088 | + const gchar *root_path = g_getenv ("NNSTREAMER_BUILD_ROOT_PATH"); |
| 1089 | + gchar *test_model; |
| 1090 | + |
| 1091 | + ASSERT_TRUE (root_path != NULL); |
| 1092 | + test_model = g_build_filename (root_path, "tests", "test_models", "models", |
| 1093 | + "mobilenet_v1_1.0_224_quant.tflite", NULL); |
| 1094 | + |
| 1095 | + in_info.num_tensors = 1; |
| 1096 | + in_info.info[0].type = NNS_TENSOR_TYPE_UINT8; |
| 1097 | + in_info.info[0].dimension[0] = 3; |
| 1098 | + in_info.info[0].dimension[1] = 224; |
| 1099 | + in_info.info[0].dimension[2] = 224; |
| 1100 | + in_info.info[0].dimension[3] = 1; |
| 1101 | + |
| 1102 | + out_info.num_tensors = 1; |
| 1103 | + out_info.info[0].type = NNS_TENSOR_TYPE_UINT8; |
| 1104 | + out_info.info[0].dimension[0] = 1001; |
| 1105 | + out_info.info[0].dimension[1] = 1; |
| 1106 | + out_info.info[0].dimension[2] = 1; |
| 1107 | + out_info.info[0].dimension[3] = 1; |
| 1108 | + |
| 1109 | + status = ml_model_open (test_model, &model, NULL, NULL, |
| 1110 | + ML_NNFW_TENSORFLOW_LITE, ML_NNFW_HW_DO_NOT_CARE); |
| 1111 | + EXPECT_EQ (status, NNS_ERROR_NONE); |
| 1112 | + |
| 1113 | + /* generate dummy data */ |
| 1114 | + input = ml_model_allocate_tensor_data (&in_info); |
| 1115 | + EXPECT_TRUE (input != NULL); |
| 1116 | + |
| 1117 | + output1 = ml_model_inference (model, input, NULL); |
| 1118 | + EXPECT_TRUE (output1 != NULL); |
| 1119 | + ml_model_free_tensor_data (output1); |
| 1120 | + |
| 1121 | + output2 = ml_model_allocate_tensor_data (&out_info); |
| 1122 | + EXPECT_TRUE (output2 != NULL); |
| 1123 | + |
| 1124 | + output1 = ml_model_inference (model, input, output2); |
| 1125 | + EXPECT_TRUE (output1 != NULL); |
| 1126 | + EXPECT_TRUE (output1 == output2); |
| 1127 | + ml_model_free_tensor_data (output2); |
| 1128 | + |
| 1129 | + ml_model_free_tensor_data (input); |
| 1130 | + |
| 1131 | + status = ml_model_close (model); |
| 1132 | + EXPECT_EQ (status, NNS_ERROR_NONE); |
| 1133 | + |
| 1134 | + g_free (test_model); |
| 1135 | +} |
| 1136 | + |
| 1137 | +/** |
| 1138 | + * @brief Test NNStreamer single shot |
| 1139 | + * @detail Failure case with invalid param. |
| 1140 | + */ |
| 1141 | +TEST (nnstreamer_capi_singleshot, failure_01) |
| 1142 | +{ |
| 1143 | + ml_simpleshot_model_h model; |
| 1144 | + nns_tensors_info_s in_info, out_info; |
| 1145 | + int status; |
| 1146 | + |
| 1147 | + const gchar *root_path = g_getenv ("NNSTREAMER_BUILD_ROOT_PATH"); |
| 1148 | + gchar *test_model; |
| 1149 | + |
| 1150 | + memset (&in_info, 0, sizeof (nns_tensors_info_s)); |
| 1151 | + memset (&out_info, 0, sizeof (nns_tensors_info_s)); |
| 1152 | + |
| 1153 | + ASSERT_TRUE (root_path != NULL); |
| 1154 | + test_model = g_build_filename (root_path, "tests", "test_models", "models", |
| 1155 | + "mobilenet_v1_1.0_224_quant.tflite", NULL); |
| 1156 | + |
| 1157 | + /* invalid file path */ |
| 1158 | + status = ml_model_open ("wrong_file_name", &model, &in_info, &out_info, |
| 1159 | + ML_NNFW_TENSORFLOW_LITE, ML_NNFW_HW_DO_NOT_CARE); |
| 1160 | + EXPECT_EQ (status, NNS_ERROR_INVALID_PARAMETER); |
| 1161 | + |
| 1162 | + /* null file path */ |
| 1163 | + status = ml_model_open (NULL, &model, &in_info, &out_info, |
| 1164 | + ML_NNFW_TENSORFLOW_LITE, ML_NNFW_HW_DO_NOT_CARE); |
| 1165 | + EXPECT_EQ (status, NNS_ERROR_INVALID_PARAMETER); |
| 1166 | + |
| 1167 | + /* invalid handle */ |
| 1168 | + status = ml_model_open (test_model, NULL, &in_info, &out_info, |
| 1169 | + ML_NNFW_TENSORFLOW_LITE, ML_NNFW_HW_DO_NOT_CARE); |
| 1170 | + EXPECT_EQ (status, NNS_ERROR_INVALID_PARAMETER); |
| 1171 | + |
| 1172 | + /* invalid input tensor info */ |
| 1173 | + status = ml_model_open (test_model, &model, &in_info, &out_info, |
| 1174 | + ML_NNFW_TENSORFLOW_LITE, ML_NNFW_HW_DO_NOT_CARE); |
| 1175 | + EXPECT_EQ (status, NNS_ERROR_INVALID_PARAMETER); |
| 1176 | + |
| 1177 | + in_info.num_tensors = 1; |
| 1178 | + in_info.info[0].type = NNS_TENSOR_TYPE_UINT8; |
| 1179 | + in_info.info[0].dimension[0] = 3; |
| 1180 | + in_info.info[0].dimension[1] = 224; |
| 1181 | + in_info.info[0].dimension[2] = 224; |
| 1182 | + in_info.info[0].dimension[3] = 1; |
| 1183 | + |
| 1184 | + /* invalid output tensor info */ |
| 1185 | + status = ml_model_open (test_model, &model, &in_info, &out_info, |
| 1186 | + ML_NNFW_TENSORFLOW_LITE, ML_NNFW_HW_DO_NOT_CARE); |
| 1187 | + EXPECT_EQ (status, NNS_ERROR_INVALID_PARAMETER); |
| 1188 | + |
| 1189 | + out_info.num_tensors = 1; |
| 1190 | + out_info.info[0].type = NNS_TENSOR_TYPE_UINT8; |
| 1191 | + out_info.info[0].dimension[0] = 1001; |
| 1192 | + out_info.info[0].dimension[1] = 1; |
| 1193 | + out_info.info[0].dimension[2] = 1; |
| 1194 | + out_info.info[0].dimension[3] = 1; |
| 1195 | + |
| 1196 | + /* unknown fw type */ |
| 1197 | + status = ml_model_open (test_model, &model, &in_info, &out_info, |
| 1198 | + ML_NNFW_UNKNOWN, ML_NNFW_HW_DO_NOT_CARE); |
| 1199 | + EXPECT_EQ (status, NNS_ERROR_NOT_SUPPORTED); |
| 1200 | + |
| 1201 | + /* invalid handle */ |
| 1202 | + status = ml_model_close (model); |
| 1203 | + EXPECT_EQ (status, NNS_ERROR_INVALID_PARAMETER); |
| 1204 | + |
| 1205 | + g_free (test_model); |
| 1206 | +} |
| 1207 | + |
985 | 1208 | /**
|
986 | 1209 | * @brief Main gtest
|
987 | 1210 | */
|
|
0 commit comments