test_shared_stack_printf: moved the test stack inside the heap

This commit is contained in:
Felipe Neves
2019-11-15 16:45:18 +08:00
parent debcc68c41
commit 98b76617be

View File

@@ -4,30 +4,29 @@
#include "freertos/task.h" #include "freertos/task.h"
#include "freertos/semphr.h" #include "freertos/semphr.h"
#include "sdkconfig.h" #include "sdkconfig.h"
#include "soc/rtc.h"
#include "esp_system.h"
#include "test_utils.h" #include "test_utils.h"
#include "esp_expression_with_stack.h" #include "esp_expression_with_stack.h"
#include <stdio.h>
static portSTACK_TYPE shared_stack[8192];
static portSTACK_TYPE *ext_stack_top = (portSTACK_TYPE *)&shared_stack[0] + (sizeof(shared_stack) / sizeof(portSTACK_TYPE));
//makes sure this is not the task stack... //makes sure this is not the task stack...
void check_stack(portSTACK_TYPE *sp) void check_stack(portSTACK_TYPE *sp, portSTACK_TYPE *base_sp)
{ {
StaticTask_t *hacked_task = (StaticTask_t *)xTaskGetCurrentTaskHandle(); StaticTask_t *hacked_task = (StaticTask_t *)xTaskGetCurrentTaskHandle();
portSTACK_TYPE *task_sp = (portSTACK_TYPE *)hacked_task->pxDummy1; portSTACK_TYPE *task_sp = (portSTACK_TYPE *)hacked_task->pxDummy1;
TEST_ASSERT((intptr_t)sp <= (intptr_t)ext_stack_top); TEST_ASSERT((intptr_t)task_sp < (intptr_t)base_sp ||
TEST_ASSERT((intptr_t)sp >= (intptr_t)&shared_stack); (intptr_t)task_sp >= (intptr_t)sp);
TEST_ASSERT((intptr_t)task_sp < (intptr_t)&shared_stack ||
(intptr_t)task_sp >= (intptr_t)&ext_stack_top);
} }
TEST_CASE("test printf using shared buffer stack", "[newlib]") TEST_CASE("test printf using shared buffer stack", "[newlib]")
{ {
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);
SemaphoreHandle_t printf_lock = xSemaphoreCreateMutex(); SemaphoreHandle_t printf_lock = xSemaphoreCreateMutex();
EXECUTE_EXPRESSION_WITH_STACK(printf_lock, ext_stack_top, printf("Executing this from external stack! \n")); EXECUTE_EXPRESSION_WITH_STACK(printf_lock, ext_stack_top, printf("Executing this from external stack! \n"));
EXECUTE_EXPRESSION_WITH_STACK(printf_lock, ext_stack_top, check_stack(ext_stack_top)); EXECUTE_EXPRESSION_WITH_STACK(printf_lock, ext_stack_top, check_stack(ext_stack_top, shared_stack));
free(shared_stack);
} }