test_suite_test_helpers.function (1102B)
1 /* BEGIN_HEADER */ 2 3 /* Test some parts of the test framework. */ 4 5 #include <test/helpers.h> 6 #include <test/memory.h> 7 8 /* END_HEADER */ 9 10 /* BEGIN_DEPENDENCIES */ 11 12 /* END_DEPENDENCIES */ 13 14 /* BEGIN_CASE depends_on:MBEDTLS_TEST_MEMORY_CAN_POISON */ 15 /* Test that poison+unpoison leaves the memory accessible. */ 16 /* We can't test that poisoning makes the memory inaccessible: 17 * there's no sane way to catch an Asan/Valgrind complaint. 18 * That negative testing is done in framework/tests/programs/metatest.c. */ 19 void memory_poison_unpoison(int align, int size) 20 { 21 unsigned char *buf = NULL; 22 const size_t buffer_size = align + size; 23 TEST_CALLOC(buf, buffer_size); 24 25 for (size_t i = 0; i < buffer_size; i++) { 26 buf[i] = (unsigned char) (i & 0xff); 27 } 28 29 const unsigned char *start = buf == NULL ? NULL : buf + align; 30 mbedtls_test_memory_poison(start, (size_t) size); 31 mbedtls_test_memory_unpoison(start, (size_t) size); 32 33 for (size_t i = 0; i < buffer_size; i++) { 34 TEST_EQUAL(buf[i], (unsigned char) (i & 0xff)); 35 } 36 37 exit: 38 mbedtls_free(buf); 39 } 40 /* END_CASE */