test: Add show_menu helper functions 45/261545/1
authorKwang Son <k.son@samsung.com>
Thu, 15 Jul 2021 08:39:20 +0000 (17:39 +0900)
committerKwang Son <k.son@samsung.com>
Wed, 21 Jul 2021 03:05:33 +0000 (12:05 +0900)
show_menu -> show_menu_linear: clean manual numbering
show_menu_yes_or_no: clean name_last

Change-Id: Ib2b1579cf16351a2d1299a6285b7f6e9a0aed540
Signed-off-by: Kwang Son <k.son@samsung.com>
test/testsuites/common/testsuite_common/mv_testsuite_common.c
test/testsuites/common/testsuite_common/mv_testsuite_common.h
test/testsuites/machine_learning/inference/inference_test_suite.c

index d368ef8..91f5bc1 100644 (file)
@@ -272,3 +272,32 @@ int load_mv_source_from_file(
 
        return err;
 }
+
+int show_menu_linear(const char *title, const char **menu, size_t len_menu)
+{
+       printf("*********************************************\n");
+       printf("* %38s *\n", title);
+       printf("*-------------------------------------------*\n");
+
+       for (size_t i = 0; i < len_menu; ++i)
+               printf("* %2i. %34s *\n", i + 1, menu[i]);
+
+       printf("*********************************************\n\n");
+       int selection = 0;
+       printf("Your choice: ");
+       if (scanf("%20i", &selection) == 0) {
+               if (scanf("%*[^\n]%*c") != 0) {
+                       printf("ERROR: Reading the input line error.\n");
+                       return -1;
+               }
+               printf("ERROR: Incorrect input.\n");
+       }
+
+       return selection;
+}
+
+int show_menu_yes_or_no(const char *title)
+{
+       const char *names_last[] = { "Yes", "No" };
+       return show_menu_linear(title, names_last, 2);
+}
\ No newline at end of file
index 1a5c2cd..66876e0 100644 (file)
@@ -142,6 +142,13 @@ int show_menu(
                const char **names,
                int number_of_option);
 
