ExampleCategoryF32.cpp 2.9 KB

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