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

Function basics

test/core/test_emmalloc.c:31–63  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29}
30
31void basics() {
32 stage("basics");
33 stage("allocate 0");
34 void* ptr = malloc(0);
35 assert(ptr != 0);
36 free(ptr);
37 stage("allocate 100");
38 void* first = malloc(100);
39 stage("free 100");
40 free(first);
41 stage("allocate another 100");
42 void* second = malloc(100);
43 stage("allocate 10");
44#ifndef WASMFS
45 // There is no strict guarantee that the second allocation be equal to the
46 // first, but in practice on a fresh heap that tends to be the case. With
47 // WasmFS, however, the heap has already seen a bunch of use by the time we
48 // get here, and due to fragmentation etc. we cannot predict getting the exact
49 // same result the second time.
50 assert(second == first);
51#endif
52 void* third = malloc(10);
53 assert(!emmalloc_validate_memory_regions());
54 stage("allocate 10 more");
55 void* four = malloc(10);
56 assert(!emmalloc_validate_memory_regions());
57 stage("free the first");
58 free(second);
59 stage("free all");
60 free(third);
61 free(four);
62 assert(!emmalloc_validate_memory_regions());
63}
64
65void previous_sbrk() {
66 stage("previous_sbrk");

Callers 1

mainFunction · 0.85

Calls 5

stageFunction · 0.85
mallocFunction · 0.70
freeFunction · 0.70
assertFunction · 0.50

Tested by

no test coverage detected