2019-11-15 08:07:57 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include "unity.h"
|
|
|
|
#include "freertos/FreeRTOS.h"
|
|
|
|
#include "freertos/task.h"
|
|
|
|
#include "freertos/semphr.h"
|
|
|
|
#include "sdkconfig.h"
|
|
|
|
#include "test_utils.h"
|
|
|
|
#include "esp_expression_with_stack.h"
|
|
|
|
|
|
|
|
//makes sure this is not the task stack...
|
2019-11-15 08:45:18 +00:00
|
|
|
void check_stack(portSTACK_TYPE *sp, portSTACK_TYPE *base_sp)
|
2019-11-15 08:07:57 +00:00
|
|
|
{
|
|
|
|
StaticTask_t *hacked_task = (StaticTask_t *)xTaskGetCurrentTaskHandle();
|
|
|
|
portSTACK_TYPE *task_sp = (portSTACK_TYPE *)hacked_task->pxDummy1;
|
2019-11-15 08:45:18 +00:00
|
|
|
TEST_ASSERT((intptr_t)task_sp < (intptr_t)base_sp ||
|
|
|
|
(intptr_t)task_sp >= (intptr_t)sp);
|
2019-11-15 08:07:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("test printf using shared buffer stack", "[newlib]")
|
|
|
|
{
|
2019-11-15 08:45:18 +00:00
|
|
|
portSTACK_TYPE *shared_stack = malloc(8192 * sizeof(portSTACK_TYPE));
|
|
|
|
portSTACK_TYPE *ext_stack_top = (portSTACK_TYPE *)&shared_stack[0] +
|
|
|
|
((sizeof(8192 * sizeof(portSTACK_TYPE))) /
|
|
|
|
sizeof(portSTACK_TYPE));
|
|
|
|
|
|
|
|
TEST_ASSERT(shared_stack != NULL);
|
|
|
|
|
2019-11-15 08:07:57 +00:00
|
|
|
SemaphoreHandle_t printf_lock = xSemaphoreCreateMutex();
|
2019-11-15 08:49:25 +00:00
|
|
|
ESP_EXECUTE_EXPRESSION_WITH_STACK(printf_lock, ext_stack_top, printf("Executing this from external stack! \n"));
|
|
|
|
ESP_EXECUTE_EXPRESSION_WITH_STACK(printf_lock, ext_stack_top, check_stack(ext_stack_top, shared_stack));
|
2019-11-15 08:45:18 +00:00
|
|
|
free(shared_stack);
|
2019-11-15 08:07:57 +00:00
|
|
|
}
|