2016-11-17 08:36:10 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
2016-11-25 08:29:58 +00:00
|
|
|
#include <stdio.h>
|
2016-11-17 08:36:10 +00:00
|
|
|
#include "unity.h"
|
|
|
|
#include "rom/ets_sys.h"
|
2016-11-25 08:29:58 +00:00
|
|
|
#include "rom/uart.h"
|
|
|
|
#include "freertos/FreeRTOS.h"
|
|
|
|
#include "freertos/task.h"
|
|
|
|
#include "esp_log.h"
|
2017-03-22 03:50:05 +00:00
|
|
|
#include "soc/cpu.h"
|
2016-11-17 08:36:10 +00:00
|
|
|
|
|
|
|
#define unity_printf ets_printf
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
2017-06-01 04:11:45 +00:00
|
|
|
// Inverse of the filter
|
|
|
|
static bool s_invert = false;
|
2016-11-17 08:36:10 +00:00
|
|
|
|
|
|
|
void unity_putc(int c)
|
|
|
|
{
|
|
|
|
if (c == '\n')
|
|
|
|
{
|
|
|
|
uart_tx_one_char('\r');
|
2017-06-05 02:43:13 +00:00
|
|
|
uart_tx_one_char('\n');
|
2016-11-17 08:36:10 +00:00
|
|
|
}
|
|
|
|
else if (c == '\r')
|
|
|
|
{
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
uart_tx_one_char(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void unity_flush()
|
|
|
|
{
|
|
|
|
uart_tx_wait_idle(0); // assume that output goes to UART0
|
|
|
|
}
|
|
|
|
|
|
|
|
void unity_testcase_register(struct test_desc_t* desc)
|
|
|
|
{
|
2017-01-23 04:54:35 +00:00
|
|
|
if (!s_unity_tests_first)
|
2016-11-17 08:36:10 +00:00
|
|
|
{
|
|
|
|
s_unity_tests_first = desc;
|
2017-01-23 04:54:35 +00:00
|
|
|
s_unity_tests_last = desc;
|
2016-11-17 08:36:10 +00:00
|
|
|
}
|
2017-01-23 04:54:35 +00:00
|
|
|
else
|
2016-11-17 08:36:10 +00:00
|
|
|
{
|
2017-01-23 04:54:35 +00:00
|
|
|
struct test_desc_t* temp = s_unity_tests_first;
|
|
|
|
s_unity_tests_first = desc;
|
|
|
|
s_unity_tests_first->next = temp;
|
2016-11-17 08:36:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void unity_run_single_test(const struct test_desc_t* test)
|
|
|
|
{
|
|
|
|
Unity.TestFile = test->file;
|
|
|
|
Unity.CurrentDetail1 = test->desc;
|
|
|
|
UnityDefaultTestRun(test->fn, test->name, test->line);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void unity_run_single_test_by_index(int index)
|
|
|
|
{
|
|
|
|
const struct test_desc_t* test;
|
|
|
|
for (test = s_unity_tests_first; test != NULL && index != 0; test = test->next, --index)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
if (test != NULL)
|
|
|
|
{
|
|
|
|
unity_run_single_test(test);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-06-01 04:11:45 +00:00
|
|
|
static void unity_run_single_test_by_index_parse(const char* filter, int index_max)
|
|
|
|
{
|
|
|
|
if (s_invert)
|
|
|
|
{
|
|
|
|
printf("Inverse is not supported for that kind of filter\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int test_index = strtol(filter, NULL, 10);
|
|
|
|
if (test_index >= 1 && test_index <= index_max)
|
|
|
|
{
|
|
|
|
uint32_t start;
|
|
|
|
RSR(CCOUNT, start);
|
|
|
|
unity_run_single_test_by_index(test_index - 1);
|
|
|
|
uint32_t end;
|
|
|
|
RSR(CCOUNT, end);
|
|
|
|
uint32_t ms = (end - start) / (XT_CLOCK_FREQ / 1000);
|
|
|
|
printf("Test ran in %dms\n", ms);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-17 08:36:10 +00:00
|
|
|
static void unity_run_single_test_by_name(const char* filter)
|
2017-06-01 04:11:45 +00:00
|
|
|
{
|
|
|
|
if (s_invert)
|
|
|
|
{
|
|
|
|
printf("Inverse is not supported for that kind of filter\n");
|
|
|
|
return;
|
|
|
|
}
|
2016-11-17 08:36:10 +00:00
|
|
|
char tmp[256];
|
|
|
|
strncpy(tmp, filter + 1, sizeof(tmp) - 1);
|
|
|
|
tmp[strlen(filter) - 2] = 0;
|
|
|
|
for (const struct test_desc_t* test = s_unity_tests_first; test != NULL; test = test->next)
|
|
|
|
{
|
|
|
|
if (strstr(test->name, tmp) != NULL)
|
|
|
|
{
|
|
|
|
unity_run_single_test(test);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void unity_run_all_tests()
|
|
|
|
{
|
2017-06-01 04:11:45 +00:00
|
|
|
if (s_invert)
|
|
|
|
{
|
|
|
|
printf("Inverse is not supported for that kind of filter\n");
|
|
|
|
return;
|
|
|
|
}
|
2016-11-17 08:36:10 +00:00
|
|
|
for (const struct test_desc_t* test = s_unity_tests_first; test != NULL; test = test->next)
|
|
|
|
{
|
|
|
|
unity_run_single_test(test);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void unity_run_tests_with_filter(const char* filter)
|
|
|
|
{
|
2017-06-01 04:11:45 +00:00
|
|
|
if (s_invert)
|
|
|
|
{
|
|
|
|
++filter;
|
2017-05-10 07:22:30 +00:00
|
|
|
}
|
2017-06-01 04:11:45 +00:00
|
|
|
|
2016-11-17 08:36:10 +00:00
|
|
|
for (const struct test_desc_t* test = s_unity_tests_first; test != NULL; test = test->next)
|
|
|
|
{
|
2017-06-01 04:11:45 +00:00
|
|
|
if ((strstr(test->desc, filter) != NULL) == !s_invert)
|
2016-11-17 08:36:10 +00:00
|
|
|
{
|
|
|
|
unity_run_single_test(test);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void trim_trailing_space(char* str)
|
|
|
|
{
|
|
|
|
char* end = str + strlen(str) - 1;
|
|
|
|
while (end >= str && isspace((int) *end))
|
|
|
|
{
|
|
|
|
*end = 0;
|
|
|
|
--end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-25 08:29:58 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-11-17 08:36:10 +00:00
|
|
|
void unity_run_menu()
|
|
|
|
{
|
2016-11-25 08:29:58 +00:00
|
|
|
int test_count = print_test_menu();
|
|
|
|
while (true)
|
2016-11-17 08:36:10 +00:00
|
|
|
{
|
2016-11-25 08:29:58 +00:00
|
|
|
char cmdline[256] = { 0 };
|
|
|
|
while(strlen(cmdline) == 0)
|
2016-11-17 08:36:10 +00:00
|
|
|
{
|
2016-11-25 08:29:58 +00:00
|
|
|
/* 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();
|
|
|
|
}
|
2016-11-17 08:36:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UNITY_BEGIN();
|
2016-11-25 08:29:58 +00:00
|
|
|
|
2017-06-01 04:11:45 +00:00
|
|
|
size_t idx = 0;
|
|
|
|
if (cmdline[idx] == '!')
|
|
|
|
{
|
|
|
|
s_invert = true;
|
|
|
|
++idx;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
s_invert = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cmdline[idx] == '*')
|
2016-11-17 08:36:10 +00:00
|
|
|
{
|
|
|
|
unity_run_all_tests();
|
|
|
|
}
|
2017-06-01 04:11:45 +00:00
|
|
|
else if (cmdline[idx] =='[')
|
2016-11-17 08:36:10 +00:00
|
|
|
{
|
2017-06-01 04:11:45 +00:00
|
|
|
unity_run_tests_with_filter(cmdline + idx);
|
2016-11-17 08:36:10 +00:00
|
|
|
}
|
2017-06-01 04:11:45 +00:00
|
|
|
else if (cmdline[idx] =='"')
|
2016-11-17 08:36:10 +00:00
|
|
|
{
|
2017-06-01 04:11:45 +00:00
|
|
|
unity_run_single_test_by_name(cmdline + idx);
|
2016-11-17 08:36:10 +00:00
|
|
|
}
|
2017-06-01 04:11:45 +00:00
|
|
|
else if (isdigit((unsigned char)cmdline[idx]))
|
2016-11-17 08:36:10 +00:00
|
|
|
{
|
2017-06-01 04:11:45 +00:00
|
|
|
unity_run_single_test_by_index_parse(cmdline + idx, test_count);
|
2016-11-17 08:36:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UNITY_END();
|
2016-11-25 08:29:58 +00:00
|
|
|
|
|
|
|
printf("Enter next test, or 'enter' to see menu\n");
|
2016-11-17 08:36:10 +00:00
|
|
|
}
|
|
|
|
}
|