Make isac_fix_test use gtest (in a hacky way)

This test is the only remaining one that does not use gtest and that's
blocking some infra cleanup tasks. Ideally this test would use
webrtc/rtc_base/flags.h but that's a lot of unnecessary work.

This also replaces some exit() status codes - the logic behind this is
if you get incorrectly specified command line arguments, exit(1) is
invoked for a failure, because it's not a test failure, and if flag
parsing was done properly, it would not be a gtest failure anyway.

BUG=webrtc:7568

Review-Url: https://codereview.webrtc.org/3000033002
Cr-Commit-Position: refs/heads/master@{#19388}
This commit is contained in:
oprypin
2017-08-17 08:25:28 -07:00
committed by Commit Bot
parent 3958ed8e6f
commit 168576be1e

View File

@ -15,6 +15,7 @@
#include <ctype.h> #include <ctype.h>
#include "webrtc/modules/audio_coding/codecs/isac/fix/include/isacfix.h" #include "webrtc/modules/audio_coding/codecs/isac/fix/include/isacfix.h"
#include "webrtc/test/gtest.h"
#include "webrtc/test/testsupport/perf_test.h" #include "webrtc/test/testsupport/perf_test.h"
// TODO(kma): Clean up the code and change benchmarking the whole codec to // TODO(kma): Clean up the code and change benchmarking the whole codec to
@ -41,6 +42,11 @@ int readframe(int16_t *data, FILE *inp, int length) {
return status; return status;
} }
// Globals needed because gtest does not provide access to argv.
// This should be reworked to use flags.
static int global_argc;
static char **global_argv;
/* Struct for bottleneck model */ /* Struct for bottleneck model */
typedef struct { typedef struct {
uint32_t send_time; /* samples */ uint32_t send_time; /* samples */
@ -92,8 +98,9 @@ void get_arrival_time2(int current_framesamples,
BN_data->rtp_number++; BN_data->rtp_number++;
} }
int main(int argc, char* argv[]) TEST(IsacFixTest, Kenny) {
{ int argc = global_argc;
char **argv = global_argv;
char inname[100], outname[100], outbitsname[100], bottleneck_file[100]; char inname[100], outname[100], outbitsname[100], bottleneck_file[100];
FILE *inp, *outp, *f_bn, *outbits; FILE *inp, *outp, *f_bn, *outbits;
@ -223,7 +230,7 @@ int main(int argc, char* argv[])
printf("outfile : Speech output file\n\n"); printf("outfile : Speech output file\n\n");
printf("Example usage : \n\n"); printf("Example usage : \n\n");
printf("%s -I bottleneck.txt speechIn.pcm speechOut.pcm\n\n", argv[0]); printf("%s -I bottleneck.txt speechIn.pcm speechOut.pcm\n\n", argv[0]);
exit(0); exit(1);
} }
@ -250,7 +257,7 @@ int main(int argc, char* argv[])
if ((rateBPS < 10000) || (rateBPS > 32000)) { if ((rateBPS < 10000) || (rateBPS > 32000)) {
printf("\n%d is not a initial rate. " printf("\n%d is not a initial rate. "
"Valid values are in the range 10000 to 32000.\n", rateBPS); "Valid values are in the range 10000 to 32000.\n", rateBPS);
exit(0); exit(1);
} }
printf("\nNew initial rate: %d\n", rateBPS); printf("\nNew initial rate: %d\n", rateBPS);
i++; i++;
@ -262,7 +269,7 @@ int main(int argc, char* argv[])
if ((framesize != 30) && (framesize != 60)) { if ((framesize != 30) && (framesize != 60)) {
printf("\n%d is not a valid frame length. " printf("\n%d is not a valid frame length. "
"Valid length are 30 and 60 msec.\n", framesize); "Valid length are 30 and 60 msec.\n", framesize);
exit(0); exit(1);
} }
printf("\nFrame Length: %d\n", framesize); printf("\nFrame Length: %d\n", framesize);
i++; i++;
@ -295,7 +302,7 @@ int main(int argc, char* argv[])
if (testNum < 1 || testNum > 10) { if (testNum < 1 || testNum > 10) {
printf("\n%d is not a valid Fault Scenario number." printf("\n%d is not a valid Fault Scenario number."
" Valid Fault Scenarios are numbered 1-10.\n", testNum); " Valid Fault Scenarios are numbered 1-10.\n", testNum);
exit(0); exit(1);
} }
i++; i++;
} }
@ -306,7 +313,7 @@ int main(int argc, char* argv[])
packetLossPercent = atoi( argv[i+1] ); packetLossPercent = atoi( argv[i+1] );
if( (packetLossPercent < 0) | (packetLossPercent > 100) ) { if( (packetLossPercent < 0) | (packetLossPercent > 100) ) {
printf( "\nInvalid packet loss perentage \n" ); printf( "\nInvalid packet loss perentage \n" );
exit( 0 ); exit( 1 );
} }
if( packetLossPercent > 0 ) { if( packetLossPercent > 0 ) {
printf( "\nSimulating %d %% of independent packet loss\n", printf( "\nSimulating %d %% of independent packet loss\n",
@ -319,8 +326,7 @@ int main(int argc, char* argv[])
readLoss = 1; readLoss = 1;
plFile = fopen( argv[i+1], "rb" ); plFile = fopen( argv[i+1], "rb" );
if( plFile == NULL ) { if( plFile == NULL ) {
printf( "\n couldn't open the frameloss file: %s\n", argv[i+1] ); FAIL() << "Couldn't open the frameloss file: " << argv[i+1];
exit( 0 );
} }
printf( "\nSimulating packet loss through the given " printf( "\nSimulating packet loss through the given "
"channel file: %s\n", argv[i+1] ); "channel file: %s\n", argv[i+1] );
@ -339,8 +345,7 @@ int main(int argc, char* argv[])
sscanf(argv[i + 1], "%s", gns_file); sscanf(argv[i + 1], "%s", gns_file);
fp_gns = fopen(gns_file, "rb"); fp_gns = fopen(gns_file, "rb");
if (fp_gns == NULL) { if (fp_gns == NULL) {
printf("Cannot read file %s.\n", gns_file); FAIL() << "Cannot read file " << gns_file << ".";
exit(0);
} }
gns = 1; gns = 1;
i++; i++;
@ -361,7 +366,7 @@ int main(int argc, char* argv[])
} else if (testCE < 1 || testCE > 3) { } else if (testCE < 1 || testCE > 3) {
printf("\n%d is not a valid CE-test number, valid Fault " printf("\n%d is not a valid CE-test number, valid Fault "
"Scenarios are numbered 1-3\n", testCE); "Scenarios are numbered 1-3\n", testCE);
exit(0); exit(1);
} }
i++; i++;
} }
@ -381,7 +386,8 @@ int main(int argc, char* argv[])
if (f_bn == NULL) { if (f_bn == NULL) {
printf("No value provided for BottleNeck and cannot read file %s\n", printf("No value provided for BottleNeck and cannot read file %s\n",
bottleneck_file); bottleneck_file);
exit(0); exit(0); // TODO(oprypin): don't silence this error
// FAIL() << "Cannot read file " << bottleneck_file;
} else { } else {
int aux_var; int aux_var;
printf("reading bottleneck rates from file %s\n\n",bottleneck_file); printf("reading bottleneck rates from file %s\n\n",bottleneck_file);
@ -389,7 +395,7 @@ int main(int argc, char* argv[])
/* Set pointer to beginning of file */ /* Set pointer to beginning of file */
fseek(f_bn, 0L, SEEK_SET); fseek(f_bn, 0L, SEEK_SET);
if (fscanf(f_bn, "%d", &aux_var) == EOF) { if (fscanf(f_bn, "%d", &aux_var) == EOF) {
exit(0); FAIL();
} }
} }
bottleneck = (int16_t)aux_var; bottleneck = (int16_t)aux_var;
@ -423,17 +429,14 @@ int main(int argc, char* argv[])
h++; h++;
} }
if ((inp = fopen(inname,"rb")) == NULL) { if ((inp = fopen(inname,"rb")) == NULL) {
printf(" iSAC: Cannot read file %s\n", inname); FAIL() << " iSAC: Cannot read file " << inname;
exit(1);
} }
if ((outp = fopen(outname,"wb")) == NULL) { if ((outp = fopen(outname,"wb")) == NULL) {
printf(" iSAC: Cannot write file %s\n", outname); FAIL() << " iSAC: Cannot write file " << outname;
exit(1);
} }
if ((outbits = fopen(outbitsname,"wb")) == NULL) { if ((outbits = fopen(outbitsname,"wb")) == NULL) {
printf(" iSAC: Cannot write file %s\n", outbitsname); FAIL() << " iSAC: Cannot write file " << outbitsname;
exit(1);
} }
printf("\nInput:%s\nOutput:%s\n\n", inname, outname); printf("\nInput:%s\nOutput:%s\n\n", inname, outname);
@ -512,8 +515,7 @@ int main(int argc, char* argv[])
if (err < 0) { if (err < 0) {
/* exit if returned with error */ /* exit if returned with error */
errtype=WebRtcIsacfix_GetErrorCode(ISAC_main_inst); errtype=WebRtcIsacfix_GetErrorCode(ISAC_main_inst);
printf("\n\n Error in SetMaxPayloadSize: %d.\n\n", errtype); FAIL() << "Error in SetMaxPayloadSize: " << errtype;
exit(EXIT_FAILURE);
} }
} }
if (payloadRate != 0) { if (payloadRate != 0) {
@ -521,8 +523,7 @@ int main(int argc, char* argv[])
if (err < 0) { if (err < 0) {
/* exit if returned with error */ /* exit if returned with error */
errtype=WebRtcIsacfix_GetErrorCode(ISAC_main_inst); errtype=WebRtcIsacfix_GetErrorCode(ISAC_main_inst);
printf("\n\n Error in SetMaxRateInBytes: %d.\n\n", errtype); FAIL() << "Error in SetMaxRateInBytes: " << errtype;
exit(EXIT_FAILURE);
} }
} }
@ -624,7 +625,7 @@ int main(int argc, char* argv[])
stream_len = static_cast<size_t>(stream_len_int); stream_len = static_cast<size_t>(stream_len_int);
if (fwrite(streamdata, sizeof(char), stream_len, outbits) != if (fwrite(streamdata, sizeof(char), stream_len, outbits) !=
stream_len) { stream_len) {
return -1; FAIL();
} }
} }
@ -637,7 +638,7 @@ int main(int argc, char* argv[])
/* Set pointer to beginning of file */ /* Set pointer to beginning of file */
fseek(f_bn, 0L, SEEK_SET); fseek(f_bn, 0L, SEEK_SET);
if (fscanf(f_bn, "%d", &aux_var) == EOF) { if (fscanf(f_bn, "%d", &aux_var) == EOF) {
exit(0); FAIL();
} }
} }
bottleneck = (int16_t)aux_var; bottleneck = (int16_t)aux_var;
@ -674,7 +675,7 @@ int main(int argc, char* argv[])
if (fscanf(fp_gns, "%d", &cur_delay) == EOF) { if (fscanf(fp_gns, "%d", &cur_delay) == EOF) {
fseek(fp_gns, 0L, SEEK_SET); fseek(fp_gns, 0L, SEEK_SET);
if (fscanf(fp_gns, "%d", &cur_delay) == EOF) { if (fscanf(fp_gns, "%d", &cur_delay) == EOF) {
exit(0); FAIL();
} }
} }
} }
@ -783,7 +784,7 @@ int main(int argc, char* argv[])
/* Write decoded speech frame to file */ /* Write decoded speech frame to file */
if (fwrite(decoded, sizeof(int16_t), if (fwrite(decoded, sizeof(int16_t),
declen, outp) != (size_t)declen) { declen, outp) != (size_t)declen) {
return -1; FAIL();
} }
// fprintf( ratefile, "%f \n", stream_len / ( ((double)declen)/ // fprintf( ratefile, "%f \n", stream_len / ( ((double)declen)/
// ((double)FS) ) * 8 ); // ((double)FS) ) * 8 );
@ -835,5 +836,12 @@ int main(int argc, char* argv[])
WebRtcIsacfix_FreeInternal(ISAC_main_inst); WebRtcIsacfix_FreeInternal(ISAC_main_inst);
} }
WebRtcIsacfix_Free(ISAC_main_inst); WebRtcIsacfix_Free(ISAC_main_inst);
return 0; }
int main(int argc, char* argv[]) {
::testing::InitGoogleTest(&argc, argv);
global_argc = argc;
global_argv = argv;
return RUN_ALL_TESTS();
} }