test_suite_version.function 2.1 KB

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