]> granicus.if.org Git - esp-idf/commitdiff
freertos: Mark uxTaskPriorityGet() as tested
authorAngus Gratton <angus@espressif.com>
Mon, 29 May 2017 06:10:38 +0000 (16:10 +1000)
committerAngus Gratton <gus@projectgus.com>
Mon, 29 May 2017 06:19:00 +0000 (16:19 +1000)
Also adds some SMP-aware dynamic task priority unit tests

components/freertos/tasks.c
components/freertos/test/test_task_priorities.c [new file with mode: 0644]
tools/unit-test-app/sdkconfig

index 2a28d51bac172ce1228898547615c7e88e14a5e6..9e8ef162650cc41f077122c83a8de601960107e3 100644 (file)
@@ -1515,13 +1515,11 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB, TaskFunction_t pxTaskCode
 /*-----------------------------------------------------------*/
 
 #if ( INCLUDE_uxTaskPriorityGet == 1 )
-/* ToDo: Make this multicore-compatible. */
        UBaseType_t uxTaskPriorityGet( TaskHandle_t xTask )
        {
        TCB_t *pxTCB;
        UBaseType_t uxReturn;
 
-               UNTESTED_FUNCTION();
                taskENTER_CRITICAL(&xTaskQueueMutex);
                {
                        /* If null is passed in here then we are changing the
@@ -1538,7 +1536,6 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB, TaskFunction_t pxTaskCode
 /*-----------------------------------------------------------*/
 
 #if ( INCLUDE_uxTaskPriorityGet == 1 )
-/* ToDo: Make this multicore-compatible. */
        UBaseType_t uxTaskPriorityGetFromISR( TaskHandle_t xTask )
        {
        TCB_t *pxTCB;
diff --git a/components/freertos/test/test_task_priorities.c b/components/freertos/test/test_task_priorities.c
new file mode 100644 (file)
index 0000000..75df359
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+  Unit tests for FreeRTOS task priority get/set
+*/
+
+#include <esp_types.h>
+#include <stdio.h>
+#include <strings.h>
+
+#include "freertos/FreeRTOS.h"
+#include "freertos/task.h"
+#include "unity.h"
+
+
+static void counter_task(void *param)
+{
+    volatile uint32_t *counter = (volatile uint32_t *)param;
+    while (1) {
+        (*counter)++;
+    }
+}
+
+
+TEST_CASE("Get/Set Priorities", "[freertos]")
+{
+    /* Two tasks per processor */
+    TaskHandle_t tasks[portNUM_PROCESSORS][2] = { 0 };
+    unsigned volatile counters[portNUM_PROCESSORS][2] = { 0 };
+
+    TEST_ASSERT_EQUAL(UNITY_FREERTOS_PRIORITY, uxTaskPriorityGet(NULL));
+
+    /* create a matrix of counter tasks on each core */
+    for (int cpu = 0; cpu < portNUM_PROCESSORS; cpu++) {
+        for (int task = 0; task < 2; task++) {
+            xTaskCreatePinnedToCore(counter_task, "count", 2048, (void *)&(counters[cpu][task]), UNITY_FREERTOS_PRIORITY - task, &(tasks[cpu][task]), cpu);
+        }
+    }
+
+    /* check they were created with the expected priorities */
+    for (int cpu = 0; cpu < portNUM_PROCESSORS; cpu++) {
+        for (int task = 0; task < 2; task++) {
+            TEST_ASSERT_EQUAL(UNITY_FREERTOS_PRIORITY - task, uxTaskPriorityGet(tasks[cpu][task]));
+        }
+    }
+
+    vTaskDelay(10);
+
+    /* at this point, only the higher priority tasks (first index) should be counting */
+    for (int cpu = 0; cpu < portNUM_PROCESSORS; cpu++) {
+        TEST_ASSERT_NOT_EQUAL(0, counters[cpu][0]);
+        TEST_ASSERT_EQUAL(0, counters[cpu][1]);
+    }
+
+    /* swap priorities! */
+    for (int cpu = 0; cpu < portNUM_PROCESSORS; cpu++) {
+        vTaskPrioritySet(tasks[cpu][0], UNITY_FREERTOS_PRIORITY - 1);
+        vTaskPrioritySet(tasks[cpu][1], UNITY_FREERTOS_PRIORITY);
+    }
+
+    /* check priorities have swapped... */
+    for (int cpu = 0; cpu < portNUM_PROCESSORS; cpu++) {
+        TEST_ASSERT_EQUAL(UNITY_FREERTOS_PRIORITY -1, uxTaskPriorityGet(tasks[cpu][0]));
+        TEST_ASSERT_EQUAL(UNITY_FREERTOS_PRIORITY, uxTaskPriorityGet(tasks[cpu][1]));
+    }
+
+    /* check the tasks which are counting have also swapped now... */
+    for (int cpu = 0; cpu < portNUM_PROCESSORS; cpu++) {
+        unsigned old_counters[2];
+        old_counters[0] = counters[cpu][0];
+        old_counters[1] = counters[cpu][1];
+        vTaskDelay(10);
+        TEST_ASSERT_EQUAL(old_counters[0], counters[cpu][0]);
+        TEST_ASSERT_NOT_EQUAL(old_counters[1], counters[cpu][1]);
+    }
+
+    /* clean up */
+    for (int cpu = 0; cpu < portNUM_PROCESSORS; cpu++) {
+        for (int task = 0; task < 2; task++) {
+            vTaskDelete(tasks[cpu][task]);
+        }
+    }
+}
index e4b89734845a4e3724792708fc33756f879c0032..abbb29229060eb6d0ee5ab026949b8904768d982 100644 (file)
@@ -111,12 +111,9 @@ CONFIG_ESP32_ENABLE_COREDUMP_TO_NONE=y
 # CONFIG_ESP32_APPTRACE_DEST_UART is not set
 CONFIG_ESP32_APPTRACE_DEST_NONE=y
 # CONFIG_ESP32_APPTRACE_ENABLE is not set
-CONFIG_BASE_MAC_STORED_DEFAULT_EFUSE=y
-# CONFIG_BASE_MAC_STORED_CUSTOMER_DEFINED_EFUSE is not set
-# CONFIG_BASE_MAC_STORED_OTHER_CUSTOMER_DEFINED_PLACE is not set
-# CONFIG_TWO_MAC_ADDRESS_FROM_EFUSE is not set
-CONFIG_FOUR_MAC_ADDRESS_FROM_EFUSE=y
-CONFIG_NUMBER_OF_MAC_ADDRESS_GENERATED_FROM_EFUSE=4
+# CONFIG_TWO_UNIVERSAL_MAC_ADDRESS is not set
+CONFIG_FOUR_UNIVERSAL_MAC_ADDRESS=y
+CONFIG_NUMBER_OF_UNIVERSAL_MAC_ADDRESS=4
 CONFIG_SYSTEM_EVENT_QUEUE_SIZE=32
 CONFIG_SYSTEM_EVENT_TASK_STACK_SIZE=2048
 CONFIG_MAIN_TASK_STACK_SIZE=4096