Skip to content

Commit

Permalink
Merge pull request #182 from lchamon/151_158-check_fir_firsym
Browse files Browse the repository at this point in the history
dsp: p_fir, p_firsym: Implement tests
  • Loading branch information
aolofsson committed Jul 7, 2015
2 parents 0dfbbd3 + 5e3873a commit d5f8716
Show file tree
Hide file tree
Showing 5 changed files with 328 additions and 2 deletions.
11 changes: 9 additions & 2 deletions tests/dsp/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ endif
LDADD = $(top_builddir)/src/libpal.la

check_PROGRAMS = check_p_acorr \
check_p_xcorr
check_p_xcorr \
check_p_fir \
check_p_firsym

check_p_acorr_SOURCES = check_p_acorr.c \
acorr_test_data.h
Expand All @@ -19,9 +21,14 @@ check_p_xcorr_SOURCES = check_p_xcorr.c \
xcorr_test_data_2.h \
xcorr_test_data_3.h

check_p_fir_SOURCES = check_p_fir.c \
fir_test_data.h

check_p_firsym_SOURCES = check_p_firsym.c \
firsym_test_data.h

TESTS = $(check_PROGRAMS)

# Ubuntu 14.04 has automake-1.11. Need automake-1.12 for nicer test features.
# This will have to do for now.
TESTS_ENVIRONMENT = ../runtest

59 changes: 59 additions & 0 deletions tests/dsp/check_p_fir.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Test program for dsp: p_fir function
*/

#include <stdio.h>
#include <math.h>
#include <pal.h>

#include "fir_test_data.h"


int main()
{
float error1, error2;
int i;
int testFail = 0;


/*** TEST 1 ***/
p_fir_f32(x1, h1, r1, nx1, nh1);

/* Compute maximum absolute error */
error1 = 0.0;
for (i = 0; i < 32; i++) {
if (error1 < fabs(r1[i] - ref1[i]))
error1 = fabs(r1[i] - ref1[i]);
}

if (error1 != 0) {
printf("p_fir: Test 1 - Maximum error = %f is not zero.\n\n", error1);
testFail = 1;
}


/*** TEST 2 ***/
p_fir_f32(x2, h2, r2, nx2, nh2);

/* Compute total absolute error */
error2 = 0.0;
for (i = 0; i < nx2; i++) {
if (error2 < fabs(r2[i] - ref2[i]))
error2 = fabs(r2[i] - ref2[i]);
}

if (error2 > EPS) {
printf("p_fir: Test 2 - Maximum error = %f < %.1e.\n\n", error2, EPS);
testFail = 1;
}


/*** RESULTS ***/
if ( testFail == 0 ) {
printf("p_fir is OK!\n");
} else {
printf("p_fir test FAILED!\n");
}

return(testFail);
}
59 changes: 59 additions & 0 deletions tests/dsp/check_p_firsym.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Test program for dsp: p_firsym function
*/

#include <stdio.h>
#include <math.h>
#include <pal.h>

#include "firsym_test_data.h"


int main()
{
float error1, error2;
int i;
int testFail = 0;


/*** TEST 1 ***/
p_firsym_f32(x1, h1, r1, nx1, nh1);

/* Compute maximum absolute error */
error1 = 0.0;
for (i = 0; i < 32; i++) {
if (error1 < fabs(r1[i] - ref1[i]))
error1 = fabs(r1[i] - ref1[i]);
}

if (error1 != 0) {
printf("p_firsym: Test 1 - Maximum error = %f is not zero.\n\n", error1);
testFail = 1;
}


/*** TEST 2 ***/
p_firsym_f32(x2, h2, r2, nx2, nh2);

/* Compute maximum absolute error */
error2 = 0.0;
for (i = 0; i < nx2; i++) {
if (error2 < fabs(r2[i] - ref2[i]))
error2 = fabs(r2[i] - ref2[i]);
}

if (error2 > EPS) {
printf("p_firsym: Test 2 - Maximum error = %f < %.1e.\n\n", error2, EPS);
testFail = 1;
}


/*** RESULTS ***/
if ( testFail == 0 ) {
printf("p_firsym is OK!\n");
} else {
printf("p_firsym test FAILED!\n");
}

return(testFail);
}
102 changes: 102 additions & 0 deletions tests/dsp/fir_test_data.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* Test data for dsp:p_fir function
* Generated using MATLAB filter(h,1,x).
*/

