]> granicus.if.org Git - esp-idf/commitdiff
unit-test-app: Don't auto-display menu after test run finishes
authorAngus Gratton <angus@espressif.com>
Fri, 25 Nov 2016 08:29:58 +0000 (19:29 +1100)
committerAngus Gratton <angus@espressif.com>
Tue, 6 Dec 2016 19:25:31 +0000 (11:25 -0800)
Previous code sometimes menu multiple times, depending on UART activity.

tools/unit-test-app/components/unity/unity_platform.c
tools/unit-test-app/main/component.mk

index 4e1c0b8e073f47cbfd64f44d2ef796ae5c3359d0..74f2108425e08dbc1ee4cdff688d5e0a146a88b8 100644 (file)
@@ -1,16 +1,16 @@
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
+#include <stdio.h>
 #include "unity.h"
 #include "rom/ets_sys.h"
+#include "rom/uart.h"
+#include "freertos/FreeRTOS.h"
+#include "freertos/task.h"
+#include "esp_log.h"
 
 #define unity_printf ets_printf
 
-// Functions which are defined in ROM, linker script provides addresses for these:
-int uart_tx_one_char(uint8_t c);
-void uart_tx_wait_idle(uint8_t uart_no);
-int UartRxString(uint8_t* dst, uint8_t max_length);
-
 // Pointers to the head and tail of linked list of test description structs:
 static struct test_desc_t* s_unity_tests_first = NULL;
 static struct test_desc_t* s_unity_tests_last = NULL;
@@ -114,35 +114,46 @@ static void trim_trailing_space(char* str)
     }
 }
 
+static int print_test_menu(void)
+{
+    int test_counter = 0;
+    unity_printf("\n\nHere's the test menu, pick your combo:\n");
+    for (const struct test_desc_t* test = s_unity_tests_first;
+         test != NULL;
+         test = test->next, ++test_counter)
+    {
+        unity_printf("(%d)\t\"%s\" %s\n", test_counter + 1, test->name, test->desc);
+    }
+    return test_counter;
+}
+
 void unity_run_menu()
 {
-    while (true) 
+    int test_count = print_test_menu();
+    while (true)
     {
-        int test_counter = 0;
-        unity_printf("\n\nHere's the test menu, pick your combo:\n");
-        for (const struct test_desc_t* test = s_unity_tests_first; 
-             test != NULL; 
-             test = test->next, ++test_counter)
+        char cmdline[256] = { 0 };
+        while(strlen(cmdline) == 0)
         {
-            unity_printf("(%d)\t\"%s\" %s\n", test_counter + 1, test->name, test->desc);
+            /* Flush anything already in the RX buffer */
+            while(uart_rx_one_char((uint8_t *) cmdline) == OK) {
+            }
+            /* Read input */
+            UartRxString((uint8_t*) cmdline, sizeof(cmdline) - 1);
+            trim_trailing_space(cmdline);
+            if(strlen(cmdline) == 0) {
+                /* if input was newline, print a new menu */
+                print_test_menu();
+            }
         }
-        
-        char cmdline[256];
-        UartRxString((uint8_t*) cmdline, sizeof(cmdline) - 1);
-        trim_trailing_space(cmdline);
 
-        if (strlen(cmdline) == 0)
-        {
-            continue;
-        }
-    
         UNITY_BEGIN();
-        
-        if (cmdline[0] == '*') 
+
+        if (cmdline[0] == '*')
         {
             unity_run_all_tests();
         }
-        else if (cmdline[0] =='[') 
+        else if (cmdline[0] =='[')
         {
             unity_run_tests_with_filter(cmdline);
         }
@@ -150,16 +161,21 @@ void unity_run_menu()
         {
             unity_run_single_test_by_name(cmdline);
         }
-        else 
+        else
         {
             int test_index = strtol(cmdline, NULL, 10);
-            if (test_index >= 1 && test_index <= test_counter)
+            if (test_index >= 1 && test_index <= test_count)
             {
+                uint32_t start = esp_log_timestamp(); /* hacky way to get ms */
                 unity_run_single_test_by_index(test_index - 1);
+                uint32_t end = esp_log_timestamp();
+                printf("Test ran in %dms\n", end - start);
             }
         }
 
         UNITY_END();
+
+        printf("Enter next test, or 'enter' to see menu\n");
     }
 }
 
index fd2dbe7b84748ae931affea1f8aef015c25fe4ac..a98f634eae065626088ba907b2cda16000478d5b 100644 (file)
@@ -1,5 +1,4 @@
 #
-# Main Makefile. This is basically the same as a component makefile.
+# "main" pseudo-component makefile.
 #
-
-include $(IDF_PATH)/make/component_common.mk
+# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)