+int show_menu_linear(
+               const char *title,
+               const char **menu,
+               size_t len_menu);
+
+int show_menu_yes_or_no(const char *title);
+
 /**
  * @brief Loads media source from JPEG image.
  *
index b838945..24e1f03 100644 (file)
@@ -328,30 +328,6 @@ void _image_classified_cb(mv_source_h source, const int number_of_classes,
        }
 }
 
-int show_menu(const char *title, const int *options, const char **names,
-                         int cnt)
-{
-       printf("*********************************************\n");
-       printf("* %38s *\n", title);
-       printf("*-------------------------------------------*\n");
-       int i = 0;
-       for (i = 0; i < cnt; ++i)
-               printf("* %2i. %34s *\n", options[i], names[i]);
-
-       printf("*********************************************\n\n");
-       int selection = 0;
-       printf("Your choice: ");
-       if (scanf("%20i", &selection) == 0) {
-               if (scanf("%*[^\n]%*c") != 0) {
-                       printf("ERROR: Reading the input line error.\n");
-                       return -1;
-               }
-               printf("ERROR: Incorrect input.\n");
-       }
-
-       return selection;
-}
-
 int perform_configure_set_model_config_path(mv_engine_config_h engine_cfg)
 {
        int err = MEDIA_VISION_ERROR_NONE;
@@ -576,7 +552,6 @@ int perform_configuration(mv_engine_config_h *engine_cfg)
        int err = MEDIA_VISION_ERROR_NONE;
 
        int sel_opt = 0;
-       const int options[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 };
        const char *names[] = { "Set Model Configuration",
                                                          "Set Model Weights",
                                                          "Set Model Data Type",
@@ -605,8 +580,7 @@ int perform_configuration(mv_engine_config_h *engine_cfg)
        }
 
        while (sel_opt == 0) {
-               sel_opt = show_menu("Select Actions: ", options, names,
-                                                       ARRAY_SIZE(options));
+               sel_opt = show_menu_linear("Select Actions: ", names, ARRAY_SIZE(names));
                switch (sel_opt) {
                case 1:
                        err = perform_configure_set_model_config_path(handle);
@@ -1371,9 +1345,6 @@ int perform_image_classification()
        int err = MEDIA_VISION_ERROR_NONE;
 
        int sel_opt = 0;
-       const int options[] = { 1, 2, 3, 4, 5, 6,
-                               7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
-                               17, 18, 19 };
        const char *names[] = { "Configuration",
                                                         "TFLite(cpu + Mobilenet)",
                                                         "OpenCV(cpu + Squeezenet)",
@@ -1399,8 +1370,7 @@ int perform_image_classification()
        mv_source_h mvSource = NULL;
 
        while (sel_opt == 0) {
-               sel_opt = show_menu("Select Action:", options, names,
-                                                       ARRAY_SIZE(options));
+               sel_opt = show_menu_linear("Select Action:", names, ARRAY_SIZE(names));
                switch (sel_opt) {
                case 1: {
                        //perform configuration
@@ -1680,13 +1650,8 @@ int perform_image_classification()
                }
 
                sel_opt = 0;
-               const int options_last[2] = { 1, 2 };
-               const char *names_last[2] = { "Yes", "No" };
-
                while (sel_opt == 0) {
-                       sel_opt =
-                                       show_menu("Run Image Classification again?: ", options_last,
-                                                         names_last, ARRAY_SIZE(options_last));
+                       sel_opt = show_menu_yes_or_no("Run Image Classification again?: ");
                        switch (sel_opt) {
                        case 1:
                                do_another = 1;
@@ -2049,7 +2014,6 @@ int perform_object_detection()
        int err = MEDIA_VISION_ERROR_NONE;
 
        int sel_opt = 0;
-       const int options[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
        const char *names[] = { "Configuration",
                                                         "TFLITE(CPU) + MobileNetV1+SSD",
                                                         "OPENCV(CPU) + MobileNetV1+SSD",
@@ -2066,8 +2030,7 @@ int perform_object_detection()
        mv_source_h mvSource = NULL;
 
        while (sel_opt == 0) {
-               sel_opt = show_menu("Select Action:", options, names,
-                                                       ARRAY_SIZE(options));
+               sel_opt = show_menu_linear("Select Action:", names, ARRAY_SIZE(names));
                switch (sel_opt) {
                case 1: {
                        //perform configuration
@@ -2255,12 +2218,8 @@ int perform_object_detection()
                }
 
                sel_opt = 0;
-               const int options_last[2] = { 1, 2 };
-               const char *names_last[2] = { "Yes", "No" };
-
                while (sel_opt == 0) {
-                       sel_opt = show_menu("Run Object Detection again?:", options_last,
-                                                               names_last, ARRAY_SIZE(options_last));
+                       sel_opt = show_menu_yes_or_no("Run Object Detection again?:");
                        switch (sel_opt) {
                        case 1:
                                do_another = 1;
@@ -2563,7 +2522,6 @@ int perform_face_detection()
        int err = MEDIA_VISION_ERROR_NONE;
 
        int sel_opt = 0;
-       const int options[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
        const char *names[] = { "Configuration",
                                                         "TFLite(CPU) + MobileNetV1 + SSD",
                                                         "OPENCV(CPU) + Resnet10 + SSD",
@@ -2579,8 +2537,8 @@ int perform_face_detection()
        mv_source_h mvSource = NULL;
 
        while (sel_opt == 0) {
-               sel_opt = show_menu("Select Action:", options, names,
-                                                       ARRAY_SIZE(options));
+               sel_opt =
+                               show_menu_linear("Select Action:", names, ARRAY_SIZE(names));
                switch (sel_opt) {
                case 1: {
                        //perform configuration
@@ -2759,12 +2717,8 @@ int perform_face_detection()
                }
 
                sel_opt = 0;
-               const int options_last[] = { 1, 2 };
-               const char *names_last[] = { "Yes", "No" };
-
                while (sel_opt == 0) {
-                       sel_opt = show_menu("Run Face Detection again?:", options_last,
-                                                               names_last, ARRAY_SIZE(options_last));
+                       sel_opt = show_menu_yes_or_no("Run Face Detection again?:");
                        switch (sel_opt) {
                        case 1:
                                do_another = 1;
@@ -2993,7 +2947,6 @@ int perform_facial_landmark_detection()
        int err = MEDIA_VISION_ERROR_NONE;
 
        int sel_opt = 0;
-       const int options[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
        const char *names[] = { "Configuration",
                                                "Tflite(CPU) + TweakCNN",
                                                "OPENCV(CPU) + TweakCNN",
@@ -3008,8 +2961,7 @@ int perform_facial_landmark_detection()
        mv_source_h mvSource = NULL;
 
        while (sel_opt == 0) {
-               sel_opt = show_menu("Select Action:", options, names,
-                                                       ARRAY_SIZE(options));
+               sel_opt = show_menu_linear("Select Action:", names, ARRAY_SIZE(names));
                switch (sel_opt) {
                case 1: {
                        //perform configuration
@@ -3174,13 +3126,8 @@ int perform_facial_landmark_detection()
                }
 
                sel_opt = 0;
-               const int options_last[] = { 1, 2 };
-               const char *names_last[] = { "Yes", "No" };
-
                while (sel_opt == 0) {
-                       sel_opt = show_menu(
-                                       "Run Facial Landmark Detection again?:", options_last,
-                                       names_last, ARRAY_SIZE(options_last));
+                       sel_opt = show_menu_yes_or_no("Run Facial Landmark Detection again?:");
                        switch (sel_opt) {
                        case 1:
                                do_another = 1;
@@ -3360,7 +3307,6 @@ int perform_pose_landmark_detection()
        int err = MEDIA_VISION_ERROR_NONE;
 
        int sel_opt = 0;
-       const int options[] = { 1, 2, 3, 4, 5, 6, 7 };
        const char *names[] = { "Configuration",
                                                "TFLITE(CPU) + CPM",
                                                "Hosted: TFLITE(CPU) + CPM",
@@ -3374,8 +3320,7 @@ int perform_pose_landmark_detection()
        mv_source_h mvSource = NULL;
 
        while (sel_opt == 0) {
-               sel_opt = show_menu("Select Action:", options, names,
-                                                       ARRAY_SIZE(options));
+               sel_opt = show_menu_linear("Select Action:", names, ARRAY_SIZE(names));
                switch (sel_opt) {
                case 1: {
                        //perform configuration
@@ -3531,13 +3476,8 @@ int perform_pose_landmark_detection()
                }
 
                sel_opt = 0;
-               const int options_last[] = { 1, 2 };
-               const char *names_last[] = { "Yes", "No" };
-
                while (sel_opt == 0) {
-                       sel_opt = show_menu(
-                                       "Run Pose Landmark Detection again?:", options_last,
-                                       names_last, ARRAY_SIZE(options_last));
+                       sel_opt = show_menu_yes_or_no("Run Pose Landmark Detection again?:");
                        switch (sel_opt) {
                        case 1:
                                do_another = 1;
@@ -3582,20 +3522,21 @@ int main()
 {
        int sel_opt = 0;
 
-       const int options[] = { 1, 2, 3, 4, 5, 6 };
-       const char *names[] = { "Image Classification", "Object Detection",
-                                                        "Face Detection", "Facial Landmark Detection",
-                                                        "Pose Landmark Detection", "Exit" };
+       const char *names[] = {
+               "Image Classification", "Object Detection",
+               "Face Detection",                  "Facial Landmark Detection",
+               "Pose Landmark Detection", "Exit"
+       };
 
        int err = MEDIA_VISION_ERROR_NONE;
        while (sel_opt == 0) {
-               sel_opt = show_menu("Select Action:", options, names,
-                                                       ARRAY_SIZE(options));
+               sel_opt = show_menu_linear("Select Action:", names, ARRAY_SIZE(names));
                switch (sel_opt) {
                case 1: {
                        err = perform_image_classification();
                        if (err != MEDIA_VISION_ERROR_NONE) {
-                               printf("Fail to perform image classification. ERROR[0x%x]\n", err);
+                               printf("Fail to perform image classification. ERROR[0x%x]\n",
+                                          err);
                        }
                } break;
                case 2: {
@@ -3613,7 +3554,8 @@ int main()
                case 4: {
                        err = perform_facial_landmark_detection();
                        if (err != MEDIA_VISION_ERROR_NONE) {
-                               printf("Fail to perform facial landmark detection. ERROR[0x%x]\n", err);
+                               printf("Fail to perform facial landmark detection. ERROR[0x%x]\n",
+                                          err);
                        }
                } break;
                case 5: {
@@ -3634,12 +3576,8 @@ int main()
                int do_another = 0;
 
                sel_opt = 0;
-               const int options_last[] = { 1, 2 };
-               const char *names_last[] = { "Yes", "No" };
-
                while (sel_opt == 0) {
-                       sel_opt =
-                                       show_menu("Another action?: ", options_last, names_last, 2);
+                       sel_opt = show_menu_yes_or_no("Another action?: ");
                        switch (sel_opt) {
                        case 1:
                                do_another = 1;