unit-test-app: Don't auto-display menu after test run finishes

Previous code sometimes menu multiple times, depending on UART activity.
This commit is contained in:
Angus Gratton 2016-11-25 19:29:58 +11:00
parent bd20288b81
commit 69df54a28c
2 changed files with 44 additions and 29 deletions

View File

@ -1,16 +1,16 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#include <stdio.h>
#include "unity.h" #include "unity.h"
#include "rom/ets_sys.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 #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: // 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_first = NULL;
static struct test_desc_t* s_unity_tests_last = NULL; static struct test_desc_t* s_unity_tests_last = NULL;
@ -114,10 +114,8 @@ static void trim_trailing_space(char* str)
} }
} }
void unity_run_menu() static int print_test_menu(void)
{ {
while (true)
{
int test_counter = 0; int test_counter = 0;
unity_printf("\n\nHere's the test menu, pick your combo:\n"); unity_printf("\n\nHere's the test menu, pick your combo:\n");
for (const struct test_desc_t* test = s_unity_tests_first; for (const struct test_desc_t* test = s_unity_tests_first;
@ -126,14 +124,27 @@ void unity_run_menu()
{ {
unity_printf("(%d)\t\"%s\" %s\n", test_counter + 1, test->name, test->desc); unity_printf("(%d)\t\"%s\" %s\n", test_counter + 1, test->name, test->desc);
} }
return test_counter;
}
char cmdline[256]; void unity_run_menu()
{
int test_count = print_test_menu();
while (true)
{
char cmdline[256] = { 0 };
while(strlen(cmdline) == 0)
{
/* 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); UartRxString((uint8_t*) cmdline, sizeof(cmdline) - 1);
trim_trailing_space(cmdline); trim_trailing_space(cmdline);
if(strlen(cmdline) == 0) {
if (strlen(cmdline) == 0) /* if input was newline, print a new menu */
{ print_test_menu();
continue; }
} }
UNITY_BEGIN(); UNITY_BEGIN();
@ -153,13 +164,18 @@ void unity_run_menu()
else else
{ {
int test_index = strtol(cmdline, NULL, 10); 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); 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(); UNITY_END();
printf("Enter next test, or 'enter' to see menu\n");
} }
} }

View File

@ -1,5 +1,4 @@
# #
# Main Makefile. This is basically the same as a component makefile. # "main" pseudo-component makefile.
# #
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
include $(IDF_PATH)/make/component_common.mk