File: test_suite_test_helpers.function

package info (click to toggle)
mbedtls 3.6.5-0.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 51,488 kB
  • sloc: ansic: 164,842; sh: 25,443; python: 15,512; makefile: 3,131; perl: 1,043; tcl: 4
file content (40 lines) | stat: -rw-r--r-- 1,102 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/* BEGIN_HEADER */

/* Test some parts of the test framework. */

#include <test/helpers.h>
#include <test/memory.h>

/* END_HEADER */

/* BEGIN_DEPENDENCIES */

/* END_DEPENDENCIES */

/* BEGIN_CASE depends_on:MBEDTLS_TEST_MEMORY_CAN_POISON */
/* Test that poison+unpoison leaves the memory accessible. */
/* We can't test that poisoning makes the memory inaccessible:
 * there's no sane way to catch an Asan/Valgrind complaint.
 * That negative testing is done in framework/tests/programs/metatest.c. */
void memory_poison_unpoison(int align, int size)
{
    unsigned char *buf = NULL;
    const size_t buffer_size = align + size;
    TEST_CALLOC(buf, buffer_size);

    for (size_t i = 0; i < buffer_size; i++) {
        buf[i] = (unsigned char) (i & 0xff);
    }

    const unsigned char *start = buf == NULL ? NULL : buf + align;
    mbedtls_test_memory_poison(start, (size_t) size);
    mbedtls_test_memory_unpoison(start, (size_t) size);

    for (size_t i = 0; i < buffer_size; i++) {
        TEST_EQUAL(buf[i], (unsigned char) (i & 0xff));
    }

exit:
    mbedtls_free(buf);
}
/* END_CASE */