test_shared_stack_printf.c 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. #include <stdio.h>
  2. #include "unity.h"
  3. #include "freertos/FreeRTOS.h"
  4. #include "freertos/task.h"
  5. #include "freertos/semphr.h"
  6. #include "sdkconfig.h"
  7. #include "test_utils.h"
  8. #include "esp_expression_with_stack.h"
  9. //makes sure this is not the task stack...
  10. void another_external_stack_function(void)
  11. {
  12. //We can even use Freertos resources inside of this context.
  13. vTaskDelay(100);
  14. printf("Executing this another printf inside a function with external stack");
  15. }
  16. TEST_CASE("test printf using shared buffer stack", "[newlib]")
  17. {
  18. portSTACK_TYPE *shared_stack = malloc(8192 * sizeof(portSTACK_TYPE));
  19. TEST_ASSERT(shared_stack != NULL);
  20. SemaphoreHandle_t printf_lock = xSemaphoreCreateMutex();
  21. TEST_ASSERT_NOT_NULL(printf_lock);
  22. ESP_EXECUTE_EXPRESSION_WITH_STACK(printf_lock, shared_stack,8192,printf("Executing this printf from external stack! \n"));
  23. ESP_EXECUTE_EXPRESSION_WITH_STACK(printf_lock, shared_stack,8192,another_external_stack_function());
  24. vSemaphoreDelete(printf_lock);
  25. free(shared_stack);
  26. }