8
8
#include "test_utils.h"
9
9
#include "esp_expression_with_stack.h"
10
10
11
+ #define SHARED_STACK_SIZE 8192
12
+
13
+ static StackType_t * shared_stack_sp = NULL ;
14
+
11
15
void external_stack_function (void )
12
16
{
13
17
printf ("Executing this printf from external stack! sp=%p\n" , get_sp ());
18
+ shared_stack_sp = (StackType_t * )get_sp ();
14
19
}
15
20
16
21
void another_external_stack_function (void )
@@ -19,11 +24,12 @@ void another_external_stack_function(void)
19
24
printf ("We can even use FreeRTOS resources delaying..., sp=%p\n" , get_sp ());
20
25
vTaskDelay (100 );
21
26
printf ("Done!, sp=%p\n" , get_sp ());
27
+ shared_stack_sp = (StackType_t * )get_sp ();
22
28
}
23
29
24
30
TEST_CASE ("test printf using shared buffer stack" , "[newlib]" )
25
31
{
26
- portSTACK_TYPE * shared_stack = malloc (8192 );
32
+ portSTACK_TYPE * shared_stack = malloc (SHARED_STACK_SIZE );
27
33
28
34
TEST_ASSERT (shared_stack != NULL );
29
35
@@ -32,8 +38,22 @@ TEST_CASE("test printf using shared buffer stack", "[newlib]")
32
38
printf ("SP: %p\n" , get_sp ());
33
39
printf ("shared_stack: %p\n" , (void * )shared_stack );
34
40
35
- esp_execute_shared_stack_function (printf_lock , shared_stack ,8192 ,external_stack_function );
36
- esp_execute_shared_stack_function (printf_lock , shared_stack ,8192 ,another_external_stack_function );
41
+ esp_execute_shared_stack_function (printf_lock ,
42
+ shared_stack ,
43
+ SHARED_STACK_SIZE ,
44
+ external_stack_function );
45
+
46
+ TEST_ASSERT (((shared_stack_sp >= shared_stack_sp ) &&
47
+ (shared_stack_sp < (shared_stack + SHARED_STACK_SIZE ))));
48
+
49
+ esp_execute_shared_stack_function (printf_lock ,
50
+ shared_stack ,
51
+ SHARED_STACK_SIZE ,
52
+ another_external_stack_function );
53
+
54
+ TEST_ASSERT (((shared_stack_sp >= shared_stack_sp ) &&
55
+ (shared_stack_sp < (shared_stack + SHARED_STACK_SIZE ))));
56
+
37
57
vSemaphoreDelete (printf_lock );
38
58
free (shared_stack );
39
59
}
0 commit comments