ExampleCategoryF32.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. /*
  41. All IDs can be found in GeneratedInclude/ExampleCategoryF32_decl.h
  42. */
  43. /*
  44. Different allocations depending on the test.
  45. */
  46. switch(id)
  47. {
  48. /* In both tests, the same function is tested as defined in desc.txt.
  49. But different configurations are used.
  50. */
  51. case ExampleCategoryF32::TEST_OP_F32_1:
  52. /* Load patterns with all samples */
  53. input1.reload(ExampleCategoryF32::INPUT1_F32_ID,mgr);
  54. input2.reload(ExampleCategoryF32::INPUT2_F32_ID,mgr);
  55. ref.reload(ExampleCategoryF32::REF_OUT_F32_ID,mgr);
  56. break;
  57. case ExampleCategoryF32::TEST_OP_F32_2:
  58. nb = 9;
  59. /* Load patterns with 9 samples */
  60. input1.reload(ExampleCategoryF32::INPUT1_F32_ID,mgr,nb);
  61. input2.reload(ExampleCategoryF32::INPUT2_F32_ID,mgr,nb);
  62. ref.reload(ExampleCategoryF32::REF_OUT_F32_ID,mgr,nb);
  63. break;
  64. }
  65. /* Create output buffer with same size as reference pattern */
  66. output.create(ref.nbSamples(),ExampleCategoryF32::OUT_F32_ID,mgr);
  67. }
  68. void ExampleCategoryF32::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
  69. {
  70. /*
  71. Dump output buffer into a file.
  72. Location of the file is defined by Folder directives in desc.txt test
  73. description file and relative to the Output folder.
  74. */
  75. output.dump(mgr);
  76. }