1/* BEGIN_HEADER */ 2#include "mbedtls/version.h" 3/* END_HEADER */ 4 5/* BEGIN_DEPENDENCIES 6 * depends_on:MBEDTLS_VERSION_C 7 * END_DEPENDENCIES 8 */ 9 10/* BEGIN_CASE */ 11void check_compiletime_version(char *version_str) 12{ 13 char build_str[100]; 14 char build_str_full[100]; 15 unsigned int build_int; 16 17 memset(build_str, 0, 100); 18 memset(build_str_full, 0, 100); 19 20 mbedtls_snprintf(build_str, 100, "%d.%d.%d", MBEDTLS_VERSION_MAJOR, 21 MBEDTLS_VERSION_MINOR, MBEDTLS_VERSION_PATCH); 22 23 mbedtls_snprintf(build_str_full, 100, "mbed TLS %d.%d.%d", MBEDTLS_VERSION_MAJOR, 24 MBEDTLS_VERSION_MINOR, MBEDTLS_VERSION_PATCH); 25 26 build_int = MBEDTLS_VERSION_MAJOR << 24 | 27 MBEDTLS_VERSION_MINOR << 16 | 28 MBEDTLS_VERSION_PATCH << 8; 29 30 TEST_ASSERT(build_int == MBEDTLS_VERSION_NUMBER); 31 TEST_ASSERT(strcmp(build_str, MBEDTLS_VERSION_STRING) == 0); 32 TEST_ASSERT(strcmp(build_str_full, MBEDTLS_VERSION_STRING_FULL) == 0); 33 TEST_ASSERT(strcmp(version_str, MBEDTLS_VERSION_STRING) == 0); 34} 35/* END_CASE */ 36 37/* BEGIN_CASE */ 38void check_runtime_version(char *version_str) 39{ 40 char build_str[100]; 41 char get_str[100]; 42 char build_str_full[100]; 43 char get_str_full[100]; 44 unsigned int get_int; 45 46 memset(build_str, 0, 100); 47 memset(get_str, 0, 100); 48 memset(build_str_full, 0, 100); 49 memset(get_str_full, 0, 100); 50 51 get_int = mbedtls_version_get_number(); 52 mbedtls_version_get_string(get_str); 53 mbedtls_version_get_string_full(get_str_full); 54 55 mbedtls_snprintf(build_str, 100, "%u.%u.%u", 56 (get_int >> 24) & 0xFF, 57 (get_int >> 16) & 0xFF, 58 (get_int >> 8) & 0xFF); 59 mbedtls_snprintf(build_str_full, 100, "mbed TLS %s", version_str); 60 61 TEST_ASSERT(strcmp(build_str, version_str) == 0); 62 TEST_ASSERT(strcmp(build_str_full, get_str_full) == 0); 63 TEST_ASSERT(strcmp(version_str, get_str) == 0); 64} 65/* END_CASE */ 66 67/* BEGIN_CASE depends_on:MBEDTLS_VERSION_FEATURES */ 68void check_feature(char *feature, int result) 69{ 70 int check = mbedtls_version_check_feature(feature); 71 TEST_ASSERT(check == result); 72} 73/* END_CASE */ 74