Subversion Repositories CharLCD

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. #include "jtest.h"
  2. #include "arr_desc.h"
  3. #include "arm_math.h"
  4. #include "ref.h"
  5. #include "type_abbrev.h"
  6. #include "test_templates.h"
  7.  
  8. /*--------------------------------------------------------------------------------*/
  9. /* Input Data */
  10. /*--------------------------------------------------------------------------------*/
  11.  
  12. ARR_DESC_DEFINE(float32_t,
  13.                 arm_sin_cos_degrees_f32,
  14.                 9,
  15.                 CURLY(
  16.                     0,
  17.                     17,
  18.                     45,
  19.                     90,
  20.                     180,
  21.                     360,
  22.                     362,
  23.                     -73,
  24.                     -191.111
  25.                       ));
  26.  
  27. /* The Q31 version of the function maps numbers in the range [-1, 0.9999999]
  28.  * to degrees in the range [-180, 179]*/
  29. ARR_DESC_DEFINE(q31_t,
  30.                 arm_sin_cos_degrees_q31,
  31.                 6,
  32.                 CURLY(
  33.                     0,
  34.                     0x80000000, /* -1 */
  35.                     0x7fffffff, /* 0.99999 */
  36.                     /* Randoms */
  37.                     0xf7badafa,
  38.                     0x285954a1,
  39.                     0xb9d09511
  40.                       ));
  41.  
  42. /*--------------------------------------------------------------------------------*/
  43. /* Output Variables */
  44. /*--------------------------------------------------------------------------------*/
  45. float32_t sin_val_fut = 0;
  46. float32_t cos_val_fut = 0;
  47. float32_t sin_val_ref = 0;
  48. float32_t cos_val_ref = 0;
  49.  
  50. /*--------------------------------------------------------------------------------*/
  51. /* Test Definitions */
  52. /*--------------------------------------------------------------------------------*/
  53.  
  54. #define MAX_DELTA_f32 50.0e-8f
  55. #define ABS(x) ((x) > 0 ? (x) : -(x))
  56.  
  57. /*
  58.   Function to test correctness of sin_cos output by comparing it with reference library
  59. */
  60. #define COMPARISON_INTERFACE(type, threshold)                           \
  61.     if ( (ABS((type) sin_val_ref - (type) sin_val_fut) >                 \
  62.          (type) threshold ) ||                                          \
  63.         (ABS((type) cos_val_ref - (type) cos_val_fut) >                 \
  64.          (type) threshold))                                             \
  65.     {                                                                   \
  66.         JTEST_DUMP_STRF("Error: %f %f\n",                               \
  67.                         ABS((type) sin_val_ref - (type) sin_val_fut),   \
  68.                         ABS((type) cos_val_ref - (type) cos_val_fut));  \
  69.         return JTEST_TEST_FAILED;                                       \
  70.     }
  71.  
  72. /*
  73.   Sine and cosine test function for float32_t input
  74. */
  75. JTEST_DEFINE_TEST(arm_sin_cos_f32_test, arm_sin_cos_f32)
  76. {
  77.     /* Test function for all input degree values */
  78.     TEMPLATE_DO_ARR_DESC(
  79.         degree_idx, TYPE_FROM_ABBREV(f32),
  80.         degree, arm_sin_cos_degrees_f32
  81.         ,
  82.         /* Display cycle count and run test */
  83.         JTEST_COUNT_CYCLES(
  84.             arm_sin_cos_f32(
  85.                 degree,
  86.                 (TYPE_FROM_ABBREV(f32) *) &sin_val_fut,
  87.                 (TYPE_FROM_ABBREV(f32) *) &cos_val_fut)
  88.         );
  89.         ref_sin_cos_f32(
  90.             degree,
  91.             (TYPE_FROM_ABBREV(f32) *) &sin_val_ref,
  92.             (TYPE_FROM_ABBREV(f32) *) &cos_val_ref);
  93.  
  94.         /* Test correctness */
  95.         COMPARISON_INTERFACE(
  96.             TYPE_FROM_ABBREV(f32),
  97.             MAX_DELTA_f32));
  98.  
  99.     return JTEST_TEST_PASSED;
  100. }
  101.  
  102.  
  103. /*
  104.   Sine and cosine test function for q31_t input
  105. */
  106. JTEST_DEFINE_TEST(arm_sin_cos_q31_test,
  107.                   arm_sin_cos_q31)
  108. {
  109.     /* Test function for all input degree values */
  110.     TEMPLATE_DO_ARR_DESC(
  111.         degree_idx, TYPE_FROM_ABBREV(q31),
  112.         degree, arm_sin_cos_degrees_q31
  113.         ,
  114.         /* Display cycle count and run test */
  115.         JTEST_COUNT_CYCLES(
  116.             arm_sin_cos_q31(
  117.                 degree,
  118.                 (TYPE_FROM_ABBREV(q31) *) &sin_val_fut,
  119.                 (TYPE_FROM_ABBREV(q31) *) &cos_val_fut)
  120.         );
  121.         ref_sin_cos_q31(
  122.             degree,
  123.             (TYPE_FROM_ABBREV(q31) *) &sin_val_ref,
  124.             (TYPE_FROM_ABBREV(q31) *) &cos_val_ref);
  125.  
  126.         /* Convert q31 numbers to float for comparison purposes. */
  127.         ref_q31_t_to_float((TYPE_FROM_ABBREV(q31) *) &sin_val_fut, &sin_val_fut, 1);
  128.         ref_q31_t_to_float((TYPE_FROM_ABBREV(q31) *) &cos_val_fut, &cos_val_fut, 1);
  129.         ref_q31_t_to_float((TYPE_FROM_ABBREV(q31) *) &sin_val_ref, &sin_val_ref, 1);
  130.         ref_q31_t_to_float((TYPE_FROM_ABBREV(q31) *) &cos_val_ref, &cos_val_ref, 1);
  131.  
  132.         /* Test correctness */
  133.         COMPARISON_INTERFACE(
  134.             TYPE_FROM_ABBREV(f32),
  135.             MAX_DELTA_f32));
  136.  
  137.     return JTEST_TEST_PASSED;
  138. }
  139.  
  140. /*--------------------------------------------------------------------------------*/
  141. /* Collect all tests in a group */
  142. /*--------------------------------------------------------------------------------*/
  143.  
  144. JTEST_DEFINE_GROUP(sin_cos_tests)
  145. {
  146.     /*
  147.       To skip a test, comment it out.
  148.     */
  149.     JTEST_TEST_CALL(arm_sin_cos_f32_test);
  150.     JTEST_TEST_CALL(arm_sin_cos_q31_test);
  151. }
  152.