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