From e54224972fb1f97a3906043c1b572676c233d31e Mon Sep 17 00:00:00 2001 From: Christophe Favergeon Date: Mon, 14 Oct 2019 10:50:29 +0200 Subject: [PATCH] CMSIS-DSP: Fixed compilation issue with AC5 compiler for test framework. --- Testing/FrameworkInclude/Error.h | 17 +++++--- Testing/FrameworkSource/Error.cpp | 58 +++++++++++++++++++-------- Testing/Source/Tests/BasicTestsQ7.cpp | 2 +- 3 files changed, 53 insertions(+), 24 deletions(-) diff --git a/Testing/FrameworkInclude/Error.h b/Testing/FrameworkInclude/Error.h index e2e8da1a..676a6df3 100644 --- a/Testing/FrameworkInclude/Error.h +++ b/Testing/FrameworkInclude/Error.h @@ -155,8 +155,18 @@ void assert_near_equal(unsigned long nb,T pa, T pb, T threshold) } }; +template <> +void assert_near_equal(unsigned long nb,double pa, double pb, double threshold); template <> void assert_near_equal(unsigned long nb,float32_t pa, float32_t pb, float32_t threshold); +template <> +void assert_near_equal(unsigned long nb,q63_t pa, q63_t pb, q63_t threshold); +template <> +void assert_near_equal(unsigned long nb,q31_t pa, q31_t pb, q31_t threshold); +template <> +void assert_near_equal(unsigned long nb,q15_t pa, q15_t pb, q15_t threshold); +template <> +void assert_near_equal(unsigned long nb,q7_t pa, q7_t pb, q7_t threshold); template void assert_near_equal(unsigned long nb,AnyPattern &pa, AnyPattern &pb, T threshold) @@ -177,15 +187,10 @@ void assert_near_equal(unsigned long nb,AnyPattern &pa, AnyPattern &pb, T for(i=0; i < pa.nbSamples(); i++) { - if (abs(ptrA[i] - ptrB[i]) > threshold) - { - throw (Error(NEAR_EQUAL_ERROR,nb)); - } + assert_near_equal(nb,ptrA[i],ptrB[i],threshold); } }; -template <> -void assert_near_equal(unsigned long nb,AnyPattern &pa, AnyPattern &pb, float32_t threshold); } #endif diff --git a/Testing/FrameworkSource/Error.cpp b/Testing/FrameworkSource/Error.cpp index e641e91c..753254cc 100644 --- a/Testing/FrameworkSource/Error.cpp +++ b/Testing/FrameworkSource/Error.cpp @@ -27,6 +27,7 @@ */ #include "arm_math.h" #include "Error.h" +#include namespace Client { @@ -43,8 +44,9 @@ void assert_not_empty_generic(unsigned long nb, AnyPattern &p) } }; + template <> -void assert_near_equal(unsigned long nb,float32_t pa, float32_t pb, float32_t threshold) +void assert_near_equal(unsigned long nb,double pa, double pb, double threshold) { if (fabs(pa - pb) > threshold) { @@ -52,31 +54,53 @@ void assert_near_equal(unsigned long nb,float32_t pa, float32_t pb, float32_t th } }; -template <> -void assert_near_equal(unsigned long nb,AnyPattern &pa, AnyPattern &pb, float32_t threshold) +template <> +void assert_near_equal(unsigned long nb,float32_t pa, float32_t pb, float32_t threshold) { - ASSERT_NOT_EMPTY(pa); - ASSERT_NOT_EMPTY(pb); + if (fabs(pa - pb) > threshold) + { + throw (Error(EQUAL_ERROR,nb)); + } +}; - if (pa.nbSamples() != pb.nbSamples()) + +template <> +void assert_near_equal(unsigned long nb,q63_t pa, q63_t pb, q63_t threshold) +{ + if (abs(pa - pb) > threshold) { - throw (Error(DIFFERENT_LENGTH_ERROR,nb)); + throw (Error(EQUAL_ERROR,nb)); } +}; - unsigned long i=0; +template <> +void assert_near_equal(unsigned long nb,q31_t pa, q31_t pb, q31_t threshold) +{ + if (abs(pa - pb) > threshold) + { + throw (Error(EQUAL_ERROR,nb)); + } +}; - float32_t *ptrA = pa.ptr(); - float32_t *ptrB = pb.ptr(); +template <> +void assert_near_equal(unsigned long nb,q15_t pa, q15_t pb, q15_t threshold) +{ + if (abs(pa - pb) > threshold) + { + throw (Error(EQUAL_ERROR,nb)); + } +}; - for(i=0; i < pa.nbSamples(); i++) +template <> +void assert_near_equal(unsigned long nb,q7_t pa, q7_t pb, q7_t threshold) +{ + if (abs(pa - pb) > threshold) { - if (fabs(ptrA[i] - ptrB[i]) > threshold) - { - throw (Error(NEAR_EQUAL_ERROR,nb)); - } + throw (Error(EQUAL_ERROR,nb)); } }; + void assert_not_empty(unsigned long nb, AnyPattern &p) { assert_not_empty_generic(nb,p); @@ -216,8 +240,8 @@ float arm_snr_q63(q63_t *pRef, q63_t *pTest, uint32_t buffSize) for (i = 0; i < buffSize; i++) { - testVal = ((float32_t)pTest[i]) / 9223372036854775808.0; - refVal = ((float32_t)pRef[i]) / 9223372036854775808.0; + testVal = ((double)pTest[i]) / 9223372036854775808.0; + refVal = ((double)pRef[i]) / 9223372036854775808.0; EnergySignal += refVal * refVal; EnergyError += (refVal - testVal) * (refVal - testVal); diff --git a/Testing/Source/Tests/BasicTestsQ7.cpp b/Testing/Source/Tests/BasicTestsQ7.cpp index 5dcac964..88162c60 100755 --- a/Testing/Source/Tests/BasicTestsQ7.cpp +++ b/Testing/Source/Tests/BasicTestsQ7.cpp @@ -71,7 +71,7 @@ q7_t *outp=output.ptr(); ASSERT_EMPTY_TAIL(output); - ASSERT_SNR(output,ref,(float32_t)SNR_THRESHOLD - 1.0); + ASSERT_SNR(output,ref,(float32_t)SNR_THRESHOLD - 1.0f); ASSERT_NEAR_EQ(output,ref,ABS_ERROR_Q7);