Merge branch 'feature/unit_test_app_tweaks' into 'master'

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

Previous code would sometimes display menu multiple times, depending on UART activity.

See merge request !253
This commit is contained in:
Ivan Grokhotkov 2016-12-07 10:28:19 +08:00
commit a35e4f5923
2 changed files with 44 additions and 29 deletions

View 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,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;
unity_printf("\n\nHere's the test menu, pick your combo:\n");
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);
}
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);
trim_trailing_space(cmdline);
if (strlen(cmdline) == 0)
{
continue;
if(strlen(cmdline) == 0) {
/* if input was newline, print a new menu */
print_test_menu();
}
}
UNITY_BEGIN();
@ -153,13 +164,18 @@ void unity_run_menu()
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");
}
}

View 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.)