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 "freertos/xtensa_api.h"
|
|
|
|
#include "esp_intr_alloc.h"
|
|
|
|
#include "xtensa/hal.h"
|
|
|
|
#include "unity.h"
|
|
|
|
#include "soc/cpu.h"
|
|
|
|
#include "test_utils.h"
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
vTaskDelete(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_task_2(void *arg) {
|
|
|
|
test_context_t *context = (test_context_t *)arg;
|
2019-11-08 05:27:02 +00:00
|
|
|
uint32_t accumulator = 0;
|
2019-11-06 08:59:16 +00:00
|
|
|
|
2019-11-08 05:27:02 +00:00
|
|
|
for(int i = 0; i < 10000; i++) {
|
|
|
|
accumulator += (portGET_RUN_TIME_COUNTER_VALUE() - context->before_sched);
|
2019-11-06 08:59:16 +00:00
|
|
|
vPortYield();
|
|
|
|
}
|
|
|
|
|
2019-11-08 05:27:02 +00:00
|
|
|
context->cycles_to_sched = accumulator / 10000;
|
|
|
|
vTaskDelete(context->t1_handle);
|
2019-11-06 08:59:16 +00:00
|
|
|
xSemaphoreGive(context->end_sema);
|
|
|
|
vTaskDelete(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("scheduling time test", "[freertos]")
|
|
|
|
{
|
|
|
|
test_context_t context;
|
|
|
|
|
|
|
|
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
|
|
|
|
xTaskCreatePinnedToCore(test_task_1, "test1" , 4096, &context, 1, &context.t1_handle,0);
|
|
|
|
xTaskCreatePinnedToCore(test_task_2, "test2" , 4096, &context, 1, NULL,0);
|
|
|
|
#endif
|
2019-11-06 08:59:16 +00:00
|
|
|
|
|
|
|
BaseType_t result = xSemaphoreTake(context.end_sema, portMAX_DELAY);
|
|
|
|
TEST_ASSERT_EQUAL_HEX32(pdTRUE, result);
|
|
|
|
TEST_PERFORMANCE_LESS_THAN(SCHEDULING_TIME , "scheduling time %d cycles" ,context.cycles_to_sched);
|
|
|
|
}
|