#define EPS 0.0001


/* Integers: result should be exact. Two additional values are added to all
* arrays to check for out-of-boundary array accesses. */
float x1[32] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32};
float h1[18] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18};
float ref1[32] = {1, 4, 10, 20, 35, 56, 84, 120, 165, 220, 286, 364, 455,
560, 680, 816, 952, 1088, 1224, 1360, 1496, 1632, 1768, 1904, 2040,
2176, 2312, 2448, 2584, 2720, 0, 0};
float r1[32];
int nx1 = 30;
int nh1 = 16;


/* Floats: error should be < 1e-4 (input is single precision ~ 1e-6 and there is
* a gain of > 59 from intermediate computations). */
float x2[100] = {0.488893770311789, 1.03469300991786, 0.726885133383238,
-0.303440924786016, 0.293871467096658, -0.787282803758638,
0.888395631757642, -1.14707010696915, -1.06887045816803,
-0.809498694424876, -2.94428416199490, 1.43838029281510,
0.325190539456198, -0.754928319169703, 1.37029854009523,
-1.71151641885370, -0.102242446085491, -0.241447041607358,
0.319206739165502, 0.312858596637428, -0.864879917324457,
-0.0300512961962686, -0.164879019209038, 0.627707287528727,
1.09326566903948, 1.10927329761440, -0.863652821988714,
0.0773590911304249, -1.21411704361541, -1.11350074148676,
-0.00684932810334806, 1.53263030828475, -0.769665913753682,
0.371378812760058, -0.225584402271252, 1.11735613881447,
-1.08906429505224, 0.0325574641649735, 0.552527021112224,
1.10061021788087, 1.54421189550395, 0.0859311331754255,
-1.49159031063761, -0.742301837259857, -1.06158173331999,
2.35045722400204, -0.615601881466894, 0.748076783703985,
-0.192418510588264, 0.888610425420721, -0.764849236567874,
-1.40226896933876, -1.42237592509150, 0.488193909859941,
-0.177375156618825, -0.196053487807333, 1.41931015064255,
0.291584373984183, 0.197811053464361, 1.58769908997406,
-0.804465956349547, 0.696624415849607, 0.835088165072682,
-0.243715140377952, 0.215670086403744, -1.16584393148205,
-1.14795277889859, 0.104874716016494, 0.722254032225002,
2.58549125261624, -0.666890670701386, 0.187331024578940,
-0.0824944253709554, -1.93302291785099, -0.438966153934773,
-1.79467884145512, 0.840375529753905, -0.888032082329010,
0.100092833139322, -0.544528929990548, 0.303520794649354,
-0.600326562133734, 0.489965321173948, 0.739363123604474,
1.71188778298155, -0.194123535758265, -2.13835526943994,
-0.839588747336614, 1.35459432800464, -1.07215528838425,
0.960953869740567, 0.124049800003193, 1.43669662271894,
-1.96089999936503, -0.197698225974150, -1.20784548525980,
2.90800803072936, 0.825218894228491, 1.37897197791661,
-1.05818025798736};
float h2[24] = {8.96196055032497, 9.96371130783181, 1.39685497922857,
10.0471344175292, 6.95595170847951, 1.07294445499350,
3.06348040753753, 6.01569671125482, 10.5325751897773,
10.6137738871920, 1.73374389845303, 10.6765205993668,
10.5288364306724, 5.33913213595125, 8.80308515777680,
1.56074972489937, 4.63937410888903, 10.0730907770797,
8.71428062515510, 10.5544166903219, 7.21314769072246,
0.392828464316085, 9.34042236455655, 10.2739257253331};
float ref2[100] = {4.38144668283389, 14.1440743241650, 17.5066120304252,
10.8803455347910, 14.4220410477185, 10.4735331750688,
5.14335459333896, 5.20455214577267, -12.3581379942700,
3.78805933604945, -23.5746205116505, -24.4523191435555,
11.6490512254190, -20.4794566776442, 3.89303020937694,
8.14158434136703, -52.2662385617696, -20.9200152056978,
-26.8964789453568, -28.8021421895547, 3.74129460903346,
-48.4228540875274, -26.9048951626906, -1.62188437848414,
-29.3012311072962, 15.6138110044446, -30.4553103418182,
-61.7326728701339, -25.8767557726614, -69.0001622082354,
-38.0373054463597, 1.18083533487212, -41.2393995684227,
-20.0756215242485, 21.2547637015502, -4.18534418726141,
9.10879322867097, -22.2155319560167, -6.69790111565424,
8.29926992873398, 3.11552235460419, 29.3561816200623,
25.2312421853411, 10.2826079991493, 3.53624491403252,
-8.22812396323694, 11.3153216708296, 20.8263852669967,
33.2539757251591, 24.5787517105350, -1.32253147982360,
-23.2087480894685, -9.11723833470803, 14.2588486434917,
7.77599820912536, -41.6761715263702, 26.5322920149295,
59.2325054728447, 20.1049008873763, 18.3242907853753,
-5.04181532485617, -7.09937268570435, 34.8923891671505,
7.37687409391624, 1.18941598357724, 6.18162924923411,
-28.2713035368162, 27.7875757520245, 26.4142659645616,
2.32945559269692, 36.9993763381585, 7.04962423098104,
30.9438791667144, -2.50541682646372, -53.8595022021612,
0.179887289987949, 17.0256554469907, -2.55802111978462,
10.3572582021471, 9.78131710085250, 16.1051712169320,
11.6790883654813, -27.7615753507540, -15.2691287803306,
-20.9308394002330, -6.01331557061655, -31.1885445500618,
-25.9346441688327, -4.54559221044078, -44.4801414096818,
-35.8143995654214, 30.0461501681512, 6.99283571572283,
-36.5748602082542, -46.2396999089475, -34.7570636394604,
-5.58620865976614, -10.8373377634534, -18.1170404789648,
36.2520278025143};
float r2[100];
int nx2 = 24;
int nh2 = 100;
99 changes: 99 additions & 0 deletions tests/dsp/firsym_test_data.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Test data for dsp:p_firsym function
* Generated using MATLAB filter([h fliplr(h(1:end-1))],1,x).
*/

