test_shared_stack_printf.c 1.0 KB

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