Stack hygiene: the worker writes a recognisable pattern to a chunk of * its own stack, yields, runs again. The data must survive across the * yield (i.e. the swap really restored the right sp). */
| 113 | * its own stack, yields, runs again. The data must survive across the |
| 114 | * yield (i.e. the swap really restored the right sp). */ |
| 115 | void stack_worker(void *arg) { |
| 116 | volatile uint64_t pattern[256]; |
| 117 | uint64_t seed = (uint64_t)(intptr_t)arg; |
| 118 | for (int i = 0; i < 256; i++) pattern[i] = seed ^ (uint64_t)i; |
| 119 | port_coroutine_yield(); |
| 120 | for (int i = 0; i < 256; i++) { |
| 121 | if (pattern[i] != (seed ^ (uint64_t)i)) { |
| 122 | fprintf(stderr, "FAIL: stack corrupted at %d (seed=%llx)\n", |
| 123 | i, (unsigned long long)seed); |
| 124 | std::exit(1); |
| 125 | } |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | void test_stack_preservation() { |
| 130 | PortCoroutine *a = port_coroutine_create(stack_worker, (void *)0xCAFEBABE, 128 * 1024); |
nothing calls this directly
no test coverage detected