From ca4f5b9ee620f0ebedf33d084ebe3201f10031d4 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 10 May 2017 17:22:30 +1000 Subject: [PATCH 1/4] unit test runer: Add capability to use ![tag] to run all-tests-except-tag Mostly useful for running ![ignore] to skip ignored tests. --- tools/unit-test-app/README.md | 10 ++++++++++ tools/unit-test-app/components/unity/unity_platform.c | 6 +++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/tools/unit-test-app/README.md b/tools/unit-test-app/README.md index eff3e12f4a..1f06be55bf 100644 --- a/tools/unit-test-app/README.md +++ b/tools/unit-test-app/README.md @@ -10,3 +10,13 @@ ESP-IDF unit tests are run using Unit Test App. The app can be built with the un * `make menuconfig` to configure the Unit Test App. * `make TEST_COMPONENTS=` with `TEST_COMPONENTS` set to names of the components to be included in the test app. Or `make TESTS_ALL=1` to build the test app with all the tests for components having `test` subdirectory. * Follow the printed instructions to flash, or run `make flash`. + +# Running Unit Tests + +The unit test loader will prompt by showing a menu of available tests to run: + +* Type a number to run a single test. +* `*` to run all tests. +* `[tagname]` to run tests with "tag" +* `![tagname]` to run tests without "tag" (`![ignore]` is very useful as it runs all CI-enabled tests.) +* `"test name here"` to run test with given name diff --git a/tools/unit-test-app/components/unity/unity_platform.c b/tools/unit-test-app/components/unity/unity_platform.c index 3f453326ca..fad3e3e595 100644 --- a/tools/unit-test-app/components/unity/unity_platform.c +++ b/tools/unit-test-app/components/unity/unity_platform.c @@ -97,9 +97,13 @@ void unity_run_all_tests() void unity_run_tests_with_filter(const char* filter) { + bool invert = filter[0] == '!'; + if (invert) { + filter++; + } for (const struct test_desc_t* test = s_unity_tests_first; test != NULL; test = test->next) { - if (strstr(test->desc, filter) != NULL) + if ((strstr(test->desc, filter) != NULL) == !invert) { unity_run_single_test(test); } From 895e7423a3cd165a7e4d9ed11405abd6616a2243 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 10 May 2017 17:23:33 +1000 Subject: [PATCH 2/4] freertos: Preempt other CPU when deleting a task running on it Includes related fix to preemption unit tests (delete a queue after deleting the task blocked on it.) --- components/freertos/tasks.c | 5 +++++ components/freertos/test/test_preemption.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/components/freertos/tasks.c b/components/freertos/tasks.c index eaff6d96ea..0392a6e3c5 100644 --- a/components/freertos/tasks.c +++ b/components/freertos/tasks.c @@ -1251,6 +1251,11 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB, TaskFunction_t pxTaskCode portPRE_TASK_DELETE_HOOK( pxTCB, &xYieldPending[xPortGetCoreID()] ); portYIELD_WITHIN_API(); } + else if ( portNUM_PROCESSORS > 1 && pxTCB == pxCurrentTCB[ !xPortGetCoreID() ] ) + { + /* if task is running on the other CPU, force a yield on that CPU to take it off */ + vPortYieldOtherCore( !xPortGetCoreID() ); + } else { /* Reset the next expected unblock time in case it referred to diff --git a/components/freertos/test/test_preemption.c b/components/freertos/test/test_preemption.c index 09dbcc003a..83ab49bf43 100644 --- a/components/freertos/test/test_preemption.c +++ b/components/freertos/test/test_preemption.c @@ -66,8 +66,8 @@ TEST_CASE("Yield from lower priority task, same CPU", "[freertos]") printf("Yielding from lower priority task took %u cycles\n", delta); TEST_ASSERT(delta < 10000); - vQueueDelete(queue); vTaskDelete(sender_task); + vQueueDelete(queue); } } From 3f68c5e9885dc36fe332643737cdf59b80391ee0 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 10 May 2017 17:24:40 +1000 Subject: [PATCH 3/4] vfs uart tests: Avoid 1 byte heap overrun & memory leak --- components/vfs/test/test_vfs_uart.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/components/vfs/test/test_vfs_uart.c b/components/vfs/test/test_vfs_uart.c index 892ca527c6..2a74db61f7 100644 --- a/components/vfs/test/test_vfs_uart.c +++ b/components/vfs/test/test_vfs_uart.c @@ -50,8 +50,8 @@ TEST_CASE("can read from stdin", "[vfs]") const size_t count = 12; srand(count); - char* data = (char*) calloc(1, count * 8 + 1); - char* buf = (char*) calloc(1, count * 8 + 1); + char* data = (char*) calloc(1, count * 8 + 2); + char* buf = (char*) calloc(1, count * 8 + 2); char* p = data; for (size_t i = 0; i < count; ++i) { p += sprintf(p, "%08x", rand()); @@ -62,6 +62,9 @@ TEST_CASE("can read from stdin", "[vfs]") size_t cb = fread(buf, 1, len, stdin); TEST_ASSERT_EQUAL(len, cb); TEST_ASSERT_EQUAL_UINT8_ARRAY(data, buf, len); + + free(data); + free(buf); } From 304f0a399aa3b2f01c550595d4fdfd91469edad8 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 10 May 2017 17:26:25 +1000 Subject: [PATCH 4/4] freertos tests: Use CCOMPARE1 always in xPortInIsrContext() test Mismatched CCOMPARE meant test would only run once. --- components/freertos/test/test_freertos_isinisrcontext.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/components/freertos/test/test_freertos_isinisrcontext.c b/components/freertos/test/test_freertos_isinisrcontext.c index 9c7d31c270..a163688ccd 100644 --- a/components/freertos/test/test_freertos_isinisrcontext.c +++ b/components/freertos/test/test_freertos_isinisrcontext.c @@ -31,12 +31,13 @@ static void testthread(void *arg) { in_int_context=0; int_handled=0; TEST_ASSERT(!xPortInIsrContext()); - xthal_set_ccompare(2, xthal_get_ccount()+8000000); - esp_intr_alloc(ETS_INTERNAL_TIMER1_INTR_SOURCE, 0, &testint, NULL, &handle); + xthal_set_ccompare(1, xthal_get_ccount()+8000000); + esp_err_t err = esp_intr_alloc(ETS_INTERNAL_TIMER1_INTR_SOURCE, 0, &testint, NULL, &handle); + TEST_ASSERT_EQUAL_HEX32(ESP_OK, err); vTaskDelay(100 / portTICK_PERIOD_MS); TEST_ASSERT(int_handled); TEST_ASSERT(in_int_context); - esp_intr_free(handle); + TEST_ASSERT_EQUAL_HEX32( ESP_OK, esp_intr_free(handle) ); vTaskDelete(NULL); }