mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Merge branch 'bugfix/ut_inverse_filter' into 'master'
unit-test-app: Fix capability to use !<filter> to inverse that filter See merge request !805
This commit is contained in:
commit
6873c19131
@ -16,6 +16,8 @@
|
|||||||
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;
|
||||||
|
|
||||||
|
// Inverse of the filter
|
||||||
|
static bool s_invert = false;
|
||||||
|
|
||||||
void unity_putc(int c)
|
void unity_putc(int c)
|
||||||
{
|
{
|
||||||
@ -73,8 +75,33 @@ static void unity_run_single_test_by_index(int index)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void unity_run_single_test_by_name(const char* filter)
|
static void unity_run_single_test_by_name(const char* filter)
|
||||||
{
|
{
|
||||||
|
if (s_invert)
|
||||||
|
{
|
||||||
|
printf("Inverse is not supported for that kind of filter\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
char tmp[256];
|
char tmp[256];
|
||||||
strncpy(tmp, filter + 1, sizeof(tmp) - 1);
|
strncpy(tmp, filter + 1, sizeof(tmp) - 1);
|
||||||
tmp[strlen(filter) - 2] = 0;
|
tmp[strlen(filter) - 2] = 0;
|
||||||
@ -89,6 +116,11 @@ static void unity_run_single_test_by_name(const char* filter)
|
|||||||
|
|
||||||
void unity_run_all_tests()
|
void unity_run_all_tests()
|
||||||
{
|
{
|
||||||
|
if (s_invert)
|
||||||
|
{
|
||||||
|
printf("Inverse is not supported for that kind of filter\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
for (const struct test_desc_t* test = s_unity_tests_first; test != NULL; test = test->next)
|
for (const struct test_desc_t* test = s_unity_tests_first; test != NULL; test = test->next)
|
||||||
{
|
{
|
||||||
unity_run_single_test(test);
|
unity_run_single_test(test);
|
||||||
@ -97,13 +129,14 @@ void unity_run_all_tests()
|
|||||||
|
|
||||||
void unity_run_tests_with_filter(const char* filter)
|
void unity_run_tests_with_filter(const char* filter)
|
||||||
{
|
{
|
||||||
bool invert = filter[0] == '!';
|
if (s_invert)
|
||||||
if (invert) {
|
{
|
||||||
filter++;
|
++filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const struct test_desc_t* test = s_unity_tests_first; test != NULL; test = test->next)
|
for (const struct test_desc_t* test = s_unity_tests_first; test != NULL; test = test->next)
|
||||||
{
|
{
|
||||||
if ((strstr(test->desc, filter) != NULL) == !invert)
|
if ((strstr(test->desc, filter) != NULL) == !s_invert)
|
||||||
{
|
{
|
||||||
unity_run_single_test(test);
|
unity_run_single_test(test);
|
||||||
}
|
}
|
||||||
@ -155,31 +188,32 @@ void unity_run_menu()
|
|||||||
|
|
||||||
UNITY_BEGIN();
|
UNITY_BEGIN();
|
||||||
|
|
||||||
if (cmdline[0] == '*')
|
size_t idx = 0;
|
||||||
|
if (cmdline[idx] == '!')
|
||||||
{
|
{
|
||||||
unity_run_all_tests();
|
s_invert = true;
|
||||||
}
|
++idx;
|
||||||
else if (cmdline[0] =='[')
|
|
||||||
{
|
|
||||||
unity_run_tests_with_filter(cmdline);
|
|
||||||
}
|
|
||||||
else if (cmdline[0] =='"')
|
|
||||||
{
|
|
||||||
unity_run_single_test_by_name(cmdline);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int test_index = strtol(cmdline, NULL, 10);
|
s_invert = false;
|
||||||
if (test_index >= 1 && test_index <= test_count)
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cmdline[idx] == '*')
|
||||||
|
{
|
||||||
|
unity_run_all_tests();
|
||||||
|
}
|
||||||
|
else if (cmdline[idx] =='[')
|
||||||
|
{
|
||||||
|
unity_run_tests_with_filter(cmdline + idx);
|
||||||
|
}
|
||||||
|
else if (cmdline[idx] =='"')
|
||||||
|
{
|
||||||
|
unity_run_single_test_by_name(cmdline + idx);
|
||||||
|
}
|
||||||
|
else if (isdigit((unsigned char)cmdline[idx]))
|
||||||
|
{
|
||||||
|
unity_run_single_test_by_index_parse(cmdline + idx, test_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
UNITY_END();
|
UNITY_END();
|
||||||
@ -187,4 +221,3 @@ void unity_run_menu()
|
|||||||
printf("Enter next test, or 'enter' to see menu\n");
|
printf("Enter next test, or 'enter' to see menu\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user