Rewrote parts of the test renderer to read the whole data from disk in one fread.

This commit is contained in:
Veikko Sariola
2020-04-16 14:05:17 +03:00
parent 374be5256e
commit 9c7db45a46

View File

@ -10,20 +10,24 @@ int main(int argc, char* argv[]) {
int n; int n;
int retval; int retval;
char test_name[] = TEST_NAME; char test_name[] = TEST_NAME;
long fsize;
long bufsize;
#ifndef GO4K_USE_16BIT_OUTPUT #ifndef GO4K_USE_16BIT_OUTPUT
float* buf; float* buf = NULL;
float* filebuf = NULL;
float v; float v;
buf = (float*)malloc(test_max_samples * 2 * sizeof(float)); bufsize = test_max_samples * 2 * sizeof(float);
buf = (float*)malloc(bufsize);
#else #else
short* buf; short* buf = NULL;
short* filebuf = NULL;
short v; short v;
buf = (short*)malloc(test_max_samples * 2 * sizeof(short)); bufsize = test_max_samples * 2 * sizeof(short);
#endif buf = (short*)malloc(bufsize);
#endif
if (buf == NULL) { if (buf == NULL) {
printf("Could not allocate buffer\n"); printf("Could not allocate buffer for 4klang rendering\n");
return 1; return 1;
} }
@ -35,35 +39,48 @@ int main(int argc, char* argv[]) {
if (f == NULL) { if (f == NULL) {
printf("No expected waveform found!\n"); printf("No expected waveform found!\n");
retval = 1; goto fail;
goto end; }
fseek(f, 0, SEEK_END);
fsize = ftell(f);
fseek(f, 0, SEEK_SET);
if (bufsize < fsize) {
printf("4klang rendered shorter wave than expected\n");
goto fail;
} }
n = 0; if (bufsize > fsize) {
while (1) { printf("4klang rendered longer wave than expected\n");
fread((void*)(&v), sizeof(v), 1, f); goto fail;
if (feof(f)) { }
if (n == test_max_samples * 2) {
retval = 0; #ifndef GO4K_USE_16BIT_OUTPUT
} filebuf = (float*)malloc(bufsize);
else { #else
printf("4klang rendered longer wave than expected\n"); filebuf = (short*)malloc(bufsize);
retval = 1; #endif
}
break; if (filebuf == NULL) {
} printf("Could not allocate buffer for file contents\n");
if (n >= test_max_samples * 2) { goto fail;
printf("4klang rendered shorter wave than expected\n"); }
retval = 1;
break; fread((void*)filebuf, test_max_samples * 2, sizeof(*filebuf), f);
}
if (buf[n] != v) { for (n = 0; n < test_max_samples * 2; n++) {
if (buf[n] != filebuf[n]) {
printf("4klang rendered different wave than expected\n"); printf("4klang rendered different wave than expected\n");
retval = 1; goto fail;
break;
} }
++n; }
}
success:
retval = 0;
goto end;
fail:
retval = 1;
end: end:
if (f != 0) { if (f != 0) {
@ -80,5 +97,10 @@ end:
free(buf); free(buf);
buf = 0; buf = 0;
} }
if (filebuf != 0) {
free(filebuf);
filebuf = 0;
}
return retval; return retval;
} }