2019-11-06 08:59:16 +00:00
|
|
|
#include <esp_types.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "freertos/FreeRTOS.h"
|
|
|
|
#include "freertos/task.h"
|
|
|
|
#include "freertos/semphr.h"
|
|
|
|
#include "freertos/queue.h"
|
|
|
|
#include "esp_intr_alloc.h"
|
|
|
|
#include "unity.h"
|
|
|
|
#include "soc/cpu.h"
|
|
|
|
#include "test_utils.h"
|
|
|
|
|
2020-04-03 19:57:57 +00:00
|
|
|
#define NUMBER_OF_ITERATIONS 10
|
|
|
|
|
2019-11-06 08:59:16 +00:00
|
|
|
typedef struct {
|
|
|
|
SemaphoreHandle_t end_sema;
|
|
|
|
uint32_t before_sched;
|
|
|
|
uint32_t cycles_to_sched;
|
2019-11-08 05:27:02 +00:00
|
|
|
TaskHandle_t t1_handle;
|
2019-11-06 08:59:16 +00:00
|
|
|
} test_context_t;
|
|
|
|
|
|
|
|
static void test_task_1(void *arg) {
|
|
|
|
test_context_t *context = (test_context_t *)arg;
|
|
|
|
|
2019-11-08 05:27:02 +00:00
|
|
|
for( ;; ) {
|
2019-11-06 08:59:16 +00:00
|
|
|
context->before_sched = portGET_RUN_TIME_COUNTER_VALUE();
|
|
|
|
vPortYield();
|
|
|
|
}
|
|
|
|
|
2020-11-10 07:40:01 +00:00
|
|
|
vTaskDelete(NULL);
|
2019-11-06 08:59:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_task_2(void *arg) {
|
|
|
|
test_context_t *context = (test_context_t *)arg;
|
2020-04-03 19:57:57 +00:00
|
|
|
uint64_t accumulator = 0;
|
|
|
|
|
|
|
|
vTaskPrioritySet(NULL, CONFIG_UNITY_FREERTOS_PRIORITY + 1);
|
|
|
|
vTaskPrioritySet(context->t1_handle, CONFIG_UNITY_FREERTOS_PRIORITY + 1);
|
|
|
|
vPortYield();
|
2019-11-06 08:59:16 +00:00
|
|
|
|
2020-04-03 19:57:57 +00:00
|
|
|
for(int i = 0; i < NUMBER_OF_ITERATIONS; i++) {
|
2019-11-08 05:27:02 +00:00
|
|
|
accumulator += (portGET_RUN_TIME_COUNTER_VALUE() - context->before_sched);
|
2019-11-06 08:59:16 +00:00
|
|
|
vPortYield();
|
|
|
|
}
|
|
|
|
|
2020-04-03 19:57:57 +00:00
|
|
|
context->cycles_to_sched = accumulator / NUMBER_OF_ITERATIONS;
|
2019-11-08 05:27:02 +00:00
|
|
|
vTaskDelete(context->t1_handle);
|
2019-11-06 08:59:16 +00:00
|
|
|
xSemaphoreGive(context->end_sema);
|
|
|
|
vTaskDelete(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("scheduling time test", "[freertos]")
|
|
|
|
{
|
2020-11-10 07:40:01 +00:00
|
|
|
test_context_t context;
|
2019-11-06 08:59:16 +00:00
|
|
|
|
|
|
|
context.end_sema = xSemaphoreCreateBinary();
|
|
|
|
TEST_ASSERT(context.end_sema != NULL);
|
|
|
|
|
2019-11-08 05:27:02 +00:00
|
|
|
#if !CONFIG_FREERTOS_UNICORE
|
|
|
|
xTaskCreatePinnedToCore(test_task_1, "test1" , 4096, &context, 1, &context.t1_handle,1);
|
2019-11-06 08:59:16 +00:00
|
|
|
xTaskCreatePinnedToCore(test_task_2, "test2" , 4096, &context, 1, NULL,1);
|
2019-11-08 05:27:02 +00:00
|
|
|
#else
|
2020-04-03 19:57:57 +00:00
|
|
|
xTaskCreatePinnedToCore(test_task_1, "test1" , 4096, &context, CONFIG_UNITY_FREERTOS_PRIORITY - 1, &context.t1_handle,0);
|
|
|
|
xTaskCreatePinnedToCore(test_task_2, "test2" , 4096, &context, CONFIG_UNITY_FREERTOS_PRIORITY - 1, NULL,0);
|
2019-11-08 05:27:02 +00:00
|
|
|
#endif
|
2019-11-06 08:59:16 +00:00
|
|
|
|
2020-11-10 07:40:01 +00:00
|
|
|
BaseType_t result = xSemaphoreTake(context.end_sema, portMAX_DELAY);
|
2019-11-06 08:59:16 +00:00
|
|
|
TEST_ASSERT_EQUAL_HEX32(pdTRUE, result);
|
2021-06-17 02:19:28 +00:00
|
|
|
TEST_PERFORMANCE_LESS_THAN(SCHEDULING_TIME , "%d cycles" ,context.cycles_to_sched);
|
2020-11-10 07:40:01 +00:00
|
|
|
}
|