Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1From fb8e3c74d582038a358936d827f53c4c0c43d4e6 Mon Sep 17 00:00:00 2001 2From: Matt Harvey <mattharvey@google.com> 3Date: Mon, 27 Nov 2023 16:28:53 -0800 4Subject: [PATCH] Fix testresample.c output span; add exit code 5 6Prior to this chance, the "Resample with different factors" test only 7passed for 60 of the 63 factors, with the 3 failing ones being the 8largest. 9 101. Since only 63 distinct factors were being considered, 100 random 11 samples was overkill. 122. To support noticing failure in continuous build systems, it's nice if 13 the test exit()s with nonzero when there are failures. 143. The root cause was a formula error when determining which indices in 15 the resampled output ought be compared. Details are explained in a 16 comment. 17--- 18 tests/testresample.c | 32 ++++++++++++++++++++++++-------- 19 1 file changed, 24 insertions(+), 8 deletions(-) 20 21diff --git a/tests/testresample.c b/tests/testresample.c 22index aa83a46..640df5a 100644 23--- a/tests/testresample.c 24+++ b/tests/testresample.c 25@@ -19,6 +19,8 @@ 26 27 #define MIN(A, B) (A) < (B)? (A) : (B) 28 29+int global_error; 30+ 31 void runtest(int srclen, double freq, double factor, 32 int srcblocksize, int dstblocksize) 33 { 34@@ -65,10 +67,12 @@ void runtest(int srclen, double freq, double factor, 35 36 if (o < 0) { 37 printf("Error: resample_process returned an error: %d\n", o); 38+ global_error = 1; 39 } 40 41 if (out <= 0) { 42 printf("Error: resample_process returned %d samples\n", out); 43+ global_error = 1; 44 free(src); 45 free(dst); 46 return; 47@@ -79,15 +83,16 @@ void runtest(int srclen, double freq, double factor, 48 printf(" Expected ~%d, got %d samples out\n", 49 expectedlen, out); 50 } 51- 52+ 53 sum = 0.0; 54 sumsq = 0.0; 55 errcount = 0.0; 56 57- /* Don't compute statistics on all output values; the last few 58- are guaranteed to be off because it's based on far less 59- interpolation. */ 60- statlen = out - fwidth; 61+ /* Don't compute statistics on all output values; the last small fraction 62+ are guaranteed to be off since they are interpolated based on far fewer 63+ values. When upsampling, the length of the range where this concern 64+ applies is in direct proportion to the upsampling factor. */ 65+ statlen = out - ((int)round(fwidth * factor)); 66 67 for(i=0; i<statlen; i++) { 68 double diff = sin((i/freq)/factor) - dst[i]; 69@@ -117,6 +122,7 @@ void runtest(int srclen, double freq, double factor, 70 printf(" i=%d: expected %.3f, got %.3f\n", 71 i, sin((i/freq)/factor), dst[i]); 72 printf(" At least %d samples had significant error.\n", errcount); 73+ global_error = 1; 74 } 75 err = sum / statlen; 76 rmserr = sqrt(sumsq / statlen); 77@@ -130,6 +136,8 @@ int main(int argc, char **argv) 78 int i, srclen, dstlen, ifreq; 79 double factor; 80 81+ global_error = 0; 82+ 83 printf("\n*** Vary source block size*** \n\n"); 84 srclen = 10000; 85 ifreq = 100; 86@@ -172,11 +180,19 @@ int main(int argc, char **argv) 87 printf("\n*** Resample with different factors ***\n\n"); 88 srclen = 10000; 89 ifreq = 100; 90- for(i=0; i<100; i++) { 91- factor = ((rand() % 64) + 1) / 4.0; 92+ for (i = 1; i < 64; i++) { 93+ factor = i / 4.0; 94+ dstlen = (int)(srclen * factor + 10); 95+ runtest(srclen, (double)ifreq, factor, srclen, dstlen); 96+ } 97+ 98+ printf("\n*** Resample with large factors ***\n\n"); 99+ srclen = 200; 100+ ifreq = 100; 101+ for (factor = 25.0; factor < 1000.0; factor *= 1.7) { 102 dstlen = (int)(srclen * factor + 10); 103 runtest(srclen, (double)ifreq, factor, srclen, dstlen); 104 } 105 106- return 0; 107+ return global_error; 108 }