#define EPS 0.0001


/* Integers: result should be exact. Two additional values are added to all
* arrays to check for out-of-boundary array accesses. */
float x1[32] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32};
float h1[11] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
float ref1[32] = {1, 4, 10, 20, 35, 56, 84, 120, 165, 218, 278, 344, 415, 490,
568, 648, 729, 810, 891, 972, 1053, 1134, 1215, 1296, 1377, 1458, 1539,
1620, 1701, 1782, 0, 0};
float r1[32];
int nx1 = 30;
int nh1 = 9;


/* Floats: error should be < 1e-4 (input is single precision ~ 1e-6 and there
* is a gain of > 36x from partial computations). */
float x2[100] = {1.12749227834159, 0.350179410603312, -0.299066030332982,
0.0228897927516298, -0.261995434966092, -1.75021236844679,
-0.285650971595330, -0.831366511567624, -0.979206305167302,
-1.15640165566400, -0.533557109315987, -2.00263573588306,
0.964229422631628, 0.520060101455458, -0.0200278516425381,
-0.0347710860284830, -0.798163584564142, 1.01868528212858,
-0.133217479507735, -0.714530163787158, 1.35138576842666,
-0.224771056052584, -0.589029030720801, -0.293753597735416,
-0.847926243637934, -1.12012830124373, 2.52599969211831,
1.65549759288735, 0.307535159238252, -1.25711835935205,
-0.865468030554804, -0.176534114231451, 0.791416061628634,
-1.33200442131525, -2.32986715580508, -1.44909729283874,
0.333510833065806, 0.391353604432901, 0.451679418928238,
-0.130284653145721, 0.183689095861942, -0.476153016619074,
0.862021611556922, -1.36169447087075, 0.455029556444334,
-0.848709379933659, -0.334886938964048, 0.552783345944550,
1.03909065350496, -1.11763868326521, 1.26065870912090,
0.660143141046978, -0.0678655535426873, -0.195221197898754,
-0.217606350143192, -0.303107621351741, 0.0230456244251053,
0.0512903558487747, 0.826062790211596, 1.52697668673337,
0.466914435684700, -0.209713338388737, 0.625190357087626,
0.183227263001437, -1.02976754356662, 0.949221831131023,
0.307061919146703, 0.135174942099456, 0.515246335524849,
0.261406324055383, -0.941485770955434, -0.162337672803828,
-0.146054634331526, -0.532011376808821, 1.68210359466318,
-0.875729346160017, -0.483815050110121, -0.712004549027423,
-1.17421233145682, -0.192239517539275, -0.274070229932602,
1.53007251442410, -0.249024742513714, -1.06421341288933,
1.60345729812004, 1.23467914689078, -0.229626450963181,
-1.50615970397972, -0.444627816446985, -0.155941035724769,
0.276068253931536, -0.261163645776479, 0.443421912904091,
0.391894209432449, -1.25067890682641, -0.947960922331432,
-0.741106093940412, -0.507817550278174, -0.320575506600239,
0.0124690413616180};
float h2[13] = {4.39760914008786, 2.85857443135720, 8.80075328246738,
4.74555210209899, 10.0171235387248, 2.00031731133138,
2.90183208174189, 1.60092878423189, 1.49675414579530,
9.56221428404098, 6.37675046102127, 6.04846222019965,
1.59450278046099};
float ref2[100] = {4.95827034861346, 4.76297277515964, 9.60861977062762,
7.67817380312583, 9.23729638790948, -3.90033663083165,
-7.47994429938189, -18.6668201529812, -18.7006595120818,
-23.7198330673552, -15.2104858808631, -33.3265261109670,
-24.9350504325131, -30.9355826106284, -21.3142039293257,
-22.5879015689510, -18.0376653315345, -20.6135007491957,
-36.6692783138386, -30.9696701756180, -42.2073906078427,
-12.0821627444424, -14.8145722328935, -20.7291075635780,
-27.3269796720801, -56.3979288177768, -32.0453266536831,
-25.2066369856754, -12.3338777451746, -25.8144275680295,
1.59843918410884, -34.1105110972878, -13.5676707462748,
-39.9650941000149, -28.4672101480550, -7.67655317406452,
-9.94156881179673, -14.4914974353187, -39.5922949599046,
-28.6491180948370, 4.56827234699208, 26.7678005988945,
5.18293451848438, -49.7412442726263, -48.2357973935824,
-52.7125636270566, 1.00918532048008, -15.2175260730140,
-6.68959348513663, -32.0036991150699, -3.08107942876001,
0.262349230998074, -1.04601999720673, -20.7466373657216,
-27.8515625602517, -33.1902651774162, -30.2995158968299,
-10.5061901649451, -18.0548864389344, 12.6772083964956,
22.6835831202765, 28.0207446882465, 36.3365039891753,
12.3447861099388, 11.4170929932386, 5.95631050806108,
10.6449164773134, 8.75477116778307, 29.2533836912012,
27.2897299020354, 31.1443305958778, 26.7887016194816,
31.8077494912980, 13.5486837335594, 22.5157291532519,
4.54503578687006, 16.4215696901601, 1.62264253808211,
18.0061643022091, -6.13179145475439, 8.03231265286830,
6.83651113450072, 0.869138305658449, 23.1915068932710,
-3.61925882019709, 8.25655870060134, -6.35749462788553,
-1.88930190781793, 2.76841017001098, 1.48769751926061,
-14.4654656042288, -27.8687525569748, -25.0840204253891,
-17.9803619861117, 19.9398563033087, -0.168975160254181,
-12.4576649232109, -42.8332101216382, -44.2388986012562,
-18.1156295206340};
float r2[100];
int nx2 = 100;
int nh2 = 13;

0 comments on commit d5f8716

Please sign in to comment.