MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / main

Function main

test/core/test_stack_get_free.c:27–48  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25int increment = 256 * 1024;
26
27int main() {
28 emscripten_stack_init();
29 TestStackValidity();
30
31 uintptr_t origFree = emscripten_stack_get_free();
32 uintptr_t prevFree = emscripten_stack_get_free();
33 printf("Stack used: %lu\n", origFree - emscripten_stack_get_free());
34 for (int i = 0; i < 10; ++i) {
35 int increment_noopt = emscripten_random() >= 0 ? increment : 2;
36 char *p = alloca(increment_noopt);
37 DoSomething(p);
38 uintptr_t free = emscripten_stack_get_free();
39 assert(prevFree - free == increment);
40 prevFree = free;
41 // Print something from the allocated region to prevent whole program
42 // optimizations from eliminating the alloca completely.
43 printf("Val: %d\n", p[10]);
44 printf("Stack used: %zu\n", origFree - emscripten_stack_get_free());
45 TestStackValidity();
46 }
47 return 0;
48}

Callers

nothing calls this directly

Calls 4

TestStackValidityFunction · 0.85
printfFunction · 0.85
DoSomethingFunction · 0.85
assertFunction · 0.50

Tested by

no test coverage detected