ExampleCategoryF32.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #include "ExampleCategoryF32.h"
  2. #include <stdio.h>
  3. #include "Error.h"
  4. /*
  5. Tests to write and test criteria depend on the algorithm.
  6. When SNR is meaningful, SNR threshold depends on the type.
  7. CMSIS-DSP tests are using similar SNR values for different type (f32, q31, q15, q7)
  8. */
  9. #define SNR_THRESHOLD 120
  10. /*
  11. With thie threshold, the test will fail
  12. #define REL_ERROR (2.0e-6)
  13. */
  14. #define REL_ERROR (5.0e-6)
  15. void ExampleCategoryF32::test_op_f32()
  16. {
  17. /* Get a pointer to the input data.
  18. For benchmark, getting pointers should be done in the setUp function
  19. since there is an overhead. Lot of checks are done before returning a pointer.
  20. */
  21. const float32_t *inp1=input1.ptr();
  22. const float32_t *inp2=input2.ptr();
  23. /* Get a pointer to the output buffer */
  24. float32_t *outp=output.ptr();
  25. /* Run the test */
  26. arm_add_f32(inp1,inp2,outp,input1.nbSamples());
  27. /* Check there is no buffer overflow on the output */
  28. ASSERT_EMPTY_TAIL(output);
  29. /* Check SNR error */
  30. ASSERT_SNR(output,ref,(float32_t)SNR_THRESHOLD);
  31. /* Check relative error */
  32. ASSERT_REL_ERROR(output,ref,REL_ERROR);
  33. }
  34. /*
  35. setUp function is used to load the patterns and create required buffers
  36. */
  37. void ExampleCategoryF32::setUp(Testing::testID_t id,std::vector<Testing::param_t>& params,Client::PatternMgr *mgr)
  38. {
  39. Testing::nbSamples_t nb=MAX_NB_SAMPLES;
  40. (void)params;
  41. /*
  42. All IDs can be found in GeneratedInclude/ExampleCategoryF32_decl.h
  43. */
  44. /*
  45. Different allocations depending on the test.
  46. */
  47. switch(id)
  48. {
  49. /* In both tests, the same function is tested as defined in desc.txt.
  50. But different configurations are used.
  51. */
  52. case ExampleCategoryF32::TEST_OP_F32_1:
  53. /* Load patterns with all samples */
  54. input1.reload(ExampleCategoryF32::INPUT1_F32_ID,mgr);
  55. input2.reload(ExampleCategoryF32::INPUT2_F32_ID,mgr);
  56. ref.reload(ExampleCategoryF32::REF_OUT_F32_ID,mgr);
  57. break;
  58. case ExampleCategoryF32::TEST_OP_F32_2:
  59. nb = 9;
  60. /* Load patterns with 9 samples */
  61. input1.reload(ExampleCategoryF32::INPUT1_F32_ID,mgr,nb);
  62. input2.reload(ExampleCategoryF32::INPUT2_F32_ID,mgr,nb);
  63. ref.reload(ExampleCategoryF32::REF_OUT_F32_ID,mgr,nb);
  64. break;
  65. }
  66. /* Create output buffer with same size as reference pattern */
  67. output.create(ref.nbSamples(),ExampleCategoryF32::OUT_F32_ID,mgr);
  68. }
  69. void ExampleCategoryF32::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
  70. {
  71. (void)id;
  72. /*
  73. Dump output buffer into a file.
  74. Location of the file is defined by Folder directives in desc.txt test
  75. description file and relative to the Output folder.
  76. */
  77. output.dump(mgr);
  78. }