| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "test_memalloc.h" | ||
| 2 | |||
| 3 | #include "gate/tests.h" | ||
| 4 | #include "gate/memalloc.h" | ||
| 5 | |||
| 6 | |||
| 7 | #define MEMALLOC_TEST_CHAR 0x55 | ||
| 8 | #define MEMALLOC_TEST_BUFFER_LENGTH 16 | ||
| 9 | |||
| 10 | 1 | GATE_TEST_FUNCTION(test_memalloc) | |
| 11 | { | ||
| 12 | char* ptr; | ||
| 13 | int index; | ||
| 14 | gate_size_t sz; | ||
| 15 | 1 | char const filled_buf[MEMALLOC_TEST_BUFFER_LENGTH] = | |
| 16 | { | ||
| 17 | MEMALLOC_TEST_CHAR, MEMALLOC_TEST_CHAR, MEMALLOC_TEST_CHAR, MEMALLOC_TEST_CHAR, | ||
| 18 | MEMALLOC_TEST_CHAR, MEMALLOC_TEST_CHAR, MEMALLOC_TEST_CHAR, MEMALLOC_TEST_CHAR, | ||
| 19 | MEMALLOC_TEST_CHAR, MEMALLOC_TEST_CHAR, MEMALLOC_TEST_CHAR, MEMALLOC_TEST_CHAR, | ||
| 20 | MEMALLOC_TEST_CHAR, MEMALLOC_TEST_CHAR, MEMALLOC_TEST_CHAR, MEMALLOC_TEST_CHAR | ||
| 21 | }; | ||
| 22 | 1 | char const empty_buf[MEMALLOC_TEST_BUFFER_LENGTH] = { 0 }; | |
| 23 | 1 | char temp_buf[MEMALLOC_TEST_BUFFER_LENGTH] = { 0 }; | |
| 24 | |||
| 25 | 1 | gate_size_t const buf_size = sizeof(filled_buf); | |
| 26 | |||
| 27 | |||
| 28 | 1 | GATE_TEST_UNIT_BEGIN(test_memalloc); | |
| 29 | |||
| 30 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 1 times.
|
8 | for (index = 1; index != 8; ++index) |
| 31 | { | ||
| 32 | 7 | sz = (gate_size_t)index * 512u; | |
| 33 |
1/2✓ Branch 3 taken 7 times.
✗ Branch 4 not taken.
|
7 | GATE_TEST_REQUIRE_NOT_EQUAL(ptr = (char*)gate_mem_alloc(sz), NULL); |
| 34 | 7 | gate_mem_fill(ptr, MEMALLOC_TEST_CHAR, sz); | |
| 35 |
1/2✓ Branch 3 taken 7 times.
✗ Branch 4 not taken.
|
7 | GATE_TEST_CHECK_EQUAL(gate_mem_compare(ptr, ptr, sz), 0); |
| 36 |
1/2✓ Branch 3 taken 7 times.
✗ Branch 4 not taken.
|
7 | GATE_TEST_CHECK_EQUAL(gate_mem_compare(ptr, filled_buf, buf_size), 0); |
| 37 |
1/2✓ Branch 3 taken 7 times.
✗ Branch 4 not taken.
|
7 | GATE_TEST_CHECK_EQUAL(gate_mem_compare(&ptr[sz - buf_size], filled_buf, buf_size), 0); |
| 38 | 7 | gate_mem_dealloc(ptr); | |
| 39 | } | ||
| 40 | |||
| 41 | { | ||
| 42 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_REQUIRE_NOT_EQUAL(ptr = (char*)gate_mem_alloc(buf_size), NULL); |
| 43 | 1 | gate_mem_fill(ptr, MEMALLOC_TEST_CHAR, buf_size); | |
| 44 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_REQUIRE_NOT_EQUAL(ptr = (char*)gate_mem_realloc(ptr, buf_size * 2), NULL); |
| 45 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_mem_compare(ptr, filled_buf, buf_size), 0); |
| 46 | |||
| 47 | 1 | gate_mem_clear(ptr, buf_size * 2); | |
| 48 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_mem_compare(&ptr[0], empty_buf, buf_size), 0); |
| 49 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_mem_compare(&ptr[buf_size], empty_buf, buf_size), 0); |
| 50 | |||
| 51 | 1 | gate_mem_clear(ptr, buf_size * 2); | |
| 52 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_mem_copy(ptr, filled_buf, buf_size), ptr); |
| 53 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_mem_compare(ptr, filled_buf, buf_size), 0); |
| 54 | |||
| 55 | 1 | gate_mem_clear(ptr, buf_size * 2); | |
| 56 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_mem_move(ptr, filled_buf, buf_size), ptr); |
| 57 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_mem_compare(ptr, filled_buf, buf_size), 0); |
| 58 | |||
| 59 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK(gate_mem_compare(ptr, empty_buf, buf_size) > 0); |
| 60 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK(gate_mem_compare(empty_buf, ptr, buf_size) < 0); |
| 61 | 1 | gate_mem_dealloc(ptr); | |
| 62 | } | ||
| 63 | |||
| 64 | { | ||
| 65 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_REQUIRE_NOT_EQUAL(ptr = (char*)gate_mem_alloc(buf_size), NULL); |
| 66 | |||
| 67 | 1 | gate_mem_fill(ptr, MEMALLOC_TEST_CHAR, buf_size); | |
| 68 | 1 | gate_mem_clear(temp_buf, buf_size); | |
| 69 | |||
| 70 | /* heap-block filled, temp_buf empty */ | ||
| 71 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_mem_compare(ptr, filled_buf, buf_size), 0); |
| 72 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_mem_compare(&temp_buf[0], empty_buf, buf_size), 0); |
| 73 | |||
| 74 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_mem_swap(ptr, &temp_buf[0], buf_size, NULL, NULL), true); |
| 75 | /* heap-block empty, temp_buf filled */ | ||
| 76 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_mem_compare(ptr, empty_buf, buf_size), 0); |
| 77 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_mem_compare(&temp_buf[0], filled_buf, buf_size), 0); |
| 78 | |||
| 79 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_mem_swap(ptr, &temp_buf[0], buf_size, NULL, NULL), true); |
| 80 | /* heap-block filled, temp_buf empty */ | ||
| 81 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_mem_compare(ptr, filled_buf, buf_size), 0); |
| 82 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_mem_compare(&temp_buf[0], empty_buf, buf_size), 0); |
| 83 | |||
| 84 | 1 | gate_mem_dealloc(ptr); | |
| 85 | } | ||
| 86 | |||
| 87 | { | ||
| 88 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_REQUIRE_NOT_EQUAL(ptr = (char*)gate_mem_alloc(buf_size * 2), NULL); |
| 89 | 1 | gate_mem_clear(&ptr[0], buf_size); | |
| 90 | 1 | gate_mem_fill(&ptr[buf_size], MEMALLOC_TEST_CHAR, buf_size); | |
| 91 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_mem_compare(&ptr[0], empty_buf, buf_size), 0); |
| 92 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_mem_compare(&ptr[buf_size], filled_buf, buf_size), 0); |
| 93 | |||
| 94 | /*00000000-FFFFFFFF -> 00000000-0000FFFF */ | ||
| 95 | 1 | gate_mem_move(&ptr[buf_size], &ptr[buf_size / 2], buf_size); | |
| 96 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_mem_compare(&ptr[0], empty_buf, buf_size), 0); |
| 97 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_mem_compare(&ptr[buf_size], empty_buf, buf_size / 2), 0); |
| 98 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_mem_compare(&ptr[buf_size + buf_size / 2], filled_buf, buf_size / 2), 0); |
| 99 | |||
| 100 | 1 | gate_mem_dealloc(ptr); | |
| 101 | } | ||
| 102 | |||
| 103 | |||
| 104 | 1 | GATE_TEST_UNIT_END; | |
| 105 | } | ||
| 106 |